Alembic: AbcCoreAbstract/MetaData.h Source File

Alembic 1.8.11

Loading...
Searching...
No Matches
MetaData.h
1//-*****************************************************************************
2//
3// Copyright (c) 2009-2011,
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_AbcCoreAbstract_MetaData_h
38#define Alembic_AbcCoreAbstract_MetaData_h
39
40#include <Alembic/AbcCoreAbstract/Foundation.h>
41
42namespace Alembic {
43namespace AbcCoreAbstract {
44namespace ALEMBIC_VERSION_NS {
45
46//-*****************************************************************************
59 class MetaData
60{
61public:
62 //-*************************************************************************
63 // TYPEDEFS
64 //-*************************************************************************
65
68 typedef Alembic::Util::TokenMap token_map_type;
69
72 typedef token_map_type::key_type key_type;
73
76 typedef token_map_type::data_type data_type;
77
81 typedef token_map_type::value_type value_type;
82
85 typedef token_map_type::const_reference const_reference;
86
89 typedef token_map_type::const_iterator const_iterator;
90
93 typedef token_map_type::const_reverse_iterator const_reverse_iterator;
94
95 //-*************************************************************************
96 // CONSTRUCTION
97 //-*************************************************************************
98
101 MetaData() {}
102
105 MetaData( const MetaData &iCopy ) : m_tokenMap( iCopy.m_tokenMap ) {}
106
109 MetaData& operator=( const MetaData &iCopy )
110 {
111 m_tokenMap = iCopy.m_tokenMap;
112 return *this;
113 }
114
115 //-*************************************************************************
116 // SERIALIZATION/DESERIALIZATION
117 //-*************************************************************************
118
123 void deserialize( const std::string &iFrom )
124 {
125 m_tokenMap.clear();
126 m_tokenMap.setUnique( iFrom, ';', '=', true );
127 }
128
132 std::string serialize() const
133 {
134 return m_tokenMap.get( ';', '=', true );
135 }
136
137 //-*************************************************************************
138 // SIZE
139 //-*************************************************************************
140 size_t size() const { return m_tokenMap.size(); }
141
142 //-*************************************************************************
143 // ITERATION
144 //-*************************************************************************
145
148 const_iterator begin() const { return m_tokenMap.begin(); }
149
152 const_iterator end() const { return m_tokenMap.end(); }
153
156 const_reverse_iterator rbegin() const { return m_tokenMap.rbegin(); }
157
160 const_reverse_iterator rend() const { return m_tokenMap.rend(); }
161
162 //-*************************************************************************
163 // ACCESS/ASSIGNMENT
164 //-*************************************************************************
165
168 void set( const std::string &iKey, const std::string &iData )
169 {
170 m_tokenMap.setValue( iKey, iData );
171 }
172
177 void setUnique( const std::string &iKey, const std::string &iData )
178 {
179 std::string found = m_tokenMap.value( iKey );
180 if ( found == "" )
181 {
182 m_tokenMap.setValue( iKey, iData );
183 }
184 else if ( found != iData )
185 {
186 ABCA_THROW( "Key: " << iKey << " already exists in MetaData" );
187 }
188 }
189
192 std::string get( const std::string &iKey ) const
193 {
194 return m_tokenMap.value( iKey );
195 }
196
199 std::string getRequired( const std::string &iKey ) const
200 {
201 std::string ret = m_tokenMap.value( iKey );
202 if ( ret == "" )
203 {
204 ABCA_THROW( "Key: " << iKey << " did not exist in MetaData" );
205 }
206 return ret;
207 }
208
211 void append( const MetaData &iMetaData )
212 {
213 for ( const_iterator iter = iMetaData.begin();
214 iter != iMetaData.end(); ++iter )
215 {
216 set( (*iter).first, (*iter).second );
217 }
218 }
219
222 void appendOnlyUnique( const MetaData &iMetaData )
223 {
224 for ( const_iterator iter = iMetaData.begin();
225 iter != iMetaData.end(); ++iter )
226 {
227 if ( !m_tokenMap.tokenExists( (*iter).first ) )
228 {
229 set( (*iter).first, (*iter).second );
230 }
231 }
232 }
233
236 void appendUnique( const MetaData &iMetaData )
237 {
238 for ( const_iterator iter = iMetaData.begin();
239 iter != iMetaData.end(); ++iter )
240 {
241 setUnique( (*iter).first, (*iter).second );
242 }
243 }
244
245 //-*************************************************************************
246 // MATCHING
247 // Simple matching for now, we'll save regex stuff for later.
248 //-*************************************************************************
249
256 bool matches( const MetaData &iMetaData ) const
257 {
258 for ( const_iterator iter = iMetaData.begin();
259 iter != iMetaData.end(); ++iter )
260 {
261 if ( get( (*iter).first ) != (*iter).second )
262 {
263 return false;
264 }
265 }
266 return true;
267 }
268
271 bool matchesOverlap( const MetaData &iMetaData ) const
272 {
273 for ( const_iterator iter = iMetaData.begin();
274 iter != iMetaData.end(); ++iter )
275 {
276 std::string found = get( (*iter).first );
277 if ( found != "" && found != (*iter).second )
278 {
279 return false;
280 }
281 }
282 return true;
283 }
284
288 bool matchesExactly( const MetaData &iMetaData ) const
289 {
290 return m_tokenMap.exactMatch( iMetaData.m_tokenMap );
291 }
292
293private:
294 Alembic::Util::TokenMap m_tokenMap;
295};
296
297} // End namespace ALEMBIC_VERSION_NS
298
299using namespace ALEMBIC_VERSION_NS;
300
301} // End namespace AbcCoreAbstract
302} // End namespace Alembic
303
304#endif
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::MetaData::begin
const_iterator begin() const
Definition MetaData.h:148
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::MetaData::MetaData
MetaData()
Definition MetaData.h:101
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::MetaData::value_type
token_map_type::value_type value_type
Definition MetaData.h:81
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::MetaData::get
std::string get(const std::string &iKey) const
Definition MetaData.h:192
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::MetaData::serialize
std::string serialize() const
Definition MetaData.h:132
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::MetaData::operator=
MetaData & operator=(const MetaData &iCopy)
Definition MetaData.h:109
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::MetaData::end
const_iterator end() const
Definition MetaData.h:152
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::MetaData::MetaData
MetaData(const MetaData &iCopy)
Definition MetaData.h:105
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::MetaData::getRequired
std::string getRequired(const std::string &iKey) const
Definition MetaData.h:199
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::MetaData::key_type
token_map_type::key_type key_type
Definition MetaData.h:72
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::MetaData::set
void set(const std::string &iKey, const std::string &iData)
Definition MetaData.h:168
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::MetaData::rbegin
const_reverse_iterator rbegin() const
Definition MetaData.h:156
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::MetaData::const_reverse_iterator
token_map_type::const_reverse_iterator const_reverse_iterator
Definition MetaData.h:93
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::MetaData::rend
const_reverse_iterator rend() const
Definition MetaData.h:160
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::MetaData::matchesOverlap
bool matchesOverlap(const MetaData &iMetaData) const
Definition MetaData.h:271
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::MetaData::setUnique
void setUnique(const std::string &iKey, const std::string &iData)
Definition MetaData.h:177
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::MetaData::matches
bool matches(const MetaData &iMetaData) const
Definition MetaData.h:256
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::MetaData::appendUnique
void appendUnique(const MetaData &iMetaData)
Definition MetaData.h:236
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::MetaData::data_type
token_map_type::data_type data_type
Definition MetaData.h:76
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::MetaData::appendOnlyUnique
void appendOnlyUnique(const MetaData &iMetaData)
Definition MetaData.h:222
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::MetaData::append
void append(const MetaData &iMetaData)
Definition MetaData.h:211
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::MetaData::deserialize
void deserialize(const std::string &iFrom)
Definition MetaData.h:123
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::MetaData::matchesExactly
bool matchesExactly(const MetaData &iMetaData) const
Definition MetaData.h:288
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::MetaData::const_iterator
token_map_type::const_iterator const_iterator
Definition MetaData.h:89
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::MetaData::const_reference
token_map_type::const_reference const_reference
Definition MetaData.h:85
Alembic::AbcCoreAbstract::ALEMBIC_VERSION_NS::MetaData::token_map_type
Alembic::Util::TokenMap token_map_type
Definition MetaData.h:68
Alembic::Util::ALEMBIC_VERSION_NS::TokenMap
A wrapper around std::map that serializes and deserializes the map into a doubly-tokenized string,...
Definition TokenMap.h:61
Alembic::Util::ALEMBIC_VERSION_NS::TokenMap::const_iterator
map_type::const_iterator const_iterator
Definition TokenMap.h:89
Alembic::Util::ALEMBIC_VERSION_NS::TokenMap::const_reverse_iterator
map_type::const_reverse_iterator const_reverse_iterator
Definition TokenMap.h:97
Alembic::Util::ALEMBIC_VERSION_NS::TokenMap::size
size_t size() const
This function returns the number of pairs. ...
Definition TokenMap.h:201
Alembic::Util::ALEMBIC_VERSION_NS::TokenMap::const_reference
map_type::const_reference const_reference
Definition TokenMap.h:105
Alembic::Util::ALEMBIC_VERSION_NS::TokenMap::value_type
map_type::value_type value_type
Definition TokenMap.h:81
Alembic::Util::ALEMBIC_VERSION_NS::TokenMap::data_type
std::string data_type
Definition TokenMap.h:77
Alembic::Util::ALEMBIC_VERSION_NS::TokenMap::key_type
map_type::key_type key_type
Definition TokenMap.h:72
Alembic
Alembic namespace ...
Definition ArchiveInfo.cpp:39