Alembic Version 1.1

Loading...
Searching...
No Matches
ArraySample.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
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
45 namespace Alembic {
46 namespace AbcCoreAbstract {
47 namespace ALEMBIC_VERSION_NS {
48
49//-*****************************************************************************
59 class ALEMBIC_EXPORT ArraySample
60{
61 public:
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
126 private:
127 const void *m_data;
128 DataType m_dataType;
129 Dimensions m_dimensions;
130};
131
132//-*****************************************************************************
138 typedef Alembic::Util::shared_ptr<ArraySample> ArraySamplePtr;
139
140//-*****************************************************************************
148 ALEMBIC_EXPORT ArraySamplePtr
149 AllocateArraySample( const DataType &iDtype,
150 const Dimensions &iDims );
151
152//-*****************************************************************************
153//-*****************************************************************************
154//-*****************************************************************************
155// HELPER STUFF!
156//-*****************************************************************************
157//-*****************************************************************************
158//-*****************************************************************************
159
160//-*****************************************************************************
161 template <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//-*****************************************************************************
180 template <class T>
181 ArraySamplePtr 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
206 using namespace ALEMBIC_VERSION_NS;
207
208} // End namespace AbcCoreAbstract
209} // End namespace Alembic
210
211#endif
Foundation.h
ArraySampleKey.h
DataType.h
Export.h
ALEMBIC_EXPORT
#define ALEMBIC_EXPORT
Definition Export.h:51
ALEMBIC_VERSION_NS
#define ALEMBIC_VERSION_NS
Definition Foundation.h:105
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::this_type
ArraySample this_type
Definition ArraySample.h:62
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::ArraySample::getKey
Key getKey() const
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::ArraySample::key_type
Key key_type
Definition ArraySample.h:64
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::ArraySample::Key
ArraySampleKey Key
Definition ArraySample.h:63
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::AbcCoreAbstract::ALEMBIC_VERSION_NS
Definition ArchiveReader.h:47
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::ArraySamplePtr
Alembic::Util::shared_ptr< ArraySample > ArraySamplePtr
Definition ArraySample.h:138
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::TAllocateArraySample
ArraySamplePtr TAllocateArraySample(size_t iDataTypeExtent, const Dimensions &iDims)
Definition ArraySample.h:181
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::AllocateArraySample
ALEMBIC_EXPORT ArraySamplePtr AllocateArraySample(const DataType &iDtype, const Dimensions &iDims)
Alembic::AbcCoreAbstract
Definition ArchiveReader.h:46
Alembic
Alembic namespace ...
Definition ArchiveInfo.h:46
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::ArraySampleKey
Definition ArraySampleKey.h:48
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::TArrayDeleter
Definition ArraySample.h:163
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::TArrayDeleter::operator()
void operator()(void *memory) const
Definition ArraySample.h:164