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
41#include <Alembic/Abc/OObject.h>
42#include <Alembic/Abc/OSchema.h>
43
44namespace Alembic {
45namespace Abc {
46namespace ALEMBIC_VERSION_NS {
47
48//-*****************************************************************************
52template <class SCHEMA>
53class OSchemaObject : public OObject
54{
55public:
56 //-*************************************************************************
57 // TYPEDEFS AND IDENTIFIERS
58 //-*************************************************************************
59 typedef SCHEMA schema_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,
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,
107 {
108 return matches( iHeader.getMetaData(), iMatching );
109 }
110
111
112 //-*************************************************************************
113 // CONSTRUCTION, DESTRUCTION, ASSIGNMENT
114 //-*************************************************************************
115
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
155
156protected:
157 SCHEMA m_schema;
158};
159
160//-*****************************************************************************
161// TEMPLATE AND INLINE FUNCTIONS
162//-*****************************************************************************
163
164//-*****************************************************************************
165template <class SCHEMA>
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
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
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
234}
235
236} // End namespace ALEMBIC_VERSION_NS
237
238using namespace ALEMBIC_VERSION_NS;
239
240} // End namespace Abc
241} // End namespace Alembic
242
243#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 set(const std::string &iKey, const std::string &iData)
Definition MetaData.h:168
void setInto(Arguments &iArgs) const
Definition Argument.h:149
const AbcA::MetaData & getMetaData() const
Definition Argument.h:86
ErrorHandler::Policy getErrorHandlerPolicy() const
Definition Argument.h:83
AbcA::TimeSamplingPtr getTimeSampling() const
Definition Argument.h:89
static bool matches(const AbcA::ObjectHeader &iHeader, SchemaInterpMatching iMatching=kStrictMatching)
static bool matches(const AbcA::MetaData &iMetaData, SchemaInterpMatching iMatching=kStrictMatching)
Alembic::Util::shared_ptr< ObjectWriter > ObjectWriterPtr
Alembic::Util::shared_ptr< TimeSampling > TimeSamplingPtr
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 namespace ...
Definition ArchiveInfo.h:46