HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
OSchema.h
Go to the documentation of this file.
1 //-*****************************************************************************
2 //
3 // Copyright (c) 2009-2012,
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_OSchema_h_
38 #define _Alembic_Abc_OSchema_h_
39 
40 #include <Alembic/Abc/Foundation.h>
42 
43 namespace Alembic {
44 namespace Abc {
45 namespace ALEMBIC_VERSION_NS {
46 
47 //-*****************************************************************************
48 //! With properties, specific flavors of properties are expressed via the
49 //! TypedScalarProperty and the TypedArrayProperty. Compound Properties
50 //! are more complex, and the specific flavors require a more complex
51 //! treatment - That's what Schemas are. The CompoundProperty equivalent
52 //! of a TypedArrayProperty or a TypedScalarProperty.
53 //!
54 //! A Schema is a collection of grouped properties which implement some
55 //! complex object, such as a poly mesh. In the simpelest, standard case,
56 //! there will be a compound property at the top with a certain name, and
57 //! inside the compound property will be some number of additional properties
58 //! that implement the object. In the case of a poly mesh, these properties
59 //! would include a list of vertices (a V3fArray), a list of indices
60 //! (an Int32Array), and a list of "per-face counts" (also an Int32Array).
61 //!
62 //! In somewhat more complex cases, such as a TransformStack, the set of
63 //! properties that are added may vary based on configuration information
64 //! provided by the user.
65 //!
66 //! Because a Schema is to a CompoundProperty what a TypedArrayProperty
67 //! or TypedScalarProperty is to a regular property, it is directly derived
68 //! from CompoundProperty. However... Whereas TypedProperties can be instanced
69 //! as typedefs, Schemas will invariably require additional functionality,
70 //! and thus the StdCompoundSchema is intended for use as a base class.
71 //!
72 //-*****************************************************************************
73 
74 
75 //-*****************************************************************************
76 //! Here is a macro for declaring SCHEMA_INFO
77 //! It takes three arguments
78 //! - the SchemaTitle( a string ),
79 //! - the SchemaBaseType( a string ),
80 //! - the DefaultSchemaName( a string )
81 //! - the name of the SchemaTrait Type to be declared.
82 //! - for example:
83 //! ALEMBIC_ABC_DECLARE_SCHEMA_INFO( "AbcGeom_PolyMesh_v1",
84 //! ".geom",
85 //! PolyMeshSchemaInfo );
86 #define ALEMBIC_ABC_DECLARE_SCHEMA_INFO( STITLE, SBTYP, SDFLT, STDEF ) \
87 struct STDEF \
88 { \
89  static const char * title() { return ( STITLE ) ; } \
90  static const char * defaultName() { return ( SDFLT ); } \
91  static const char * schemaBaseType() { return ( SBTYP ); } \
92 }
93 
94 //-*****************************************************************************
95 //! Usually used as a base class, but could also theoretically be used
96 //! as a standalone
97 template <class INFO>
98 class OSchema : public OCompoundProperty
99 {
100 public:
101  //-*************************************************************************
102  // TYPEDEFS AND IDENTIFIERS
103  //-*************************************************************************
104 
105  typedef INFO info_type;
107 
108  //! Return the schema title expected of this
109  //! property. An empty title matches everything
110  static const char * getSchemaTitle()
111  {
112  return INFO::title();
113  }
114 
115  //! Return the schema base type expected of this
116  //! property. An empty base type means it's the root type.
117  static const char * getSchemaBaseType()
118  {
119  return INFO::schemaBaseType();
120  }
121 
122  //! Return the default name for instances of this schema. Often
123  //! something like ".geom"
124  static const char * getDefaultSchemaName()
125  {
126  return INFO::defaultName();
127  }
128 
129  //! This will check whether or not a given entity (as represented by
130  //! a metadata) strictly matches the interpretation of this
131  //! schema object
132  static bool matches( const AbcA::MetaData &iMetaData,
134  {
135  if ( std::string() == getSchemaTitle() || iMatching == kNoMatching )
136  { return true; }
137 
138  if ( iMatching == kStrictMatching || iMatching == kSchemaTitleMatching )
139  {
140  return iMetaData.get( "schema" ) == getSchemaTitle();
141  }
142 
143  return false;
144  }
145 
146  //! This will check whether or not a given object (as represented by
147  //! an object header) strictly matches the interpretation of this
148  //! schema object, as well as the data type.
149  static bool matches( const AbcA::PropertyHeader &iHeader,
151  {
152  return matches( iHeader.getMetaData(), iMatching );
153  }
154 
155  //-*************************************************************************
156  // CONSTRUCTION, DESTRUCTION, ASSIGNMENT
157  //-*************************************************************************
158 
159  //! The default constructor creates an empty OSchema
160  //! function set.
161  OSchema() {}
162 
163  //! Creates a new Compound Property Writer with the schema
164  //! information added to the metadata.
165  template <class CPROP_PTR>
166  OSchema( CPROP_PTR iParentObject,
167  const std::string &iName,
168 
169  const Argument &iArg0 = Argument(),
170  const Argument &iArg1 = Argument(),
171  const Argument &iArg2 = Argument() )
172  {
173  this_type::init( iParentObject, iName, iArg0, iArg1, iArg2 );
174  }
175 
176  //! Creates a new Compound Property Writer with the schema
177  //! information and also the default name.
178  template <class CPROP_PTR>
179  explicit OSchema( CPROP_PTR iParentObject,
180 
181  const Argument &iArg0 = Argument(),
182  const Argument &iArg1 = Argument(),
183  const Argument &iArg2 = Argument() )
184  {
185  this_type::init( iParentObject,
186  INFO::defaultName(),
187  iArg0, iArg1, iArg2 );
188  }
189 
190  virtual ~OSchema() {}
191 
192  //! Default copy constructor used
193  //! Default assignment operator used.
194 
195 private:
196  template <class CPROP_PTR>
197  void init( CPROP_PTR iParentObject,
198  const std::string &iName,
199  const Argument &iArg0,
200  const Argument &iArg1,
201  const Argument &iArg2 );
202 };
203 
204 //-*****************************************************************************
205 // TEMPLATE AND INLINE FUNCTIONS
206 //-*****************************************************************************
207 template <class INFO>
208 template <class CPROP_PTR>
209 void OSchema<INFO>::init( CPROP_PTR iParent,
210  const std::string &iName,
211  const Argument &iArg0,
212  const Argument &iArg1,
213  const Argument &iArg2 )
214 {
215  Arguments args;
216  iArg0.setInto( args );
217  iArg1.setInto( args );
218  iArg2.setInto( args );
219 
220  getErrorHandler().setPolicy( args.getErrorHandlerPolicy() );
221 
222  ALEMBIC_ABC_SAFE_CALL_BEGIN( "OSchema::OSchema::init()" );
223 
224 
225  // Get actual writer for parent.
226  ABCA_ASSERT( iParent,
227  "NULL parent passed into OSchema ctor" );
229  GetCompoundPropertyWriterPtr( iParent );
230  ABCA_ASSERT( parent, "NULL CompoundPropertyWriterPtr" );
231 
232  // Put schema title into metadata.
233  AbcA::MetaData mdata = args.getMetaData();
234  std::string emptyStr;
235  if ( emptyStr != getSchemaTitle() )
236  {
237  mdata.set( "schema", getSchemaTitle() );
238  }
239  if ( emptyStr != getSchemaBaseType() )
240  {
241  mdata.set( "schemaBaseType", getSchemaBaseType() );
242  }
243 
244  // Create property.
245  m_property = parent->createCompoundProperty( iName, mdata );
246 
248 }
249 
250 } // End namespace ALEMBIC_VERSION_NS
251 
252 using namespace ALEMBIC_VERSION_NS;
253 
254 } // End namespace Abc
255 } // End namespace Alembic
256 
257 #endif
static bool matches(const AbcA::MetaData &iMetaData, SchemaInterpMatching iMatching=kStrictMatching)
Definition: OSchema.h:132
OSchema(CPROP_PTR iParentObject, const Argument &iArg0=Argument(), const Argument &iArg1=Argument(), const Argument &iArg2=Argument())
Definition: OSchema.h:179
static const char * getDefaultSchemaName()
Definition: OSchema.h:124
static const char * getSchemaTitle()
Definition: OSchema.h:110
GLsizei const GLchar *const * string
Definition: glcorearb.h:813
void setInto(Arguments &iArgs) const
Definition: Argument.h:135
OSchema(CPROP_PTR iParentObject, const std::string &iName, const Argument &iArg0=Argument(), const Argument &iArg1=Argument(), const Argument &iArg2=Argument())
Definition: OSchema.h:166
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 set(const std::string &iKey, const std::string &iData)
Definition: MetaData.h:168
std::string get(const std::string &iKey) const
Definition: MetaData.h:192
static bool matches(const AbcA::PropertyHeader &iHeader, SchemaInterpMatching iMatching=kStrictMatching)
Definition: OSchema.h:149
AbcA::CompoundPropertyWriterPtr GetCompoundPropertyWriterPtr(AbcA::CompoundPropertyWriterPtr iPtr)
Definition: Foundation.h:164
static const char * getSchemaBaseType()
Definition: OSchema.h:117
const AbcA::MetaData & getMetaData() const
Definition: Argument.h:81
#define ABCA_ASSERT(COND, TEXT)
Definition: Foundation.h:99
#define ALEMBIC_VERSION_NS
Definition: Foundation.h:104
Alembic::Util::shared_ptr< CompoundPropertyWriter > CompoundPropertyWriterPtr