Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

CEGUIPropertySet.cpp

Go to the documentation of this file.
00001 /************************************************************************
00002         filename:       CEGUIPropertySet.cpp
00003         created:        21/2/2004
00004         author:         Paul D Turner
00005         
00006         purpose:        Implements PropertySet class
00007 *************************************************************************/
00008 /*************************************************************************
00009     Crazy Eddie's GUI System (http://www.cegui.org.uk)
00010     Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
00011 
00012     This library is free software; you can redistribute it and/or
00013     modify it under the terms of the GNU Lesser General Public
00014     License as published by the Free Software Foundation; either
00015     version 2.1 of the License, or (at your option) any later version.
00016 
00017     This library is distributed in the hope that it will be useful,
00018     but WITHOUT ANY WARRANTY; without even the implied warranty of
00019     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020     Lesser General Public License for more details.
00021 
00022     You should have received a copy of the GNU Lesser General Public
00023     License along with this library; if not, write to the Free Software
00024     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025 *************************************************************************/
00026 #include "CEGUIPropertySet.h"
00027 #include "CEGUIProperty.h"
00028 #include "CEGUIExceptions.h"
00029 
00030 // Start of CEGUI namespace section
00031 namespace CEGUI
00032 {
00033 
00034 /*************************************************************************
00035         Add a new property to the set
00036 *************************************************************************/
00037 void PropertySet::addProperty(Property* property)
00038 {
00039         if (property == NULL)
00040         {
00041                 throw NullObjectException((utf8*)"The given Property object pointer is NULL.");
00042         }
00043 
00044         if (d_properties.find(property->getName()) != d_properties.end())
00045         {
00046                 throw AlreadyExistsException((utf8*)"A Property named '" + property->getName() + (utf8*)"' already exists in the PropertySet.");
00047         }
00048 
00049         d_properties[property->getName()] = property;
00050 }
00051 
00052 /*************************************************************************
00053         Remove a property from the set
00054 *************************************************************************/
00055 void PropertySet::removeProperty(const String& name)
00056 {
00057         PropertyRegistry::iterator pos = d_properties.find(name);
00058 
00059         if (pos != d_properties.end())
00060         {
00061                 d_properties.erase(pos);
00062         }
00063 }
00064 
00065 /*************************************************************************
00066         Remove all properties from the set
00067 *************************************************************************/
00068 void PropertySet::clearProperties(void)
00069 {
00070         d_properties.clear();
00071 }
00072 
00073 /*************************************************************************
00074         Return true if a property with the given name is in the set
00075 *************************************************************************/
00076 bool PropertySet::isPropertyPresent(const String& name) const
00077 {
00078         return (d_properties.find(name) != d_properties.end());
00079 }
00080 
00081 /*************************************************************************
00082         Return the help string for a property
00083 *************************************************************************/
00084 const String& PropertySet::getPropertyHelp(const String& name) const
00085 {
00086         PropertyRegistry::const_iterator pos = d_properties.find(name);
00087 
00088         if (pos == d_properties.end())
00089         {
00090                 throw UnknownObjectException((utf8*)"There is no Property named '" + name + (utf8*)"' available in the set.");
00091         }
00092 
00093         return pos->second->getHelp();
00094 }
00095 
00096 /*************************************************************************
00097         Return the current value of a property
00098 *************************************************************************/
00099 String PropertySet::getProperty(const String& name) const
00100 {
00101         PropertyRegistry::const_iterator pos = d_properties.find(name);
00102 
00103         if (pos == d_properties.end())
00104         {
00105                 throw UnknownObjectException((utf8*)"There is no Property named '" + name + (utf8*)"' available in the set.");
00106         }
00107 
00108         return pos->second->get(this);
00109 }
00110 
00111 /*************************************************************************
00112         Set the current value of a property
00113 *************************************************************************/
00114 void PropertySet::setProperty(const String& name,const String& value)
00115 {
00116         PropertyRegistry::iterator pos = d_properties.find(name);
00117 
00118         if (pos == d_properties.end())
00119         {
00120                 throw UnknownObjectException((utf8*)"There is no Property named '" + name + (utf8*)"' available in the set.");
00121         }
00122 
00123         pos->second->set(this, value);
00124 }
00125 
00126 
00127 /*************************************************************************
00128         Return a PropertySet::PropertyIterator object to iterate over the
00129         available Properties.
00130 *************************************************************************/
00131 PropertySet::PropertyIterator PropertySet::getIterator(void) const
00132 {
00133         return PropertyIterator(d_properties.begin(), d_properties.end());
00134 }
00135 
00136 
00137 /*************************************************************************
00138         Returns whether a Property is at it's default value.
00139 *************************************************************************/
00140 bool PropertySet::isPropertyDefault(const String& name) const
00141 {
00142         PropertyRegistry::const_iterator pos = d_properties.find(name);
00143 
00144         if (pos == d_properties.end())
00145         {
00146                 throw UnknownObjectException((utf8*)"There is no Property named '" + name + (utf8*)"' available in the set.");
00147         }
00148 
00149         return pos->second->isDefault(this);
00150 }
00151 
00152 
00153 /*************************************************************************
00154         Returns the default value of a Property as a String.    
00155 *************************************************************************/
00156 String PropertySet::getPropertyDefault(const String& name) const
00157 {
00158         PropertyRegistry::const_iterator pos = d_properties.find(name);
00159 
00160         if (pos == d_properties.end())
00161         {
00162                 throw UnknownObjectException((utf8*)"There is no Property named '" + name + (utf8*)"' available in the set.");
00163         }
00164 
00165         return pos->second->getDefault(this);
00166 }
00167 
00168 } // End of  CEGUI namespace section

Generated on Wed Sep 7 09:56:33 2005 for Crazy Eddies GUI System by  doxygen 1.4.3