HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ISchema.h
Go to the documentation of this file.
1 //-*****************************************************************************
2 //
3 // Copyright (c) 2009-2011,
4 // Sony Pictures Imageworks, Inc. and
5 // Industrial Light & Magic, a division of Lucasfilm Entertainment Company Ltd.
6 //
7 // All rights reserved.
8 //
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions are
11 // met:
12 // * Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
14 // * Redistributions in binary form must reproduce the above
15 // copyright notice, this list of conditions and the following disclaimer
16 // in the documentation and/or other materials provided with the
17 // distribution.
18 // * Neither the name of Sony Pictures Imageworks, nor
19 // Industrial Light & Magic nor the names of their contributors may be used
20 // to endorse or promote products derived from this software without specific
21 // prior written permission.
22 //
23 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 //
35 //-*****************************************************************************
36 
37 #ifndef Alembic_Abc_ISchema_h
38 #define Alembic_Abc_ISchema_h
39 
40 #include <Alembic/Abc/Foundation.h>
41 #include <Alembic/Abc/OSchema.h>
43 
44 namespace Alembic {
45 namespace Abc {
46 namespace ALEMBIC_VERSION_NS {
47 
48 //-*****************************************************************************
49 //! See Schema Notes in OSchema.h
50 //! ...
51 //-*****************************************************************************
52 
53 //-*****************************************************************************
54 //! Usually used as a base class, but could also theoretically be used
55 //! as a standalone
56 template <class INFO>
57 class ISchema : public ICompoundProperty
58 {
59 public:
60  //-*************************************************************************
61  // TYPEDEFS AND IDENTIFIERS
62  //-*************************************************************************
63  typedef INFO info_type;
65 
66  //! Return the schema title expected of this
67  //! property. An empty title matches everything
68  static const char * getSchemaTitle()
69  {
70  return INFO::title();
71  }
72 
73  //! Return the default name for instances of this schema. Often
74  //! something like ".geom"
75  static const char * getDefaultSchemaName()
76  {
77  return INFO::defaultName();
78  }
79 
80  //! This will check whether or not a given entity (as represented by
81  //! a metadata) strictly matches the interpretation of this
82  //! schema object
83  static bool matches( const AbcA::MetaData &iMetaData,
85  {
86  if ( std::string() == getSchemaTitle() || iMatching == kNoMatching )
87  { return true; }
88 
89  if ( iMatching == kStrictMatching || iMatching == kSchemaTitleMatching )
90  {
91  return iMetaData.get( "schema" ) == getSchemaTitle();
92  }
93 
94  return false;
95  }
96 
97  //! This will check whether or not a given object (as represented by
98  //! an object header) strictly matches the interpretation of this
99  //! schema object, as well as the data type.
100  static bool matches( const AbcA::PropertyHeader &iHeader,
102  {
103  return matches( iHeader.getMetaData(), iMatching );
104  }
105 
106  //-*************************************************************************
107  // CONSTRUCTION, DESTRUCTION, ASSIGNMENT
108  //-*************************************************************************
109 
110  //! The default constructor creates an empty ISchema
111  //! function set.
112  ISchema() {}
113 
114  //! Creates a new Compound Property Reader with the schema
115  //! information added to the metadata.
116  //! arguments count include error handling, strictness matching.
117  ISchema( const ICompoundProperty &iParent,
118  const std::string &iName,
119  const Argument &iArg0 = Argument(),
120  const Argument &iArg1 = Argument() )
121  {
122  init( iParent, iName, iArg0, iArg1 );
123  }
124 
125  //! Wrap an existing compound property, checking that it matches
126  //! the schema title info, if strict matching has been selected.
127  //! Arguments allow selection of error handling and matching strictness
128  ISchema( const ICompoundProperty &iProperty,
129  const Argument &iArg0 = Argument(),
130  const Argument &iArg1 = Argument() )
131  : ICompoundProperty( iProperty.getPtr(),
132  GetErrorHandlerPolicy( iProperty, iArg0, iArg1 ) )
133  {
134  ALEMBIC_ABC_SAFE_CALL_BEGIN( "ISchema::ISchema( wrap )" );
135 
136  const AbcA::PropertyHeader &pheader = this->getHeader();
137 
138  ABCA_ASSERT( matches( pheader,
139  GetSchemaInterpMatching( iArg0, iArg1 ) ),
140  "Incorrect match of schema: "
141  << pheader.getMetaData().get( "schema" )
142  << " to expected: "
143  << INFO::title() );
144 
145  // not wrapped, we want to use the default name
146  if ( !iProperty.getParent().valid() )
147  {
148  init( iProperty, getDefaultSchemaName(),
149  iArg0, iArg1 );
150  }
151 
153  }
154 
155  // Deprecated in favor of the constructor above
156  ISchema( const ICompoundProperty &iProperty,
157  WrapExistingFlag iFlag,
158  const Argument &iArg0 = Argument(),
159  const Argument &iArg1 = Argument() )
160  {
161  *this = ISchema( iProperty, iArg0, iArg1 );
162  }
163 
164  //! Default copy constructor used
165  //! Default assignment operator used.
166  //
167  virtual ~ISchema() {}
168 
169 private:
170  void init( const ICompoundProperty & iParentObject,
171  const std::string &iName,
172  const Argument &iArg0,
173  const Argument &iArg1 );
174 };
175 
176 //-*****************************************************************************
177 // TEMPLATE AND INLINE FUNCTIONS
178 //-*****************************************************************************
179 template <class INFO>
180 void ISchema<INFO>::init( const ICompoundProperty & iParent,
181  const std::string &iName,
182  const Argument &iArg0,
183  const Argument &iArg1 )
184 {
185  Arguments args;
186  iArg0.setInto( args );
187  iArg1.setInto( args );
188 
189  getErrorHandler().setPolicy( args.getErrorHandlerPolicy() );
190 
191  ALEMBIC_ABC_SAFE_CALL_BEGIN( "ISchema::ISchema::init()" );
192 
193  // Get actual reader for parent.
194  ABCA_ASSERT( iParent,
195  "NULL parent passed into ISchema ctor" );
196  AbcA::CompoundPropertyReaderPtr parent = iParent.getPtr();
197  ABCA_ASSERT( parent, "NULL CompoundPropertyReaderPtr" );
198 
199  const AbcA::PropertyHeader *pheader = parent->getPropertyHeader( iName );
200 
201  ABCA_ASSERT( pheader != NULL,
202  "Nonexistent compound property: " << iName );
203 
204  // Check metadata for schema.
205  ABCA_ASSERT( matches( *pheader, args.getSchemaInterpMatching() ),
206 
207  "Incorrect match of schema: "
208  << pheader->getMetaData().get( "schema" )
209  << " to expected: "
210  << INFO::title() );
211 
212  // Get property.
213  m_property = parent->getCompoundProperty( iName );
214 
216 }
217 
218 } // End namespace ALEMBIC_VERSION_NS
219 
220 using namespace ALEMBIC_VERSION_NS;
221 
222 } // End namespace Abc
223 } // End namespace Alembic
224 
225 #endif
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
SchemaInterpMatching getSchemaInterpMatching() const
Definition: Argument.h:95
void setInto(Arguments &iArgs) const
Definition: Argument.h:149
static bool matches(const AbcA::MetaData &iMetaData, SchemaInterpMatching iMatching=kStrictMatching)
Definition: ISchema.h:83
Alembic::Util::shared_ptr< CompoundPropertyReader > CompoundPropertyReaderPtr
ErrorHandler::Policy getErrorHandlerPolicy() const
Definition: Argument.h:83
#define ALEMBIC_ABC_SAFE_CALL_END_RESET()
Definition: ErrorHandler.h:181
ErrorHandler::Policy GetErrorHandlerPolicy(SOMETHING iSomething, const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument(), const Argument &iArg3=Argument())
Definition: Argument.h:242
SchemaInterpMatching GetSchemaInterpMatching(const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument(), const Argument &iArg3=Argument())
Definition: Argument.h:318
#define ALEMBIC_ABC_SAFE_CALL_BEGIN(CONTEXT)
Definition: ErrorHandler.h:172
ISchema(const ICompoundProperty &iProperty, const Argument &iArg0=Argument(), const Argument &iArg1=Argument())
Definition: ISchema.h:128
static const char * getDefaultSchemaName()
Definition: ISchema.h:75
ISchema(const ICompoundProperty &iProperty, WrapExistingFlag iFlag, const Argument &iArg0=Argument(), const Argument &iArg1=Argument())
Definition: ISchema.h:156
static const char * getSchemaTitle()
Definition: ISchema.h:68
std::string get(const std::string &iKey) const
Definition: MetaData.h:192
**If you just want to fire and args
Definition: thread.h:609
static bool matches(const AbcA::PropertyHeader &iHeader, SchemaInterpMatching iMatching=kStrictMatching)
Definition: ISchema.h:100
ISchema(const ICompoundProperty &iParent, const std::string &iName, const Argument &iArg0=Argument(), const Argument &iArg1=Argument())
Definition: ISchema.h:117
#define ABCA_ASSERT(COND, TEXT)
Definition: Foundation.h:99
#define ALEMBIC_VERSION_NS
Definition: Foundation.h:88