Alembic Version 1.1
Loading...
Searching...
No Matches
MetaData.h
Go to the documentation of this file.
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
41
42namespace Alembic {
43namespace AbcCoreAbstract {
44namespace ALEMBIC_VERSION_NS {
45
46//-*****************************************************************************
60{
61public:
62 //-*************************************************************************
63 // TYPEDEFS
64 //-*************************************************************************
65
69
73
77
82
86
90
94
95 //-*************************************************************************
96 // CONSTRUCTION
97 //-*************************************************************************
98
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
#define ABCA_THROW(TEXT)
Definition Foundation.h:96
#define ALEMBIC_VERSION_NS
Definition Foundation.h:105
std::string get(const std::string &iKey) const
Definition MetaData.h:192
MetaData & operator=(const MetaData &iCopy)
Definition MetaData.h:109
std::string getRequired(const std::string &iKey) const
Definition MetaData.h:199
void set(const std::string &iKey, const std::string &iData)
Definition MetaData.h:168
token_map_type::const_reverse_iterator const_reverse_iterator
Definition MetaData.h:93
bool matchesOverlap(const MetaData &iMetaData) const
Definition MetaData.h:271
void setUnique(const std::string &iKey, const std::string &iData)
Definition MetaData.h:177
bool matches(const MetaData &iMetaData) const
Definition MetaData.h:256
void appendUnique(const MetaData &iMetaData)
Definition MetaData.h:236
void appendOnlyUnique(const MetaData &iMetaData)
Definition MetaData.h:222
bool matchesExactly(const MetaData &iMetaData) const
Definition MetaData.h:288
token_map_type::const_iterator const_iterator
Definition MetaData.h:89
token_map_type::const_reference const_reference
Definition MetaData.h:85
A wrapper around std::map that serializes and deserializes the map into a doubly-tokenized string,...
Definition TokenMap.h:61
reverse_iterator rend()
same as std::map rend Returns an reverse_iterator corresponding to the reverse end of the map.
Definition TokenMap.h:285
map_type::const_iterator const_iterator
Definition TokenMap.h:89
map_type::const_reverse_iterator const_reverse_iterator
Definition TokenMap.h:97
size_t size() const
This function returns the number of pairs. ...
Definition TokenMap.h:201
bool tokenExists(const std::string &token) const
This function returns whether the map contains an entry for a particular token.
Definition TokenMap.h:205
bool exactMatch(const TokenMap &iOther) const
Definition TokenMap.h:298
map_type::const_reference const_reference
Definition TokenMap.h:105
iterator end()
same as std::map end Returns an iterator corresponding to the end of the map.
Definition TokenMap.h:261
void setValue(const std::string &keyStr, const std::string &valueStr)
This function sets the value of a token. It will either add a new token-value pair if the map does no...
Definition TokenMap.h:239
reverse_iterator rbegin()
same as std::map rbegin Returns an reverse_iterator corresponding to the reverse_beginning of the map...
Definition TokenMap.h:275
std::string value(const std::string &token) const
This function returns the string value associated with a particular token, or the empty string "" if ...
Definition TokenMap.h:213
std::string get(char pairSeparator=';', char assignSeparator='=', bool check=false) const
This function turns the map back into a doubly-tokenized string.
void setUnique(const std::string &config, char pairSeparator=';', char assignSeparator='=', bool quiet=true)
This function sets only unique (not already stored) token/value pairs by deserializing them from a do...
iterator begin()
same as std::map begin Returns an iterator corresponding to the beginning of the map or the end of th...
Definition TokenMap.h:252
Alembic namespace ...
Definition ArchiveInfo.h:46