Loading...
Searching...
No Matches
MetaData.h
Go to the documentation of this file.
//-*****************************************************************************
//
// Copyright (c) 2009-2011,
// 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 Sony Pictures Imageworks, nor
// Industrial Light & Magic, nor the names of their 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_AbcCoreAbstract_MetaData_h
#define Alembic_AbcCoreAbstract_MetaData_h
#include <Alembic/AbcCoreAbstract/Foundation.h>
namespace Alembic {
namespace AbcCoreAbstract {
namespace ALEMBIC_VERSION_NS {
//-*****************************************************************************
class MetaData
{
public:
//-*************************************************************************
// TYPEDEFS
//-*************************************************************************
typedef Alembic::Util::TokenMap token_map_type;
typedef token_map_type::key_type key_type;
typedef token_map_type::data_type data_type;
typedef token_map_type::value_type value_type;
typedef token_map_type::const_reference const_reference;
typedef token_map_type::const_iterator const_iterator;
typedef token_map_type::const_reverse_iterator const_reverse_iterator;
//-*************************************************************************
// CONSTRUCTION
//-*************************************************************************
MetaData() {}
MetaData( const MetaData &iCopy ) : m_tokenMap( iCopy.m_tokenMap ) {}
MetaData& operator=( const MetaData &iCopy )
{
m_tokenMap = iCopy.m_tokenMap;
return *this;
}
//-*************************************************************************
// SERIALIZATION/DESERIALIZATION
//-*************************************************************************
void deserialize( const std::string &iFrom )
{
m_tokenMap.clear();
m_tokenMap.setUnique( iFrom, ';', '=', true );
}
std::string serialize() const
{
return m_tokenMap.get( ';', '=', true );
}
//-*************************************************************************
// SIZE
//-*************************************************************************
size_t size() const { return m_tokenMap.size(); }
//-*************************************************************************
// ITERATION
//-*************************************************************************
const_iterator begin() const { return m_tokenMap.begin(); }
const_iterator end() const { return m_tokenMap.end(); }
const_reverse_iterator rbegin() const { return m_tokenMap.rbegin(); }
const_reverse_iterator rend() const { return m_tokenMap.rend(); }
//-*************************************************************************
// ACCESS/ASSIGNMENT
//-*************************************************************************
void set( const std::string &iKey, const std::string &iData )
{
m_tokenMap.setValue( iKey, iData );
}
void setUnique( const std::string &iKey, const std::string &iData )
{
std::string found = m_tokenMap.value( iKey );
if ( found == "" )
{
m_tokenMap.setValue( iKey, iData );
}
else if ( found != iData )
{
ABCA_THROW( "Key: " << iKey << " already exists in MetaData" );
}
}
std::string get( const std::string &iKey ) const
{
return m_tokenMap.value( iKey );
}
std::string getRequired( const std::string &iKey ) const
{
std::string ret = m_tokenMap.value( iKey );
if ( ret == "" )
{
ABCA_THROW( "Key: " << iKey << " did not exist in MetaData" );
}
return ret;
}
void append( const MetaData &iMetaData )
{
for ( const_iterator iter = iMetaData.begin();
iter != iMetaData.end(); ++iter )
{
set( (*iter).first, (*iter).second );
}
}
void appendOnlyUnique( const MetaData &iMetaData )
{
for ( const_iterator iter = iMetaData.begin();
iter != iMetaData.end(); ++iter )
{
if ( !m_tokenMap.tokenExists( (*iter).first ) )
{
set( (*iter).first, (*iter).second );
}
}
}
void appendUnique( const MetaData &iMetaData )
{
for ( const_iterator iter = iMetaData.begin();
iter != iMetaData.end(); ++iter )
{
setUnique( (*iter).first, (*iter).second );
}
}
//-*************************************************************************
// MATCHING
// Simple matching for now, we'll save regex stuff for later.
//-*************************************************************************
bool matches( const MetaData &iMetaData ) const
{
for ( const_iterator iter = iMetaData.begin();
iter != iMetaData.end(); ++iter )
{
if ( get( (*iter).first ) != (*iter).second )
{
return false;
}
}
return true;
}
bool matchesOverlap( const MetaData &iMetaData ) const
{
for ( const_iterator iter = iMetaData.begin();
iter != iMetaData.end(); ++iter )
{
std::string found = get( (*iter).first );
if ( found != "" && found != (*iter).second )
{
return false;
}
}
return true;
}
bool matchesExactly( const MetaData &iMetaData ) const
{
return m_tokenMap.exactMatch( iMetaData.m_tokenMap );
}
private:
Alembic::Util::TokenMap m_tokenMap;
};
} // End namespace ALEMBIC_VERSION_NS
using namespace ALEMBIC_VERSION_NS;
} // End namespace AbcCoreAbstract
} // End namespace Alembic
#endif
Foundation.h
ABCA_THROW
#define ABCA_THROW(TEXT)
Definition Foundation.h:96
ALEMBIC_VERSION_NS
#define ALEMBIC_VERSION_NS
Definition Foundation.h:105
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::size
size_t size() const
Definition MetaData.h:140
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::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::AbcCoreAbstract::ALEMBIC_VERSION_NS
Definition ArchiveReader.h:47
Alembic::AbcCoreAbstract
Definition ArchiveReader.h:46
Alembic
Alembic namespace ...
Definition ArchiveInfo.h:46