Alembic: AbcCoreAbstract/ArraySample.h Source File

Alembic 1.8.11

Loading...
Searching...
No Matches
ArraySample.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_AbcCoreAbstract_ArraySample_h
38#define Alembic_AbcCoreAbstract_ArraySample_h
39
40#include <Alembic/Util/Export.h>
41#include <Alembic/AbcCoreAbstract/Foundation.h>
42#include <Alembic/AbcCoreAbstract/ArraySampleKey.h>
43#include <Alembic/AbcCoreAbstract/DataType.h>
44
45namespace Alembic {
46namespace AbcCoreAbstract {
47namespace ALEMBIC_VERSION_NS {
48
49//-*****************************************************************************
59 class ALEMBIC_EXPORT ArraySample
60{
61public:
62 typedef ArraySample this_type;
63 typedef ArraySampleKey Key;
64 typedef Key key_type;
65
68 ArraySample()
69 : m_data( NULL )
70 , m_dataType()
71 , m_dimensions() {}
72
75 ArraySample( const void * iData,
76 const DataType &iDataType,
77 const Dimensions & iDims )
78 : m_data( iData )
79 , m_dataType( iDataType )
80 , m_dimensions( iDims ) {}
81
84
87 const void* getData() const { return m_data; }
88
91 const DataType &getDataType() const { return m_dataType; }
92
95 const Dimensions& getDimensions() const { return m_dimensions; }
96
99 size_t size() const { return m_dimensions.numPoints(); }
100
103 Key getKey() const;
104
111 bool valid() const
112 {
113 return ( m_dataType.getPod() != kUnknownPOD ) &&
114 !( m_data == NULL && m_dimensions.rank() < 1 );
115 }
116
119 void reset()
120 {
121 m_data = NULL;
122 m_dataType = DataType();
123 m_dimensions = Dimensions();
124 }
125
126private:
127 const void *m_data;
128 DataType m_dataType;
129 Dimensions m_dimensions;
130};
131
132//-*****************************************************************************
138typedef Alembic::Util::shared_ptr<ArraySample> ArraySamplePtr;
139
140//-*****************************************************************************
148ALEMBIC_EXPORT ArraySamplePtr
149AllocateArraySample( const DataType &iDtype,
150 const Dimensions &iDims );
151
152//-*****************************************************************************
153//-*****************************************************************************
154//-*****************************************************************************
155// HELPER STUFF!
156//-*****************************************************************************
157//-*****************************************************************************
158//-*****************************************************************************
159
160//-*****************************************************************************
161template <class T>
162 struct TArrayDeleter
163{
164 void operator()( void *memory ) const
165 {
166 ArraySample *arraySample = static_cast<ArraySample*>( memory );
167 if ( arraySample )
168 {
169 T *data = reinterpret_cast<T*>(
170 const_cast<void*>( arraySample->getData() ) );
171
172 // Delete[] NULL is okay.
173 delete[] data;
174 }
175 delete arraySample;
176 }
177};
178
179//-*****************************************************************************
180template <class T>
181ArraySamplePtr TAllocateArraySample( size_t iDataTypeExtent,
182 const Dimensions &iDims )
183{
184 DataType dtype( PODTraitsFromType<T>::pod_enum, iDataTypeExtent );
185 size_t numPODs = iDims.numPoints() * iDataTypeExtent;
186 if ( numPODs > 0 )
187 {
188 T *data = new T[numPODs];
189 ArraySamplePtr ret(
190 new ArraySample( reinterpret_cast<const void *>( data ),
191 dtype, iDims ),
192 TArrayDeleter<T>() );
193 return ret;
194 }
195 else
196 {
197 ArraySamplePtr ret(
198 new ArraySample( ( const void * )NULL,
199 dtype, iDims ) );
200 return ret;
201 }
202}
203
204} // End namespace ALEMBIC_VERSION_NS
205
206using namespace ALEMBIC_VERSION_NS;
207
208} // End namespace AbcCoreAbstract
209} // End namespace Alembic
210
211#endif
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::ArraySample
Definition ArraySample.h:60
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::ArraySample::valid
bool valid() const
Definition ArraySample.h:111
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::ArraySample::getDataType
const DataType & getDataType() const
Definition ArraySample.h:91
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::ArraySample
ArraySample(const void *iData, const DataType &iDataType, const Dimensions &iDims)
Definition ArraySample.h:75
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::ArraySample::size
size_t size() const
Definition ArraySample.h:99
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::ArraySample::ArraySample
ArraySample()
Definition ArraySample.h:68
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::ArraySample::reset
void reset()
Definition ArraySample.h:119
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::DataType
Definition DataType.h:52
Alembic
Alembic namespace ...
Definition ArchiveInfo.cpp:39
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::ArraySampleKey
Definition ArraySampleKey.h:48
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::TArrayDeleter
Definition ArraySample.h:163