Alembic 1.8.11

Loading...
Searching...
No Matches
ISchemaObject.h
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_ISchemaObject_h
38#define Alembic_Abc_ISchemaObject_h
39
40#include <Alembic/Abc/Foundation.h>
41#include <Alembic/Abc/IObject.h>
42#include <Alembic/Abc/ISchema.h>
43#include <Alembic/Abc/Argument.h>
44#include <Alembic/Abc/Base.h>
45
46 namespace Alembic {
47 namespace Abc {
48 namespace ALEMBIC_VERSION_NS {
49
50//-*****************************************************************************
54 template <class SCHEMA>
55 class ISchemaObject : public IObject
56{
57 public:
58 //-*************************************************************************
59 // TYPEDEFS AND IDENTIFIERS
60 //-*************************************************************************
61 typedef SCHEMA schema_type;
62 typedef ISchemaObject<SCHEMA> this_type;
63
70 static std::string getSchemaObjTitle()
71 {
72 return SCHEMA::getSchemaTitle() + std::string( ":" )
73 + SCHEMA::getDefaultSchemaName();
74 }
75
76 static const char * getSchemaTitle()
77 {
78 return SCHEMA::getSchemaTitle();
79 }
80
84 static bool matches( const AbcA::MetaData &iMetaData,
85 SchemaInterpMatching iMatching = kStrictMatching )
86 {
87
88 if ( std::string() == getSchemaTitle() || iMatching == kNoMatching )
89 {
90 return true;
91 }
92
93
94 if ( iMatching == kStrictMatching )
95 {
96 return iMetaData.get( "schemaObjTitle" ) == getSchemaObjTitle() ||
97 iMetaData.get( "schema" ) == getSchemaObjTitle();
98 }
99
100 if ( iMatching == kSchemaTitleMatching )
101 {
102 return iMetaData.get( "schema" ) == getSchemaTitle();
103 }
104
105 return false;
106 }
107
111 static bool matches( const AbcA::ObjectHeader &iHeader,
112 SchemaInterpMatching iMatching = kStrictMatching )
113 {
114 return matches( iHeader.getMetaData(), iMatching );
115 }
116
117
118 //-*************************************************************************
119 // CONSTRUCTION, DESTRUCTION, ASSIGNMENT
120 //-*************************************************************************
121
124 ISchemaObject() {}
125
127 ISchemaObject( const IObject & iParent,
128 const std::string &iName,
129 const Argument &iArg0 = Argument(),
130 const Argument &iArg1 = Argument() )
131 : IObject( iParent, iName, GetErrorHandlerPolicyFromArgs( iArg0, iArg1 ) )
132 {
133 Arguments args;
134 iArg0.setInto( args );
135 iArg1.setInto( args );
136
137 ALEMBIC_ABC_SAFE_CALL_BEGIN(
138 "ISchemaObject::ISchemaObject( IObject )" );
139
140 const AbcA::ObjectHeader &oheader = this->getHeader();
141
142 ABCA_ASSERT( matches( oheader, args.getSchemaInterpMatching() ),
143 "Incorrect match of schema: "
144 << oheader.getMetaData().get( "schema" )
145 << " to expected: "
146 << getSchemaTitle() );
147
148 ABCA_ASSERT(m_object, "Bad child: " << iName);
149 // Make the schema.
150 m_schema = SCHEMA( m_object->getProperties(),
151 SCHEMA::getDefaultSchemaName(),
152 this->getErrorHandlerPolicy(),
153 args.getSchemaInterpMatching() );
154
155 ALEMBIC_ABC_SAFE_CALL_END_RESET();
156 }
157
160 ISchemaObject( const IObject & iObject,
161 const Argument &iArg0 = Argument(),
162 const Argument &iArg1 = Argument() )
163 : IObject( iObject )
164 {
165 getErrorHandler().setPolicy(
166 GetErrorHandlerPolicy( iObject, iArg0, iArg1 ) );
167
168 ALEMBIC_ABC_SAFE_CALL_BEGIN(
169 "ISchemaObject::ISchemaObject( wrap )" );
170
171 const AbcA::ObjectHeader &oheader = this->getHeader();
172
173 ABCA_ASSERT( matches( oheader.getMetaData(),
174 GetSchemaInterpMatching( iArg0, iArg1 ) ),
175 "Incorrect match of schema: "
176 << oheader.getMetaData().get( "schemaObjTitle" )
177 << " to expected: "
178 << getSchemaObjTitle() );
179
180 m_schema = SCHEMA( this->getProperties(),
181 SCHEMA::getDefaultSchemaName(),
182 this->getErrorHandlerPolicy(),
183 GetSchemaInterpMatching( iArg0, iArg1 ) );
184
185 ALEMBIC_ABC_SAFE_CALL_END_RESET();
186 }
187
188 // Deprecated in favor of the constructor above
189 ISchemaObject( const IObject & iObject,
190 WrapExistingFlag iFlag,
191 const Argument &iArg0 = Argument(),
192 const Argument &iArg1 = Argument() )
193 : IObject( iObject )
194 {
195 getErrorHandler().setPolicy(
196 GetErrorHandlerPolicy( iObject, iArg0, iArg1 ) );
197
198 ALEMBIC_ABC_SAFE_CALL_BEGIN(
199 "ISchemaObject::ISchemaObject( wrapflag )" );
200
201 const AbcA::ObjectHeader &oheader = this->getHeader();
202
203 ABCA_ASSERT( matches( oheader.getMetaData(),
204 GetSchemaInterpMatching( iArg0, iArg1 ) ),
205 "Incorrect match of schema: "
206 << oheader.getMetaData().get( "schemaObjTitle" )
207 << " to expected: "
208 << getSchemaObjTitle() );
209
210 m_schema = SCHEMA( this->getProperties(),
211 SCHEMA::getDefaultSchemaName(),
212 this->getErrorHandlerPolicy(),
213 GetSchemaInterpMatching( iArg0, iArg1 ) );
214
215 ALEMBIC_ABC_SAFE_CALL_END_RESET();
216 }
217
218 //-*************************************************************************
219 // ABC BASE MECHANISMS
220 // These functions are used by Abc to deal with errors, rewrapping,
221 // and so on.
222 //-*************************************************************************
223
226 SCHEMA &getSchema() { return m_schema; }
227 const SCHEMA &getSchema() const { return m_schema; }
228
231 void reset() { m_schema.reset(); IObject::reset(); }
232
235 bool valid() const
236 {
237 return ( IObject::valid() && m_schema.valid() );
238 }
239
242 ALEMBIC_OVERRIDE_OPERATOR_BOOL( this_type::valid() );
243
244 protected:
245 SCHEMA m_schema;
246};
247
248//-*****************************************************************************
249// TEMPLATE AND INLINE FUNCTIONS
250//-*****************************************************************************
251
252 inline ErrorHandler::Policy GetErrorHandlerPolicy( const Argument &iArg0,
253 const Argument &iArg1 )
254{
255 Arguments args;
256 iArg0.setInto( args );
257 iArg1.setInto( args );
258 return args.getErrorHandlerPolicy();
259}
260
261} // End namespace ALEMBIC_VERSION_NS
262
263 using namespace ALEMBIC_VERSION_NS;
264
265} // End namespace Abc
266} // End namespace Alembic
267
268#endif
Alembic::Abc::ALEMBIC_VERSION_NS::Argument
Definition Argument.h:120
Alembic::Abc::ALEMBIC_VERSION_NS::Arguments
Definition Argument.h:49
Alembic::Abc::ALEMBIC_VERSION_NS::IObject
Definition IObject.h:54
Alembic::Abc::ALEMBIC_VERSION_NS::IObject::IObject
IObject()
Definition IObject.h:68
Alembic::Abc::ALEMBIC_VERSION_NS::IObject::getHeader
const AbcA::ObjectHeader & getHeader() const
Definition IObject.cpp:67
Alembic::Abc::ALEMBIC_VERSION_NS::IObject::getProperties
ICompoundProperty getProperties() const
Definition IObject.cpp:379
Alembic::Abc::ALEMBIC_VERSION_NS::IObject::reset
void reset()
Reset returns this function set to an empty, default state.
Definition IObject.cpp:369
Alembic::Abc::ALEMBIC_VERSION_NS::IObject::valid
bool valid() const
Definition IObject.h:251
Alembic::Abc::ALEMBIC_VERSION_NS::ISchemaObject::ISchemaObject
ISchemaObject(const IObject &iObject, const Argument &iArg0=Argument(), const Argument &iArg1=Argument())
Definition ISchemaObject.h:160
Alembic::Abc::ALEMBIC_VERSION_NS::ISchemaObject::ALEMBIC_OVERRIDE_OPERATOR_BOOL
ALEMBIC_OVERRIDE_OPERATOR_BOOL(this_type::valid())
Alembic::Abc::ALEMBIC_VERSION_NS::ISchemaObject::valid
bool valid() const
Definition ISchemaObject.h:235
Alembic::Abc::ALEMBIC_VERSION_NS::ISchemaObject::reset
void reset()
Definition ISchemaObject.h:231
Alembic::Abc::ALEMBIC_VERSION_NS::ISchemaObject::getSchemaObjTitle
static std::string getSchemaObjTitle()
Definition ISchemaObject.h:70
Alembic::Abc::ALEMBIC_VERSION_NS::ISchemaObject::getSchema
SCHEMA & getSchema()
Definition ISchemaObject.h:226
Alembic::Abc::ALEMBIC_VERSION_NS::ISchemaObject::ISchemaObject
ISchemaObject(const IObject &iParent, const std::string &iName, const Argument &iArg0=Argument(), const Argument &iArg1=Argument())
The primary constructor creates an ISchemaObject as a child of iParent.
Definition ISchemaObject.h:127
Alembic::Abc::ALEMBIC_VERSION_NS::ISchemaObject::matches
static bool matches(const AbcA::MetaData &iMetaData, SchemaInterpMatching iMatching=kStrictMatching)
Definition ISchemaObject.h:84
Alembic::Abc::ALEMBIC_VERSION_NS::ISchemaObject::ISchemaObject
ISchemaObject()
Definition ISchemaObject.h:124
Alembic::Abc::ALEMBIC_VERSION_NS::ISchemaObject::matches
static bool matches(const AbcA::ObjectHeader &iHeader, SchemaInterpMatching iMatching=kStrictMatching)
Definition ISchemaObject.h:111
Alembic
Alembic namespace ...
Definition ArchiveInfo.cpp:39