Loading...
Searching...
No Matches
TokenMap.h
Go to the documentation of this file.
//-*****************************************************************************
//
// Copyright (c) 2009-2015,
// Sony Pictures Imageworks Inc. and
// Industrial Light & Magic, a division of Lucasfilm Entertainment Company Ltd.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Industrial Light & Magic nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//-*****************************************************************************
//-*****************************************************************************
//-*****************************************************************************
#ifndef Alembic_Util_TokenMap_h
#define Alembic_Util_TokenMap_h
#include <Alembic/Util/Export.h>
#include <Alembic/Util/Exception.h>
#include <Alembic/Util/Foundation.h>
namespace Alembic {
namespace Util {
namespace ALEMBIC_VERSION_NS {
//-*****************************************************************************
// TOKEN MAP
//
//-*****************************************************************************
class ALEMBIC_EXPORT TokenMap
{
public:
//-*************************************************************************
// TYPEDEFS
//-*************************************************************************
typedef std::map<std::string,std::string> map_type;
typedef map_type::key_type key_type;
// CJH: Not defined? typedef map_type::data_type data_type;
typedef std::string data_type;
typedef map_type::value_type value_type;
typedef map_type::iterator iterator;
typedef map_type::const_iterator const_iterator;
typedef map_type::reverse_iterator reverse_iterator;
typedef map_type::const_reverse_iterator const_reverse_iterator;
typedef map_type::reference reference;
typedef map_type::const_reference const_reference;
//-*************************************************************************
// CONSTRUCTORS
//-*************************************************************************
TokenMap() {}
//-*************************************************************************
explicit TokenMap( const std::string &config,
char pairSeparator = ';',
char assignSeparator = '=',
bool unique = false,
bool quiet = true )
{
if ( unique )
{
setUnique( config, pairSeparator, assignSeparator, quiet );
}
else
{
set( config, pairSeparator, assignSeparator );
}
}
//-*************************************************************************
//-*************************************************************************
//-*************************************************************************
// SET
void set( const std::string &config,
char pairSeparator = ';',
char assignSeparator = '=' );
//-*************************************************************************
// SET UNIQUE
void setUnique( const std::string &config,
char pairSeparator = ';',
char assignSeparator = '=',
bool quiet = true );
//-*************************************************************************
// GET
std::string get( char pairSeparator = ';',
char assignSeparator = '=',
bool check = false ) const;
//-*************************************************************************
// CLEAR THE MAP
//-*************************************************************************
void clear() { m_map.clear(); }
//-*************************************************************************
// INDIVIDUAL TOKEN ACCESS
//-*************************************************************************
size_t size() const { return m_map.size(); }
bool tokenExists( const std::string &token ) const
{
return ( m_map.count( token ) > 0 );
}
std::string value( const std::string &token ) const
{
const_iterator fiter = m_map.find( token );
if ( fiter != m_map.end() )
{
return (*fiter).second;
}
else
{
return "";
}
}
std::string operator[]( const std::string &token ) const
{
return value( token );
}
void setValue( const std::string &keyStr,
const std::string &valueStr )
{
m_map[keyStr] = valueStr;
}
//-*************************************************************************
// ITERATION
//-*************************************************************************
iterator begin() { return m_map.begin(); }
const_iterator begin() const { return m_map.begin(); }
iterator end() { return m_map.end(); }
const_iterator end() const { return m_map.end(); }
//-*************************************************************************
// REVERSE ITERATION
//-*************************************************************************
reverse_iterator rbegin() { return m_map.rbegin(); }
const_reverse_iterator rbegin() const { return m_map.rbegin(); }
reverse_iterator rend() { return m_map.rend(); }
const_reverse_iterator rend() const { return m_map.rend(); }
//-*************************************************************************
// COMPARISON
//-*************************************************************************
bool exactMatch( const TokenMap &iOther ) const
{
return m_map == iOther.m_map;
}
protected:
map_type m_map;
};
//-*****************************************************************************
inline bool operator==( const TokenMap &iA, const TokenMap &iB )
{
return iA.exactMatch( iB );
}
} // End namespace ALEMBIC_VERSION_NS
using namespace ALEMBIC_VERSION_NS;
} // End namespace Util
} // End namespace Alembic
#endif
Exception.h
Header file containing class definition for class Alembic::Util::Exception.
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::rend
reverse_iterator rend()
same as std::map rend Returns an reverse_iterator corresponding to the reverse end of the map.
Definition TokenMap.h:285
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::reverse_iterator
map_type::reverse_iterator reverse_iterator
Definition TokenMap.h:93
Alembic::Util::ALEMBIC_VERSION_NS::TokenMap::tokenExists
bool tokenExists(const std::string &token) const
This function returns whether the map contains an entry for a particular token.
Definition TokenMap.h:205
Alembic::Util::ALEMBIC_VERSION_NS::TokenMap::set
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...
Definition TokenMap.cpp:49
Alembic::Util::ALEMBIC_VERSION_NS::TokenMap::reference
map_type::reference reference
Definition TokenMap.h:101
Alembic::Util::ALEMBIC_VERSION_NS::TokenMap::exactMatch
bool exactMatch(const TokenMap &iOther) const
Definition TokenMap.h:298
Alembic::Util::ALEMBIC_VERSION_NS::TokenMap::rend
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
Alembic::Util::ALEMBIC_VERSION_NS::TokenMap::begin
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
Alembic::Util::ALEMBIC_VERSION_NS::TokenMap::TokenMap
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
Alembic::Util::ALEMBIC_VERSION_NS::TokenMap::iterator
map_type::iterator iterator
Definition TokenMap.h:85
Alembic::Util::ALEMBIC_VERSION_NS::TokenMap::const_reference
map_type::const_reference const_reference
Definition TokenMap.h:105
Alembic::Util::ALEMBIC_VERSION_NS::TokenMap::map_type
std::map< std::string, std::string > map_type
Definition TokenMap.h:68
Alembic::Util::ALEMBIC_VERSION_NS::TokenMap::TokenMap
TokenMap()
Default constructor Map is initialized with no entries. Values can be added using The set and setUniq...
Definition TokenMap.h:113
Alembic::Util::ALEMBIC_VERSION_NS::TokenMap::end
iterator end()
same as std::map end Returns an iterator corresponding to the end of the map.
Definition TokenMap.h:261
Alembic::Util::ALEMBIC_VERSION_NS::TokenMap::setValue
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
Alembic::Util::ALEMBIC_VERSION_NS::TokenMap::rbegin
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
Alembic::Util::ALEMBIC_VERSION_NS::TokenMap::rbegin
reverse_iterator rbegin()
same as std::map rbegin Returns an reverse_iterator corresponding to the reverse_beginning of the map...
Definition TokenMap.h:275
Alembic::Util::ALEMBIC_VERSION_NS::TokenMap::value
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
Alembic::Util::ALEMBIC_VERSION_NS::TokenMap::end
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
Alembic::Util::ALEMBIC_VERSION_NS::TokenMap::value_type
map_type::value_type value_type
Definition TokenMap.h:81
Alembic::Util::ALEMBIC_VERSION_NS::TokenMap::setUnique
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...
Definition TokenMap.cpp:81
Alembic::Util::ALEMBIC_VERSION_NS::TokenMap::begin
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::Util::ALEMBIC_VERSION_NS::TokenMap::operator[]
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
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