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
40#include <Alembic/Abc/Foundation.h>
41#include <Alembic/Abc/OSchema.h>
42#include <Alembic/Abc/ICompoundProperty.h>
43
44 namespace Alembic {
45 namespace Abc {
46 namespace ALEMBIC_VERSION_NS {
47
48//-*****************************************************************************
51//-*****************************************************************************
52
53//-*****************************************************************************
56 template <class INFO>
57 class ISchema : public ICompoundProperty
58{
59 public:
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
169 private:
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//-*****************************************************************************
179 template <class INFO>
180 void 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
220 using namespace ALEMBIC_VERSION_NS;
221
222} // End namespace Abc
223} // End namespace Alembic
224
225#endif
ABCA_ASSERT
#define ABCA_ASSERT(COND, TEXT)
Definition: Foundation.h:99
Foundation.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
ICompoundProperty.h
OSchema.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::PropertyHeader
Definition: PropertyHeader.h:79
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::PropertyHeader::getMetaData
const MetaData & getMetaData() const
Definition: PropertyHeader.h:165
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::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::getParent
ICompoundProperty getParent() const
Alembic::Abc::ALEMBIC_VERSION_NS::ISchema
Definition: ISchema.h:58
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::this_type
ISchema< INFO > this_type
Definition: ISchema.h:64
Alembic::Abc::ALEMBIC_VERSION_NS::ISchema::getSchemaTitle
static const char * getSchemaTitle()
Definition: ISchema.h:68
Alembic::Abc::ALEMBIC_VERSION_NS::ISchema::info_type
INFO info_type
Definition: ISchema.h:63
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::Abc::ALEMBIC_VERSION_NS::ISchema::ISchema
ISchema(const ICompoundProperty &iProperty, WrapExistingFlag iFlag, const Argument &iArg0=Argument(), const Argument &iArg1=Argument())
Definition: ISchema.h:156
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::CompoundPropertyReaderPtr
Alembic::Util::shared_ptr< CompoundPropertyReader > CompoundPropertyReaderPtr
Definition: ForwardDeclarations.h:92
Alembic::Abc::ALEMBIC_VERSION_NS
Definition: ArchiveInfo.h:48
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