vpr::AttributeMapBase Class Reference

Basic interface for adding attributes to classes. More...

#include <vpr/Util/AttributeMapBase.h>

Inheritance diagram for vpr::AttributeMapBase:

Inheritance graph
[legend]
List of all members.

Public Member Functions

template<typename TYPE>
void setAttrib (const std::string &name, TYPE val)
 Sets an attribute to the given value.
template<typename TYPE>
TYPE getAttrib (const std::string &name)
 Gets an attribute value.
bool attribExists (const std::string &name)
 Does the named attribute exist?

Detailed Description

Basic interface for adding attributes to classes.

Useful for having custom setter/getter type settings that are only used in certain contexts.

This is based upon boost::any type.

Definition at line 63 of file AttributeMapBase.h.


Member Function Documentation

template<typename TYPE>
void vpr::AttributeMapBase::setAttrib ( const std::string &  name,
TYPE  val 
) [inline]

Sets an attribute to the given value.

Parameters:
name The name of the attribute to set.
val The value to be set.

Definition at line 73 of file AttributeMapBase.h.

00074    {
00075       mAttribMap[name] = val;
00076    }

template<typename TYPE>
TYPE vpr::AttributeMapBase::getAttrib ( const std::string &  name  )  [inline]

Gets an attribute value.

If not previously set, then return the value of a default constructed instance of the given type.

Definition at line 85 of file AttributeMapBase.h.

References attribExists().

00086    {
00087       TYPE ret_val;     // Construct default return value
00088       if(attribExists(name))
00089       {
00090          boost::any any_val = mAttribMap[name];
00091          try
00092          {
00093             ret_val = boost::any_cast<TYPE>(any_val);
00094          }
00095          catch(const boost::bad_any_cast&)
00096          {
00097             ret_val = TYPE();    // Default value
00098          }
00099       }
00100       return ret_val;
00101    }

bool vpr::AttributeMapBase::attribExists ( const std::string &  name  )  [inline]

Does the named attribute exist?

Returns:
true if it exists.

Definition at line 107 of file AttributeMapBase.h.

Referenced by getAttrib().

00108    {
00109       attrib_map_t::iterator found = mAttribMap.find(name);
00110       return (found != mAttribMap.end());
00111    }


The documentation for this class was generated from the following file:
Generated on Thu Jan 4 10:56:01 2007 for VR Juggler Portable Runtime by  doxygen 1.5.1