Alembic Version 1.1
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
41#include <Alembic/Abc/OSchema.h>
43
44namespace Alembic {
45namespace Abc {
46namespace ALEMBIC_VERSION_NS {
47
48//-*****************************************************************************
51//-*****************************************************************************
52
53//-*****************************************************************************
56template <class INFO>
58{
59public:
60 //-*************************************************************************
61 // TYPEDEFS AND IDENTIFIERS
62 //-*************************************************************************
63 typedef INFO info_type;
65
68 static const char * getSchemaTitle()
69 {
70 return INFO::title();
71 }
72
75 static const char * getDefaultSchemaName()
76 {
77 return INFO::defaultName();
78 }
79
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
100 static bool matches( const AbcA::PropertyHeader &iHeader,
102 {
103 return matches( iHeader.getMetaData(), iMatching );
104 }
105
106 //-*************************************************************************
107 // CONSTRUCTION, DESTRUCTION, ASSIGNMENT
108 //-*************************************************************************
109
113
117 ISchema( const ICompoundProperty &iParent,
118 const std::string &iName,
119 const Argument &iArg0 = Argument(),
120 const Argument &iArg1 = Argument() )
121 {
122 init( iParent, iName, iArg0, iArg1 );
123 }
124
128 ISchema( const ICompoundProperty &iProperty,
129 const Argument &iArg0 = Argument(),
130 const Argument &iArg1 = Argument() )
131 : ICompoundProperty( iProperty.getPtr(),
132 GetErrorHandlerPolicy( iProperty, iArg0, iArg1 ) )
133 {
134 ALEMBIC_ABC_SAFE_CALL_BEGIN( "ISchema::ISchema( wrap )" );
135
136 const AbcA::PropertyHeader &pheader = this->getHeader();
137
138 ABCA_ASSERT( matches( pheader,
139 GetSchemaInterpMatching( iArg0, iArg1 ) ),
140 "Incorrect match of schema: "
141 << pheader.getMetaData().get( "schema" )
142 << " to expected: "
143 << INFO::title() );
144
145 // not wrapped, we want to use the default name
146 if ( !iProperty.getParent().valid() )
147 {
148 init( iProperty, getDefaultSchemaName(),
149 iArg0, iArg1 );
150 }
151
153 }
154
155 // Deprecated in favor of the constructor above
156 ISchema( const ICompoundProperty &iProperty,
157 WrapExistingFlag iFlag,
158 const Argument &iArg0 = Argument(),
159 const Argument &iArg1 = Argument() )
160 {
161 *this = ISchema( iProperty, iArg0, iArg1 );
162 }
163
166 //
167 virtual ~ISchema() {}
168
169private:
170 void init( const ICompoundProperty & iParentObject,
171 const std::string &iName,
172 const Argument &iArg0,
173 const Argument &iArg1 );
174};
175
176//-*****************************************************************************
177// TEMPLATE AND INLINE FUNCTIONS
178//-*****************************************************************************
179template <class INFO>
180void ISchema<INFO>::init( const ICompoundProperty & iParent,
181 const std::string &iName,
182 const Argument &iArg0,
183 const Argument &iArg1 )
184{
185 Arguments args;
186 iArg0.setInto( args );
187 iArg1.setInto( args );
188
189 getErrorHandler().setPolicy( args.getErrorHandlerPolicy() );
190
191 ALEMBIC_ABC_SAFE_CALL_BEGIN( "ISchema::ISchema::init()" );
192
193 // Get actual reader for parent.
194 ABCA_ASSERT( iParent,
195 "NULL parent passed into ISchema ctor" );
196 AbcA::CompoundPropertyReaderPtr parent = iParent.getPtr();
197 ABCA_ASSERT( parent, "NULL CompoundPropertyReaderPtr" );
198
199 const AbcA::PropertyHeader *pheader = parent->getPropertyHeader( iName );
200
201 ABCA_ASSERT( pheader != NULL,
202 "Nonexistent compound property: " << iName );
203
204 // Check metadata for schema.
205 ABCA_ASSERT( matches( *pheader, args.getSchemaInterpMatching() ),
206
207 "Incorrect match of schema: "
208 << pheader->getMetaData().get( "schema" )
209 << " to expected: "
210 << INFO::title() );
211
212 // Get property.
213 m_property = parent->getCompoundProperty( iName );
214
216}
217
218} // End namespace ALEMBIC_VERSION_NS
219
220using namespace ALEMBIC_VERSION_NS;
221
222} // End namespace Abc
223} // End namespace Alembic
224
225#endif
#define ABCA_ASSERT(COND, TEXT)
Definition: Foundation.h:99
#define ALEMBIC_ABC_SAFE_CALL_BEGIN(CONTEXT)
Definition: ErrorHandler.h:172
#define ALEMBIC_ABC_SAFE_CALL_END_RESET()
Definition: ErrorHandler.h:181
#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
static bool matches(const AbcA::PropertyHeader &iHeader, SchemaInterpMatching iMatching=kStrictMatching)
Definition: ISchema.h:100
static const char * getDefaultSchemaName()
Definition: ISchema.h:75
static bool matches(const AbcA::MetaData &iMetaData, SchemaInterpMatching iMatching=kStrictMatching)
Definition: ISchema.h:83
ISchema(const ICompoundProperty &iProperty, const Argument &iArg0=Argument(), const Argument &iArg1=Argument())
Definition: ISchema.h:128
static const char * getSchemaTitle()
Definition: ISchema.h:68
ISchema(const ICompoundProperty &iParent, const std::string &iName, const Argument &iArg0=Argument(), const Argument &iArg1=Argument())
Definition: ISchema.h:117
ISchema(const ICompoundProperty &iProperty, WrapExistingFlag iFlag, const Argument &iArg0=Argument(), const Argument &iArg1=Argument())
Definition: ISchema.h:156
Alembic::Util::shared_ptr< CompoundPropertyReader > CompoundPropertyReaderPtr
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