37#ifndef Alembic_AbcCoreHDF5_SimplePwImpl_h
38#define Alembic_AbcCoreHDF5_SimplePwImpl_h
40#include <Alembic/AbcCoreHDF5/Foundation.h>
41#include <Alembic/AbcCoreHDF5/WriteUtil.h>
42#include <Alembic/AbcCoreHDF5/DataTypeRegistry.h>
43#include <Alembic/AbcCoreHDF5/HDF5Util.h>
46namespace AbcCoreHDF5 {
47namespace ALEMBIC_VERSION_NS {
71template <
class ABSTRACT,
class IMPL,
class SAMPLE,
class KEY>
72class SimplePwImpl :
public ABSTRACT
75 SimplePwImpl( AbcA::CompoundPropertyWriterPtr iParent,
77 const std::string & iName,
78 const AbcA::MetaData & iMetaData,
79 const AbcA::DataType & iDataType,
80 uint32_t iTimeSamplingIndex,
81 AbcA::PropertyType iPropType );
84 virtual ~SimplePwImpl();
90 virtual const AbcA::PropertyHeader & getHeader()
const;
92 virtual AbcA::ObjectWriterPtr getObject();
94 virtual AbcA::CompoundPropertyWriterPtr getParent();
97 hid_t getSampleIGroup();
101 virtual void setSample( SAMPLE iSamp );
103 virtual void setFromPreviousSample( );
105 virtual size_t getNumSamples();
107 virtual void setTimeSamplingIndex( uint32_t iIndex );
111 AbcA::CompoundPropertyWriterPtr m_parent;
119 PropertyHeaderPtr m_header;
122 hid_t m_fileDataType;
123 bool m_cleanFileDataType;
124 hid_t m_nativeDataType;
125 bool m_cleanNativeDataType;
129 hid_t m_sampleIGroup;
132 uint32_t m_nextSampleIndex;
135 uint32_t m_firstChangedIndex;
140 uint32_t m_lastChangedIndex;
143 uint32_t m_timeSamplingIndex;
155template <
class ABSTRACT,
class IMPL,
class SAMPLE,
class KEY>
156SimplePwImpl<ABSTRACT,IMPL,SAMPLE,KEY>::SimplePwImpl
158 AbcA::CompoundPropertyWriterPtr iParent,
160 const std::string & iName,
161 const AbcA::MetaData & iMetaData,
162 const AbcA::DataType & iDataType,
163 uint32_t iTimeSamplingIndex,
164 AbcA::PropertyType iPropType
166 : m_parent( iParent )
167 , m_parentGroup( iParentGroup )
168 , m_fileDataType( -1 )
169 , m_cleanFileDataType( false )
170 , m_nativeDataType( -1 )
171 , m_cleanNativeDataType( false )
172 , m_sampleIGroup( -1 )
173 , m_nextSampleIndex( 0 )
174 , m_firstChangedIndex( 0 )
175 , m_lastChangedIndex( 0 )
176 , m_timeSamplingIndex(iTimeSamplingIndex)
179 ABCA_ASSERT( m_parent,
"Invalid parent" );
181 ABCA_ASSERT( iName !=
"" && iName.find(
'/') == std::string::npos,
185 AbcA::TimeSamplingPtr ts =
186 m_parent->getObject()->getArchive()->getTimeSampling(
187 m_timeSamplingIndex );
189 m_header = PropertyHeaderPtr(
new AbcA::PropertyHeader( iName, iPropType,
190 iMetaData, iDataType, ts ) );
192 ABCA_ASSERT( m_header,
"Invalid property header" );
193 ABCA_ASSERT( m_parentGroup >= 0,
"Invalid parent group" );
194 ABCA_ASSERT( m_header->getDataType().getExtent() > 0,
195 "Invalid DatatType extent");
198 PlainOldDataType POD = m_header->getDataType().getPod();
199 if ( POD != kStringPOD && POD != kWstringPOD )
201 m_fileDataType = GetFileH5T( m_header->getDataType(),
202 m_cleanFileDataType );
203 m_nativeDataType = GetNativeH5T( m_header->getDataType(),
204 m_cleanNativeDataType );
206 ABCA_ASSERT( m_fileDataType >= 0,
"Couldn't get file datatype" );
207 ABCA_ASSERT( m_nativeDataType >= 0,
"Couldn't get native datatype" );
217template <
class ABSTRACT,
class IMPL,
class SAMPLE,
class KEY>
218const AbcA::PropertyHeader &
219SimplePwImpl<ABSTRACT,IMPL,SAMPLE,KEY>::getHeader()
const
221 ABCA_ASSERT( m_header,
"Invalid header" );
226template <
class ABSTRACT,
class IMPL,
class SAMPLE,
class KEY>
228SimplePwImpl<ABSTRACT,IMPL,SAMPLE,KEY>::getObject()
230 ABCA_ASSERT( m_parent,
"Invalid parent" );
231 return m_parent->getObject();
235template <
class ABSTRACT,
class IMPL,
class SAMPLE,
class KEY>
236AbcA::CompoundPropertyWriterPtr
237SimplePwImpl<ABSTRACT,IMPL,SAMPLE,KEY>::getParent()
239 ABCA_ASSERT( m_parent,
"Invalid parent" );
244template <
class ABSTRACT,
class IMPL,
class SAMPLE,
class KEY>
245hid_t SimplePwImpl<ABSTRACT,IMPL,SAMPLE,KEY>::getSampleIGroup()
247 if ( m_sampleIGroup >= 0 )
249 return m_sampleIGroup;
252 ABCA_ASSERT( m_parentGroup >= 0,
"invalid parent group" );
253 ABCA_ASSERT( m_nextSampleIndex > 0,
254 "can't create sampleI group before numSamples > 1" );
256 const std::string groupName = m_header->getName() +
".smpi";
258 hid_t copl = CreationOrderPlist();
261 m_sampleIGroup = H5Gcreate2( m_parentGroup,
266 ABCA_ASSERT( m_sampleIGroup >= 0,
267 "Could not create simple samples group named: "
270 return m_sampleIGroup;
274template <
class ABSTRACT,
class IMPL,
class SAMPLE,
class KEY>
275void SimplePwImpl<ABSTRACT,IMPL,SAMPLE,KEY>::setSample
281 !m_header->getTimeSampling()->getTimeSamplingType().isAcyclic() ||
282 m_header->getTimeSampling()->getNumStoredTimes() >
284 "Can not write more samples than we have times for when using "
285 "Acyclic sampling." );
288 KEY key =
static_cast<IMPL*
>(
this)->computeSampleKey( iSamp );
291 if ( m_nextSampleIndex == 0 ||
292 !(
static_cast<IMPL*
>(
this)->sameAsPreviousSample( iSamp, key )) )
294 const std::string &myName = m_header->getName();
297 if (m_firstChangedIndex != 0)
300 for ( index_t smpI = m_lastChangedIndex + 1;
301 smpI < m_nextSampleIndex; ++smpI )
304 static_cast<IMPL*
>(
this)->copyPreviousSample(
306 getSampleName( myName, smpI ),
312 m_firstChangedIndex = m_nextSampleIndex;
317 static_cast<IMPL*
>(
this)->writeSample(
318 m_nextSampleIndex == 0 ? m_parentGroup : getSampleIGroup(),
319 getSampleName( myName, m_nextSampleIndex ),
320 m_nextSampleIndex, iSamp, key );
323 m_lastChangedIndex = m_nextSampleIndex;
327 m_nextSampleIndex ++;
331template <
class ABSTRACT,
class IMPL,
class SAMPLE,
class KEY>
332void SimplePwImpl<ABSTRACT,IMPL,SAMPLE,KEY>::setFromPreviousSample
339 !m_header->getTimeSampling()->getTimeSamplingType().isAcyclic() ||
340 m_header->getTimeSampling()->getNumStoredTimes() >
342 "Can not set more samples than we have times for when using "
343 "Acyclic sampling." );
345 ABCA_ASSERT( m_nextSampleIndex > 0,
346 "Can't set from previous sample before any samples have been written" );
348 m_nextSampleIndex ++;
352template <
class ABSTRACT,
class IMPL,
class SAMPLE,
class KEY>
353size_t SimplePwImpl<ABSTRACT,IMPL,SAMPLE,KEY>::getNumSamples()
355 return (
size_t )m_nextSampleIndex;
358template <
class ABSTRACT,
class IMPL,
class SAMPLE,
class KEY>
359void SimplePwImpl<ABSTRACT,IMPL,SAMPLE,KEY>::setTimeSamplingIndex
363 AbcA::TimeSamplingPtr ts =
364 m_parent->getObject()->getArchive()->getTimeSampling(
367 ABCA_ASSERT( !ts->getTimeSamplingType().isAcyclic() ||
368 ts->getNumStoredTimes() >= m_nextSampleIndex,
369 "Already have written more samples than we have times for when using "
370 "Acyclic sampling." );
372 m_header->setTimeSampling(ts);
373 m_timeSamplingIndex = iIndex;
377template <
class ABSTRACT,
class IMPL,
class SAMPLE,
class KEY>
378SimplePwImpl<ABSTRACT,IMPL,SAMPLE,KEY>::~SimplePwImpl()
384 if ( m_fileDataType >= 0 && m_cleanFileDataType )
385 { H5Tclose( m_fileDataType ); }
386 if ( m_nativeDataType >= 0 && m_cleanNativeDataType )
387 { H5Tclose( m_nativeDataType ); }
390 ABCA_ASSERT( m_parentGroup >= 0,
"Invalid parent group" );
393 if ( m_sampleIGroup >= 0 )
397 ABCA_ASSERT( m_firstChangedIndex > 0,
"Corrupt SimplePwImpl" );
398 H5Gclose( m_sampleIGroup );
403 AbcA::ArchiveWriterPtr archive = m_parent->getObject()->getArchive();
405 index_t maxSamples = archive->getMaxNumSamplesForTimeSamplingIndex(
406 m_timeSamplingIndex );
408 uint32_t numSamples = m_nextSampleIndex;
411 if ( m_lastChangedIndex == 0 && m_nextSampleIndex > 0 )
416 if ( maxSamples < numSamples )
418 archive->setMaxNumSamplesForTimeSamplingIndex( m_timeSamplingIndex,
423 catch ( std::exception & exc )
425 std::cerr <<
"AbcCoreHDF5::SimplePwImpl<A,I,K>::"
426 <<
"~SimplePwImpl(): EXCEPTION: "
427 << exc.what() << std::endl;
431 std::cerr <<
"AbcCoreHDF5::SimplePwImpl<A,I,K>::~SimplePwImpl(): "
432 <<
"UNKNOWN EXCEPTION: " << std::endl;
438 m_nativeDataType = -1;
443using namespace ALEMBIC_VERSION_NS;
Alembic namespace ...
Definition ArchiveInfo.cpp:39