osgEarth 2.1.1
Public Types | Public Member Functions | Protected Attributes

osgEarth::Config Class Reference

Collaboration diagram for osgEarth::Config:

List of all members.

Public Types

typedef std::map< std::string,
osg::ref_ptr< osg::Referenced > > 
RefMap

Public Member Functions

 Config ()
 Config (const std::string &key)
 Config (const std::string &key, const std::string &value)
 Config (const Config &rhs)
void setURIContext (const URIContext &value)
const URIContexturiContext () const
bool loadXML (std::istream &in)
bool empty () const
std::string & key ()
const std::string & key () const
const std::string & value () const
std::string & value ()
Propertiesattrs ()
const Propertiesattrs () const
std::string attr (const std::string &name) const
std::string & attr (const std::string &name)
const ConfigSetchildren () const
const ConfigSet children (const std::string &key) const
bool hasChild (const std::string &key) const
void remove (const std::string &key)
const Configchild (const std::string &key) const
void merge (const Config &rhs)
template<typename T >
void addIfSet (const std::string &key, const optional< T > &opt)
template<typename T >
void addObjIfSet (const std::string &key, const osg::ref_ptr< T > &opt)
template<typename T >
void addObjIfSet (const std::string &key, const optional< T > &obj)
template<typename X , typename Y >
void addIfSet (const std::string &key, const std::string &val, const optional< X > &target, const Y &targetValue)
void addChild (const std::string &key, const std::string &value)
void add (const std::string &key, const std::string &value)
void addChild (const Config &conf)
void add (const Config &conf)
void add (const std::string &key, const Config &conf)
void add (const ConfigSet &set)
template<typename T >
void updateIfSet (const std::string &key, const optional< T > &opt)
template<typename T >
void updateObjIfSet (const std::string &key, const osg::ref_ptr< T > &opt)
template<typename T >
void updateObjIfSet (const std::string &key, const optional< T > &obj)
template<typename X , typename Y >
void updateIfSet (const std::string &key, const std::string &val, const optional< X > &target, const Y &targetValue)
void updateChild (const std::string &key, const std::string &value)
void update (const std::string &key, const std::string &value)
void updateChild (const Config &conf)
void update (const Config &conf)
void update (const std::string &key, const Config &conf)
bool hasValue (const std::string &key) const
const std::string value (const std::string &key) const
template<typename T >
value (const std::string &key, T fallback) const
bool boolValue (bool fallback) const
template<typename T >
bool getIfSet (const std::string &key, optional< T > &output) const
template<typename T >
bool getObjIfSet (const std::string &key, optional< T > &output) const
template<typename T >
bool getObjIfSet (const std::string &key, osg::ref_ptr< T > &output) const
template<typename X , typename Y >
bool getIfSet (const std::string &key, const std::string &val, optional< X > &target, const Y &targetValue) const
std::string toString (int indent=0) const
std::string toHashString () const
void addNonSerializable (const std::string &key, osg::Referenced *obj)
void updateNonSerializable (const std::string &key, osg::Referenced *obj)
template<typename X >
X * getNonSerializable (const std::string &key) const
template<>
void addIfSet (const std::string &key, const optional< Config > &opt)
template<>
void updateIfSet (const std::string &key, const optional< Config > &opt)
template<>
bool getIfSet (const std::string &key, optional< Config > &output) const
template<>
void addIfSet (const std::string &key, const optional< URI > &opt)
template<>
void updateIfSet (const std::string &key, const optional< URI > &opt)
template<>
bool getIfSet (const std::string &key, optional< URI > &output) const

Protected Attributes

std::string _key
std::string _defaultValue
Properties _attrs
ConfigSet _children
URIContext _uriContext
RefMap _refMap

Detailed Description

Config is a general-purpose container for serializable data. You store an object's members to Config, and then translate the Config to a particular format (like XML or JSON). Likewise, the object can de-serialize a Config back into member data. Config support the optional<> template for optional values.

Definition at line 53 of file Config.


Member Typedef Documentation

typedef std::map<std::string, osg::ref_ptr<osg::Referenced> > osgEarth::Config::RefMap

support for conveying non-serializable objects in a Config (in memory only)

Definition at line 323 of file Config.


Constructor & Destructor Documentation

osgEarth::Config::Config ( ) [inline]

Definition at line 56 of file Config.

{ }
osgEarth::Config::Config ( const std::string &  key) [inline]

Definition at line 58 of file Config.

: _key(key) { }
osgEarth::Config::Config ( const std::string &  key,
const std::string &  value 
) [inline]

Definition at line 60 of file Config.

: _key( key ), _defaultValue( value ) { }
osgEarth::Config::Config ( const Config rhs) [inline]

Definition at line 62 of file Config.

: _key(rhs._key), _defaultValue(rhs._defaultValue), _attrs(rhs._attrs), _children(rhs._children), _refMap(rhs._refMap), _uriContext(rhs._uriContext) { }

Member Function Documentation

void osgEarth::Config::add ( const std::string &  key,
const std::string &  value 
) [inline]

Definition at line 158 of file Config.

                                                                 {
            _children.push_back( Config( key, value ) );
            _children.back().setURIContext( _uriContext );
        }

Here is the caller graph for this function:

void osgEarth::Config::add ( const Config conf) [inline]

Definition at line 167 of file Config.

                                       {
            _children.push_back( conf );
            _children.back().setURIContext( _uriContext );
        }
void osgEarth::Config::add ( const std::string &  key,
const Config conf 
) [inline]

Definition at line 172 of file Config.

                                                             {
            Config temp = conf;
            temp.key() = key;
            add( temp );
        }

Here is the call graph for this function:

void osgEarth::Config::add ( const ConfigSet set) [inline]

Definition at line 178 of file Config.

                                         {
            for( ConfigSet::const_iterator i = set.begin(); i != set.end(); i++ )
                add( *i );
        }
void osgEarth::Config::addChild ( const std::string &  key,
const std::string &  value 
) [inline]

Definition at line 154 of file Config.

                                                                      {
            add( key, value );
        }

Here is the caller graph for this function:

void osgEarth::Config::addChild ( const Config conf) [inline]

Definition at line 163 of file Config.

                                            {
            add( conf );
        }
template<typename T >
void osgEarth::Config::addIfSet ( const std::string &  key,
const optional< T > &  opt 
) [inline]

Definition at line 124 of file Config.

                                                                      {
            if ( opt.isSet() ) {
                add( key, osgEarth::toString<T>( opt.value() ) );
            }
        }

Here is the call graph for this function:

Here is the caller graph for this function:

template<typename X , typename Y >
void osgEarth::Config::addIfSet ( const std::string &  key,
const std::string &  val,
const optional< X > &  target,
const Y &  targetValue 
) [inline]

Definition at line 149 of file Config.

                                                                                                                     {
            if ( target.isSetTo( targetValue ) )
                add( key, val );
        }

Here is the call graph for this function:

template<>
void osgEarth::Config::addIfSet ( const std::string &  key,
const optional< Config > &  opt 
) [inline]

Definition at line 351 of file Config.

                                                                                     {
        if ( opt.isSet() ) {
            Config conf = opt.value();
            conf.key() = key;
            add( conf );
        }
    }

Here is the call graph for this function:

template<>
void osgEarth::Config::addIfSet ( const std::string &  key,
const optional< URI > &  opt 
) [inline]

Definition at line 381 of file Config.

                                                                               {
        if ( opt.isSet() ) {
            add( Config(key, opt->base()) );
        }
    }
void osgEarth::Config::addNonSerializable ( const std::string &  key,
osg::Referenced *  obj 
) [inline]

Definition at line 325 of file Config.

                                                                            {
            _refMap[key] = obj;
        }

Here is the caller graph for this function:

template<typename T >
void osgEarth::Config::addObjIfSet ( const std::string &  key,
const osg::ref_ptr< T > &  opt 
) [inline]

Definition at line 131 of file Config.

                                                                           {
            if ( opt.valid() ) {
                Config conf = opt->getConfig();
                conf.key() = key;
                add( conf );
            }
        }

Here is the call graph for this function:

Here is the caller graph for this function:

template<typename T >
void osgEarth::Config::addObjIfSet ( const std::string &  key,
const optional< T > &  obj 
) [inline]

Definition at line 140 of file Config.

                                                                         {
            if ( obj.isSet() ) {
                Config conf = obj->getConfig();
                conf.key() = key;
                add( conf );
            }
        }

Here is the call graph for this function:

std::string osgEarth::Config::attr ( const std::string &  name) const [inline]

Definition at line 83 of file Config.

                                                      {
            Properties::const_iterator i = _attrs.find(name);
            return i != _attrs.end()? trim(i->second) : "";
        }

Here is the call graph for this function:

Here is the caller graph for this function:

std::string& osgEarth::Config::attr ( const std::string &  name) [inline]

Definition at line 88 of file Config.

{ return _attrs[name]; }
Properties& osgEarth::Config::attrs ( ) [inline]

Definition at line 80 of file Config.

{ return _attrs; }

Here is the caller graph for this function:

const Properties& osgEarth::Config::attrs ( ) const [inline]

Definition at line 81 of file Config.

{ return _attrs; }
bool osgEarth::Config::boolValue ( bool  fallback) const [inline]

Definition at line 267 of file Config.

                                              {
            return osgEarth::as<bool>( _defaultValue, fallback );
        }

Here is the call graph for this function:

Here is the caller graph for this function:

const Config & Config::child ( const std::string &  key) const

Definition at line 54 of file Config.cpp.

{
    for( ConfigSet::const_iterator i = _children.begin(); i != _children.end(); i++ ) {
        if ( i->key() == childName )
            return *i;
    }
    return emptyConfig();
}

Here is the call graph for this function:

Here is the caller graph for this function:

const ConfigSet& osgEarth::Config::children ( ) const [inline]

Definition at line 91 of file Config.

{ return _children; }

Here is the caller graph for this function:

const ConfigSet osgEarth::Config::children ( const std::string &  key) const [inline]

Definition at line 93 of file Config.

                                                               {
            ConfigSet r;
            for(ConfigSet::const_iterator i = _children.begin(); i != _children.end(); i++ ) {
                if ( i->key() == key )
                    r.push_back( *i );
            }
            return r;
        }
bool osgEarth::Config::empty ( ) const [inline]

Definition at line 70 of file Config.

                           {
            return _key.empty() && _defaultValue.empty() && _children.empty();
        }

Here is the caller graph for this function:

template<typename T >
bool osgEarth::Config::getIfSet ( const std::string &  key,
optional< T > &  output 
) const [inline]

Definition at line 273 of file Config.

                                                                         {
            std::string r = attr(key);
            if ( r.empty() && hasChild(key) )
                r = child(key).value();
            if ( !r.empty() ) {
                output = osgEarth::as<T>( r, output.defaultValue() );
                return true;
            } 
            else
                return false;
        }

Here is the call graph for this function:

template<typename X , typename Y >
bool osgEarth::Config::getIfSet ( const std::string &  key,
const std::string &  val,
optional< X > &  target,
const Y &  targetValue 
) const [inline]

Definition at line 308 of file Config.

                                                                                                                     {
            if ( hasValue( key ) && value( key ) == val ) {
                target = targetValue;
                return true;
            }
            else 
                return false;
        }
template<>
bool osgEarth::Config::getIfSet ( const std::string &  key,
optional< Config > &  output 
) const [inline]

Definition at line 370 of file Config.

                                                                                        {
        if ( hasChild( key ) ) {
            output = child(key);
            return true;
        }
        else
            return false;
    }
template<>
bool osgEarth::Config::getIfSet ( const std::string &  key,
optional< URI > &  output 
) const [inline]

Definition at line 396 of file Config.

                                                                                  {
        if ( hasValue( key ) ) {
            output = URI( value(key), _uriContext );
            return true;
        }
        else
            return false;
    }
template<typename X >
X* osgEarth::Config::getNonSerializable ( const std::string &  key) const [inline]

Definition at line 334 of file Config.

                                                            {
            RefMap::const_iterator i = _refMap.find(key);
            return i == _refMap.end() ? 0 : dynamic_cast<X*>( i->second.get() );
        }

Here is the caller graph for this function:

template<typename T >
bool osgEarth::Config::getObjIfSet ( const std::string &  key,
osg::ref_ptr< T > &  output 
) const [inline]

Definition at line 298 of file Config.

                                                                              {
            if ( hasChild( key ) ) {
                output = new T( child(key) );
                return true;
            }
            else
                return false;
        }
template<typename T >
bool osgEarth::Config::getObjIfSet ( const std::string &  key,
optional< T > &  output 
) const [inline]

Definition at line 287 of file Config.

                                                                            {
            if ( hasChild( key ) ) {
                output = T( child(key) );
                return true;
            }
            else
                return false;
        }

Here is the caller graph for this function:

bool osgEarth::Config::hasChild ( const std::string &  key) const [inline]

Definition at line 102 of file Config.

                                                    {
            for(ConfigSet::const_iterator i = _children.begin(); i != _children.end(); i++ )
                if ( i->key() == key )
                    return true;
            return false;
        }

Here is the caller graph for this function:

bool osgEarth::Config::hasValue ( const std::string &  key) const [inline]

Definition at line 247 of file Config.

                                                    {
            return !value(key).empty();
        }

Here is the caller graph for this function:

std::string& osgEarth::Config::key ( ) [inline]

Definition at line 74 of file Config.

{ return _key; }

Here is the caller graph for this function:

const std::string& osgEarth::Config::key ( ) const [inline]

Definition at line 75 of file Config.

{ return _key; }
bool Config::loadXML ( std::istream &  in)

Definition at line 45 of file Config.cpp.

{
    osg::ref_ptr<XmlDocument> xml = XmlDocument::load( in );
    if ( xml.valid() )
        *this = xml->getConfig();
    return xml.valid();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void Config::merge ( const Config rhs)

Definition at line 64 of file Config.cpp.

{
    for( Properties::const_iterator a = rhs._attrs.begin(); a != rhs._attrs.end(); ++a )
        _attrs[ a->first ] = a->second;

    for( ConfigSet::const_iterator c = rhs._children.begin(); c != rhs._children.end(); ++c )
        addChild( *c );
}

Here is the call graph for this function:

Here is the caller graph for this function:

void osgEarth::Config::remove ( const std::string &  key) [inline]

Definition at line 109 of file Config.

                                            {
            _attrs.erase(key);            
            for(ConfigSet::iterator i = _children.begin(); i != _children.end(); ) {
                if ( i->key() == key )
                    i = _children.erase( i );
                else
                    ++i;
            }
        }

Here is the caller graph for this function:

void Config::setURIContext ( const URIContext value)

Context for resolving relative URIs that occur in this Config

Definition at line 33 of file Config.cpp.

{
    _uriContext = context;
    for( ConfigSet::iterator i = _children.begin(); i != _children.end(); i++ )
    { 
        i->setURIContext( context.add(i->_uriContext) );
        //URI newURI( i->uriContext(), context );
        //i->setURIContext( *newURI );
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

std::string Config::toHashString ( ) const

Definition at line 102 of file Config.cpp.

{
    std::stringstream buf;
    buf << std::fixed;
    buf << "{" << (_key.empty()? "anonymous" : _key) << ":";
    if ( !_defaultValue.empty() ) buf << _defaultValue;
    if ( !_attrs.empty() ) {
        buf << "[";
        for( Properties::const_iterator a = _attrs.begin(); a != _attrs.end(); a++ )
            buf << a->first << "=" << a->second << ",";
        buf << "]";
    }
    if ( !_children.empty() ) {
        for( ConfigSet::const_iterator c = _children.begin(); c != _children.end(); c++ )
            buf << (*c).toHashString();
    }

    buf << "}";

        std::string bufStr;
        bufStr = buf.str();
    return bufStr;
}

Here is the caller graph for this function:

std::string Config::toString ( int  indent = 0) const

Definition at line 74 of file Config.cpp.

{
    std::stringstream buf;
    buf << std::fixed;
    for( int i=0; i<indent; i++ ) buf << "  ";
    buf << "{ " << (_key.empty()? "anonymous" : _key) << ": ";
    if ( !_defaultValue.empty() ) buf << _defaultValue;
    if ( !_attrs.empty() ) {
        buf << std::endl;
        for( int i=0; i<indent+1; i++ ) buf << "  ";
        buf << "attrs: [ ";
        for( Properties::const_iterator a = _attrs.begin(); a != _attrs.end(); a++ )
            buf << a->first << "=" << a->second << ", ";
        buf << " ]";
    }
    if ( !_children.empty() ) {
        for( ConfigSet::const_iterator c = _children.begin(); c != _children.end(); c++ )
            buf << std::endl << (*c).toString( indent+1 );
    }

    buf << " }";

        std::string bufStr;
        bufStr = buf.str();
    return bufStr;
}

Here is the caller graph for this function:

void osgEarth::Config::update ( const Config conf) [inline]

Definition at line 233 of file Config.

                                          {
            remove(conf.key());
            add( conf );
            //_children.push_back( conf );
        }

Here is the call graph for this function:

void osgEarth::Config::update ( const std::string &  key,
const std::string &  value 
) [inline]

Definition at line 223 of file Config.

                                                                    {
            remove(key);
            add( Config(key, value) );
            //_children.push_back( Config( key, value ) );
        }

Here is the caller graph for this function:

void osgEarth::Config::update ( const std::string &  key,
const Config conf 
) [inline]

Definition at line 239 of file Config.

                                                                {
            remove(key);
            Config temp = conf;
            temp.key() = key;
            add( temp );
        }

Here is the call graph for this function:

void osgEarth::Config::updateChild ( const std::string &  key,
const std::string &  value 
) [inline]

Definition at line 219 of file Config.

                                                                         {
            update( key, value );
        }
void osgEarth::Config::updateChild ( const Config conf) [inline]

Definition at line 229 of file Config.

                                               {
            update( conf );
        }
template<typename X , typename Y >
void osgEarth::Config::updateIfSet ( const std::string &  key,
const std::string &  val,
const optional< X > &  target,
const Y &  targetValue 
) [inline]

Definition at line 212 of file Config.

                                                                                                                        {
            if ( target.isSetTo( targetValue ) ) {
                remove(key);
                add( key, val );
            }
        }

Here is the call graph for this function:

template<>
void osgEarth::Config::updateIfSet ( const std::string &  key,
const optional< Config > &  opt 
) [inline]

Definition at line 360 of file Config.

                                                                                        {
        if ( opt.isSet() ) {
            remove(key);
            Config conf = opt.value();
            conf.key() = key;
            add( conf );
        }
    }

Here is the call graph for this function:

template<typename T >
void osgEarth::Config::updateIfSet ( const std::string &  key,
const optional< T > &  opt 
) [inline]

Definition at line 184 of file Config.

                                                                         {
            if ( opt.isSet() ) {
                remove(key);
                add( key, osgEarth::toString<T>( opt.value() ) );
            }
        }

Here is the call graph for this function:

Here is the caller graph for this function:

template<>
void osgEarth::Config::updateIfSet ( const std::string &  key,
const optional< URI > &  opt 
) [inline]

Definition at line 388 of file Config.

                                                                                  {
        if ( opt.isSet() ) {
            remove(key);
            add( Config(key, opt->base()) );
        }
    }
void osgEarth::Config::updateNonSerializable ( const std::string &  key,
osg::Referenced *  obj 
) [inline]

Definition at line 329 of file Config.

                                                                               {
            _refMap[key] = obj;
        }

Here is the caller graph for this function:

template<typename T >
void osgEarth::Config::updateObjIfSet ( const std::string &  key,
const osg::ref_ptr< T > &  opt 
) [inline]

Definition at line 192 of file Config.

                                                                              {
            if ( opt.valid() ) {
                remove(key);
                Config conf = opt->getConfig();
                conf.key() = key;
                add( conf );
            }
        }

Here is the call graph for this function:

Here is the caller graph for this function:

template<typename T >
void osgEarth::Config::updateObjIfSet ( const std::string &  key,
const optional< T > &  obj 
) [inline]

Definition at line 202 of file Config.

                                                                            {
            if ( obj.isSet() ) {
                remove(key);
                Config conf = obj->getConfig();
                conf.key() = key;
                add( conf );
            }
        }

Here is the call graph for this function:

const URIContext& osgEarth::Config::uriContext ( ) const [inline]

Definition at line 66 of file Config.

{ return _uriContext; }

Here is the caller graph for this function:

template<typename T >
T osgEarth::Config::value ( const std::string &  key,
fallback 
) const [inline]

Definition at line 260 of file Config.

                                                          {
            std::string r = attr(key);
            if ( r.empty() && hasChild( key ) )
                r = child(key).value();
            return osgEarth::as<T>( r, fallback );
        }
std::string& osgEarth::Config::value ( ) [inline]

Definition at line 78 of file Config.

{ return _defaultValue; }
const std::string osgEarth::Config::value ( const std::string &  key) const [inline]

Definition at line 251 of file Config.

                                                            {
            std::string r = trim(child(key).value());
            if ( r.empty() )
                r = attr(key);
            return r;
        }

Here is the call graph for this function:

const std::string& osgEarth::Config::value ( ) const [inline]

Definition at line 77 of file Config.

{ return _defaultValue; }

Here is the caller graph for this function:


Member Data Documentation

Definition at line 342 of file Config.

Definition at line 343 of file Config.

std::string osgEarth::Config::_defaultValue [protected]

Definition at line 341 of file Config.

std::string osgEarth::Config::_key [protected]

Definition at line 340 of file Config.

Definition at line 346 of file Config.

Definition at line 344 of file Config.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines