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  ABCA_ASSERT(m_object, "Bad child: " << iName);
149  // Make the schema.
150  m_schema = SCHEMA( m_object->getProperties(),
151  SCHEMA::getDefaultSchemaName(),
152  this->getErrorHandlerPolicy(),
153  args.getSchemaInterpMatching() );
154 
156  }
157 
158  //! Wrap an existing schema object.
159  //! ...
160  ISchemaObject( const IObject & iObject,
161  const Argument &iArg0 = Argument(),
162  const Argument &iArg1 = Argument() )
163  : IObject( iObject )
164  {
166  GetErrorHandlerPolicy( iObject, iArg0, iArg1 ) );
167 
169  "ISchemaObject::ISchemaObject( wrap )" );
170 
171  const AbcA::ObjectHeader &oheader = this->getHeader();
172 
173  ABCA_ASSERT( matches( oheader.getMetaData(),
174  GetSchemaInterpMatching( iArg0, iArg1 ) ),
175  "Incorrect match of schema: "
176  << oheader.getMetaData().get( "schemaObjTitle" )
177  << " to expected: "
178  << getSchemaObjTitle() );
179 
180  m_schema = SCHEMA( this->getProperties(),
181  SCHEMA::getDefaultSchemaName(),
182  this->getErrorHandlerPolicy(),
183  GetSchemaInterpMatching( iArg0, iArg1 ) );
184 
186  }
187 
188  // Deprecated in favor of the constructor above
189  ISchemaObject( const IObject & iObject,
190  WrapExistingFlag iFlag,
191  const Argument &iArg0 = Argument(),
192  const Argument &iArg1 = Argument() )
193  : IObject( iObject )
194  {
196  GetErrorHandlerPolicy( iObject, iArg0, iArg1 ) );
197 
199  "ISchemaObject::ISchemaObject( wrapflag )" );
200 
201  const AbcA::ObjectHeader &oheader = this->getHeader();
202 
203  ABCA_ASSERT( matches( oheader.getMetaData(),
204  GetSchemaInterpMatching( iArg0, iArg1 ) ),
205  "Incorrect match of schema: "
206  << oheader.getMetaData().get( "schemaObjTitle" )
207  << " to expected: "
208  << getSchemaObjTitle() );
209 
210  m_schema = SCHEMA( this->getProperties(),
211  SCHEMA::getDefaultSchemaName(),
212  this->getErrorHandlerPolicy(),
213  GetSchemaInterpMatching( iArg0, iArg1 ) );
214 
216  }
217 
218  //-*************************************************************************
219  // ABC BASE MECHANISMS
220  // These functions are used by Abc to deal with errors, rewrapping,
221  // and so on.
222  //-*************************************************************************
223 
224  //! Schemas are not necessarily cheap to copy, so we return by reference
225  //! rather than by value.
226  SCHEMA &getSchema() { return m_schema; }
227  const SCHEMA &getSchema() const { return m_schema; }
228 
229  //! Reset returns this function set to an empty, default
230  //! state.
231  void reset() { m_schema.reset(); IObject::reset(); }
232 
233  //! Valid returns whether this function set is
234  //! valid.
235  bool valid() const
236  {
237  return ( IObject::valid() && m_schema.valid() );
238  }
239 
240  //! The unspecified-bool-type operator casts the object to "true"
241  //! if it is valid, and "false" otherwise.
243 
244 protected:
245  SCHEMA m_schema;
246 };
247 
248 //-*****************************************************************************
249 // TEMPLATE AND INLINE FUNCTIONS
250 //-*****************************************************************************
251 
253  const Argument &iArg1 )
254 {
255  Arguments args;
256  iArg0.setInto( args );
257  iArg1.setInto( args );
258  return args.getErrorHandlerPolicy();
259 }
260 
261 } // End namespace ALEMBIC_VERSION_NS
262 
263 using namespace ALEMBIC_VERSION_NS;
264 
265 } // End namespace Abc
266 } // End namespace Alembic
267 
268 #endif
static bool matches(const AbcA::ObjectHeader &iHeader, SchemaInterpMatching iMatching=kStrictMatching)
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
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
**If you just want to fire and args
Definition: thread.h:609
#define ABCA_ASSERT(COND, TEXT)
Definition: Foundation.h:99
#define ALEMBIC_VERSION_NS
Definition: Foundation.h:88