HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 //! With properties, specific flavors of properties are expressed via the
77 //! TypedScalarProperty and the TypedArrayProperty. Compound Properties
78 //! are more complex, and the specific flavors require a more complex
79 //! treatment - That's what Schemas are. The CompoundProperty equivalent
80 //! of a TypedArrayProperty or a TypedScalarProperty.
81 //!
82 //! A Schema is a collection of grouped properties which implement some
83 //! complex object, such as a poly mesh. In the simpelest, standard case,
84 //! there will be a compound property at the top with a certain name, and
85 //! inside the compound property will be some number of additional properties
86 //! that implement the object. In the case of a poly mesh, these properties
87 //! would include a list of vertices (a V3fArray), a list of indices
88 //! (an Int32Array), and a list of "per-face counts" (also an Int32Array).
89 
90 
91 //-*****************************************************************************
92 //! Here is a macro for declaring SCHEMA_INFO
93 //! It takes these arguments
94 //! - the SchemaTitle( a string ),
95 //! - the SchemaBaseType( a string ),
96 //! - the DefaultSchemaName( a string ),
97 //! - whether to set replace when the sparse argument is provided( bool ),
98 //! - the name of the SchemaInfo Type to be declared.
99 //! - for example:
100 //! ALEMBIC_ABC_DECLARE_SCHEMA_INFO( "AbcGeom_PolyMesh_v1",
101 //! "AbcGeom_GeomBase_v1",
102 //! ".geom",
103 //! false,
104 //! PolyMeshSchemaInfo );
105 #define ALEMBIC_ABC_DECLARE_SCHEMA_INFO( STITLE, SBTYP, SDFLT, SPREP, STDEF ) \
106 struct STDEF \
107 { \
108  static const char * title() { return ( STITLE ) ; } \
109  static const char * defaultName() { return ( SDFLT ); } \
110  static const char * schemaBaseType() { return ( SBTYP ); } \
111  static bool replaceOnSparse() { return SPREP; } \
112 }
113 
114 //-*****************************************************************************
115 //! Usually used as a base class, but could also theoretically be used
116 //! as a standalone
117 template <class INFO>
119 {
120 public:
121  //-*************************************************************************
122  // TYPEDEFS AND IDENTIFIERS
123  //-*************************************************************************
124 
125  typedef INFO info_type;
127 
128  //! Return the schema title expected of this
129  //! property. An empty title matches everything
130  static const char * getSchemaTitle()
131  {
132  return INFO::title();
133  }
134 
135  //! Return the schema base type expected of this
136  //! property. An empty base type means it's the root type.
137  static const char * getSchemaBaseType()
138  {
139  return INFO::schemaBaseType();
140  }
141 
142  //! Return the default name for instances of this schema. Often
143  //! something like ".geom"
144  static const char * getDefaultSchemaName()
145  {
146  return INFO::defaultName();
147  }
148 
149  //! Returns whether this schema also sets replace in the MetaData if
150  //! kSparse is passed into the args. For some schemas like xforms it
151  //! doesn't make sense to sparsely override the properties, instead
152  //! you want to replace everything on the schema with a whole set of new
153  //! properties, or even NO properties.
154  static bool replaceOnSparse()
155  {
156  return INFO::replaceOnSparse();
157  }
158 
159  //! This will check whether or not a given entity (as represented by
160  //! a metadata) strictly matches the interpretation of this
161  //! schema object
162  static bool matches( const AbcA::MetaData &iMetaData,
164  {
165  if ( std::string() == getSchemaTitle() || iMatching == kNoMatching )
166  { return true; }
167 
168  if ( iMatching == kStrictMatching || iMatching == kSchemaTitleMatching )
169  {
170  return iMetaData.get( "schema" ) == getSchemaTitle();
171  }
172 
173  return false;
174  }
175 
176  //! This will check whether or not a given object (as represented by
177  //! an object header) strictly matches the interpretation of this
178  //! schema object, as well as the data type.
179  static bool matches( const AbcA::PropertyHeader &iHeader,
181  {
182  return matches( iHeader.getMetaData(), iMatching );
183  }
184 
185  //-*************************************************************************
186  // CONSTRUCTION, DESTRUCTION, ASSIGNMENT
187  //-*************************************************************************
188 
189  //! The default constructor creates an empty OSchema
190  //! function set.
191  OSchema() {}
192 
193  //! Creates a new Compound Property Writer with the schema
194  //! information added to the metadata.
196  const std::string &iName,
197 
198  const Argument &iArg0 = Argument(),
199  const Argument &iArg1 = Argument(),
200  const Argument &iArg2 = Argument(),
201  const Argument &iArg3 = Argument() )
202  {
203  this_type::init( iParent, iName, iArg0, iArg1, iArg2, iArg3 );
204  }
205 
206  //! Creates a new Compound Property Writer with the schema
207  //! information added to the metadata.
209  const std::string &iName,
210 
211  const Argument &iArg0 = Argument(),
212  const Argument &iArg1 = Argument(),
213  const Argument &iArg2 = Argument() )
214  {
215  *this = OSchema( iParent.getPtr(), iName,
216  GetErrorHandlerPolicy( iParent ), iArg0, iArg1, iArg2);
217  }
218 
219  virtual ~OSchema() {}
220 
221  //! Default copy constructor used
222  //! Default assignment operator used.
223 
224 private:
225  void init( AbcA::CompoundPropertyWriterPtr iParent,
226  const std::string &iName,
227  const Argument &iArg0,
228  const Argument &iArg1,
229  const Argument &iArg2,
230  const Argument &iArg3 );
231 };
232 
233 //-*****************************************************************************
234 // TEMPLATE AND INLINE FUNCTIONS
235 //-*****************************************************************************
236 template <class INFO>
238  const std::string &iName,
239  const Argument &iArg0,
240  const Argument &iArg1,
241  const Argument &iArg2,
242  const Argument &iArg3 )
243 {
244  Arguments args;
245  iArg0.setInto( args );
246  iArg1.setInto( args );
247  iArg2.setInto( args );
248  iArg3.setInto( args );
249 
250  getErrorHandler().setPolicy( args.getErrorHandlerPolicy() );
251 
252  ALEMBIC_ABC_SAFE_CALL_BEGIN( "OSchema::OSchema::init()" );
253 
254 
255  // Get actual writer for parent.
256  ABCA_ASSERT( iParent,
257  "NULL parent passed into OSchema ctor" );
258 
259  // Put schema title into metadata.
260  AbcA::MetaData mdata = args.getMetaData();
261  std::string emptyStr;
262  if ( emptyStr != getSchemaTitle() && !args.isSparse() )
263  {
264  mdata.set( "schema", getSchemaTitle() );
265  }
266  if ( emptyStr != getSchemaBaseType() && !args.isSparse() )
267  {
268  mdata.set( "schemaBaseType", getSchemaBaseType() );
269  }
270 
271  // Create property.
272  m_property = iParent->createCompoundProperty( iName, mdata );
273 
275 }
276 
277 } // End namespace ALEMBIC_VERSION_NS
278 
279 using namespace ALEMBIC_VERSION_NS;
280 
281 } // End namespace Abc
282 } // End namespace Alembic
283 
284 #endif
OSchema(OCompoundProperty iParent, const std::string &iName, const Argument &iArg0=Argument(), const Argument &iArg1=Argument(), const Argument &iArg2=Argument())
Definition: OSchema.h:208
static bool matches(const AbcA::MetaData &iMetaData, SchemaInterpMatching iMatching=kStrictMatching)
Definition: OSchema.h:162
static const char * getDefaultSchemaName()
Definition: OSchema.h:144
static const char * getSchemaTitle()
Definition: OSchema.h:130
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
void setInto(Arguments &iArgs) const
Definition: Argument.h:149
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
#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
**If you just want to fire and args
Definition: thread.h:609
OSchema(AbcA::CompoundPropertyWriterPtr iParent, const std::string &iName, const Argument &iArg0=Argument(), const Argument &iArg1=Argument(), const Argument &iArg2=Argument(), const Argument &iArg3=Argument())
Definition: OSchema.h:195
static bool matches(const AbcA::PropertyHeader &iHeader, SchemaInterpMatching iMatching=kStrictMatching)
Definition: OSchema.h:179
static const char * getSchemaBaseType()
Definition: OSchema.h:137
const AbcA::MetaData & getMetaData() const
Definition: Argument.h:86
#define ABCA_ASSERT(COND, TEXT)
Definition: Foundation.h:99
#define ALEMBIC_VERSION_NS
Definition: Foundation.h:88
Alembic::Util::shared_ptr< CompoundPropertyWriter > CompoundPropertyWriterPtr