Alembic Version 1.1

ISchemaObject.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_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 // Make the schema.
149 m_schema = SCHEMA( m_object->getProperties(),
150 SCHEMA::getDefaultSchemaName(),
151 this->getErrorHandlerPolicy(),
152 args.getSchemaInterpMatching() );
153
154 ALEMBIC_ABC_SAFE_CALL_END_RESET();
155 }
156
159 ISchemaObject( const IObject & iObject,
160 const Argument &iArg0 = Argument(),
161 const Argument &iArg1 = Argument() )
162 : IObject( iObject )
163 {
164 getErrorHandler().setPolicy(
165 GetErrorHandlerPolicy( iObject, iArg0, iArg1 ) );
166
167 ALEMBIC_ABC_SAFE_CALL_BEGIN(
168 "ISchemaObject::ISchemaObject( wrap )" );
169
170 const AbcA::ObjectHeader &oheader = this->getHeader();
171
172 ABCA_ASSERT( matches( oheader.getMetaData(),
173 GetSchemaInterpMatching( iArg0, iArg1 ) ),
174 "Incorrect match of schema: "
175 << oheader.getMetaData().get( "schemaObjTitle" )
176 << " to expected: "
177 << getSchemaObjTitle() );
178
179 m_schema = SCHEMA( this->getProperties(),
180 SCHEMA::getDefaultSchemaName(),
181 this->getErrorHandlerPolicy(),
182 GetSchemaInterpMatching( iArg0, iArg1 ) );
183
184 ALEMBIC_ABC_SAFE_CALL_END_RESET();
185 }
186
187 // Deprecated in favor of the constructor above
188 ISchemaObject( const IObject & iObject,
189 WrapExistingFlag iFlag,
190 const Argument &iArg0 = Argument(),
191 const Argument &iArg1 = Argument() )
192 : IObject( iObject )
193 {
194 getErrorHandler().setPolicy(
195 GetErrorHandlerPolicy( iObject, iArg0, iArg1 ) );
196
197 ALEMBIC_ABC_SAFE_CALL_BEGIN(
198 "ISchemaObject::ISchemaObject( wrapflag )" );
199
200 const AbcA::ObjectHeader &oheader = this->getHeader();
201
202 ABCA_ASSERT( matches( oheader.getMetaData(),
203 GetSchemaInterpMatching( iArg0, iArg1 ) ),
204 "Incorrect match of schema: "
205 << oheader.getMetaData().get( "schemaObjTitle" )
206 << " to expected: "
207 << getSchemaObjTitle() );
208
209 m_schema = SCHEMA( this->getProperties(),
210 SCHEMA::getDefaultSchemaName(),
211 this->getErrorHandlerPolicy(),
212 GetSchemaInterpMatching( iArg0, iArg1 ) );
213
214 ALEMBIC_ABC_SAFE_CALL_END_RESET();
215 }
216
217 //-*************************************************************************
218 // ABC BASE MECHANISMS
219 // These functions are used by Abc to deal with errors, rewrapping,
220 // and so on.
221 //-*************************************************************************
222
225 SCHEMA &getSchema() { return m_schema; }
226 const SCHEMA &getSchema() const { return m_schema; }
227
230 void reset() { m_schema.reset(); IObject::reset(); }
231
234 bool valid() const
235 {
236 return ( IObject::valid() && m_schema.valid() );
237 }
238
241 ALEMBIC_OVERRIDE_OPERATOR_BOOL( this_type::valid() );
242
243 protected:
244 SCHEMA m_schema;
245};
246
247//-*****************************************************************************
248// TEMPLATE AND INLINE FUNCTIONS
249//-*****************************************************************************
250
251 inline ErrorHandler::Policy GetErrorHandlerPolicy( const Argument &iArg0,
252 const Argument &iArg1 )
253{
254 Arguments args;
255 iArg0.setInto( args );
256 iArg1.setInto( args );
257 return args.getErrorHandlerPolicy();
258}
259
260} // End namespace ALEMBIC_VERSION_NS
261
262 using namespace ALEMBIC_VERSION_NS;
263
264} // End namespace Abc
265} // End namespace Alembic
266
267#endif
ABCA_ASSERT
#define ABCA_ASSERT(COND, TEXT)
Definition: Foundation.h:99
Foundation.h
Argument.h
Base.h
ALEMBIC_ABC_SAFE_CALL_BEGIN
#define ALEMBIC_ABC_SAFE_CALL_BEGIN(CONTEXT)
Definition: ErrorHandler.h:172
ALEMBIC_ABC_SAFE_CALL_END_RESET
#define ALEMBIC_ABC_SAFE_CALL_END_RESET()
Definition: ErrorHandler.h:181
IObject.h
ISchema.h
ALEMBIC_VERSION_NS
#define ALEMBIC_VERSION_NS
Definition: Foundation.h:105
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::MetaData
Definition: MetaData.h:60
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::MetaData::get
std::string get(const std::string &iKey) const
Definition: MetaData.h:192
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::ObjectHeader
Definition: ObjectHeader.h:52
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::ObjectHeader::getMetaData
const MetaData & getMetaData() const
Definition: ObjectHeader.h:93
Alembic::Abc::ALEMBIC_VERSION_NS::Argument
Definition: Argument.h:120
Alembic::Abc::ALEMBIC_VERSION_NS::Argument::setInto
void setInto(Arguments &iArgs) const
Definition: Argument.h:149
Alembic::Abc::ALEMBIC_VERSION_NS::Arguments
Definition: Argument.h:49
Alembic::Abc::ALEMBIC_VERSION_NS::Arguments::getSchemaInterpMatching
SchemaInterpMatching getSchemaInterpMatching() const
Definition: Argument.h:95
Alembic::Abc::ALEMBIC_VERSION_NS::Arguments::getErrorHandlerPolicy
ErrorHandler::Policy getErrorHandlerPolicy() const
Definition: Argument.h:83
Alembic::Abc::ALEMBIC_VERSION_NS::Base::getErrorHandler
ErrorHandler & getErrorHandler() const
Definition: Base.h:76
Alembic::Abc::ALEMBIC_VERSION_NS::Base::getErrorHandlerPolicy
ErrorHandler::Policy getErrorHandlerPolicy() const
Definition: Base.h:81
Alembic::Abc::ALEMBIC_VERSION_NS::ErrorHandler::setPolicy
void setPolicy(Policy iPolicy)
Definition: ErrorHandler.h:84
Alembic::Abc::ALEMBIC_VERSION_NS::ErrorHandler::Policy
Policy
Definition: ErrorHandler.h:52
Alembic::Abc::ALEMBIC_VERSION_NS::IObject
Definition: IObject.h:54
Alembic::Abc::ALEMBIC_VERSION_NS::IObject::getHeader
const AbcA::ObjectHeader & getHeader() const
Alembic::Abc::ALEMBIC_VERSION_NS::IObject::getProperties
ICompoundProperty getProperties() const
Alembic::Abc::ALEMBIC_VERSION_NS::IObject::m_object
AbcA::ObjectReaderPtr m_object
Definition: IObject.h:269
Alembic::Abc::ALEMBIC_VERSION_NS::IObject::reset
void reset()
Reset returns this function set to an empty, default state.
Alembic::Abc::ALEMBIC_VERSION_NS::IObject::valid
bool valid() const
Definition: IObject.h:251
Alembic::Abc::ALEMBIC_VERSION_NS::ISchemaObject
Definition: ISchemaObject.h:56
Alembic::Abc::ALEMBIC_VERSION_NS::ISchemaObject::this_type
ISchemaObject< SCHEMA > this_type
Definition: ISchemaObject.h:62
Alembic::Abc::ALEMBIC_VERSION_NS::ISchemaObject::ISchemaObject
ISchemaObject(const IObject &iObject, const Argument &iArg0=Argument(), const Argument &iArg1=Argument())
Definition: ISchemaObject.h:159
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:234
Alembic::Abc::ALEMBIC_VERSION_NS::ISchemaObject::reset
void reset()
Definition: ISchemaObject.h:230
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:225
Alembic::Abc::ALEMBIC_VERSION_NS::ISchemaObject::getSchema
const SCHEMA & getSchema() const
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::schema_type
SCHEMA schema_type
Definition: ISchemaObject.h:61
Alembic::Abc::ALEMBIC_VERSION_NS::ISchemaObject::ISchemaObject
ISchemaObject(const IObject &iObject, WrapExistingFlag iFlag, const Argument &iArg0=Argument(), const Argument &iArg1=Argument())
Definition: ISchemaObject.h:188
Alembic::Abc::ALEMBIC_VERSION_NS::ISchemaObject::ISchemaObject
ISchemaObject()
Definition: ISchemaObject.h:124
Alembic::Abc::ALEMBIC_VERSION_NS::ISchemaObject::m_schema
SCHEMA m_schema
Definition: ISchemaObject.h:244
Alembic::Abc::ALEMBIC_VERSION_NS::ISchemaObject::getSchemaTitle
static const char * getSchemaTitle()
Definition: ISchemaObject.h:76
Alembic::Abc::ALEMBIC_VERSION_NS::ISchemaObject::matches
static bool matches(const AbcA::ObjectHeader &iHeader, SchemaInterpMatching iMatching=kStrictMatching)
Definition: ISchemaObject.h:111
Alembic::Abc::ALEMBIC_VERSION_NS
Definition: ArchiveInfo.h:48
Alembic::Abc::ALEMBIC_VERSION_NS::GetErrorHandlerPolicyFromArgs
ErrorHandler::Policy GetErrorHandlerPolicyFromArgs(const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument(), const Argument &iArg3=Argument())
Definition: Argument.h:258
Alembic::Abc::ALEMBIC_VERSION_NS::GetErrorHandlerPolicy
ErrorHandler::Policy GetErrorHandlerPolicy(SOMETHING iSomething, const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument(), const Argument &iArg3=Argument())
Definition: Argument.h:242
Alembic::Abc::ALEMBIC_VERSION_NS::SchemaInterpMatching
SchemaInterpMatching
Definition: Foundation.h:77
Alembic::Abc::ALEMBIC_VERSION_NS::kSchemaTitleMatching
@ kSchemaTitleMatching
Definition: Foundation.h:80
Alembic::Abc::ALEMBIC_VERSION_NS::kNoMatching
@ kNoMatching
Definition: Foundation.h:79
Alembic::Abc::ALEMBIC_VERSION_NS::kStrictMatching
@ kStrictMatching
Definition: Foundation.h:78
Alembic::Abc::ALEMBIC_VERSION_NS::WrapExistingFlag
WrapExistingFlag
Definition: Foundation.h:94
Alembic::Abc::ALEMBIC_VERSION_NS::GetSchemaInterpMatching
SchemaInterpMatching GetSchemaInterpMatching(const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument(), const Argument &iArg3=Argument())
Definition: Argument.h:318
Alembic
Alembic namespace ...
Definition: ArchiveInfo.h:46