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