Alembic: Abc/ISchema.h Source File

Alembic 1.8.11

Loading...
Searching...
No Matches
ISchema.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_ISchema_h
38#define Alembic_Abc_ISchema_h
39
40#include <Alembic/Abc/Foundation.h>
41#include <Alembic/Abc/OSchema.h>
42#include <Alembic/Abc/ICompoundProperty.h>
43
44namespace Alembic {
45namespace Abc {
46namespace ALEMBIC_VERSION_NS {
47
48//-*****************************************************************************
51//-*****************************************************************************
52
53//-*****************************************************************************
56template <class INFO>
57 class ISchema : public ICompoundProperty
58{
59public:
60 //-*************************************************************************
61 // TYPEDEFS AND IDENTIFIERS
62 //-*************************************************************************
63 typedef INFO info_type;
64 typedef ISchema<INFO> this_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,
84 SchemaInterpMatching iMatching = kStrictMatching )
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,
101 SchemaInterpMatching iMatching = kStrictMatching )
102 {
103 return matches( iHeader.getMetaData(), iMatching );
104 }
105
106 //-*************************************************************************
107 // CONSTRUCTION, DESTRUCTION, ASSIGNMENT
108 //-*************************************************************************
109
112 ISchema() {}
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
152 ALEMBIC_ABC_SAFE_CALL_END_RESET();
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
215 ALEMBIC_ABC_SAFE_CALL_END_RESET();
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
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::IBasePropertyT< AbcA::CompoundPropertyReaderPtr >::getHeader
const AbcA::PropertyHeader & getHeader() const
Definition IBaseProperty.h:192
Alembic::Abc::ALEMBIC_VERSION_NS::IBasePropertyT::valid
bool valid() const
Definition IBaseProperty.h:164
Alembic::Abc::ALEMBIC_VERSION_NS::IBasePropertyT< AbcA::CompoundPropertyReaderPtr >::getPtr
AbcA::CompoundPropertyReaderPtr getPtr() const
Definition IBaseProperty.h:156
Alembic::Abc::ALEMBIC_VERSION_NS::ICompoundProperty
Definition ICompoundProperty.h:53
Alembic::Abc::ALEMBIC_VERSION_NS::ICompoundProperty::ICompoundProperty
ICompoundProperty()
Definition ICompoundProperty.h:65
Alembic::Abc::ALEMBIC_VERSION_NS::ICompoundProperty::getParent
ICompoundProperty getParent() const
Definition ICompoundProperty.cpp:139
Alembic::Abc::ALEMBIC_VERSION_NS::ISchema::matches
static bool matches(const AbcA::PropertyHeader &iHeader, SchemaInterpMatching iMatching=kStrictMatching)
Definition ISchema.h:100
Alembic::Abc::ALEMBIC_VERSION_NS::ISchema::~ISchema
virtual ~ISchema()
Definition ISchema.h:167
Alembic::Abc::ALEMBIC_VERSION_NS::ISchema::getDefaultSchemaName
static const char * getDefaultSchemaName()
Definition ISchema.h:75
Alembic::Abc::ALEMBIC_VERSION_NS::ISchema::matches
static bool matches(const AbcA::MetaData &iMetaData, SchemaInterpMatching iMatching=kStrictMatching)
Definition ISchema.h:83
Alembic::Abc::ALEMBIC_VERSION_NS::ISchema::ISchema
ISchema(const ICompoundProperty &iProperty, const Argument &iArg0=Argument(), const Argument &iArg1=Argument())
Definition ISchema.h:128
Alembic::Abc::ALEMBIC_VERSION_NS::ISchema::getSchemaTitle
static const char * getSchemaTitle()
Definition ISchema.h:68
Alembic::Abc::ALEMBIC_VERSION_NS::ISchema::ISchema
ISchema(const ICompoundProperty &iParent, const std::string &iName, const Argument &iArg0=Argument(), const Argument &iArg1=Argument())
Definition ISchema.h:117
Alembic::Abc::ALEMBIC_VERSION_NS::ISchema::ISchema
ISchema()
Definition ISchema.h:112
Alembic
Alembic namespace ...
Definition ArchiveInfo.cpp:39