HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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  template <class OBJECT_PTR>
124  OSchemaObject( OBJECT_PTR iParentObject,
125  const std::string &iName,
126 
127  const Argument &iArg0 = Argument(),
128  const Argument &iArg1 = Argument(),
129  const Argument &iArg2 = Argument() );
130 
131  //-*************************************************************************
132  // ABC BASE MECHANISMS
133  // These functions are used by Abc to deal with errors, validity,
134  // and so on.
135  //-*************************************************************************
136 
137  //! Schemas are not necessarily cheap to copy, so we return by reference
138  //! rather than by value.
139  SCHEMA &getSchema() { return m_schema; }
140  const SCHEMA &getSchema() const { return m_schema; }
141 
142  //! Reset returns this function set to an empty, default
143  //! state.
144  void reset() { m_schema.reset(); OObject::reset(); }
145 
146  //! Valid returns whether this function set is
147  //! valid.
148  bool valid() const
149  {
150  return ( OObject::valid() && m_schema.valid() );
151  }
152 
153  //! The unspecified-bool-type operator casts the object to "true"
154  //! if it is valid, and "false" otherwise.
156 
157 protected:
158  SCHEMA m_schema;
159 };
160 
161 //-*****************************************************************************
162 // TEMPLATE AND INLINE FUNCTIONS
163 //-*****************************************************************************
164 
165 //-*****************************************************************************
166 template <class SCHEMA>
167 template <class OBJECT_PTR>
169 (
170  OBJECT_PTR iParentObject,
171  const std::string &iName,
172  const Argument &iArg0,
173  const Argument &iArg1,
174  const Argument &iArg2 )
175 {
176  Arguments args( GetErrorHandlerPolicy( iParentObject ) );
177  iArg0.setInto( args );
178  iArg1.setInto( args );
179  iArg2.setInto( args );
180 
181  getErrorHandler().setPolicy( args.getErrorHandlerPolicy() );
182 
184  "OSchemaObject::OSchemaObject( OObject )" );
185 
186  // Extract the parent.
187  AbcA::ObjectWriterPtr parent = GetObjectWriterPtr( iParentObject );
188  ABCA_ASSERT( parent,
189  "NULL Parent ObjectWriter in OSchemaObject ctor" );
190 
191  // The object schema title is derived from the schema's title.
192  // It is never empty.
193  AbcA::MetaData metaData = args.getMetaData();
194  metaData.set( "schema", SCHEMA::getSchemaTitle() );
195  metaData.set( "schemaObjTitle", getSchemaObjTitle() );
196  if ( std::string() != SCHEMA::getSchemaBaseType() )
197  {
198  metaData.set( "schemaBaseType", SCHEMA::getSchemaBaseType() );
199  }
200 
201  // Make the object.
202  AbcA::ObjectHeader ohdr( iName, metaData );
203  m_object = parent->createChild( ohdr );
204 
205  AbcA::TimeSamplingPtr tsPtr = args.getTimeSampling();
206  uint32_t tsIndex = args.getTimeSamplingIndex();
207 
208  // if we specified a valid TimeSamplingPtr, use it to determine the index
209  // otherwise we'll use the index, which defaults to the intrinsic 0 index
210  if (tsPtr)
211  {
212  tsIndex = parent->getArchive()->addTimeSampling(*tsPtr);
213  }
214 
215  // Make the schema.
216  m_schema = SCHEMA( m_object->getProperties(),
217  this->getErrorHandlerPolicy(),
218  tsIndex );
219 
221 }
222 
223 } // End namespace ALEMBIC_VERSION_NS
224 
225 using namespace ALEMBIC_VERSION_NS;
226 
227 } // End namespace Abc
228 } // End namespace Alembic
229 
230 #endif
ErrorHandler::Policy GetErrorHandlerPolicy(SOMETHING iSomething, const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument())
Definition: Argument.h:219
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:813
void setInto(Arguments &iArgs) const
Definition: Argument.h:135
static bool matches(const AbcA::ObjectHeader &iHeader, SchemaInterpMatching iMatching=kStrictMatching)
AbcA::TimeSamplingPtr getTimeSampling() const
Definition: Argument.h:84
Alembic::Util::shared_ptr< TimeSampling > TimeSamplingPtr
Definition: TimeSampling.h:137
ErrorHandler::Policy getErrorHandlerPolicy() const
Definition: Argument.h:78
#define ALEMBIC_ABC_SAFE_CALL_END_RESET()
Definition: ErrorHandler.h:181
AbcA::ObjectWriterPtr GetObjectWriterPtr(AbcA::ObjectWriterPtr iPtr)
Definition: Foundation.h:184
#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
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