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