Alembic 1.8.11

Loading...
Searching...
No Matches
ITypedArrayProperty.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_ITypedArrayProperty_h
37#define Alembic_Abc_ITypedArrayProperty_h
38
39#include <Alembic/Abc/Foundation.h>
40#include <Alembic/Abc/IArrayProperty.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 ITypedArrayProperty : public IArrayProperty
51{
52 public:
53 //-*************************************************************************
54 // TYPEDEFS AND IDENTIFIERS
55 //-*************************************************************************
56 typedef TRAITS traits_type;
57 typedef ITypedArrayProperty<TRAITS> this_type;
58 typedef typename TRAITS::value_type value_type;
59 typedef TypedArraySample<TRAITS> sample_type;
60 typedef shared_ptr<sample_type> sample_ptr_type;
61
64 static const char * getInterpretation()
65 {
66 return TRAITS::interpretation();
67 }
68
72 static bool matches( const AbcA::MetaData &iMetaData,
73 SchemaInterpMatching iMatching = kStrictMatching )
74 {
75 if ( iMatching == kStrictMatching )
76 {
77 return ( iMetaData.get( "interpretation" ) ==
78 getInterpretation() );
79 }
80 return true;
81 }
82
86 static bool matches( const AbcA::PropertyHeader &iHeader,
87 SchemaInterpMatching iMatching = kStrictMatching )
88 {
89 return ( iHeader.getDataType().getPod() ==
90 TRAITS::dataType().getPod() &&
91 ( iHeader.getDataType().getExtent() ==
92 TRAITS::dataType().getExtent() ||
93 std::string() == getInterpretation() ) ) &&
94 iHeader.isArray() &&
95 matches( iHeader.getMetaData(), iMatching );
96 }
97
98 //-*************************************************************************
99 // CONSTRUCTION, DESTRUCTION, ASSIGNMENT
100 //-*************************************************************************
101
104 ITypedArrayProperty() {}
105
111 ITypedArrayProperty( const ICompoundProperty &iParent,
112 const std::string &iName,
113 const Argument &iArg0 = Argument(),
114 const Argument &iArg1 = Argument() )
115 {
116 Arguments args( GetErrorHandlerPolicy( iParent ) );
117 iArg0.setInto( args );
118 iArg1.setInto( args );
119
120 getErrorHandler().setPolicy( args.getErrorHandlerPolicy() );
121
122 ALEMBIC_ABC_SAFE_CALL_BEGIN(
123 "ITypedArrayProperty::ITypedArrayProperty()" );
124
125 AbcA::CompoundPropertyReaderPtr parent = iParent.getPtr();
126 ABCA_ASSERT( parent != NULL,
127 "NULL CompoundPropertyReader passed into "
128 << "ITypedArrayProperty ctor" );
129
130 const AbcA::PropertyHeader *pheader =
131 parent->getPropertyHeader( iName );
132 ABCA_ASSERT( pheader != NULL,
133 "Nonexistent array property: " << iName );
134
135 ABCA_ASSERT( matches( *pheader, args.getSchemaInterpMatching() ),
136 "Incorrect match of header datatype: "
137 << pheader->getDataType()
138 << " to expected: "
139 << TRAITS::dataType()
140 << ",\n...or incorrect match of interpretation: "
141 << pheader->getMetaData().get( "interpretation" )
142 << " to expected: "
143 << TRAITS::interpretation() );
144
145 m_property = parent->getArrayProperty( iName );
146
147 ALEMBIC_ABC_SAFE_CALL_END_RESET();
148 }
149
153 ITypedArrayProperty( AbcA::ArrayPropertyReaderPtr iProperty,
154 const Argument &iArg0 = Argument(),
155 const Argument &iArg1 = Argument() )
156 {
157 ALEMBIC_ABC_SAFE_CALL_BEGIN(
158 "ITypedArrayProperty::ITypedArrayProperty()" );
159
160 const AbcA::PropertyHeader &pheader = iProperty->getHeader();
161
162 ABCA_ASSERT( matches( pheader,GetSchemaInterpMatching( iArg0, iArg1 ) ),
163 "Incorrect match of header datatype: "
164 << pheader.getDataType()
165 << " to expected: "
166 << TRAITS::dataType()
167 << ",\n...or incorrect match of interpretation: "
168 << pheader.getMetaData().get( "interpretation" )
169 << " to expected: "
170 << TRAITS::interpretation() );
171
172 m_property = iProperty;
173
174 ALEMBIC_ABC_SAFE_CALL_END_RESET();
175 }
176
177 // Deprecated in favor of the constructor above
178 ITypedArrayProperty( AbcA::ArrayPropertyReaderPtr iProp,
179 WrapExistingFlag iWrapFlag,
180 const Argument &iArg0 = Argument(),
181 const Argument &iArg1 = Argument() )
182 {
183 *this = ITypedArrayProperty( iProp, iArg0, iArg1 );
184 }
185
186 //-*************************************************************************
187 // ARRAY PROPERTY FEATURES
188 //-*************************************************************************
189
192 void get( sample_ptr_type& iVal,
193 const ISampleSelector &iSS = ISampleSelector() ) const
194 {
195 AbcA::ArraySamplePtr ptr;
196 IArrayProperty::get( ptr, iSS );
197 iVal = Alembic::Util::static_pointer_cast<sample_type,
198 AbcA::ArraySample>( ptr );
199 }
200
203 sample_ptr_type getValue( const ISampleSelector &iSS = ISampleSelector() ) const
204 {
205 sample_ptr_type ret;
206 get( ret, iSS );
207 return ret;
208 }
209};
210
211//-*****************************************************************************
212//-*****************************************************************************
213//-*****************************************************************************
214
215 typedef ITypedArrayProperty<BooleanTPTraits> IBoolArrayProperty;
216 typedef ITypedArrayProperty<Uint8TPTraits> IUcharArrayProperty;
217 typedef ITypedArrayProperty<Int8TPTraits> ICharArrayProperty;
218 typedef ITypedArrayProperty<Uint16TPTraits> IUInt16ArrayProperty;
219 typedef ITypedArrayProperty<Int16TPTraits> IInt16ArrayProperty;
220 typedef ITypedArrayProperty<Uint32TPTraits> IUInt32ArrayProperty;
221 typedef ITypedArrayProperty<Int32TPTraits> IInt32ArrayProperty;
222 typedef ITypedArrayProperty<Uint64TPTraits> IUInt64ArrayProperty;
223 typedef ITypedArrayProperty<Int64TPTraits> IInt64ArrayProperty;
224 typedef ITypedArrayProperty<Float16TPTraits> IHalfArrayProperty;
225 typedef ITypedArrayProperty<Float32TPTraits> IFloatArrayProperty;
226 typedef ITypedArrayProperty<Float64TPTraits> IDoubleArrayProperty;
227 typedef ITypedArrayProperty<StringTPTraits> IStringArrayProperty;
228 typedef ITypedArrayProperty<WstringTPTraits> IWstringArrayProperty;
229
230 typedef ITypedArrayProperty<V2sTPTraits> IV2sArrayProperty;
231 typedef ITypedArrayProperty<V2iTPTraits> IV2iArrayProperty;
232 typedef ITypedArrayProperty<V2fTPTraits> IV2fArrayProperty;
233 typedef ITypedArrayProperty<V2dTPTraits> IV2dArrayProperty;
234
235 typedef ITypedArrayProperty<V3sTPTraits> IV3sArrayProperty;
236 typedef ITypedArrayProperty<V3iTPTraits> IV3iArrayProperty;
237 typedef ITypedArrayProperty<V3fTPTraits> IV3fArrayProperty;
238 typedef ITypedArrayProperty<V3dTPTraits> IV3dArrayProperty;
239
240 typedef ITypedArrayProperty<P2sTPTraits> IP2sArrayProperty;
241 typedef ITypedArrayProperty<P2iTPTraits> IP2iArrayProperty;
242 typedef ITypedArrayProperty<P2fTPTraits> IP2fArrayProperty;
243 typedef ITypedArrayProperty<P2dTPTraits> IP2dArrayProperty;
244
245 typedef ITypedArrayProperty<P3sTPTraits> IP3sArrayProperty;
246 typedef ITypedArrayProperty<P3iTPTraits> IP3iArrayProperty;
247 typedef ITypedArrayProperty<P3fTPTraits> IP3fArrayProperty;
248 typedef ITypedArrayProperty<P3dTPTraits> IP3dArrayProperty;
249
250 typedef ITypedArrayProperty<Box2sTPTraits> IBox2sArrayProperty;
251 typedef ITypedArrayProperty<Box2iTPTraits> IBox2iArrayProperty;
252 typedef ITypedArrayProperty<Box2fTPTraits> IBox2fArrayProperty;
253 typedef ITypedArrayProperty<Box2dTPTraits> IBox2dArrayProperty;
254
255 typedef ITypedArrayProperty<Box3sTPTraits> IBox3sArrayProperty;
256 typedef ITypedArrayProperty<Box3iTPTraits> IBox3iArrayProperty;
257 typedef ITypedArrayProperty<Box3fTPTraits> IBox3fArrayProperty;
258 typedef ITypedArrayProperty<Box3dTPTraits> IBox3dArrayProperty;
259
260 typedef ITypedArrayProperty<M33fTPTraits> IM33fArrayProperty;
261 typedef ITypedArrayProperty<M33dTPTraits> IM33dArrayProperty;
262 typedef ITypedArrayProperty<M44fTPTraits> IM44fArrayProperty;
263 typedef ITypedArrayProperty<M44dTPTraits> IM44dArrayProperty;
264
265 typedef ITypedArrayProperty<QuatfTPTraits> IQuatfArrayProperty;
266 typedef ITypedArrayProperty<QuatdTPTraits> IQuatdArrayProperty;
267
268 typedef ITypedArrayProperty<C3hTPTraits> IC3hArrayProperty;
269 typedef ITypedArrayProperty<C3fTPTraits> IC3fArrayProperty;
270 typedef ITypedArrayProperty<C3cTPTraits> IC3cArrayProperty;
271
272 typedef ITypedArrayProperty<C4hTPTraits> IC4hArrayProperty;
273 typedef ITypedArrayProperty<C4fTPTraits> IC4fArrayProperty;
274 typedef ITypedArrayProperty<C4cTPTraits> IC4cArrayProperty;
275
276 typedef ITypedArrayProperty<N2fTPTraits> IN2fArrayProperty;
277 typedef ITypedArrayProperty<N2dTPTraits> IN2dArrayProperty;
278
279 typedef ITypedArrayProperty<N3fTPTraits> IN3fArrayProperty;
280 typedef ITypedArrayProperty<N3dTPTraits> IN3dArrayProperty;
281
282
283} // End namespace ALEMBIC_VERSION_NS
284
285 using namespace ALEMBIC_VERSION_NS;
286
287} // End namespace Abc
288} // End namespace Alembic
289
290#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::IArrayProperty::get
void get(AbcA::ArraySamplePtr &oSample, const ISampleSelector &iSS=ISampleSelector()) const
Definition IArrayProperty.cpp:113
Alembic::Abc::ALEMBIC_VERSION_NS::IArrayProperty::IArrayProperty
IArrayProperty()
Definition IArrayProperty.h:66
Alembic::Abc::ALEMBIC_VERSION_NS::IBasePropertyT::getPtr
PROP_PTR getPtr() const
Definition IBaseProperty.h:156
Alembic::Abc::ALEMBIC_VERSION_NS::ICompoundProperty
Definition ICompoundProperty.h:53
Alembic::Abc::ALEMBIC_VERSION_NS::ISampleSelector
Definition ISampleSelector.h:49
Alembic::Abc::ALEMBIC_VERSION_NS::ITypedArrayProperty
Definition ITypedArrayProperty.h:51
Alembic::Abc::ALEMBIC_VERSION_NS::ITypedArrayProperty::matches
static bool matches(const AbcA::MetaData &iMetaData, SchemaInterpMatching iMatching=kStrictMatching)
Definition ITypedArrayProperty.h:72
Alembic::Abc::ALEMBIC_VERSION_NS::ITypedArrayProperty::ITypedArrayProperty
ITypedArrayProperty(const ICompoundProperty &iParent, const std::string &iName, const Argument &iArg0=Argument(), const Argument &iArg1=Argument())
Definition ITypedArrayProperty.h:111
Alembic::Abc::ALEMBIC_VERSION_NS::ITypedArrayProperty::matches
static bool matches(const AbcA::PropertyHeader &iHeader, SchemaInterpMatching iMatching=kStrictMatching)
Definition ITypedArrayProperty.h:86
Alembic::Abc::ALEMBIC_VERSION_NS::ITypedArrayProperty::get
void get(sample_ptr_type &iVal, const ISampleSelector &iSS=ISampleSelector()) const
Definition ITypedArrayProperty.h:192
Alembic::Abc::ALEMBIC_VERSION_NS::ITypedArrayProperty::getInterpretation
static const char * getInterpretation()
Definition ITypedArrayProperty.h:64
Alembic::Abc::ALEMBIC_VERSION_NS::ITypedArrayProperty::ITypedArrayProperty
ITypedArrayProperty()
Definition ITypedArrayProperty.h:104
Alembic::Abc::ALEMBIC_VERSION_NS::ITypedArrayProperty::getValue
sample_ptr_type getValue(const ISampleSelector &iSS=ISampleSelector()) const
Definition ITypedArrayProperty.h:203
Alembic::Abc::ALEMBIC_VERSION_NS::ITypedArrayProperty::ITypedArrayProperty
ITypedArrayProperty(AbcA::ArrayPropertyReaderPtr iProperty, const Argument &iArg0=Argument(), const Argument &iArg1=Argument())
Definition ITypedArrayProperty.h:153
Alembic::Abc::ALEMBIC_VERSION_NS::TypedArraySample
Definition TypedArraySample.h:52
Alembic
Alembic namespace ...
Definition ArchiveInfo.cpp:39