ArraySample.h
Go to the documentation of this file.
//-*****************************************************************************
//
// Copyright (c) 2009-2012,
// Sony Pictures Imageworks, Inc. and
// Industrial Light & Magic, a division of Lucasfilm Entertainment Company Ltd.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Sony Pictures Imageworks, nor
// Industrial Light & Magic nor the names of their contributors may be used
// to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//-*****************************************************************************
#ifndef Alembic_AbcCoreAbstract_ArraySample_h
#define Alembic_AbcCoreAbstract_ArraySample_h
#include <Alembic/Util/Export.h>
#include <Alembic/AbcCoreAbstract/Foundation.h>
#include <Alembic/AbcCoreAbstract/ArraySampleKey.h>
#include <Alembic/AbcCoreAbstract/DataType.h>
namespace Alembic {
namespace AbcCoreAbstract {
namespace ALEMBIC_VERSION_NS {
//-*****************************************************************************
class ALEMBIC_EXPORT ArraySample
{
public:
typedef ArraySample this_type;
typedef ArraySampleKey Key;
typedef Key key_type;
ArraySample()
: m_data( NULL )
, m_dataType()
, m_dimensions() {}
ArraySample( const void * iData,
const DataType &iDataType,
const Dimensions & iDims )
: m_data( iData )
, m_dataType( iDataType )
, m_dimensions( iDims ) {}
const void* getData() const { return m_data; }
const DataType &getDataType() const { return m_dataType; }
const Dimensions& getDimensions() const { return m_dimensions; }
size_t size() const { return m_dimensions.numPoints(); }
Key getKey() const;
bool valid() const
{
return ( m_dataType.getPod() != kUnknownPOD ) &&
!( m_data == NULL && m_dimensions.rank() < 1 );
}
void reset()
{
m_data = NULL;
m_dataType = DataType();
m_dimensions = Dimensions();
}
private:
const void *m_data;
DataType m_dataType;
Dimensions m_dimensions;
};
//-*****************************************************************************
typedef Alembic::Util::shared_ptr<ArraySample> ArraySamplePtr;
//-*****************************************************************************
ALEMBIC_EXPORT ArraySamplePtr
AllocateArraySample( const DataType &iDtype,
const Dimensions &iDims );
//-*****************************************************************************
//-*****************************************************************************
//-*****************************************************************************
// HELPER STUFF!
//-*****************************************************************************
//-*****************************************************************************
//-*****************************************************************************
//-*****************************************************************************
template <class T>
struct TArrayDeleter
{
void operator()( void *memory ) const
{
ArraySample *arraySample = static_cast< ArraySample*>( memory );
if ( arraySample )
{
T *data = reinterpret_cast<T*>(
const_cast<void*>( arraySample->getData() ) );
// Delete[] NULL is okay.
delete[] data;
}
delete arraySample;
}
};
//-*****************************************************************************
template <class T>
ArraySamplePtr TAllocateArraySample( size_t iDataTypeExtent,
const Dimensions &iDims )
{
DataType dtype( PODTraitsFromType<T>::pod_enum, iDataTypeExtent );
size_t numPODs = iDims.numPoints() * iDataTypeExtent;
if ( numPODs > 0 )
{
T *data = new T[numPODs];
ArraySamplePtr ret(
new ArraySample( reinterpret_cast<const void *>( data ),
dtype, iDims ),
TArrayDeleter<T>() );
return ret;
}
else
{
ArraySamplePtr ret(
new ArraySample( ( const void * )NULL,
dtype, iDims ) );
return ret;
}
}
} // End namespace ALEMBIC_VERSION_NS
using namespace ALEMBIC_VERSION_NS;
} // End namespace AbcCoreAbstract
} // End namespace Alembic
#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::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::Util::ALEMBIC_VERSION_NS::kUnknownPOD
@ kUnknownPOD
Unknown.
Definition: PlainOldDataType.h:222
Alembic::Util::ALEMBIC_VERSION_NS::Dimensions
BaseDimensions< Alembic::Util::uint64_t > Dimensions
Definition: Dimensions.h:189
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