Alembic: Abc/TypedArraySample.h Source File

Alembic 1.8.11

Loading...
Searching...
No Matches
TypedArraySample.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
37#ifndef Alembic_Abc_TypedArraySample_h
38#define Alembic_Abc_TypedArraySample_h
39
40#include <Alembic/Abc/Foundation.h>
41#include <Alembic/Abc/TypedPropertyTraits.h>
42
43namespace Alembic {
44namespace Abc {
45namespace ALEMBIC_VERSION_NS {
46
47using Alembic::Util::Dimensions;
48
49//-*****************************************************************************
50template <class TRAITS>
51 class TypedArraySample : public AbcA::ArraySample
52{
53public:
54 typedef TRAITS traits_type;
55 typedef TypedArraySample<TRAITS> this_type;
56 typedef typename TRAITS::value_type value_type;
57 typedef typename std::vector<value_type> value_vector;
58
59 //-*************************************************************************
60 // Default
61 TypedArraySample()
62 : AbcA::ArraySample( NULL, TRAITS::dataType(), Dimensions() ) {}
63
64 //-*************************************************************************
65 // From pointer+num or pointer+dims
66 TypedArraySample( const value_type *iValues, size_t iNumVals )
67 : AbcA::ArraySample( reinterpret_cast<const void *>( iValues ),
68 TRAITS::dataType(), Dimensions( iNumVals ) ) {}
69
70 TypedArraySample( const value_type *iValues, const Dimensions &iDims )
71 : AbcA::ArraySample( reinterpret_cast<const void *>( iValues ),
72 TRAITS::dataType(), iDims ) {}
73
74 //-*************************************************************************
75 // From std::vector
76 TypedArraySample( const value_vector &iVec )
77 : AbcA::ArraySample( reinterpret_cast<const void *>( iVec.size() > 0 ?
78 &iVec.front() :
79 NULL ),
80 TRAITS::dataType(), Dimensions( iVec.size() ) ) {}
81
82 // This is for the case in which the data is multi-dimensional
83 TypedArraySample( const value_vector &iVec,
84 const Dimensions &iDims )
85 : AbcA::ArraySample( reinterpret_cast<const void *>( iVec.size() > 0 ?
86 &iVec.front() :
87 NULL ),
88 TRAITS::dataType(), iDims )
89 {
90 ABCA_ASSERT( iDims.numPoints() == iVec.size(),
91 "Invalid dimensions in TypedArraySample" );
92 }
93
94 //-*************************************************************************
95 // COPY & ASSIGMENT
96 //-*************************************************************************
97
98 // From base copy
99 TypedArraySample( const AbcA::ArraySample &iCopy )
100 : AbcA::ArraySample( iCopy )
101 {
102 ABCA_ASSERT( iCopy.getDataType() == TRAITS::dataType(),
103 "Invalid DataType in TypedArraySample. Expected: "
104 << TRAITS::dataType()
105 << ", but got: " << iCopy.getDataType() );
106 }
107
108 TypedArraySample<TRAITS> operator=( const AbcA::ArraySample &iCopy )
109 {
110 ArraySample::operator=( iCopy );
111
112 ABCA_ASSERT( iCopy.getDataType() == TRAITS::dataType(),
113 "Invalid DataType in TypedArraySample. Expected: "
114 << TRAITS::dataType()
115 << ", but got: " << iCopy.getDataType() );
116
117 return *this;
118 }
119
120 const value_type *get() const
121 {
122 return reinterpret_cast<const value_type *>( getData() );
123 }
124
125 const value_type *operator->() const { return this->get(); }
126
127 //-*************************************************************************
128 const value_type &operator[]( const size_t i ) const
129 {
130 return this->get()[i];
131 }
132
133 //-*************************************************************************
134 size_t size() const { return this->getDimensions().numPoints(); }
135
136 static TypedArraySample<TRAITS> emptySample()
137 {
138 return TypedArraySample<TRAITS>( NULL, 0 );
139 }
140
141 //-*************************************************************************
142 ALEMBIC_OPERATOR_BOOL( ArraySample::valid() );
143
144};
145
146//-*****************************************************************************
147// TYPEDEFS
148//-*****************************************************************************
149typedef TypedArraySample<BooleanTPTraits> BoolArraySample;
150typedef TypedArraySample<Uint8TPTraits> UcharArraySample;
151typedef TypedArraySample<Int8TPTraits> CharArraySample;
152typedef TypedArraySample<Uint16TPTraits> UInt16ArraySample;
153typedef TypedArraySample<Int16TPTraits> Int16ArraySample;
154typedef TypedArraySample<Uint32TPTraits> UInt32ArraySample;
155typedef TypedArraySample<Int32TPTraits> Int32ArraySample;
156typedef TypedArraySample<Uint64TPTraits> UInt64ArraySample;
157typedef TypedArraySample<Int64TPTraits> Int64ArraySample;
158typedef TypedArraySample<Float16TPTraits> HalfArraySample;
159typedef TypedArraySample<Float32TPTraits> FloatArraySample;
160typedef TypedArraySample<Float64TPTraits> DoubleArraySample;
161typedef TypedArraySample<StringTPTraits> StringArraySample;
162typedef TypedArraySample<WstringTPTraits> WstringArraySample;
163
164typedef TypedArraySample<V2sTPTraits> V2sArraySample;
165typedef TypedArraySample<V2iTPTraits> V2iArraySample;
166typedef TypedArraySample<V2fTPTraits> V2fArraySample;
167typedef TypedArraySample<V2dTPTraits> V2dArraySample;
168
169typedef TypedArraySample<V3sTPTraits> V3sArraySample;
170typedef TypedArraySample<V3iTPTraits> V3iArraySample;
171typedef TypedArraySample<V3fTPTraits> V3fArraySample;
172typedef TypedArraySample<V3dTPTraits> V3dArraySample;
173
174typedef TypedArraySample<P2sTPTraits> P2sArraySample;
175typedef TypedArraySample<P2iTPTraits> P2iArraySample;
176typedef TypedArraySample<P2fTPTraits> P2fArraySample;
177typedef TypedArraySample<P2dTPTraits> P2dArraySample;
178
179typedef TypedArraySample<P3sTPTraits> P3sArraySample;
180typedef TypedArraySample<P3iTPTraits> P3iArraySample;
181typedef TypedArraySample<P3fTPTraits> P3fArraySample;
182typedef TypedArraySample<P3dTPTraits> P3dArraySample;
183
184typedef TypedArraySample<Box2sTPTraits> Box2sArraySample;
185typedef TypedArraySample<Box2iTPTraits> Box2iArraySample;
186typedef TypedArraySample<Box2fTPTraits> Box2fArraySample;
187typedef TypedArraySample<Box2dTPTraits> Box2dArraySample;
188
189typedef TypedArraySample<Box3sTPTraits> Box3sArraySample;
190typedef TypedArraySample<Box3iTPTraits> Box3iArraySample;
191typedef TypedArraySample<Box3fTPTraits> Box3fArraySample;
192typedef TypedArraySample<Box3dTPTraits> Box3dArraySample;
193
194typedef TypedArraySample<M33fTPTraits> M33fArraySample;
195typedef TypedArraySample<M33dTPTraits> M33dArraySample;
196
197typedef TypedArraySample<M44fTPTraits> M44fArraySample;
198typedef TypedArraySample<M44dTPTraits> M44dArraySample;
199
200typedef TypedArraySample<QuatfTPTraits> QuatfArraySample;
201typedef TypedArraySample<QuatdTPTraits> QuatdArraySample;
202
203typedef TypedArraySample<C3hTPTraits> C3hArraySample;
204typedef TypedArraySample<C3fTPTraits> C3fArraySample;
205typedef TypedArraySample<C3cTPTraits> C3cArraySample;
206
207typedef TypedArraySample<C4hTPTraits> C4hArraySample;
208typedef TypedArraySample<C4fTPTraits> C4fArraySample;
209typedef TypedArraySample<C4cTPTraits> C4cArraySample;
210
211typedef TypedArraySample<N2fTPTraits> N2fArraySample;
212typedef TypedArraySample<N2dTPTraits> N2dArraySample;
213
214typedef TypedArraySample<N3fTPTraits> N3fArraySample;
215typedef TypedArraySample<N3dTPTraits> N3dArraySample;
216
217//-*****************************************************************************
218typedef Alembic::Util::shared_ptr<BoolArraySample> BoolArraySamplePtr;
219typedef Alembic::Util::shared_ptr<UcharArraySample> UcharArraySamplePtr;
220typedef Alembic::Util::shared_ptr<CharArraySample> CharArraySamplePtr;
221typedef Alembic::Util::shared_ptr<UInt16ArraySample> UInt16ArraySamplePtr;
222typedef Alembic::Util::shared_ptr<Int16ArraySample> Int16ArraySamplePtr;
223typedef Alembic::Util::shared_ptr<UInt32ArraySample> UInt32ArraySamplePtr;
224typedef Alembic::Util::shared_ptr<Int32ArraySample> Int32ArraySamplePtr;
225typedef Alembic::Util::shared_ptr<UInt64ArraySample> UInt64ArraySamplePtr;
226typedef Alembic::Util::shared_ptr<Int64ArraySample> Int64ArraySamplePtr;
227typedef Alembic::Util::shared_ptr<HalfArraySample> HalfArraySamplePtr;
228typedef Alembic::Util::shared_ptr<FloatArraySample> FloatArraySamplePtr;
229typedef Alembic::Util::shared_ptr<DoubleArraySample> DoubleArraySamplePtr;
230typedef Alembic::Util::shared_ptr<StringArraySample> StringArraySamplePtr;
231typedef Alembic::Util::shared_ptr<WstringArraySample> WstringArraySamplePtr;
232
233typedef Alembic::Util::shared_ptr<V2sArraySample> V2sArraySamplePtr;
234typedef Alembic::Util::shared_ptr<V2iArraySample> V2iArraySamplePtr;
235typedef Alembic::Util::shared_ptr<V2fArraySample> V2fArraySamplePtr;
236typedef Alembic::Util::shared_ptr<V2dArraySample> V2dArraySamplePtr;
237
238typedef Alembic::Util::shared_ptr<V3sArraySample> V3sArraySamplePtr;
239typedef Alembic::Util::shared_ptr<V3iArraySample> V3iArraySamplePtr;
240typedef Alembic::Util::shared_ptr<V3fArraySample> V3fArraySamplePtr;
241typedef Alembic::Util::shared_ptr<V3dArraySample> V3dArraySamplePtr;
242
243typedef Alembic::Util::shared_ptr<P2sArraySample> P2sArraySamplePtr;
244typedef Alembic::Util::shared_ptr<P2iArraySample> P2iArraySamplePtr;
245typedef Alembic::Util::shared_ptr<P2fArraySample> P2fArraySamplePtr;
246typedef Alembic::Util::shared_ptr<P2dArraySample> P2dArraySamplePtr;
247
248typedef Alembic::Util::shared_ptr<P3sArraySample> P3sArraySamplePtr;
249typedef Alembic::Util::shared_ptr<P3iArraySample> P3iArraySamplePtr;
250typedef Alembic::Util::shared_ptr<P3fArraySample> P3fArraySamplePtr;
251typedef Alembic::Util::shared_ptr<P3dArraySample> P3dArraySamplePtr;
252
253typedef Alembic::Util::shared_ptr<Box2sArraySample> Box2sArraySamplePtr;
254typedef Alembic::Util::shared_ptr<Box2iArraySample> Box2iArraySamplePtr;
255typedef Alembic::Util::shared_ptr<Box2fArraySample> Box2fArraySamplePtr;
256typedef Alembic::Util::shared_ptr<Box2dArraySample> Box2dArraySamplePtr;
257
258typedef Alembic::Util::shared_ptr<Box3sArraySample> Box3sArraySamplePtr;
259typedef Alembic::Util::shared_ptr<Box3iArraySample> Box3iArraySamplePtr;
260typedef Alembic::Util::shared_ptr<Box3fArraySample> Box3fArraySamplePtr;
261typedef Alembic::Util::shared_ptr<Box3dArraySample> Box3dArraySamplePtr;
262
263typedef Alembic::Util::shared_ptr<M33fArraySample> M33fArraySamplePtr;
264typedef Alembic::Util::shared_ptr<M33dArraySample> M33dArraySamplePtr;
265
266typedef Alembic::Util::shared_ptr<M44fArraySample> M44fArraySamplePtr;
267typedef Alembic::Util::shared_ptr<M44dArraySample> M44dArraySamplePtr;
268
269typedef Alembic::Util::shared_ptr<QuatfArraySample> QuatfArraySamplePtr;
270typedef Alembic::Util::shared_ptr<QuatdArraySample> QuatdArraySamplePtr;
271
272typedef Alembic::Util::shared_ptr<C3hArraySample> C3hArraySamplePtr;
273typedef Alembic::Util::shared_ptr<C3fArraySample> C3fArraySamplePtr;
274typedef Alembic::Util::shared_ptr<C3cArraySample> C3cArraySamplePtr;
275
276typedef Alembic::Util::shared_ptr<C4hArraySample> C4hArraySamplePtr;
277typedef Alembic::Util::shared_ptr<C4fArraySample> C4fArraySamplePtr;
278typedef Alembic::Util::shared_ptr<C4cArraySample> C4cArraySamplePtr;
279
280typedef Alembic::Util::shared_ptr<N2fArraySample> N2fArraySamplePtr;
281typedef Alembic::Util::shared_ptr<N2dArraySample> N2dArraySamplePtr;
282
283typedef Alembic::Util::shared_ptr<N3fArraySample> N3fArraySamplePtr;
284typedef Alembic::Util::shared_ptr<N3dArraySample> N3dArraySamplePtr;
285
286} // End namespace ALEMBIC_VERSION_NS
287
288using namespace ALEMBIC_VERSION_NS;
289
290} // End namespace Abc
291} // End namespace Alembic
292
293#endif
Alembic::Abc::ALEMBIC_VERSION_NS::TypedArraySample
Definition TypedArraySample.h:52
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::ArraySample::valid
bool valid() const
Definition ArraySample.h:111
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::ArraySample::getDimensions
const Dimensions & getDimensions() const
Definition ArraySample.h:95
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::ArraySample::getData
const void * getData() const
Definition ArraySample.h:87
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::ArraySample::size
size_t size() const
Definition ArraySample.h:99
Alembic
Alembic namespace ...
Definition ArchiveInfo.cpp:39