Alembic Version 1.1
TokenMap.h
Go to the documentation of this file.
1//-*****************************************************************************
2//
3// Copyright (c) 2009-2015,
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 Industrial Light & Magic nor the names of
19// its contributors may be used to endorse or promote products derived
20// from this software without specific prior written permission.
21//
22// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33//
34//-*****************************************************************************
35
36//-*****************************************************************************
40//-*****************************************************************************
41#ifndef Alembic_Util_TokenMap_h
42#define Alembic_Util_TokenMap_h
43
44#include <Alembic/Util/Export.h>
47
48namespace Alembic {
49namespace Util {
50namespace ALEMBIC_VERSION_NS {
51
52//-*****************************************************************************
53// TOKEN MAP
54//
58//-*****************************************************************************
59
61{
62public:
63 //-*************************************************************************
64 // TYPEDEFS
65 //-*************************************************************************
68 typedef std::map<std::string,std::string> map_type;
69
72 typedef map_type::key_type key_type;
73
76 // CJH: Not defined? typedef map_type::data_type data_type;
77 typedef std::string data_type;
78
81 typedef map_type::value_type value_type;
82
85 typedef map_type::iterator iterator;
86
89 typedef map_type::const_iterator const_iterator;
90
93 typedef map_type::reverse_iterator reverse_iterator;
94
97 typedef map_type::const_reverse_iterator const_reverse_iterator;
98
101 typedef map_type::reference reference;
102
105 typedef map_type::const_reference const_reference;
106
107 //-*************************************************************************
108 // CONSTRUCTORS
109 //-*************************************************************************
114
115 //-*************************************************************************
121 explicit TokenMap( const std::string &config,
122 char pairSeparator = ';',
123 char assignSeparator = '=',
124 bool unique = false,
125 bool quiet = true )
126 {
127 if ( unique )
128 {
129 setUnique( config, pairSeparator, assignSeparator, quiet );
130 }
131 else
132 {
133 set( config, pairSeparator, assignSeparator );
134 }
135 }
136
137 //-*************************************************************************
140
141 //-*************************************************************************
144
145 //-*************************************************************************
146 // SET
156 void set( const std::string &config,
157 char pairSeparator = ';',
158 char assignSeparator = '=' );
159
160 //-*************************************************************************
161 // SET UNIQUE
171 void setUnique( const std::string &config,
172 char pairSeparator = ';',
173 char assignSeparator = '=',
174 bool quiet = true );
175
176
177 //-*************************************************************************
178 // GET
186 std::string get( char pairSeparator = ';',
187 char assignSeparator = '=',
188 bool check = false ) const;
189
190 //-*************************************************************************
191 // CLEAR THE MAP
192 //-*************************************************************************
193 void clear() { m_map.clear(); }
194
195 //-*************************************************************************
196 // INDIVIDUAL TOKEN ACCESS
197 //-*************************************************************************
198
201 size_t size() const { return m_map.size(); }
202
205 bool tokenExists( const std::string &token ) const
206 {
207 return ( m_map.count( token ) > 0 );
208 }
209
213 std::string value( const std::string &token ) const
214 {
215 const_iterator fiter = m_map.find( token );
216 if ( fiter != m_map.end() )
217 {
218 return (*fiter).second;
219 }
220 else
221 {
222 return "";
223 }
224 }
225
229 std::string operator[]( const std::string &token ) const
230 {
231 return value( token );
232 }
233
239 void setValue( const std::string &keyStr,
240 const std::string &valueStr )
241 {
242 m_map[keyStr] = valueStr;
243 }
244
245 //-*************************************************************************
246 // ITERATION
247 //-*************************************************************************
248
252 iterator begin() { return m_map.begin(); }
253
257 const_iterator begin() const { return m_map.begin(); }
258
261 iterator end() { return m_map.end(); }
262
265 const_iterator end() const { return m_map.end(); }
266
267 //-*************************************************************************
268 // REVERSE ITERATION
269 //-*************************************************************************
270
275 reverse_iterator rbegin() { return m_map.rbegin(); }
276
280 const_reverse_iterator rbegin() const { return m_map.rbegin(); }
281
285 reverse_iterator rend() { return m_map.rend(); }
286
290 const_reverse_iterator rend() const { return m_map.rend(); }
291
292 //-*************************************************************************
293 // COMPARISON
294 //-*************************************************************************
295
298 bool exactMatch( const TokenMap &iOther ) const
299 {
300 return m_map == iOther.m_map;
301 }
302
303protected:
305};
306
307//-*****************************************************************************
308inline bool operator==( const TokenMap &iA, const TokenMap &iB )
309{
310 return iA.exactMatch( iB );
311}
312
313} // End namespace ALEMBIC_VERSION_NS
314
315using namespace ALEMBIC_VERSION_NS;
316
317} // End namespace Util
318} // End namespace Alembic
319
320#endif
Header file containing class definition for class Alembic::Util::Exception.
#define ALEMBIC_EXPORT
Definition: Export.h:51
#define ALEMBIC_VERSION_NS
Definition: Foundation.h:105
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
map_type::reverse_iterator reverse_iterator
Definition: TokenMap.h:93
bool tokenExists(const std::string &token) const
This function returns whether the map contains an entry for a particular token.
Definition: TokenMap.h:205
void set(const std::string &config, char pairSeparator=';', char assignSeparator='=')
This function sets the token/value pairs in the map by deserializing them from a doubly-delimited str...
bool exactMatch(const TokenMap &iOther) const
Definition: TokenMap.h:298
const_reverse_iterator rend() const
same as std::map rend const Returns an const_reverse_iterator corresponding to the end of the map.
Definition: TokenMap.h:290
const_iterator begin() const
same as std::map begin const Returns a const_iterator corresponding to the beginning of the map or th...
Definition: TokenMap.h:257
TokenMap(const std::string &config, char pairSeparator=';', char assignSeparator='=', bool unique=false, bool quiet=true)
Explicit constructor Map is initialized from given string, using the delimiter scheme as presented....
Definition: TokenMap.h:121
map_type::const_reference const_reference
Definition: TokenMap.h:105
std::map< std::string, std::string > map_type
Definition: TokenMap.h:68
TokenMap()
Default constructor Map is initialized with no entries. Values can be added using The set and setUniq...
Definition: TokenMap.h:113
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
const_reverse_iterator rbegin() const
same as std::map rbegin const Returns a const_reverse_iterator corresponding to the beginning of the ...
Definition: TokenMap.h:280
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
const_iterator end() const
same as std::map end const Returns an const_iterator corresponding to the end of the map.
Definition: TokenMap.h:265
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
std::string operator[](const std::string &token) const
This function is a shorthand for value It will not return a modifiable entry. To modify,...
Definition: TokenMap.h:229
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:137
Alembic namespace ...
Definition: ArchiveInfo.h:46