PropertySet Class Reference

A set of named property values, which can be strings, integers, floating point, etc. More...

Inherited by PropertiesFile.

List of all members.

Public Member Functions

 PropertySet (const bool ignoreCaseOfKeyNames=false) throw ()
 Creates an empty PropertySet.
 PropertySet (const PropertySet &other) throw ()
 Creates a copy of another PropertySet.
PropertySetoperator= (const PropertySet &other) throw ()
 Copies another PropertySet over this one.
virtual ~PropertySet ()
 Destructor.
const String getValue (const String &keyName, const String &defaultReturnValue=String::empty) const throw ()
 Returns one of the properties as a string.
int getIntValue (const String &keyName, const int defaultReturnValue=0) const throw ()
 Returns one of the properties as an integer.
double getDoubleValue (const String &keyName, const double defaultReturnValue=0.0) const throw ()
 Returns one of the properties as an double.
bool getBoolValue (const String &keyName, const bool defaultReturnValue=false) const throw ()
 Returns one of the properties as an boolean.
XmlElementgetXmlValue (const String &keyName) const
 Returns one of the properties as an XML element.
void setValue (const String &keyName, const String &value) throw ()
 Sets a named property as a string.
void setValue (const String &keyName, const int value) throw ()
 Sets a named property to an integer.
void setValue (const String &keyName, const double value) throw ()
 Sets a named property to a double.
void setValue (const String &keyName, const bool value) throw ()
 Sets a named property to a boolean.
void setValue (const String &keyName, const XmlElement *const xml)
 Sets a named property to an XML element.
void removeValue (const String &keyName) throw ()
 Deletes a property.
bool containsKey (const String &keyName) const throw ()
 Returns true if the properies include the given key.
void clear ()
 Removes all values.
StringPairArraygetAllProperties () throw ()
 Returns the keys/value pair array containing all the properties.
const CriticalSectiongetLock () const throw ()
 Returns the lock used when reading or writing to this set.
XmlElementcreateXml (const String &nodeName) const throw ()
 Returns an XML element which encapsulates all the items in this property set.
void restoreFromXml (const XmlElement &xml) throw ()
 Reloads a set of properties that were previously stored as XML.
void setFallbackPropertySet (PropertySet *fallbackProperties) throw ()
 Sets up a second PopertySet that will be used to look up any values that aren't set in this one.
PropertySetgetFallbackPropertySet () const throw ()
 Returns the fallback property set.

Protected Member Functions

virtual void propertyChanged ()
 Subclasses can override this to be told when one of the properies has been changed.

Detailed Description

A set of named property values, which can be strings, integers, floating point, etc.

Effectively, this just wraps a StringPairArray in an interface that makes it easier to load and save types other than strings.

See the PropertiesFile class for a subclass of this, which automatically broadcasts change messages and saves/loads the list from a file.


Constructor & Destructor Documentation

PropertySet::PropertySet ( const bool  ignoreCaseOfKeyNames = false  )  throw ()

Creates an empty PropertySet.

Parameters:
ignoreCaseOfKeyNames if true, the names of properties are compared in a case-insensitive way
PropertySet::PropertySet ( const PropertySet other  )  throw ()

Creates a copy of another PropertySet.

virtual PropertySet::~PropertySet (  )  [virtual]

Destructor.


Member Function Documentation

PropertySet& PropertySet::operator= ( const PropertySet other  )  throw ()

Copies another PropertySet over this one.

const String PropertySet::getValue ( const String keyName,
const String defaultReturnValue = String::empty 
) const throw ()

Returns one of the properties as a string.

If the value isn't found in this set, then this will look for it in a fallback property set (if you've specified one with the setFallbackPropertySet() method), and if it can't find one there, it'll return the default value passed-in.

Parameters:
keyName the name of the property to retrieve
defaultReturnValue a value to return if the named property doesn't actually exist
int PropertySet::getIntValue ( const String keyName,
const int  defaultReturnValue = 0 
) const throw ()

Returns one of the properties as an integer.

If the value isn't found in this set, then this will look for it in a fallback property set (if you've specified one with the setFallbackPropertySet() method), and if it can't find one there, it'll return the default value passed-in.

Parameters:
keyName the name of the property to retrieve
defaultReturnValue a value to return if the named property doesn't actually exist
double PropertySet::getDoubleValue ( const String keyName,
const double  defaultReturnValue = 0.0 
) const throw ()

Returns one of the properties as an double.

If the value isn't found in this set, then this will look for it in a fallback property set (if you've specified one with the setFallbackPropertySet() method), and if it can't find one there, it'll return the default value passed-in.

Parameters:
keyName the name of the property to retrieve
defaultReturnValue a value to return if the named property doesn't actually exist
bool PropertySet::getBoolValue ( const String keyName,
const bool  defaultReturnValue = false 
) const throw ()

Returns one of the properties as an boolean.

The result will be true if the string found for this key name can be parsed as a non-zero integer.

If the value isn't found in this set, then this will look for it in a fallback property set (if you've specified one with the setFallbackPropertySet() method), and if it can't find one there, it'll return the default value passed-in.

Parameters:
keyName the name of the property to retrieve
defaultReturnValue a value to return if the named property doesn't actually exist
XmlElement* PropertySet::getXmlValue ( const String keyName  )  const

Returns one of the properties as an XML element.

The result will a new XMLElement object that the caller must delete. If may return 0 if the key isn't found, or if the entry contains an string that isn't valid XML.

If the value isn't found in this set, then this will look for it in a fallback property set (if you've specified one with the setFallbackPropertySet() method), and if it can't find one there, it'll return the default value passed-in.

Parameters:
keyName the name of the property to retrieve
void PropertySet::setValue ( const String keyName,
const String value 
) throw ()

Sets a named property as a string.

Parameters:
keyName the name of the property to set. (This mustn't be an empty string)
value the new value to set it to
void PropertySet::setValue ( const String keyName,
const int  value 
) throw ()

Sets a named property to an integer.

Parameters:
keyName the name of the property to set. (This mustn't be an empty string)
value the new value to set it to
void PropertySet::setValue ( const String keyName,
const double  value 
) throw ()

Sets a named property to a double.

Parameters:
keyName the name of the property to set. (This mustn't be an empty string)
value the new value to set it to
void PropertySet::setValue ( const String keyName,
const bool  value 
) throw ()

Sets a named property to a boolean.

Parameters:
keyName the name of the property to set. (This mustn't be an empty string)
value the new value to set it to
void PropertySet::setValue ( const String keyName,
const XmlElement *const   xml 
)

Sets a named property to an XML element.

Parameters:
keyName the name of the property to set. (This mustn't be an empty string)
xml the new element to set it to. If this is zero, the value will be set to an empty string
See also:
getXmlValue
void PropertySet::removeValue ( const String keyName  )  throw ()

Deletes a property.

Parameters:
keyName the name of the property to delete. (This mustn't be an empty string)
bool PropertySet::containsKey ( const String keyName  )  const throw ()

Returns true if the properies include the given key.

void PropertySet::clear (  ) 

Removes all values.

StringPairArray& PropertySet::getAllProperties (  )  throw ()

Returns the keys/value pair array containing all the properties.

const CriticalSection& PropertySet::getLock (  )  const throw ()

Returns the lock used when reading or writing to this set.

XmlElement* PropertySet::createXml ( const String nodeName  )  const throw ()

Returns an XML element which encapsulates all the items in this property set.

The string parameter is the tag name that should be used for the node.

See also:
restoreFromXml
void PropertySet::restoreFromXml ( const XmlElement xml  )  throw ()

Reloads a set of properties that were previously stored as XML.

The node passed in must have been created by the createXml() method.

See also:
createXml
void PropertySet::setFallbackPropertySet ( PropertySet fallbackProperties  )  throw ()

Sets up a second PopertySet that will be used to look up any values that aren't set in this one.

If you set this up to be a pointer to a second property set, then whenever one of the getValue() methods fails to find an entry in this set, it will look up that value in the fallback set, and if it finds it, it will return that.

Make sure that you don't delete the fallback set while it's still being used by another set! To remove the fallback set, just call this method with a null pointer.

See also:
getFallbackPropertySet
PropertySet* PropertySet::getFallbackPropertySet (  )  const throw ()

Returns the fallback property set.

See also:
setFallbackPropertySet
virtual void PropertySet::propertyChanged (  )  [protected, virtual]

Subclasses can override this to be told when one of the properies has been changed.

Reimplemented in PropertiesFile.


The documentation for this class was generated from the following file:
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Mon Apr 26 11:42:16 2010 for JUCE by  doxygen 1.6.3