Alembic Version 1.1
Loading...
Searching...
No Matches
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
41#include <Alembic/Abc/IObject.h>
42#include <Alembic/Abc/ISchema.h>
44#include <Alembic/Abc/Base.h>
45
46namespace Alembic {
47namespace Abc {
48namespace ALEMBIC_VERSION_NS {
49
50//-*****************************************************************************
54template <class SCHEMA>
55class ISchemaObject : public IObject
56{
57public:
58 //-*************************************************************************
59 // TYPEDEFS AND IDENTIFIERS
60 //-*************************************************************************
61 typedef SCHEMA schema_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,
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,
113 {
114 return matches( iHeader.getMetaData(), iMatching );
115 }
116
117
118 //-*************************************************************************
119 // CONSTRUCTION, DESTRUCTION, ASSIGNMENT
120 //-*************************************************************************
121
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
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(),
153
155 }
156
159 ISchemaObject( const IObject & iObject,
160 const Argument &iArg0 = Argument(),
161 const Argument &iArg1 = Argument() )
162 : IObject( iObject )
163 {
165 GetErrorHandlerPolicy( iObject, iArg0, iArg1 ) );
166
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
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 {
195 GetErrorHandlerPolicy( iObject, iArg0, iArg1 ) );
196
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
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
243protected:
244 SCHEMA m_schema;
245};
246
247//-*****************************************************************************
248// TEMPLATE AND INLINE FUNCTIONS
249//-*****************************************************************************
250
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
262using namespace ALEMBIC_VERSION_NS;
263
264} // End namespace Abc
265} // End namespace Alembic
266
267#endif
#define ABCA_ASSERT(COND, TEXT)
Definition Foundation.h:99
#define ALEMBIC_ABC_SAFE_CALL_BEGIN(CONTEXT)
#define ALEMBIC_ABC_SAFE_CALL_END_RESET()
#define ALEMBIC_VERSION_NS
Definition Foundation.h:105
std::string get(const std::string &iKey) const
Definition MetaData.h:192
void setInto(Arguments &iArgs) const
Definition Argument.h:149
SchemaInterpMatching getSchemaInterpMatching() const
Definition Argument.h:95
ErrorHandler::Policy getErrorHandlerPolicy() const
Definition Argument.h:83
ErrorHandler & getErrorHandler() const
Definition Base.h:76
ErrorHandler::Policy getErrorHandlerPolicy() const
Definition Base.h:81
const AbcA::ObjectHeader & getHeader() const
ICompoundProperty getProperties() const
void reset()
Reset returns this function set to an empty, default state.
ISchemaObject(const IObject &iObject, const Argument &iArg0=Argument(), const Argument &iArg1=Argument())
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.
static bool matches(const AbcA::MetaData &iMetaData, SchemaInterpMatching iMatching=kStrictMatching)
ISchemaObject(const IObject &iObject, WrapExistingFlag iFlag, const Argument &iArg0=Argument(), const Argument &iArg1=Argument())
static bool matches(const AbcA::ObjectHeader &iHeader, SchemaInterpMatching iMatching=kStrictMatching)
ErrorHandler::Policy GetErrorHandlerPolicyFromArgs(const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument(), const Argument &iArg3=Argument())
Definition Argument.h:258
ErrorHandler::Policy GetErrorHandlerPolicy(SOMETHING iSomething, const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument(), const Argument &iArg3=Argument())
Definition Argument.h:242
SchemaInterpMatching GetSchemaInterpMatching(const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument(), const Argument &iArg3=Argument())
Definition Argument.h:318
Alembic namespace ...
Definition ArchiveInfo.h:46