PropertyManager.cpp

00001 /***************************************************************************
00002  *                                                                         *
00003  *   (c) Art Tevs, MPI Informatik Saarbruecken                             *
00004  *       mailto: <tevs@mpi-sb.mpg.de>                                      *
00005  *                                                                         *
00006  *   This program is free software; you can redistribute it and/or modify  *
00007  *   it under the terms of the GNU General Public License as published by  *
00008  *   the Free Software Foundation; either version 2 of the License, or     *
00009  *   (at your option) any later version.                                   *
00010  *                                                                         *
00011  ***************************************************************************/
00012 
00013 //----------------------------------------------------------------------------------
00014 // Includes
00015 //----------------------------------------------------------------------------------
00016 #include "PropertyManager.h"
00017 #include "Exception.h"
00018 
00019 namespace nrEngine {
00020 
00021         //----------------------------------------------------------------------------------
00022         PropertyManager::PropertyManager()
00023         {
00024 
00025         }
00026 
00027         //----------------------------------------------------------------------------------
00028         PropertyManager::~PropertyManager()
00029         {
00030                 // clean the property map
00031                 mPropertyMap.clear();
00032         }
00033                 
00034         //----------------------------------------------------------------------------------
00035         void PropertyManager::createGroup(const std::string& name)
00036         {
00037                 mPropertyMap.insert(std::pair<std::string, PropertyList>(name, PropertyList()));
00038         }
00039 
00040         //----------------------------------------------------------------------------------
00041         const PropertyList& PropertyManager::getPropertyList(const std::string& group)
00042         {
00043                 return mPropertyMap[group];
00044         }
00045 
00046         //----------------------------------------------------------------------------------
00047         Property& PropertyManager::getProperty(const std::string& name, const std::string& group)
00048         {
00049                 return mPropertyMap[group][name];
00050         }
00051 
00052         //----------------------------------------------------------------------------------
00053         Property& PropertyManager::getPropertyByFullName(const std::string& fullname)
00054         {
00055                 // iterate through all groups
00056                 PropertyMap::iterator it = mPropertyMap.begin();
00057                 for (; it != mPropertyMap.end(); it++)
00058                 {
00059                         // search for such an element
00060                         PropertyList::iterator jt = it->second.begin();
00061                         for (; jt != it->second.end(); jt++)
00062                                 if (jt->getFullName() == fullname)
00063                                 {
00064                                         return *jt;
00065                                 }
00066                 }
00067 
00068                 // we have not found any such element, so create one
00069                 NR_Log(Log::LOG_ENGINE, Log::LL_WARNING, "PropertyManager: Property with fullname '%s' is not registered, so create it in default group", fullname.c_str());
00070                 return getProperty(fullname, "");               
00071         }
00072         
00073         //----------------------------------------------------------------------------------
00074         void PropertyManager::set(const Property& property, const std::string& name, const std::string& group)
00075         {
00076                 Property& p = getProperty(name, group);
00077                 p.copyDataOnly(property);
00078                 p.mName = name;
00079                 p.mFullName = group + std::string(".") + name;          
00080         }
00081         
00082         //----------------------------------------------------------------------------------
00083         void PropertyManager::setByFullName(const Property& property, const std::string& fullname)
00084         {
00085                 // get property by fullname
00086                 Property& p = getPropertyByFullName(fullname);
00087                 p.copyDataOnly(property);
00088                 p.mFullName = fullname;
00089                 if (p.mName.length() == 0) p.mName = fullname;
00090         }
00091 
00092 
00093         //----------------------------------------------------------------------------------
00094         void PropertyManager::set(const boost::any& value, const std::string& name, const std::string& group)
00095         {
00096                 // get property
00097                 Property& p = getProperty(name, group);
00098 
00099                 // set new value
00100                 p.mValue = value;
00101         }
00102 
00103         //----------------------------------------------------------------------------------
00104         void PropertyManager::setByFullName(const boost::any& value, const std::string& fullname)
00105         {
00106                 // get property
00107                 Property& p = getPropertyByFullName(fullname);
00108 
00109                 // set new value
00110                 p.mValue = value;
00111         }
00112 
00113 };
00114 
00115 
00116 

Generated on Wed Sep 12 23:19:42 2007 for nrEngine by  doxygen 1.5.1