Alembic Version 1.1

Loading...
Searching...
No Matches
OSchemaObject.h
Go to the documentation of this file.
1//-*****************************************************************************
2//
3// Copyright (c) 2009-2012,
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_OSchemaObject_h
38#define Alembic_Abc_OSchemaObject_h
39
40#include <Alembic/Abc/Foundation.h>
41#include <Alembic/Abc/OObject.h>
42#include <Alembic/Abc/OSchema.h>
43
44 namespace Alembic {
45 namespace Abc {
46 namespace ALEMBIC_VERSION_NS {
47
48//-*****************************************************************************
52 template <class SCHEMA>
53 class OSchemaObject : public OObject
54{
55 public:
56 //-*************************************************************************
57 // TYPEDEFS AND IDENTIFIERS
58 //-*************************************************************************
59 typedef SCHEMA schema_type;
60 typedef OSchemaObject<SCHEMA> this_type;
61
68 static std::string getSchemaObjTitle()
69 {
70 return SCHEMA::getSchemaTitle() + std::string( ":" ) +
71 SCHEMA::getDefaultSchemaName();
72 }
73
74 static const char * getSchemaTitle()
75 {
76 return SCHEMA::getSchemaTitle();
77 }
78
82 static bool matches( const AbcA::MetaData &iMetaData,
83 SchemaInterpMatching iMatching = kStrictMatching )
84 {
85 if ( std::string() == getSchemaTitle() || iMatching == kNoMatching )
86 { return true; }
87
88 if ( iMatching == kStrictMatching )
89 {
90
91 return iMetaData.get( "schemaObjTitle" ) == getSchemaObjTitle();
92 }
93
94 if ( iMatching == kSchemaTitleMatching )
95 {
96 return iMetaData.get( "schema" ) == getSchemaTitle();
97 }
98
99 return false;
100 }
101
105 static bool matches( const AbcA::ObjectHeader &iHeader,
106 SchemaInterpMatching iMatching = kStrictMatching )
107 {
108 return matches( iHeader.getMetaData(), iMatching );
109 }
110
111
112 //-*************************************************************************
113 // CONSTRUCTION, DESTRUCTION, ASSIGNMENT
114 //-*************************************************************************
115
118 OSchemaObject() {}
119
123 OSchemaObject( OObject iParent,
124 const std::string &iName,
125
126 const Argument &iArg0 = Argument(),
127 const Argument &iArg1 = Argument(),
128 const Argument &iArg2 = Argument() );
129
130 //-*************************************************************************
131 // ABC BASE MECHANISMS
132 // These functions are used by Abc to deal with errors, validity,
133 // and so on.
134 //-*************************************************************************
135
138 SCHEMA &getSchema() { return m_schema; }
139 const SCHEMA &getSchema() const { return m_schema; }
140
143 void reset() { m_schema.reset(); OObject::reset(); }
144
147 bool valid() const
148 {
149 return ( OObject::valid() && m_schema.valid() );
150 }
151
154 ALEMBIC_OVERRIDE_OPERATOR_BOOL( this_type::valid() );
155
156 protected:
157 SCHEMA m_schema;
158};
159
160//-*****************************************************************************
161// TEMPLATE AND INLINE FUNCTIONS
162//-*****************************************************************************
163
164//-*****************************************************************************
165 template <class SCHEMA>
166 OSchemaObject<SCHEMA>::OSchemaObject
167(
168 OObject iParent,
169 const std::string &iName,
170 const Argument &iArg0,
171 const Argument &iArg1,
172 const Argument &iArg2 )
173{
174 Arguments args( GetErrorHandlerPolicy( iParent ) );
175 iArg0.setInto( args );
176 iArg1.setInto( args );
177 iArg2.setInto( args );
178
179 getErrorHandler().setPolicy( args.getErrorHandlerPolicy() );
180
181 ALEMBIC_ABC_SAFE_CALL_BEGIN(
182 "OSchemaObject::OSchemaObject( OObject )" );
183
184 // Extract the parent.
185 AbcA::ObjectWriterPtr parent = iParent.getPtr();
186 ABCA_ASSERT( parent,
187 "NULL Parent ObjectWriter in OSchemaObject ctor" );
188
189 // The object schema title is derived from the schema's title.
190 // It is never empty (unless sparse)
191 AbcA::MetaData metaData = args.getMetaData();
192
193 SparseFlag sparseFlag = kSparse;
194 if ( !args.isSparse() )
195 {
196 sparseFlag = kFull;
197 metaData.set( "schema", SCHEMA::getSchemaTitle() );
198 metaData.set( "schemaObjTitle", getSchemaObjTitle() );
199 if ( std::string() != SCHEMA::getSchemaBaseType() )
200 {
201 metaData.set( "schemaBaseType", SCHEMA::getSchemaBaseType() );
202 }
203 }
204
205 // Make the object.
206 AbcA::ObjectHeader ohdr( iName, metaData );
207 m_object = parent->createChild( ohdr );
208
209 AbcA::TimeSamplingPtr tsPtr = args.getTimeSampling();
210 uint32_t tsIndex = args.getTimeSamplingIndex();
211
212 // if we specified a valid TimeSamplingPtr, use it to determine the index
213 // otherwise we'll use the index, which defaults to the intrinsic 0 index
214 if (tsPtr)
215 {
216 tsIndex = parent->getArchive()->addTimeSampling(*tsPtr);
217 }
218
219 AbcA::MetaData schemaMetaData;
220 if ( args.isSparse() && SCHEMA::replaceOnSparse() )
221 {
222 schemaMetaData.set( "replace", "1" );
223 }
224
225 // Make the schema.
226 m_schema = SCHEMA( m_object->getProperties(),
227 SCHEMA::getDefaultSchemaName(),
228 this->getErrorHandlerPolicy(),
229 tsIndex,
230 schemaMetaData,
231 sparseFlag );
232
233 ALEMBIC_ABC_SAFE_CALL_END_RESET();
234}
235
236} // End namespace ALEMBIC_VERSION_NS
237
238 using namespace ALEMBIC_VERSION_NS;
239
240} // End namespace Abc
241} // End namespace Alembic
242
243#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
OObject.h
OSchema.h
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::getMetaData
const AbcA::MetaData & getMetaData() const
Definition Argument.h:86
Alembic::Abc::ALEMBIC_VERSION_NS::Arguments::isSparse
bool isSparse() const
Definition Argument.h:98
Alembic::Abc::ALEMBIC_VERSION_NS::Arguments::getTimeSamplingIndex
uint32_t getTimeSamplingIndex() const
Definition Argument.h:92
Alembic::Abc::ALEMBIC_VERSION_NS::Arguments::getErrorHandlerPolicy
ErrorHandler::Policy getErrorHandlerPolicy() const
Definition Argument.h:83
Alembic::Abc::ALEMBIC_VERSION_NS::Arguments::getTimeSampling
AbcA::TimeSamplingPtr getTimeSampling() const
Definition Argument.h:89
Alembic::Abc::ALEMBIC_VERSION_NS::Base::getErrorHandler
ErrorHandler & getErrorHandler() const
Definition Base.h:76
Alembic::Abc::ALEMBIC_VERSION_NS::OObject::OObject
OObject()
Definition OObject.h:68
Alembic::Abc::ALEMBIC_VERSION_NS::OObject::getPtr
AbcA::ObjectWriterPtr getPtr()
Definition OObject.h:220
Alembic::Abc::ALEMBIC_VERSION_NS::OObject::reset
void reset()
Definition OObject.h:225
Alembic::Abc::ALEMBIC_VERSION_NS::OObject::m_object
AbcA::ObjectWriterPtr m_object
Definition OObject.h:254
Alembic::Abc::ALEMBIC_VERSION_NS::OObject::valid
bool valid() const
Definition OObject.h:229
Alembic::Abc::ALEMBIC_VERSION_NS::OSchemaObject::this_type
OSchemaObject< SCHEMA > this_type
Definition OSchemaObject.h:60
Alembic::Abc::ALEMBIC_VERSION_NS::OSchemaObject::reset
void reset()
Definition OSchemaObject.h:143
Alembic::Abc::ALEMBIC_VERSION_NS::OSchemaObject::OSchemaObject
OSchemaObject()
Definition OSchemaObject.h:118
Alembic::Abc::ALEMBIC_VERSION_NS::OSchemaObject::getSchema
const SCHEMA & getSchema() const
Definition OSchemaObject.h:139
Alembic::Abc::ALEMBIC_VERSION_NS::OSchemaObject::getSchemaObjTitle
static std::string getSchemaObjTitle()
Definition OSchemaObject.h:68
Alembic::Abc::ALEMBIC_VERSION_NS::OSchemaObject::OSchemaObject
OSchemaObject(OObject iParent, const std::string &iName, const Argument &iArg0=Argument(), const Argument &iArg1=Argument(), const Argument &iArg2=Argument())
Definition OSchemaObject.h:167
Alembic::Abc::ALEMBIC_VERSION_NS::OSchemaObject::matches
static bool matches(const AbcA::ObjectHeader &iHeader, SchemaInterpMatching iMatching=kStrictMatching)
Definition OSchemaObject.h:105
Alembic::Abc::ALEMBIC_VERSION_NS::OSchemaObject< OCollectionsSchema >::m_schema
OCollectionsSchema m_schema
Definition OSchemaObject.h:157
Alembic::Abc::ALEMBIC_VERSION_NS::OSchemaObject::ALEMBIC_OVERRIDE_OPERATOR_BOOL
ALEMBIC_OVERRIDE_OPERATOR_BOOL(this_type::valid())
Alembic::Abc::ALEMBIC_VERSION_NS::OSchemaObject::valid
bool valid() const
Definition OSchemaObject.h:147
Alembic::Abc::ALEMBIC_VERSION_NS::OSchemaObject::matches
static bool matches(const AbcA::MetaData &iMetaData, SchemaInterpMatching iMatching=kStrictMatching)
Definition OSchemaObject.h:82
Alembic::Abc::ALEMBIC_VERSION_NS::OSchemaObject::getSchema
SCHEMA & getSchema()
Definition OSchemaObject.h:138
Alembic::Abc::ALEMBIC_VERSION_NS::OSchemaObject::getSchemaTitle
static const char * getSchemaTitle()
Definition OSchemaObject.h:74
Alembic::Abc::ALEMBIC_VERSION_NS::OSchemaObject::schema_type
SCHEMA schema_type
Definition OSchemaObject.h:59
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::SparseFlag
SparseFlag
Definition Foundation.h:113
Alembic::Abc::ALEMBIC_VERSION_NS::kSparse
@ kSparse
Definition Foundation.h:115
Alembic::Abc::ALEMBIC_VERSION_NS::kFull
@ kFull
Definition Foundation.h:114
Alembic::Abc
Definition ArchiveInfo.h:47
Alembic
Alembic namespace ...
Definition ArchiveInfo.h:46