HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OSchemaObject.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_OSchemaObject_h
38 #define Alembic_Abc_OSchemaObject_h
39 
40 #include <Alembic/Abc/Foundation.h>
41 #include <Alembic/Abc/OObject.h>
42 #include <Alembic/Abc/OSchema.h>
43 
44 namespace Alembic {
45 namespace Abc {
46 namespace ALEMBIC_VERSION_NS {
47 
48 //-*****************************************************************************
49 //! An OSchemaObject is an object with a single schema. This is just
50 //! a convenience class, really, but it also deals with setting up and
51 //! validating metadata
52 template <class SCHEMA>
53 class OSchemaObject : public OObject
54 {
55 public:
56  //-*************************************************************************
57  // TYPEDEFS AND IDENTIFIERS
58  //-*************************************************************************
59  typedef SCHEMA schema_type;
61 
62  //! Our schema title contains the schema title of the underlying
63  //! compound property, along with the default name of that compound
64  //! property. So, for example - most AbcGeom types put their
65  //! data in ".geom", so, "AbcGeom_PolyMesh_v1:.geom"
66  //! Sometimes schema titles from underlying schemas are "", but
67  //! ours never are.
69  {
70  return SCHEMA::getSchemaTitle() + std::string( ":" ) +
71  SCHEMA::getDefaultSchemaName();
72  }
73 
74  static const char * getSchemaTitle()
75  {
76  return SCHEMA::getSchemaTitle();
77  }
78 
79  //! This will check whether or not a given entity (as represented by
80  //! a metadata) strictly matches the interpretation of this
81  //! schema object
82  static bool matches( const AbcA::MetaData &iMetaData,
84  {
85  if ( std::string() == getSchemaTitle() || iMatching == kNoMatching )
86  { return true; }
87 
88  if ( iMatching == kStrictMatching )
89  {
90 
91  return iMetaData.get( "schemaObjTitle" ) == getSchemaObjTitle();
92  }
93 
94  if ( iMatching == kSchemaTitleMatching )
95  {
96  return iMetaData.get( "schema" ) == getSchemaTitle();
97  }
98 
99  return false;
100  }
101 
102  //! This will check whether or not a given object (as represented by
103  //! an object header) strictly matches the interpretation of this
104  //! schema object, as well as the data type.
105  static bool matches( const AbcA::ObjectHeader &iHeader,
107  {
108  return matches( iHeader.getMetaData(), iMatching );
109  }
110 
111 
112  //-*************************************************************************
113  // CONSTRUCTION, DESTRUCTION, ASSIGNMENT
114  //-*************************************************************************
115 
116  //! The default constructor creates an empty OSchemaObject function set.
117  //! ...
119 
120  //! The primary constructor creates an OSchemaObject as a child of the
121  //! first argument, which is any Abc or AbcCoreAbstract (or other)
122  //! object which can be intrusively cast to an ObjectWriterPtr.
123  OSchemaObject( OObject iParent,
124  const std::string &iName,
125 
126  const Argument &iArg0 = Argument(),
127  const Argument &iArg1 = Argument(),
128  const Argument &iArg2 = Argument() );
129 
130  //-*************************************************************************
131  // ABC BASE MECHANISMS
132  // These functions are used by Abc to deal with errors, validity,
133  // and so on.
134  //-*************************************************************************
135 
136  //! Schemas are not necessarily cheap to copy, so we return by reference
137  //! rather than by value.
138  SCHEMA &getSchema() { return m_schema; }
139  const SCHEMA &getSchema() const { return m_schema; }
140 
141  //! Reset returns this function set to an empty, default
142  //! state.
143  void reset() { m_schema.reset(); OObject::reset(); }
144 
145  //! Valid returns whether this function set is
146  //! valid.
147  bool valid() const
148  {
149  return ( OObject::valid() && m_schema.valid() );
150  }
151 
152  //! The unspecified-bool-type operator casts the object to "true"
153  //! if it is valid, and "false" otherwise.
155 
156 protected:
157  SCHEMA m_schema;
158 };
159 
160 //-*****************************************************************************
161 // TEMPLATE AND INLINE FUNCTIONS
162 //-*****************************************************************************
163 
164 //-*****************************************************************************
165 template <class SCHEMA>
167 (
168  OObject iParent,
169  const std::string &iName,
170  const Argument &iArg0,
171  const Argument &iArg1,
172  const Argument &iArg2 )
173 {
174  Arguments args( GetErrorHandlerPolicy( iParent ) );
175  iArg0.setInto( args );
176  iArg1.setInto( args );
177  iArg2.setInto( args );
178 
179  getErrorHandler().setPolicy( args.getErrorHandlerPolicy() );
180 
182  "OSchemaObject::OSchemaObject( OObject )" );
183 
184  // Extract the parent.
185  AbcA::ObjectWriterPtr parent = iParent.getPtr();
186  ABCA_ASSERT( parent,
187  "NULL Parent ObjectWriter in OSchemaObject ctor" );
188 
189  // The object schema title is derived from the schema's title.
190  // It is never empty (unless sparse)
191  AbcA::MetaData metaData = args.getMetaData();
192 
193  SparseFlag sparseFlag = kSparse;
194  if ( !args.isSparse() )
195  {
196  sparseFlag = kFull;
197  metaData.set( "schema", SCHEMA::getSchemaTitle() );
198  metaData.set( "schemaObjTitle", getSchemaObjTitle() );
199  if ( std::string() != SCHEMA::getSchemaBaseType() )
200  {
201  metaData.set( "schemaBaseType", SCHEMA::getSchemaBaseType() );
202  }
203  }
204 
205  // Make the object.
206  AbcA::ObjectHeader ohdr( iName, metaData );
207  m_object = parent->createChild( ohdr );
208 
209  AbcA::TimeSamplingPtr tsPtr = args.getTimeSampling();
210  uint32_t tsIndex = args.getTimeSamplingIndex();
211 
212  // if we specified a valid TimeSamplingPtr, use it to determine the index
213  // otherwise we'll use the index, which defaults to the intrinsic 0 index
214  if (tsPtr)
215  {
216  tsIndex = parent->getArchive()->addTimeSampling(*tsPtr);
217  }
218 
219  AbcA::MetaData schemaMetaData;
220  if ( args.isSparse() && SCHEMA::replaceOnSparse() )
221  {
222  schemaMetaData.set( "replace", "1" );
223  }
224 
225  // Make the schema.
226  m_schema = SCHEMA( m_object->getProperties(),
227  SCHEMA::getDefaultSchemaName(),
228  this->getErrorHandlerPolicy(),
229  tsIndex,
230  schemaMetaData,
231  sparseFlag );
232 
234 }
235 
236 } // End namespace ALEMBIC_VERSION_NS
237 
238 using namespace ALEMBIC_VERSION_NS;
239 
240 } // End namespace Abc
241 } // End namespace Alembic
242 
243 #endif
Alembic::Util::shared_ptr< ObjectWriter > ObjectWriterPtr
static bool matches(const AbcA::MetaData &iMetaData, SchemaInterpMatching iMatching=kStrictMatching)
Definition: OSchemaObject.h:82
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
void setInto(Arguments &iArgs) const
Definition: Argument.h:149
static bool matches(const AbcA::ObjectHeader &iHeader, SchemaInterpMatching iMatching=kStrictMatching)
AbcA::TimeSamplingPtr getTimeSampling() const
Definition: Argument.h:89
Alembic::Util::shared_ptr< TimeSampling > TimeSamplingPtr
Definition: TimeSampling.h:137
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
AbcA::ObjectWriterPtr getPtr()
Definition: OObject.h:220
#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
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