Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

plist::Dictionary Class Reference

#include <plistCollections.h>

Inheritance diagram for plist::Dictionary:

Inheritance graph
[legend]
List of all members.

Detailed Description

Maintains a set of (key,value) pairs, where a value can be any subclass of ObjectBase.

You can add or set entries by a quite a few variations on addEntry() and setEntry(). Basically these boil down to either:

  • pass a pointer to an ObjectBase or directly pass a primitive value (int, float, char, etc.), in which case the Array will assume management of the corresponding ObjectBase instance (freeing the memory region when removed)
  • pass a reference to an ObjectBase, in which case you retain control over the object's allocation

Definition at line 135 of file plistCollections.h.

Public Types

typedef std::map< std::string,
ObjectBase * > 
storage_t
 shorthand for the type of the storage
typedef storage_t::iterator iterator
 shorthand for iterators to be returned
typedef storage_t::const_iterator const_iterator
 shorthand for iterators to be returned

Public Member Functions

 Dictionary ()
 constructor
 Dictionary (bool growable)
 constructor
 Dictionary (const Dictionary &d)
 copy constructor (don't assign listeners)
Dictionaryoperator= (const Dictionary &d)
 assignment (don't assign listeners); subclass should call fireEntriesChanged after calling this (and updating its own storage)
 ~Dictionary ()
 destructor
template<typename T>
void setValue (const std::string &name, const T &val, bool warnExists=false)
 insert a new entry to the map; expects val to be either a primitive type, like int, float, etc., or one of the variable-sized Collection's, like Array
template<typename T>
void addValue (const std::string &name, const T &val, const std::string &comment="", bool warnExists=true)
 insert a new entry to the map, and corresponding comment; expects val to be either a primitive type, like int, float, etc., or one of the variable-sized Collection's, like Array
virtual void setValue (const std::string &name, const char val[], bool warnExists=false)
 "specialization" (actually just another override) for handling character arrays as strings
virtual void addValue (const std::string &name, const char val[], const std::string &comment="")
 "specialization" (actually just another override) for handling character arrays as strings
virtual void addValue (const std::string &name, const char val[], const std::string &comment, bool warnExists)
 "specialization" (actually just another override) for handling character arrays as strings
virtual void setEntry (const std::string &name, ObjectBase &val, bool warnExists=false)
 insert a new entry to the dictionary, with key name and value val (replaces any previous entry by same name, but can give a warning)
virtual void addEntry (const std::string &name, ObjectBase &val, const std::string &comment="")
 insert a new entry to the dictionary, with key name and value val (replaces any previous entry by same name, but can give a warning)
virtual void addEntry (const std::string &name, ObjectBase &val, const std::string &comment, bool warnExists)
 insert a new entry to the dictionary, with key name and value val (replaces any previous entry by same name, but can give a warning)
virtual void setEntry (const std::string &name, ObjectBase *val, bool warnExists=false)
virtual void addEntry (const std::string &name, ObjectBase *val, const std::string &comment="")
virtual void addEntry (const std::string &name, ObjectBase *val, const std::string &comment, bool warnExists)
 insert a new entry to the dictionary, with key name and value val (replaces any previous entry by same name, but can give a warning)
virtual void removeEntry (const std::string &name)
 remove the entry with key name
virtual ObjectBasegetEntry (const std::string &name) const
 return the value of the key name, or NULL if it doesn't exist
virtual ObjectBaseoperator[] (const std::string &name)
virtual ObjectBaseresolveEntry (const std::string &path) const
 recursively resolves path interpreted as a series of collection entry names separated by '.', returns NULL if it doesn't exist
virtual iterator findEntry (const std::string &name)
 returns an iterator to an entry in the current dictionary
virtual const_iterator findEntry (const std::string &name) const
 returns an iterator to an entry in the current dictionary
virtual void clear ()
 remove all entries in one fell swoop
const_iterator begin () const
 return an STL const_iterator to the first entry
const_iterator end () const
 return the one-past-end const_iterator
virtual size_t size () const
 return the size of the dictionary
void setComment (const std::string &name, const std::string &comment)
 replaces previous comment for name, or adds it if it doesn't already exist (can preceed actual entry!)
const std::string & getComment (const std::string &name) const
 returns comment retrieved from loaded file, or any subsequent call to setComment
virtual void loadXML (xmlNode *node)
 From the name of node, will instantiate a new ObjectBase subclass to load it.
virtual void saveXML (xmlNode *node) const
 subclasses are expected to provide a working implementation
virtual void saveXML (xmlNode *node, bool onlyOverwrite, std::set< std::string > &seen) const
 saves the dictionary into the specified node
virtual std::string toString () const
 return current value as a string
virtual unsigned int getLongestKeyLen () const
 return the length of the longest key for formatting purposes
virtual bool canContain (const ObjectBase &)
 returns true if the Collection subclass allows storage of the argument
virtual Dictionaryclone () const __attribute__((warn_unused_result))
 implements the clone function for Dictionaries
template<>
void setValue (const std::string &name, const char *const &val, bool warnExists)
 specialization of Dictionary::setValue() for char* strings
template<>
void addValue (const std::string &name, const char *const &val, const std::string &comment, bool warnExists)
 specialization of Dictionary::addValue() for char* strings
template<>
void setValue (const std::string &name, char *const &val, bool warnExists)
 specialization of Dictionary::setValue() for char* strings
template<>
void addValue (const std::string &name, char *const &val, const std::string &comment, bool warnExists)
 specialization of Dictionary::addValue() for char* strings

Protected Types

typedef std::map< std::string,
std::string > 
comments_t
 shorthand for the type of comments

Protected Member Functions

virtual void fireEntryRemoved (ObjectBase &val)
 run through collectionListeners, calling CollectionListener::plistCollectionEntryRemoved(*this,val)
virtual void takeObject (const std::string &name, ObjectBase *obj)
 indicates that the storage implementation should mark this as an externally supplied heap reference, which needs to be deleted on removal/destruction
virtual bool loadXMLNode (const std::string &key, xmlNode *val, const std::string &comment)
 called with each node being loaded so subclass can handle appropriately
virtual bool saveOverXMLNode (xmlNode *k, xmlNode *val, const std::string &key, std::string comment, const std::string &indentStr, std::set< std::string > &seen) const
 called with each node being saved so subclass can handle appropriately, return true if successful and reset key if changed
virtual void saveXMLNode (xmlNode *node, const std::string &key, const ObjectBase *val, const std::string &indentStr) const
 called with each node being saved so subclass can handle appropriately, return true if successful and set key
iterator getSubEntry (const std::string &name, std::string::size_type &seppos)
 returns an entry matching just the prefix
const_iterator getSubEntry (const std::string &name, std::string::size_type &seppos) const
 returns an entry matching just the prefix
virtual void cloneMyRef ()
 called after an assignment or copy to clone the objects in myRef to perform a deep copy

Protected Attributes

storage_t dict
 storage of entries -- mapping from keys to value pointers
std::set< ObjectBase * > myRef
 objects which have been handed over to the collection for eventual de-allocation
comments_t comments
 storage of entry comments -- mapping from keys to help text comments for manual editing or user feedback

Friends

std::ostream & operator<< (std::ostream &os, const Dictionary &d)
 provides textual output


Member Function Documentation

Dictionary::const_iterator plist::Dictionary::getSubEntry ( const std::string &  name,
std::string::size_type &  seppos 
) const [protected]

returns an entry matching just the prefix

Parameters:
[in] name the name being looked up
[out] seppos the position of the separator (sub-collections are separated by '.')
Returns:
iterator of the sub entry

Definition at line 380 of file plistCollections.cc.

Dictionary::iterator plist::Dictionary::getSubEntry ( const std::string &  name,
std::string::size_type &  seppos 
) [protected]

returns an entry matching just the prefix

Parameters:
[in] name the name being looked up
[out] seppos the position of the separator (sub-collections are separated by '.')
Returns:
iterator of the sub entry

Definition at line 368 of file plistCollections.cc.

Referenced by resolveEntry().

void plist::Dictionary::loadXML ( xmlNode node  )  [virtual]

From the name of node, will instantiate a new ObjectBase subclass to load it.

The mapping from node names to actual instantiated types is:

If successful, returns a pointer to a newly allocated region, which the caller is responsible for freeing. If an error occurs, NULL is returned.

Reimplemented from plist::ObjectBase.

Definition at line 229 of file plistCollections.cc.

Referenced by ConfigDictionary::loadXMLNode().

void plist::Dictionary::saveXML ( xmlNode node,
bool  onlyOverwrite,
std::set< std::string > &  seen 
) const [virtual]

saves the dictionary into the specified node

Parameters:
[in] node the xml node which should be saved into
[in] onlyOverwrite if is true, only saves entries for keys already found in the node
[in] seen used to keep track of which nodes have been seen in node -- may be of particular interest with onlyOverride set
seen is not cleared before being used.

Reimplemented in OutputConfig< T >, Config, and OutputConfig< plist::Primitive< float > >.

Definition at line 272 of file plistCollections.cc.


Member Data Documentation

storage of entry comments -- mapping from keys to help text comments for manual editing or user feedback

not every key necessarily has a comment!

Definition at line 264 of file plistCollections.h.

Referenced by addEntry(), getComment(), operator=(), saveOverXMLNode(), saveXMLNode(), and setComment().


The documentation for this class was generated from the following files:

Tekkotsu v3.0
Generated Fri May 11 20:09:08 2007 by Doxygen 1.4.7