Alembic: AbcCoreHDF5/WrittenArraySampleMap.h Source File

Alembic 1.8.11

Loading...
Searching...
No Matches
WrittenArraySampleMap.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_AbcCoreHDF5_WrittenArraySampleMap_h
38#define Alembic_AbcCoreHDF5_WrittenArraySampleMap_h
39
40#include <Alembic/AbcCoreAbstract/ArraySampleKey.h>
41#include <Alembic/AbcCoreHDF5/Foundation.h>
42#include <Alembic/AbcCoreHDF5/HDF5Util.h>
43
44
45namespace Alembic {
46namespace AbcCoreHDF5 {
47namespace ALEMBIC_VERSION_NS {
48
49//-*****************************************************************************
50// A Written Array Sample ID is a receipt that contains information that
51// refers to the exact location in an HDF5 file that an array sample was written
52// to. It also contains the Key of the array sample, so it may be verified.
53//
54// This object is used to "reuse" an already written array sample by linking
55// it from the previous usage.
56//-*****************************************************************************
57 class WrittenArraySampleID
58{
59public:
60 WrittenArraySampleID()
61 : m_sampleKey() {}
62
63 WrittenArraySampleID( const AbcA::ArraySample::Key &iKey, hid_t iObjLocID )
64 : m_sampleKey( iKey )
65 {
66 int strLen = H5Iget_name( iObjLocID, NULL, 0 );
67 ABCA_ASSERT( strLen > 0, "WrittenSampleID() passed in bad iObjLocID" );
68
69 // add 1 to account for the NULL seperator
70 strLen ++;
71
72 m_objectLocation.resize( strLen );
73 H5Iget_name( iObjLocID, &(m_objectLocation[0]), strLen );
74 }
75
76 const AbcA::ArraySample::Key &getKey() const { return m_sampleKey; }
77
78 std::string getObjectLocation() const { return m_objectLocation; }
79
80private:
81 AbcA::ArraySample::Key m_sampleKey;
82 std::string m_objectLocation;
83};
84
85//-*****************************************************************************
86typedef Alembic::Util::shared_ptr<WrittenArraySampleID> WrittenArraySampleIDPtr;
87
88//-*****************************************************************************
89// This class handles the mapping.
90 class WrittenArraySampleMap
91{
92protected:
93 friend class AwImpl;
94
95 WrittenArraySampleMap() {}
96
97public:
98
99 // Returns 0 if it can't find it
100 WrittenArraySampleIDPtr find( const AbcA::ArraySample::Key &key ) const
101 {
102 Map::const_iterator miter = m_map.find( key );
103 if ( miter != m_map.end() )
104 {
105 return (*miter).second;
106 }
107 else
108 {
109 return WrittenArraySampleIDPtr();
110 }
111 }
112
113 // Store. Will clobber if you've already stored it.
114 void store( WrittenArraySampleIDPtr r )
115 {
116 if ( !r )
117 {
118 ABCA_THROW( "Invalid WrittenArraySampleIDPtr" );
119 }
120
121 m_map[r->getKey()] = r;
122 }
123
124protected:
125 typedef AbcA::UnorderedMapUtil<WrittenArraySampleIDPtr>::umap_type Map;
126 Map m_map;
127};
128
129} // End namespace ALEMBIC_VERSION_NS
130
131using namespace ALEMBIC_VERSION_NS;
132
133} // End namespace AbcCoreHDF5
134} // End namespace Alembic
135
136#endif
Alembic
Alembic namespace ...
Definition ArchiveInfo.cpp:39