37#ifndef Alembic_AbcCoreHDF5_SimplePrImpl_h
38#define Alembic_AbcCoreHDF5_SimplePrImpl_h
40#include <Alembic/AbcCoreHDF5/Foundation.h>
42#include <Alembic/AbcCoreHDF5/OrImpl.h>
43#include <Alembic/AbcCoreHDF5/ArImpl.h>
44#include <Alembic/AbcCoreHDF5/ReadUtil.h>
45#include <Alembic/AbcCoreHDF5/DataTypeRegistry.h>
46#include <Alembic/AbcCoreHDF5/HDF5Util.h>
49namespace AbcCoreHDF5 {
50namespace ALEMBIC_VERSION_NS {
73template <
class ABSTRACT,
class IMPL,
class SAMPLE>
74class SimplePrImpl :
public ABSTRACT
77 SimplePrImpl( AbcA::CompoundPropertyReaderPtr iParent,
79 PropertyHeaderPtr iHeader,
81 uint32_t iFirstChangedIndex,
82 uint32_t iLastChangedIndex );
88 virtual ~SimplePrImpl();
90 virtual const AbcA::PropertyHeader &getHeader()
const;
92 virtual AbcA::ObjectReaderPtr getObject();
94 virtual AbcA::CompoundPropertyReaderPtr getParent();
96 virtual size_t getNumSamples();
98 virtual bool isConstant();
100 virtual void getSample( index_t iSampleIndex,
103 virtual std::pair<index_t, chrono_t> getFloorIndex( chrono_t iTime );
105 virtual std::pair<index_t, chrono_t> getCeilIndex( chrono_t iTime );
107 virtual std::pair<index_t, chrono_t> getNearIndex( chrono_t iTime );
109 virtual bool getKey( index_t iSampleIndex, AbcA::ArraySampleKey & oKey );
113 index_t verifySampleIndex( index_t iSampleIndex );
115 void checkSamplesIGroup();
118 AbcA::CompoundPropertyReaderPtr m_parent;
127 PropertyHeaderPtr m_header;
130 hid_t m_fileDataType;
131 bool m_cleanFileDataType;
132 hid_t m_nativeDataType;
133 bool m_cleanNativeDataType;
138 uint32_t m_numSamples;
141 uint32_t m_firstChangedIndex;
145 uint32_t m_lastChangedIndex;
165template <
class ABSTRACT,
class IMPL,
class SAMPLE>
166SimplePrImpl<ABSTRACT,IMPL,SAMPLE>::SimplePrImpl
168 AbcA::CompoundPropertyReaderPtr iParent,
170 PropertyHeaderPtr iHeader,
171 uint32_t iNumSamples,
172 uint32_t iFirstChangedIndex,
173 uint32_t iLastChangedIndex
175 : m_parent( iParent )
176 , m_parentGroup( iParentGroup )
177 , m_header( iHeader )
178 , m_fileDataType( -1 )
179 , m_cleanFileDataType( false )
180 , m_nativeDataType( -1 )
181 , m_cleanNativeDataType( false )
182 , m_numSamples( iNumSamples )
183 , m_firstChangedIndex( iFirstChangedIndex )
184 , m_lastChangedIndex( iLastChangedIndex )
187 ABCA_ASSERT( m_parent,
"Invalid parent" );
188 ABCA_ASSERT( m_parentGroup.isValidObject(),
"Invalid parent group" );
189 ABCA_ASSERT( m_header,
"Invalid header" );
190 ABCA_ASSERT( m_header->getPropertyType() != AbcA::kCompoundProperty,
191 "Tried to create a simple property with a compound header" );
194 PlainOldDataType POD = m_header->getDataType().getPod();
195 if ( POD != kStringPOD && POD != kWstringPOD )
197 m_fileDataType = GetFileH5T( m_header->getDataType(),
198 m_cleanFileDataType );
199 m_nativeDataType = GetNativeH5T( m_header->getDataType(),
200 m_cleanNativeDataType );
204 const std::string &myName = m_header->getName();
207 ABCA_ASSERT( m_firstChangedIndex <= m_numSamples &&
208 m_lastChangedIndex <= m_numSamples &&
209 m_firstChangedIndex <= m_lastChangedIndex,
210 "Corrupt sampling information for property: " << myName
211 <<
" first change index: " << m_firstChangedIndex
212 <<
" last change index: " << m_lastChangedIndex
213 <<
" total number of samples: " << m_numSamples );
222template <
class ABSTRACT,
class IMPL,
class SAMPLE>
223const AbcA::PropertyHeader &
224SimplePrImpl<ABSTRACT,IMPL,SAMPLE>::getHeader()
const
226 ABCA_ASSERT( m_header,
"Invalid header" );
231template <
class ABSTRACT,
class IMPL,
class SAMPLE>
233SimplePrImpl<ABSTRACT,IMPL,SAMPLE>::getObject()
235 ABCA_ASSERT( m_parent,
"Invalid parent" );
236 return m_parent->getObject();
240template <
class ABSTRACT,
class IMPL,
class SAMPLE>
241AbcA::CompoundPropertyReaderPtr
242SimplePrImpl<ABSTRACT,IMPL,SAMPLE>::getParent()
244 ABCA_ASSERT( m_parent,
"Invalid parent" );
249template <
class ABSTRACT,
class IMPL,
class SAMPLE>
250size_t SimplePrImpl<ABSTRACT,IMPL,SAMPLE>::getNumSamples()
252 return (
size_t )m_numSamples;
256template <
class ABSTRACT,
class IMPL,
class SAMPLE>
257bool SimplePrImpl<ABSTRACT,IMPL,SAMPLE>::isConstant()
260 return ( m_firstChangedIndex == 0 );
264template <
class ABSTRACT,
class IMPL,
class SAMPLE>
265index_t SimplePrImpl<ABSTRACT,IMPL,SAMPLE>::verifySampleIndex( index_t iIndex )
268 ABCA_ASSERT( iIndex >= 0 &&
269 iIndex < m_numSamples,
270 "Invalid sample index: " << iIndex
271 <<
", should be between 0 and " << m_numSamples-1 );
274 if ( iIndex > m_lastChangedIndex )
276 iIndex = m_lastChangedIndex;
279 else if ( iIndex < m_firstChangedIndex )
288template <
class ABSTRACT,
class IMPL,
class SAMPLE>
289void SimplePrImpl<ABSTRACT,IMPL,SAMPLE>::checkSamplesIGroup()
292 if ( !m_samplesIGroup.isValidObject() )
294 Alembic::Util::scoped_lock l( m_samplesIGroupMutex );
296 if ( m_samplesIGroup.isValidObject() )
299 std::string samplesIName = m_header->getName() +
".smpi";
300 ABCA_ASSERT( GroupExists( m_parentGroup, samplesIName ),
301 "Invalid property: " << m_header->getName()
302 <<
", missing smpi" );
304 m_samplesIGroup = OpenGroup( m_parentGroup,
305 samplesIName.c_str() );
306 ABCA_ASSERT( m_samplesIGroup.isValidObject(),
307 "Invalid property: " << m_header->getName()
308 <<
", invalid smpi group" );
313template <
class ABSTRACT,
class IMPL,
class SAMPLE>
314std::pair<index_t, chrono_t>
315SimplePrImpl<ABSTRACT,IMPL,SAMPLE>::getFloorIndex( chrono_t iTime )
317 return m_header->getTimeSampling()->getFloorIndex( iTime, m_numSamples );
321template <
class ABSTRACT,
class IMPL,
class SAMPLE>
322std::pair<index_t, chrono_t>
323SimplePrImpl<ABSTRACT,IMPL,SAMPLE>::getCeilIndex( chrono_t iTime )
325 return m_header->getTimeSampling()->getCeilIndex( iTime, m_numSamples );
329template <
class ABSTRACT,
class IMPL,
class SAMPLE>
330std::pair<index_t, chrono_t>
331SimplePrImpl<ABSTRACT,IMPL,SAMPLE>::getNearIndex( chrono_t iTime )
333 return m_header->getTimeSampling()->getNearIndex( iTime, m_numSamples );
337template <
class ABSTRACT,
class IMPL,
class SAMPLE>
339SimplePrImpl<ABSTRACT,IMPL,SAMPLE>::getSample( index_t iSampleIndex,
342 iSampleIndex = verifySampleIndex( iSampleIndex );
345 const std::string &myName = m_header->getName();
347 if ( iSampleIndex == 0 )
352 std::string sample0Name = getSampleName( myName, 0 );
353 if ( m_header->getPropertyType() == AbcA::kScalarProperty )
355 ABCA_ASSERT( AttrExists( m_parentGroup, sample0Name.c_str() ),
356 "Invalid property in SimplePrImpl getSample: "
357 << myName <<
", missing smp0" );
361 ABCA_ASSERT( DatasetExists( m_parentGroup, sample0Name ),
362 "Invalid propertyin SimplePrImpl getSample: "
363 << myName <<
", missing smp1" );
366 static_cast<IMPL *
>( this )->readSample( m_parentGroup.getObject(),
373 checkSamplesIGroup();
376 std::string sampleName = getSampleName( myName, iSampleIndex );
377 static_cast<IMPL *
>( this )->readSample( m_samplesIGroup.getObject(),
385template <
class ABSTRACT,
class IMPL,
class SAMPLE>
387SimplePrImpl<ABSTRACT,IMPL,SAMPLE>::getKey( index_t iSampleIndex,
390 iSampleIndex = verifySampleIndex( iSampleIndex );
393 const std::string &myName = m_header->getName();
395 if ( iSampleIndex == 0 )
400 std::string sample0Name = getSampleName( myName, 0 );
401 if ( m_header->getPropertyType() == AbcA::kScalarProperty )
403 ABCA_ASSERT( AttrExists( m_parentGroup, sample0Name.c_str() ),
404 "Invalid property in SimplePrImpl getKey: "
405 << myName <<
", missing smp0" );
409 ABCA_ASSERT( DatasetExists( m_parentGroup, sample0Name ),
410 "Invalid property in SimplePrImpl getKey: "
411 << myName <<
", missing smp1" );
414 return static_cast<IMPL *
>( this )->readKey( m_parentGroup.getObject(),
420 checkSamplesIGroup();
423 std::string sampleName = getSampleName( myName, iSampleIndex );
424 return static_cast<IMPL*
>( this )->readKey( m_samplesIGroup.getObject(),
431template <
class ABSTRACT,
class IMPL,
class SAMPLE>
432SimplePrImpl<ABSTRACT,IMPL,SAMPLE>::~SimplePrImpl()
435 CloseObject( m_samplesIGroup );
437 if ( m_fileDataType >= 0 && m_cleanFileDataType )
439 H5Tclose( m_fileDataType );
443 if ( m_nativeDataType >= 0 && m_cleanNativeDataType )
445 H5Tclose( m_nativeDataType );
446 m_nativeDataType = -1;
452using namespace ALEMBIC_VERSION_NS;
Definition HDF5Hierarchy.h:50
Definition Foundation.h:176
Alembic namespace ...
Definition ArchiveInfo.cpp:39
Definition ArraySampleKey.h:48