Alembic Version 1.1
OTypedScalarProperty.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#ifndef Alembic_Abc_OTypedScalarProperty_h
37#define Alembic_Abc_OTypedScalarProperty_h
38
42
43namespace Alembic {
44namespace Abc {
45namespace ALEMBIC_VERSION_NS {
46
47//-*****************************************************************************
48template <class TRAITS>
50{
51public:
52 //-*************************************************************************
53 // TYPE IDENTIFICATION
54 //-*************************************************************************
55 typedef TRAITS traits_type;
57 typedef typename TRAITS::value_type value_type;
58
61 static const char * getInterpretation()
62 {
63 return TRAITS::interpretation();
64 }
65
69 static bool matches( const AbcA::MetaData &iMetaData,
71 {
72 return ( iMetaData.get( "interpretation" ) ==
74 }
75
79 static bool matches( const AbcA::PropertyHeader &iHeader,
81 {
82 return ( iHeader.getDataType().getPod() ==
83 TRAITS::dataType().getPod() &&
84 ( iHeader.getDataType().getExtent() ==
85 TRAITS::dataType().getExtent() ||
86 std::string() == getInterpretation() ) ) &&
87 iHeader.isScalar() &&
88 matches( iHeader.getMetaData(), iMatching );
89 }
90
91 //-*************************************************************************
92 // CONSTRUCTION, DESTRUCTION, ASSIGNMENT
93 //-*************************************************************************
94
98
104 const std::string &iName,
105
106 const Argument &iArg0 = Argument(),
107 const Argument &iArg1 = Argument(),
108 const Argument &iArg2 = Argument(),
109 const Argument &iArg3 = Argument() )
110 {
111 init( iParent, iName, iArg0, iArg1, iArg2, iArg3 );
112 }
113
118 OCompoundProperty iParent,
119 const std::string &iName,
120
121 const Argument &iArg0 = Argument(),
122 const Argument &iArg1 = Argument(),
123 const Argument &iArg2 = Argument() )
124 {
125 init( iParent.getPtr(), iName, GetErrorHandlerPolicy( iParent ),
126 iArg0, iArg1, iArg2 );
127 }
128
134 const Argument &iArg0 = Argument(),
135 const Argument &iArg1 = Argument() )
136 : OScalarProperty( iProp, GetErrorHandlerPolicy( iProp, iArg0, iArg1 ) )
137 {
139 "OTypedScalarProperty::OTypedScalarProperty()" );
140
141 const AbcA::PropertyHeader &pheader = iProp->getHeader();
142
143 ABCA_ASSERT( matches( pheader, GetSchemaInterpMatching( iArg0,iArg1 ) ),
144
145 "Incorrect match of header datatype: "
146 << pheader.getDataType()
147 << " to expected: "
148 << TRAITS::dataType()
149 << ",\n...or incorrect match of interpretation: "
150 << pheader.getMetaData().get( "interpretation" )
151 << " to expected: "
152 << TRAITS::interpretation() );
153
155 }
156
157 // Deprecated in favor of the constructor above
160 WrapExistingFlag iWrapFlag,
161 const Argument &iArg0 = Argument(),
162 const Argument &iArg1 = Argument() )
163 {
164 *this = OTypedScalarProperty( iProp, iArg0, iArg1 );
165 }
166
167 //-*************************************************************************
168 // SCALAR PROPERTY FEATURES
169 //-*************************************************************************
170
173 void set( const value_type &iVal )
174 {
175 OScalarProperty::set( reinterpret_cast<const void *>( &iVal ) );
176 }
177
178private:
179
180 void init( AbcA::CompoundPropertyWriterPtr iParent,
181 const std::string &iName,
182 const Argument &iArg0,
183 const Argument &iArg1,
184 const Argument &iArg2,
185 const Argument &iArg3 )
186 {
187 Arguments args;
188 iArg0.setInto( args );
189 iArg1.setInto( args );
190 iArg2.setInto( args );
191 iArg3.setInto( args );
192
194
195 ALEMBIC_ABC_SAFE_CALL_BEGIN( "OTypedScalarProperty::init()" );
196
197 ABCA_ASSERT( iParent, "NULL CompoundPropertyWriterPtr" );
198
199 AbcA::MetaData mdata = args.getMetaData();
200 if ( std::string() != getInterpretation() )
201 {
202 mdata.set( "interpretation", getInterpretation() );
203 }
204
206
207 uint32_t tsIndex = args.getTimeSamplingIndex();
208
209 // if we specified a valid TimeSamplingPtr, use it to determine the
210 // index otherwise we'll use the index, which defaults to the intrinsic
211 // 0 index
212 if (tsPtr)
213 {
214 tsIndex = iParent->getObject()->getArchive()->addTimeSampling(
215 *tsPtr);
216 }
217
218 m_property = iParent->createScalarProperty( iName, mdata,
219 TRAITS::dataType(), tsIndex );
220
222 }
223
224};
225
226//-*****************************************************************************
227//-*****************************************************************************
228//-*****************************************************************************
229
244
249
254
259
264
269
274
279
282
286
290
293
296
297} // End namespace ALEMBIC_VERSION_NS
298
299using namespace ALEMBIC_VERSION_NS;
300
301} // End namespace Abc
302} // End namespace Alembic
303
304#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 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
ErrorHandler & getErrorHandler() const
Definition: Base.h:76
static bool matches(const AbcA::PropertyHeader &iHeader, SchemaInterpMatching iMatching=kStrictMatching)
OTypedScalarProperty(AbcA::ScalarPropertyWriterPtr iProp, WrapExistingFlag iWrapFlag, const Argument &iArg0=Argument(), const Argument &iArg1=Argument())
OTypedScalarProperty(AbcA::ScalarPropertyWriterPtr iProp, const Argument &iArg0=Argument(), const Argument &iArg1=Argument())
OTypedScalarProperty(OCompoundProperty iParent, const std::string &iName, const Argument &iArg0=Argument(), const Argument &iArg1=Argument(), const Argument &iArg2=Argument())
OTypedScalarProperty(AbcA::CompoundPropertyWriterPtr iParent, const std::string &iName, const Argument &iArg0=Argument(), const Argument &iArg1=Argument(), const Argument &iArg2=Argument(), const Argument &iArg3=Argument())
static bool matches(const AbcA::MetaData &iMetaData, SchemaInterpMatching iMatching=kStrictMatching)
Alembic::Util::shared_ptr< CompoundPropertyWriter > CompoundPropertyWriterPtr
Alembic::Util::shared_ptr< TimeSampling > TimeSamplingPtr
Definition: TimeSampling.h:137
Alembic::Util::shared_ptr< ScalarPropertyWriter > ScalarPropertyWriterPtr
OTypedScalarProperty< M33dTPTraits > OM33dProperty
OTypedScalarProperty< Box2dTPTraits > OBox2dProperty
OTypedScalarProperty< M44dTPTraits > OM44dProperty
OTypedScalarProperty< C3hTPTraits > OC3hProperty
OTypedScalarProperty< C4hTPTraits > OC4hProperty
OTypedScalarProperty< V3dTPTraits > OV3dProperty
OTypedScalarProperty< P3iTPTraits > OP3iProperty
OTypedScalarProperty< N3dTPTraits > ON3dProperty
OTypedScalarProperty< C3cTPTraits > OC3cProperty
OTypedScalarProperty< N3fTPTraits > ON3fProperty
OTypedScalarProperty< Float32TPTraits > OFloatProperty
OTypedScalarProperty< QuatfTPTraits > OQuatfProperty
OTypedScalarProperty< Box3dTPTraits > OBox3dProperty
OTypedScalarProperty< Float64TPTraits > ODoubleProperty
OTypedScalarProperty< Box2sTPTraits > OBox2sProperty
OTypedScalarProperty< M44fTPTraits > OM44fProperty
OTypedScalarProperty< V3fTPTraits > OV3fProperty
OTypedScalarProperty< Uint64TPTraits > OUInt64Property
OTypedScalarProperty< Box2iTPTraits > OBox2iProperty
OTypedScalarProperty< C4cTPTraits > OC4cProperty
OTypedScalarProperty< Box2fTPTraits > OBox2fProperty
ErrorHandler::Policy GetErrorHandlerPolicy(SOMETHING iSomething, const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument(), const Argument &iArg3=Argument())
Definition: Argument.h:242
OTypedScalarProperty< Int8TPTraits > OCharProperty
OTypedScalarProperty< Int64TPTraits > OInt64Property
OTypedScalarProperty< BooleanTPTraits > OBoolProperty
OTypedScalarProperty< Uint16TPTraits > OUInt16Property
OTypedScalarProperty< WstringTPTraits > OWstringProperty
OTypedScalarProperty< Float16TPTraits > OHalfProperty
OTypedScalarProperty< P3dTPTraits > OP3dProperty
OTypedScalarProperty< N2dTPTraits > ON2dProperty
OTypedScalarProperty< P3sTPTraits > OP3sProperty
OTypedScalarProperty< M33fTPTraits > OM33fProperty
OTypedScalarProperty< V3iTPTraits > OV3iProperty
OTypedScalarProperty< Uint8TPTraits > OUcharProperty
OTypedScalarProperty< QuatdTPTraits > OQuatdProperty
OTypedScalarProperty< Box3sTPTraits > OBox3sProperty
OTypedScalarProperty< V2sTPTraits > OV2sProperty
OTypedScalarProperty< C4fTPTraits > OC4fProperty
OTypedScalarProperty< P2fTPTraits > OP2fProperty
OTypedScalarProperty< V3sTPTraits > OV3sProperty
OTypedScalarProperty< Int16TPTraits > OInt16Property
OTypedScalarProperty< C3fTPTraits > OC3fProperty
OTypedScalarProperty< V2dTPTraits > OV2dProperty
SchemaInterpMatching GetSchemaInterpMatching(const Argument &iArg0, const Argument &iArg1=Argument(), const Argument &iArg2=Argument(), const Argument &iArg3=Argument())
Definition: Argument.h:318
OTypedScalarProperty< Box3fTPTraits > OBox3fProperty
OTypedScalarProperty< P2dTPTraits > OP2dProperty
OTypedScalarProperty< P3fTPTraits > OP3fProperty
OTypedScalarProperty< Uint32TPTraits > OUInt32Property
OTypedScalarProperty< N2fTPTraits > ON2fProperty
OTypedScalarProperty< P2sTPTraits > OP2sProperty
OTypedScalarProperty< Int32TPTraits > OInt32Property
OTypedScalarProperty< V2iTPTraits > OV2iProperty
OTypedScalarProperty< P2iTPTraits > OP2iProperty
OTypedScalarProperty< Box3iTPTraits > OBox3iProperty
OTypedScalarProperty< V2fTPTraits > OV2fProperty
OTypedScalarProperty< StringTPTraits > OStringProperty
Alembic namespace ...
Definition: ArchiveInfo.h:46