AttributeMapBase.h

Go to the documentation of this file.
00001 /****************** <VPR heading BEGIN do not edit this line> *****************
00002  *
00003  * VR Juggler Portable Runtime
00004  *
00005  * Original Authors:
00006  *   Allen Bierbaum, Patrick Hartling, Kevin Meinert, Carolina Cruz-Neira
00007  *
00008  * -----------------------------------------------------------------
00009  * File:          $RCSfile$
00010  * Date modified: $Date: 2005-01-17 22:34:01 -0600 (Mon, 17 Jan 2005) $
00011  * Version:       $Revision: 16635 $
00012  * -----------------------------------------------------------------
00013  *
00014  ****************** <VPR heading END do not edit this line> ******************/
00015 
00016 /*************** <auto-copyright.pl BEGIN do not edit this line> **************
00017  *
00018  * VR Juggler is (C) Copyright 1998-2005 by Iowa State University
00019  *
00020  * Original Authors:
00021  *   Allen Bierbaum, Christopher Just,
00022  *   Patrick Hartling, Kevin Meinert,
00023  *   Carolina Cruz-Neira, Albert Baker
00024  *
00025  * This library is free software; you can redistribute it and/or
00026  * modify it under the terms of the GNU Library General Public
00027  * License as published by the Free Software Foundation; either
00028  * version 2 of the License, or (at your option) any later version.
00029  *
00030  * This library is distributed in the hope that it will be useful,
00031  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00032  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00033  * Library General Public License for more details.
00034  *
00035  * You should have received a copy of the GNU Library General Public
00036  * License along with this library; if not, write to the
00037  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00038  * Boston, MA 02111-1307, USA.
00039  *
00040  *************** <auto-copyright.pl END do not edit this line> ***************/
00041 
00042 #ifndef _VPR_ATTRIBUTE_MAP_BASE_H
00043 #define _VPR_ATTRIBUTE_MAP_BASE_H
00044 
00045 #include <vpr/vprConfig.h>
00046 #include <map>
00047 #include <string>
00048 #include <boost/any.hpp>
00049 
00050 
00051 namespace vpr
00052 {
00053 
00063 class AttributeMapBase
00064 {
00065 public:
00072    template<typename TYPE>
00073    void setAttrib(const std::string& name, TYPE val)
00074    {
00075       mAttribMap[name] = val;
00076    }
00077 
00084    template<typename TYPE>
00085    TYPE getAttrib(const std::string& name)
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    }
00102 
00107    bool attribExists(const std::string& name)
00108    {
00109       attrib_map_t::iterator found = mAttribMap.find(name);
00110       return (found != mAttribMap.end());
00111    }
00112 
00113 private:
00114    typedef std::map<std::string, boost::any> attrib_map_t;
00115    attrib_map_t   mAttribMap;
00116 };
00117 
00118 } // namespace vpr
00119 
00120 
00121 #endif

Generated on Thu Jan 4 10:52:09 2007 for VR Juggler Portable Runtime by  doxygen 1.5.1