Alembic 1.8.11

Loading...
Searching...
No Matches
OTypedArrayProperty.h
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_OTypedArrayProperty_h
37#define Alembic_Abc_OTypedArrayProperty_h
38
39#include <Alembic/Abc/Foundation.h>
40#include <Alembic/Abc/OArrayProperty.h>
41#include <Alembic/Abc/TypedPropertyTraits.h>
42#include <Alembic/Abc/TypedArraySample.h>
43
44 namespace Alembic {
45 namespace Abc {
46 namespace ALEMBIC_VERSION_NS {
47
48//-*****************************************************************************
49 template <class TRAITS>
50 class OTypedArrayProperty : public OArrayProperty
51{
52 public:
53 //-*************************************************************************
54 // TYPEDEFS AND IDENTIFIERS
55 //-*************************************************************************
56 typedef TRAITS traits_type;
57 typedef OTypedArrayProperty<TRAITS> this_type;
58 typedef typename TRAITS::value_type value_type;
59 typedef TypedArraySample<TRAITS> sample_type;
60
63 static const char * getInterpretation()
64 {
65 return TRAITS::interpretation();
66 }
67
71 static bool matches( const AbcA::MetaData &iMetaData,
72 SchemaInterpMatching iMatching = kStrictMatching )
73 {
74 return ( iMetaData.get( "interpretation" ) ==
75 getInterpretation() );
76 }
77
81 static bool matches( const AbcA::PropertyHeader &iHeader,
82 SchemaInterpMatching iMatching = kStrictMatching )
83 {
84 return ( iHeader.getDataType().getPod() ==
85 TRAITS::dataType().getPod() &&
86 ( iHeader.getDataType().getExtent() ==
87 TRAITS::dataType().getExtent() ||
88 std::string() == getInterpretation() ) ) &&
89 iHeader.isArray() &&
90 matches( iHeader.getMetaData(), iMatching );
91 }
92
93 //-*************************************************************************
94 // CONSTRUCTION, DESTRUCTION, ASSIGNMENT
95 //-*************************************************************************
96
99 OTypedArrayProperty() {}
100
101
105 OTypedArrayProperty(
106 AbcA::CompoundPropertyWriterPtr iParent,
107 const std::string &iName,
108
109 const Argument &iArg0 = Argument(),
110 const Argument &iArg1 = Argument(),
111 const Argument &iArg2 = Argument(),
112 const Argument &iArg3 = Argument() )
113 {
114 init( iParent, iName, iArg0, iArg1, iArg2, iArg3 );
115 }
116
120 OTypedArrayProperty(
121 OCompoundProperty iParent,
122 const std::string &iName,
123
124 const Argument &iArg0 = Argument(),
125 const Argument &iArg1 = Argument(),
126 const Argument &iArg2 = Argument() )
127 {
128 init( iParent.getPtr(), iName, GetErrorHandlerPolicy( iParent ),
129 iArg0, iArg1, iArg2 );
130 }
131
134 OTypedArrayProperty(
135 AbcA::ArrayPropertyWriterPtr iProp,
136 const Argument &iArg0 = Argument(),
137 const Argument &iArg1 = Argument() )
138 : OArrayProperty( iProp,
139 GetErrorHandlerPolicy( iProp, iArg0, iArg1 ) )
140 {
141 init( iProp, iArg0, iArg1 );
142 }
143
144
145 // Deprecated in favor of constructor above
146 OTypedArrayProperty(
147 AbcA::ArrayPropertyWriterPtr iProp,
148 WrapExistingFlag iWrapFlag,
149 const Argument &iArg0 = Argument(),
150 const Argument &iArg1 = Argument() )
151 : OArrayProperty( iProp,
152 GetErrorHandlerPolicy( iProp, iArg0, iArg1 ) )
153 {
154 init( iProp, iArg0, iArg1 );
155 }
156
157 //-*************************************************************************
158 // ARRAY PROPERTY FEATURES
159 //-*************************************************************************
160
163 void set( const sample_type &iVal )
164 {
165 OArrayProperty::set( iVal );
166 }
167
168 private:
169
170 void init( AbcA::CompoundPropertyWriterPtr iParent,
171 const std::string &iName,
172
173 const Argument &iArg0,
174 const Argument &iArg1,
175 const Argument &iArg2,
176 const Argument &iArg3 )
177 {
178 Arguments args;
179 iArg0.setInto( args );
180 iArg1.setInto( args );
181 iArg2.setInto( args );
182 iArg3.setInto( args );
183
184 getErrorHandler().setPolicy( args.getErrorHandlerPolicy() );
185
186 ALEMBIC_ABC_SAFE_CALL_BEGIN( "OTypedArrayProperty::init()" );
187
188 // Get actual writer for parent.
189 ABCA_ASSERT( iParent, "NULL CompoundPropertyWriterPtr" );
190
191 // Put interpretation into metadata.
192 AbcA::MetaData mdata = args.getMetaData();
193 if ( std::string() != getInterpretation() )
194 {
195 mdata.set( "interpretation", getInterpretation() );
196 }
197
198 // Create property.
199 AbcA::TimeSamplingPtr tsPtr = args.getTimeSampling();
200 uint32_t tsIndex = args.getTimeSamplingIndex();
201
202 // if we specified a valid TimeSamplingPtr, use it to determine the
203 // index otherwise we'll use the index, which defaults to the intrinsic
204 // 0 index
205 if (tsPtr)
206 {
207 tsIndex = iParent->getObject()->getArchive()->addTimeSampling(
208 *tsPtr);
209 }
210
211 m_property = iParent->createArrayProperty( iName, mdata,
212 TRAITS::dataType(), tsIndex );
213
214 ALEMBIC_ABC_SAFE_CALL_END_RESET();
215 }
216
217 void init( AbcA::ArrayPropertyWriterPtr iProp,
218 const Argument &iArg0, const Argument &iArg1 )
219 {
220 ALEMBIC_ABC_SAFE_CALL_BEGIN(
221 "OTypedArrayProperty::init( ArrayPtr )" );
222
223 const AbcA::PropertyHeader &pheader = iProp->getHeader();
224
225 ABCA_ASSERT( matches( pheader, GetSchemaInterpMatching( iArg0,iArg1 ) ),
226 "Incorrect match of header datatype: "
227 << pheader.getDataType()
228 << " to expected: "
229 << TRAITS::dataType()
230 << ",\n...or incorrect match of interpretation: "
231 << pheader.getMetaData().get( "interpretation" )
232 << " to expected: "
233 << TRAITS::interpretation() );
234
235 ALEMBIC_ABC_SAFE_CALL_END_RESET();
236 }
237};
238
239//-*****************************************************************************
240//-*****************************************************************************
241//-*****************************************************************************
242
243 typedef OTypedArrayProperty<BooleanTPTraits> OBoolArrayProperty;
244 typedef OTypedArrayProperty<Uint8TPTraits> OUcharArrayProperty;
245 typedef OTypedArrayProperty<Int8TPTraits> OCharArrayProperty;
246 typedef OTypedArrayProperty<Uint16TPTraits> OUInt16ArrayProperty;
247 typedef OTypedArrayProperty<Int16TPTraits> OInt16ArrayProperty;
248 typedef OTypedArrayProperty<Uint32TPTraits> OUInt32ArrayProperty;
249 typedef OTypedArrayProperty<Int32TPTraits> OInt32ArrayProperty;
250 typedef OTypedArrayProperty<Uint64TPTraits> OUInt64ArrayProperty;
251 typedef OTypedArrayProperty<Int64TPTraits> OInt64ArrayProperty;
252 typedef OTypedArrayProperty<Float16TPTraits> OHalfArrayProperty;
253 typedef OTypedArrayProperty<Float32TPTraits> OFloatArrayProperty;
254 typedef OTypedArrayProperty<Float64TPTraits> ODoubleArrayProperty;
255 typedef OTypedArrayProperty<StringTPTraits> OStringArrayProperty;
256 typedef OTypedArrayProperty<WstringTPTraits> OWstringArrayProperty;
257
258 typedef OTypedArrayProperty<V2sTPTraits> OV2sArrayProperty;
259 typedef OTypedArrayProperty<V2iTPTraits> OV2iArrayProperty;
260 typedef OTypedArrayProperty<V2fTPTraits> OV2fArrayProperty;
261 typedef OTypedArrayProperty<V2dTPTraits> OV2dArrayProperty;
262
263 typedef OTypedArrayProperty<V3sTPTraits> OV3sArrayProperty;
264 typedef OTypedArrayProperty<V3iTPTraits> OV3iArrayProperty;
265 typedef OTypedArrayProperty<V3fTPTraits> OV3fArrayProperty;
266 typedef OTypedArrayProperty<V3dTPTraits> OV3dArrayProperty;
267
268 typedef OTypedArrayProperty<P2sTPTraits> OP2sArrayProperty;
269 typedef OTypedArrayProperty<P2iTPTraits> OP2iArrayProperty;
270 typedef OTypedArrayProperty<P2fTPTraits> OP2fArrayProperty;
271 typedef OTypedArrayProperty<P2dTPTraits> OP2dArrayProperty;
272
273 typedef OTypedArrayProperty<P3sTPTraits> OP3sArrayProperty;
274 typedef OTypedArrayProperty<P3iTPTraits> OP3iArrayProperty;
275 typedef OTypedArrayProperty<P3fTPTraits> OP3fArrayProperty;
276 typedef OTypedArrayProperty<P3dTPTraits> OP3dArrayProperty;
277
278 typedef OTypedArrayProperty<Box2sTPTraits> OBox2sArrayProperty;
279 typedef OTypedArrayProperty<Box2iTPTraits> OBox2iArrayProperty;
280 typedef OTypedArrayProperty<Box2fTPTraits> OBox2fArrayProperty;
281 typedef OTypedArrayProperty<Box2dTPTraits> OBox2dArrayProperty;
282
283 typedef OTypedArrayProperty<Box3sTPTraits> OBox3sArrayProperty;
284 typedef OTypedArrayProperty<Box3iTPTraits> OBox3iArrayProperty;
285 typedef OTypedArrayProperty<Box3fTPTraits> OBox3fArrayProperty;
286 typedef OTypedArrayProperty<Box3dTPTraits> OBox3dArrayProperty;
287
288 typedef OTypedArrayProperty<M33fTPTraits> OM33fArrayProperty;
289 typedef OTypedArrayProperty<M33dTPTraits> OM33dArrayProperty;
290 typedef OTypedArrayProperty<M44fTPTraits> OM44fArrayProperty;
291 typedef OTypedArrayProperty<M44dTPTraits> OM44dArrayProperty;
292
293 typedef OTypedArrayProperty<QuatfTPTraits> OQuatfArrayProperty;
294 typedef OTypedArrayProperty<QuatdTPTraits> OQuatdArrayProperty;
295
296 typedef OTypedArrayProperty<C3hTPTraits> OC3hArrayProperty;
297 typedef OTypedArrayProperty<C3fTPTraits> OC3fArrayProperty;
298 typedef OTypedArrayProperty<C3cTPTraits> OC3cArrayProperty;
299
300 typedef OTypedArrayProperty<C4hTPTraits> OC4hArrayProperty;
301 typedef OTypedArrayProperty<C4fTPTraits> OC4fArrayProperty;
302 typedef OTypedArrayProperty<C4cTPTraits> OC4cArrayProperty;
303
304 typedef OTypedArrayProperty<N2fTPTraits> ON2fArrayProperty;
305 typedef OTypedArrayProperty<N2dTPTraits> ON2dArrayProperty;
306
307 typedef OTypedArrayProperty<N3fTPTraits> ON3fArrayProperty;
308 typedef OTypedArrayProperty<N3dTPTraits> ON3dArrayProperty;
309
310} // End namespace ALEMBIC_VERSION_NS
311
312 using namespace ALEMBIC_VERSION_NS;
313
314} // End namespace Abc
315} // End namespace Alembic
316
317#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::OArrayProperty
Definition OArrayProperty.h:53
Alembic::Abc::ALEMBIC_VERSION_NS::OArrayProperty::OArrayProperty
OArrayProperty()
Definition OArrayProperty.h:65
Alembic::Abc::ALEMBIC_VERSION_NS::OArrayProperty::set
void set(const AbcA::ArraySample &iSample)
Definition OArrayProperty.cpp:72
Alembic::Abc::ALEMBIC_VERSION_NS::OBasePropertyT::getPtr
PROP_PTR getPtr() const
Definition OBaseProperty.h:162
Alembic::Abc::ALEMBIC_VERSION_NS::OCompoundProperty
Definition OCompoundProperty.h:53
Alembic::Abc::ALEMBIC_VERSION_NS::OTypedArrayProperty
Definition OTypedArrayProperty.h:51
Alembic::Abc::ALEMBIC_VERSION_NS::OTypedArrayProperty::matches
static bool matches(const AbcA::MetaData &iMetaData, SchemaInterpMatching iMatching=kStrictMatching)
Definition OTypedArrayProperty.h:71
Alembic::Abc::ALEMBIC_VERSION_NS::OTypedArrayProperty::OTypedArrayProperty
OTypedArrayProperty()
Definition OTypedArrayProperty.h:99
Alembic::Abc::ALEMBIC_VERSION_NS::OTypedArrayProperty::OTypedArrayProperty
OTypedArrayProperty(AbcA::ArrayPropertyWriterPtr iProp, const Argument &iArg0=Argument(), const Argument &iArg1=Argument())
Definition OTypedArrayProperty.h:134
Alembic::Abc::ALEMBIC_VERSION_NS::OTypedArrayProperty::getInterpretation
static const char * getInterpretation()
Definition OTypedArrayProperty.h:63
Alembic::Abc::ALEMBIC_VERSION_NS::OTypedArrayProperty::set
void set(const sample_type &iVal)
Definition OTypedArrayProperty.h:163
Alembic::Abc::ALEMBIC_VERSION_NS::OTypedArrayProperty::matches
static bool matches(const AbcA::PropertyHeader &iHeader, SchemaInterpMatching iMatching=kStrictMatching)
Definition OTypedArrayProperty.h:81
Alembic::Abc::ALEMBIC_VERSION_NS::OTypedArrayProperty::OTypedArrayProperty
OTypedArrayProperty(AbcA::CompoundPropertyWriterPtr iParent, const std::string &iName, const Argument &iArg0=Argument(), const Argument &iArg1=Argument(), const Argument &iArg2=Argument(), const Argument &iArg3=Argument())
Definition OTypedArrayProperty.h:105
Alembic::Abc::ALEMBIC_VERSION_NS::OTypedArrayProperty::OTypedArrayProperty
OTypedArrayProperty(OCompoundProperty iParent, const std::string &iName, const Argument &iArg0=Argument(), const Argument &iArg1=Argument(), const Argument &iArg2=Argument())
Definition OTypedArrayProperty.h:120
Alembic::Abc::ALEMBIC_VERSION_NS::TypedArraySample
Definition TypedArraySample.h:52
Alembic
Alembic namespace ...
Definition ArchiveInfo.cpp:39