HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ISchema.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_ISchema_h_
38 #define _Alembic_Abc_ISchema_h_
39 
40 #include <Alembic/Abc/Foundation.h>
41 #include <Alembic/Abc/OSchema.h>
43 
44 namespace Alembic {
45 namespace Abc {
46 namespace ALEMBIC_VERSION_NS {
47 
48 //-*****************************************************************************
49 //! See Schema Notes in OSchema.h
50 //! ...
51 //-*****************************************************************************
52 
53 //-*****************************************************************************
54 //! Usually used as a base class, but could also theoretically be used
55 //! as a standalone
56 template <class INFO>
57 class ISchema : public ICompoundProperty
58 {
59 public:
60  //-*************************************************************************
61  // TYPEDEFS AND IDENTIFIERS
62  //-*************************************************************************
63  typedef INFO info_type;
65 
66  //! Return the schema title expected of this
67  //! property. An empty title matches everything
68  static const char * getSchemaTitle()
69  {
70  return INFO::title();
71  }
72 
73  //! Return the default name for instances of this schema. Often
74  //! something like ".geom"
75  static const char * getDefaultSchemaName()
76  {
77  return INFO::defaultName();
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  if ( std::string() == getSchemaTitle() || iMatching == kNoMatching )
87  { return true; }
88 
89  if ( iMatching == kStrictMatching || iMatching == kSchemaTitleMatching )
90  {
91  return iMetaData.get( "schema" ) == getSchemaTitle();
92  }
93 
94  return false;
95  }
96 
97  //! This will check whether or not a given object (as represented by
98  //! an object header) strictly matches the interpretation of this
99  //! schema object, as well as the data type.
100  static bool matches( const AbcA::PropertyHeader &iHeader,
102  {
103  return matches( iHeader.getMetaData(), iMatching );
104  }
105 
106  //-*************************************************************************
107  // CONSTRUCTION, DESTRUCTION, ASSIGNMENT
108  //-*************************************************************************
109 
110  //! The default constructor creates an empty ISchema
111  //! function set.
112  ISchema() {}
113 
114  //! Creates a new Compound Property Reader with the schema
115  //! information added to the metadata.
116  //! arguments count include error handling, strictness matching.
117  template <class CPROP_PTR>
118  ISchema( CPROP_PTR iParentObject,
119  const std::string &iName,
120 
121  const Argument &iArg0 = Argument(),
122  const Argument &iArg1 = Argument() )
123  {
124  this_type::init( iParentObject, iName, iArg0, iArg1 );
125  }
126 
127  //! Creates a new Compound Property Reader with the schema
128  //! information and also the default name.
129  template <class CPROP_PTR>
130  explicit ISchema( CPROP_PTR iParentObject,
131 
132  const Argument &iArg0 = Argument(),
133  const Argument &iArg1 = Argument() )
134  {
135  this_type::init( iParentObject,
136  INFO::defaultName(),
137  iArg0, iArg1 );
138  }
139 
140  //! Wrap an existing compound property, checking that it matches
141  //! the schema title info, if strict matching has been selected.
142  //! Arguments allow selection of error handling and matching strictness
143  template<class CPROP_PTR>
144  ISchema( CPROP_PTR iProperty,
145  WrapExistingFlag iFlag,
146  const Argument &iArg0 = Argument(),
147  const Argument &iArg1 = Argument() );
148 
149  //! Default copy constructor used
150  //! Default assignment operator used.
151  //
152  virtual ~ISchema() {}
153 
154 private:
155  template <class CPROP_PTR>
156  void init( CPROP_PTR iParentObject,
157  const std::string &iName,
158  const Argument &iArg0,
159  const Argument &iArg1 );
160 };
161 
162 //-*****************************************************************************
163 // TEMPLATE AND INLINE FUNCTIONS
164 //-*****************************************************************************
165 template <class INFO>
166 template <class CPROP_PTR>
167 void ISchema<INFO>::init( CPROP_PTR iParent,
168  const std::string &iName,
169  const Argument &iArg0,
170  const Argument &iArg1 )
171 {
172  Arguments args;
173  iArg0.setInto( args );
174  iArg1.setInto( args );
175 
176  getErrorHandler().setPolicy( args.getErrorHandlerPolicy() );
177 
178  ALEMBIC_ABC_SAFE_CALL_BEGIN( "ISchema::ISchema::init()" );
179 
180  // Get actual reader for parent.
181  ABCA_ASSERT( iParent,
182  "NULL parent passed into ISchema ctor" );
184  GetCompoundPropertyReaderPtr( iParent );
185  ABCA_ASSERT( parent, "NULL CompoundPropertyReaderPtr" );
186 
187  const AbcA::PropertyHeader *pheader = parent->getPropertyHeader( iName );
188 
189  ABCA_ASSERT( pheader != NULL,
190  "Nonexistent compound property: " << iName );
191 
192  // Check metadata for schema.
193  ABCA_ASSERT( matches( *pheader, args.getSchemaInterpMatching() ),
194 
195  "Incorrect match of schema: "
196  << pheader->getMetaData().get( "schema" )
197  << " to expected: "
198  << INFO::title() );
199 
200  // Get property.
201  m_property = parent->getCompoundProperty( iName );
202 
204 }
205 
206 //-*****************************************************************************
207 template<class INFO>
208 template<class COMPOUND_PTR>
210  COMPOUND_PTR iProperty,
211  WrapExistingFlag iFlag,
212  const Argument &iArg0,
213  const Argument &iArg1 )
214  : ICompoundProperty( iProperty,
215  iFlag,
216  GetErrorHandlerPolicy( iProperty,
217  iArg0, iArg1 ) )
218 {
220  "ISchema::ISchema( wrap )" );
221 
222  const AbcA::PropertyHeader &pheader = this->getHeader();
223 
224  ABCA_ASSERT( matches( pheader,
225  GetSchemaInterpMatching( iArg0, iArg1 ) ),
226 
227  "Incorrect match of schema: "
228  << pheader.getMetaData().get( "schema" )
229  << " to expected: "
230  << INFO::title() );
231 
233 }
234 
235 } // End namespace ALEMBIC_VERSION_NS
236 
237 using namespace ALEMBIC_VERSION_NS;
238 
239 } // End namespace Abc
240 } // End namespace Alembic
241 
242 #endif
ErrorHandler::Policy GetErrorHandlerPolicy(SOMETHING iSomething, const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument())
Definition: Argument.h:219
GLsizei const GLchar *const * string
Definition: glcorearb.h:813
ISchema(CPROP_PTR iParentObject, const std::string &iName, const Argument &iArg0=Argument(), const Argument &iArg1=Argument())
Definition: ISchema.h:118
SchemaInterpMatching getSchemaInterpMatching() const
Definition: Argument.h:90
void setInto(Arguments &iArgs) const
Definition: Argument.h:135
static bool matches(const AbcA::MetaData &iMetaData, SchemaInterpMatching iMatching=kStrictMatching)
Definition: ISchema.h:83
Alembic::Util::shared_ptr< CompoundPropertyReader > CompoundPropertyReaderPtr
ISchema(CPROP_PTR iParentObject, const Argument &iArg0=Argument(), const Argument &iArg1=Argument())
Definition: ISchema.h:130
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
static const char * getDefaultSchemaName()
Definition: ISchema.h:75
static const char * getSchemaTitle()
Definition: ISchema.h:68
AbcA::CompoundPropertyReaderPtr GetCompoundPropertyReaderPtr(AbcA::CompoundPropertyReaderPtr iPtr)
Definition: Foundation.h:171
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
static bool matches(const AbcA::PropertyHeader &iHeader, SchemaInterpMatching iMatching=kStrictMatching)
Definition: ISchema.h:100
#define ABCA_ASSERT(COND, TEXT)
Definition: Foundation.h:99
#define ALEMBIC_VERSION_NS
Definition: Foundation.h:104