HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ISchemaObject.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_ISchemaObject_h
38 #define Alembic_Abc_ISchemaObject_h
39 
40 #include <Alembic/Abc/Foundation.h>
41 #include <Alembic/Abc/IObject.h>
42 #include <Alembic/Abc/ISchema.h>
43 #include <Alembic/Abc/Argument.h>
44 #include <Alembic/Abc/Base.h>
45 
46 namespace Alembic {
47 namespace Abc {
48 namespace ALEMBIC_VERSION_NS {
49 
50 //-*****************************************************************************
51 //! An ISchemaObject is an object with a single schema. This is just
52 //! a convenience class, really, but it also deals with setting up and
53 //! validating metadata
54 template <class SCHEMA>
55 class ISchemaObject : public IObject
56 {
57 public:
58  //-*************************************************************************
59  // TYPEDEFS AND IDENTIFIERS
60  //-*************************************************************************
61  typedef SCHEMA schema_type;
63 
64  //! Our schema title contains the schema title of the underlying
65  //! compound property, along with the default name of that compound
66  //! property. So, for example - most AbcGeom types put their
67  //! data in ".geom", so, "AbcGeom_PolyMesh_v1:.geom"
68  //! Sometimes schema titles from underlying schemas are "", but
69  //! ours never are.
71  {
72  return SCHEMA::getSchemaTitle() + std::string( ":" )
73  + SCHEMA::getDefaultSchemaName();
74  }
75 
76  static const char * getSchemaTitle()
77  {
78  return SCHEMA::getSchemaTitle();
79  }
80 
81  //! This will check whether or not a given entity (as represented by
82  //! a metadata) strictly matches the interpretation of this
83  //! schema object
84  static bool matches( const AbcA::MetaData &iMetaData,
86  {
87 
88  if ( std::string() == getSchemaTitle() || iMatching == kNoMatching )
89  {
90  return true;
91  }
92 
93 
94  if ( iMatching == kStrictMatching )
95  {
96  return iMetaData.get( "schemaObjTitle" ) == getSchemaObjTitle() ||
97  iMetaData.get( "schema" ) == getSchemaObjTitle();
98  }
99 
100  if ( iMatching == kSchemaTitleMatching )
101  {
102  return iMetaData.get( "schema" ) == getSchemaTitle();
103  }
104 
105  return false;
106  }
107 
108  //! This will check whether or not a given object (as represented by
109  //! an object header) strictly matches the interpretation of this
110  //! schema object, as well as the data type.
111  static bool matches( const AbcA::ObjectHeader &iHeader,
113  {
114  return matches( iHeader.getMetaData(), iMatching );
115  }
116 
117 
118  //-*************************************************************************
119  // CONSTRUCTION, DESTRUCTION, ASSIGNMENT
120  //-*************************************************************************
121 
122  //! The default constructor creates an empty ISchemaObject function set.
123  //! ...
125 
126  //! The primary constructor creates an ISchemaObject as a child of iParent
127  ISchemaObject( const IObject & iParent,
128  const std::string &iName,
129  const Argument &iArg0 = Argument(),
130  const Argument &iArg1 = Argument() )
131  : IObject( iParent, iName, GetErrorHandlerPolicyFromArgs( iArg0, iArg1 ) )
132  {
133  Arguments args;
134  iArg0.setInto( args );
135  iArg1.setInto( args );
136 
138  "ISchemaObject::ISchemaObject( IObject )" );
139 
140  const AbcA::ObjectHeader &oheader = this->getHeader();
141 
142  ABCA_ASSERT( matches( oheader, args.getSchemaInterpMatching() ),
143  "Incorrect match of schema: "
144  << oheader.getMetaData().get( "schema" )
145  << " to expected: "
146  << getSchemaTitle() );
147 
148  // Make the schema.
149  m_schema = SCHEMA( m_object->getProperties(),
150  SCHEMA::getDefaultSchemaName(),
151  this->getErrorHandlerPolicy(),
152  args.getSchemaInterpMatching() );
153 
155  }
156 
157  //! Wrap an existing schema object.
158  //! ...
159  ISchemaObject( const IObject & iObject,
160  const Argument &iArg0 = Argument(),
161  const Argument &iArg1 = Argument() )
162  : IObject( iObject )
163  {
165  GetErrorHandlerPolicy( iObject, iArg0, iArg1 ) );
166 
168  "ISchemaObject::ISchemaObject( wrap )" );
169 
170  const AbcA::ObjectHeader &oheader = this->getHeader();
171 
172  ABCA_ASSERT( matches( oheader.getMetaData(),
173  GetSchemaInterpMatching( iArg0, iArg1 ) ),
174  "Incorrect match of schema: "
175  << oheader.getMetaData().get( "schemaObjTitle" )
176  << " to expected: "
177  << getSchemaObjTitle() );
178 
179  m_schema = SCHEMA( this->getProperties(),
180  SCHEMA::getDefaultSchemaName(),
181  this->getErrorHandlerPolicy(),
182  GetSchemaInterpMatching( iArg0, iArg1 ) );
183 
185  }
186 
187  // Deprecated in favor of the constructor above
188  ISchemaObject( const IObject & iObject,
189  WrapExistingFlag iFlag,
190  const Argument &iArg0 = Argument(),
191  const Argument &iArg1 = Argument() )
192  : IObject( iObject )
193  {
195  GetErrorHandlerPolicy( iObject, iArg0, iArg1 ) );
196 
198  "ISchemaObject::ISchemaObject( wrapflag )" );
199 
200  const AbcA::ObjectHeader &oheader = this->getHeader();
201 
202  ABCA_ASSERT( matches( oheader.getMetaData(),
203  GetSchemaInterpMatching( iArg0, iArg1 ) ),
204  "Incorrect match of schema: "
205  << oheader.getMetaData().get( "schemaObjTitle" )
206  << " to expected: "
207  << getSchemaObjTitle() );
208 
209  m_schema = SCHEMA( this->getProperties(),
210  SCHEMA::getDefaultSchemaName(),
211  this->getErrorHandlerPolicy(),
212  GetSchemaInterpMatching( iArg0, iArg1 ) );
213 
215  }
216 
217  //-*************************************************************************
218  // ABC BASE MECHANISMS
219  // These functions are used by Abc to deal with errors, rewrapping,
220  // and so on.
221  //-*************************************************************************
222 
223  //! Schemas are not necessarily cheap to copy, so we return by reference
224  //! rather than by value.
225  SCHEMA &getSchema() { return m_schema; }
226  const SCHEMA &getSchema() const { return m_schema; }
227 
228  //! Reset returns this function set to an empty, default
229  //! state.
230  void reset() { m_schema.reset(); IObject::reset(); }
231 
232  //! Valid returns whether this function set is
233  //! valid.
234  bool valid() const
235  {
236  return ( IObject::valid() && m_schema.valid() );
237  }
238 
239  //! The unspecified-bool-type operator casts the object to "true"
240  //! if it is valid, and "false" otherwise.
242 
243 protected:
244  SCHEMA m_schema;
245 };
246 
247 //-*****************************************************************************
248 // TEMPLATE AND INLINE FUNCTIONS
249 //-*****************************************************************************
250 
252  const Argument &iArg1 )
253 {
254  Arguments args;
255  iArg0.setInto( args );
256  iArg1.setInto( args );
257  return args.getErrorHandlerPolicy();
258 }
259 
260 } // End namespace ALEMBIC_VERSION_NS
261 
262 using namespace ALEMBIC_VERSION_NS;
263 
264 } // End namespace Abc
265 } // End namespace Alembic
266 
267 #endif
static bool matches(const AbcA::ObjectHeader &iHeader, SchemaInterpMatching iMatching=kStrictMatching)
GLsizei const GLchar *const * string
Definition: glcorearb.h:813
SchemaInterpMatching getSchemaInterpMatching() const
Definition: Argument.h:95
ErrorHandler::Policy getErrorHandlerPolicy() const
Definition: Base.h:81
void setInto(Arguments &iArgs) const
Definition: Argument.h:149
ISchemaObject(const IObject &iObject, WrapExistingFlag iFlag, const Argument &iArg0=Argument(), const Argument &iArg1=Argument())
ICompoundProperty getProperties() const
ErrorHandler::Policy GetErrorHandlerPolicyFromArgs(const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument(), const Argument &iArg3=Argument())
Definition: Argument.h:258
static bool matches(const AbcA::MetaData &iMetaData, SchemaInterpMatching iMatching=kStrictMatching)
Definition: ISchemaObject.h:84
const AbcA::ObjectHeader & getHeader() const
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
ISchemaObject(const IObject &iObject, const Argument &iArg0=Argument(), const Argument &iArg1=Argument())
ISchemaObject(const IObject &iParent, const std::string &iName, const Argument &iArg0=Argument(), const Argument &iArg1=Argument())
The primary constructor creates an ISchemaObject as a child of iParent.
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
ErrorHandler & getErrorHandler() const
Definition: Base.h:76
void reset()
Reset returns this function set to an empty, default state.
std::string get(const std::string &iKey) const
Definition: MetaData.h:192
#define ABCA_ASSERT(COND, TEXT)
Definition: Foundation.h:99
#define ALEMBIC_VERSION_NS
Definition: Foundation.h:105