Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

plist::DictionaryBase Class Reference

Maintains a set of (key,value) pairs, see DictionaryOf, and the Dictionary typedef. More...

#include <plistCollections.h>

Inheritance diagram for plist::DictionaryBase:

Detailed Description

Maintains a set of (key,value) pairs, see DictionaryOf, and the Dictionary typedef.

You can add or set entries by a quite a few variations on addEntry(), setEntry(), or addValue(). 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 dictionary 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 269 of file plistCollections.h.

List of all members.

Classes

struct  ConversionTo
 This conversion policy accepts entries of the specified template type, and will try to create new instances of that type constructed from any values which are passed. More...
struct  ConversionTo< plist::Primitive< double > >
 This is a specialization for double conversions to add RealConversions. More...
struct  ConversionTo< plist::Primitive< float > >
 This is a specialization for float conversions to add RealConversions. More...
struct  DeniedValueConversions
 Indicates that no value conversions are allowed. More...
struct  EntryConstraint
 This base conversion policy doesn't actually specify any conversions at all -- this serves as a base class to provide the ability to directly add entries of the specified type; the subclasses will add value conversions. More...
struct  IntegerConversion
 Abstract base class to test whether the collection will accept integers (possibly converting to another value type, or storing directly as a [unsigned] long depending on concrete type). More...
struct  RealConversion
 Abstract base class to test whether the collection will accept floating point numbers (possibly converting to another value type, or storing directly as a double depending on concrete type). More...
struct  StringConversion
 Abstract base class to test whether the collection will accept strings (possibly converting to a value type, or storing directly as string depending on concrete type). More...
struct  WrapValueConversion
 This conversion policy accepts any entries of the specified template type, values will be directly wrapped as Primitives so no conversion at all is actually performed. More...

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

virtual bool removeEntry (const std::string &name)
 remove the entry with key name, returns true if something was actually removed (if false, wasn't there to begin with)
virtual bool renameEntry (const std::string &oldname, const std::string &newname)
 change the key for an entry from oldname to newname, returns false if oldname didn't exist (thus no change was made)
virtual bool swapEntry (const std::string &a, const std::string &b)
 exchange the values for a pair of keys -- if either key doesn't exist, forwards call to renameEntry()
virtual ObjectBasegetEntry (const std::string &name)=0
 returns a reference to the entry with the specified name, creating it if it doesn't exist
virtual ObjectBaseoperator[] (const std::string &name)=0
 returns a reference to the entry with the specified name, creating it if it doesn't exist
virtual ObjectBaseresolveEntry (const std::string &path) const
 returns a pointer to entry with the specified 'path', which may recurse through sub-collections
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)
 This specialization looks for the SensorInfo::sensorType, then has the factory construct the correct subtype before loading the node into and returning that.
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 regex_t *reg=NULL, unsigned int depth=-1) const
 returns the length of the longest key, subject to an optional regular expression and max depth
bool ownsReference (ObjectBase *val) const
 returns true if the specified object will be deallocated when removed from the dictionary

Protected Types

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

Protected Member Functions

 DictionaryBase (bool growable)
 constructor
 DictionaryBase (const DictionaryBase &d)
 copy constructor (don't assign listeners)
DictionaryBaseoperator= (const DictionaryBase &d)
 assignment (don't assign listeners)
 ~DictionaryBase ()
 destructor
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 void fireEntryRemoved (ObjectBase &val)
 run through collectionListeners, calling CollectionListener::plistCollectionEntryRemoved(*this,val)
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
virtual bool loadXMLNode (const std::string &key, xmlNode *val, const std::string &comment)=0
 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, size_t longestKeyLen) const
 called with each node being saved so subclass can handle appropriately, return true if successful and set key

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 DictionaryBase &d)
 provides textual output

Member Typedef Documentation

typedef std::map<std::string,std::string> plist::DictionaryBase::comments_t [protected]

shorthand for the type of comments

Definition at line 474 of file plistCollections.h.

typedef storage_t::const_iterator plist::DictionaryBase::const_iterator

shorthand for iterators to be returned

Reimplemented in InstanceTracker< FamilyT, ClassNameT, FactoryBaseT, FactoryT >.

Definition at line 277 of file plistCollections.h.

typedef storage_t::iterator plist::DictionaryBase::iterator

shorthand for iterators to be returned

Reimplemented in InstanceTracker< FamilyT, ClassNameT, FactoryBaseT, FactoryT >.

Definition at line 275 of file plistCollections.h.


Constructor & Destructor Documentation

plist::DictionaryBase::DictionaryBase ( bool  growable  )  [explicit, protected]

constructor

Definition at line 430 of file plistCollections.h.

plist::DictionaryBase::DictionaryBase ( const DictionaryBase d  )  [protected]

copy constructor (don't assign listeners)

Definition at line 432 of file plistCollections.h.

plist::DictionaryBase::~DictionaryBase (  )  [protected]

destructor

Definition at line 437 of file plistCollections.h.


Member Function Documentation

void plist::DictionaryBase::clear (  )  [virtual]

remove all entries in one fell swoop

Implements plist::Collection.

Reimplemented in ConvexPolyObstacle, HierarchicalObstacle, and plist::RGBColor< T >.

Definition at line 614 of file plistCollections.cc.

Referenced by Grasper::computeGoalStates(), and ~DictionaryBase().

void plist::DictionaryBase::cloneMyRef (  )  [protected, virtual]

called after an assignment or copy to clone the objects in myRef to perform a deep copy

Definition at line 640 of file plistCollections.cc.

Referenced by DictionaryBase().

const_iterator plist::DictionaryBase::findEntry ( const std::string &  name  )  const
void plist::DictionaryBase::fireEntryRemoved ( ObjectBase val  )  [protected, virtual]

run through collectionListeners, calling CollectionListener::plistCollectionEntryRemoved(*this,val)

Reimplemented from plist::Collection.

Reimplemented in plist::RGBColor< T >.

Definition at line 631 of file plistCollections.cc.

Referenced by removeEntry(), and renameEntry().

const std::string & plist::DictionaryBase::getComment ( const std::string &  name  )  const

returns comment retrieved from loaded file, or any subsequent call to setComment

Definition at line 402 of file plistCollections.cc.

Referenced by plist::DictionaryOf< PO, Alloc >::operator=(), and plist::DictionaryOf< PO, Alloc >::set().

virtual ObjectBase& plist::DictionaryBase::getEntry ( const std::string &  name  )  [pure virtual]
unsigned int plist::DictionaryBase::getLongestKeyLen ( const regex_t *  reg = NULL,
unsigned int  depth = -1 
) const [virtual]

returns the length of the longest key, subject to an optional regular expression and max depth

Implements plist::Collection.

Reimplemented in plist::RGBColor< T >.

Definition at line 573 of file plistCollections.cc.

Referenced by saveXML(), KinematicJoint::saveXML(), and OutputConfig< T >::saveXML().

DictionaryBase::const_iterator plist::DictionaryBase::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 601 of file plistCollections.cc.

DictionaryBase::iterator plist::DictionaryBase::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 589 of file plistCollections.cc.

Referenced by resolveEntry().

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

This specialization looks for the SensorInfo::sensorType, then has the factory construct the correct subtype before loading the node into and returning that.

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

supports use of plist::ArrayOf<PlannerObstacle> for polymorphic load/save

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.

attempts to load a new T instance from the specified xmlNode

Reimplemented from plist::ObjectBase.

Reimplemented in KinematicJoint, RectangularObstacle, CircularObstacle, EllipticalObstacle, ConvexPolyObstacle, BoxObstacle, CylindricalObstacle, SphericalObstacle, EllipsoidObstacle, InstanceTracker< FamilyT, ClassNameT, FactoryBaseT, FactoryT >, and plist::RGBColor< T >.

Definition at line 411 of file plistCollections.cc.

Referenced by plist::loadXML(), InstanceTracker< FamilyT, ClassNameT, FactoryBaseT, FactoryT >::loadXML(), and ConfigDictionary::loadXMLNode().

virtual bool plist::DictionaryBase::loadXMLNode ( const std::string &  key,
xmlNode val,
const std::string &  comment 
) [protected, pure virtual]
DictionaryBase& plist::DictionaryBase::operator= ( const DictionaryBase d  )  [protected]

assignment (don't assign listeners)

Definition at line 434 of file plistCollections.h.

virtual ObjectBase& plist::DictionaryBase::operator[] ( const std::string &  name  )  [pure virtual]
bool plist::DictionaryBase::ownsReference ( ObjectBase val  )  const

returns true if the specified object will be deallocated when removed from the dictionary

Definition at line 426 of file plistCollections.h.

bool plist::DictionaryBase::renameEntry ( const std::string &  oldname,
const std::string &  newname 
) [virtual]

change the key for an entry from oldname to newname, returns false if oldname didn't exist (thus no change was made)

If the collection owns the reference to the object, you have to use this function instead of a pair of calls to removeEntry/addEntry, otherwise you will wind up with an invalid pointer!

Definition at line 303 of file plistCollections.cc.

Referenced by swapEntry().

ObjectBase * plist::DictionaryBase::resolveEntry ( const std::string &  path  )  const [virtual]

returns a pointer to entry with the specified 'path', which may recurse through sub-collections

Implements plist::Collection.

Reimplemented in plist::RGBColor< T >.

Definition at line 374 of file plistCollections.cc.

Referenced by Config::parseLine(), Controller::setConfig(), and Config::setValue().

bool plist::DictionaryBase::saveOverXMLNode ( xmlNode k,
xmlNode val,
const std::string &  key,
std::string  comment,
const std::string &  indentStr,
std::set< std::string > &  seen 
) const [protected, virtual]

called with each node being saved so subclass can handle appropriately, return true if successful and reset key if changed

Reimplemented in ConfigDictionary.

Definition at line 671 of file plistCollections.cc.

Referenced by saveXML().

void plist::DictionaryBase::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 (this overrides the current savePolicy value)
[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 KinematicJoint, OutputConfig< T >, Config, and OutputConfig< plist::Primitive< float > >.

Definition at line 485 of file plistCollections.cc.

void plist::DictionaryBase::saveXMLNode ( xmlNode node,
const std::string &  key,
const ObjectBase val,
const std::string &  indentStr,
size_t  longestKeyLen 
) const [protected, virtual]

called with each node being saved so subclass can handle appropriately, return true if successful and set key

Definition at line 728 of file plistCollections.cc.

Referenced by KinematicJoint::doSaveXMLNode(), saveXML(), and OutputConfig< T >::saveXML().

void plist::DictionaryBase::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!)

Definition at line 393 of file plistCollections.cc.

Referenced by plist::DictionaryOf< PO, Alloc >::loadXMLNode(), plist::DictionaryOf< PO, Alloc >::operator=(), and plist::DictionaryOf< PO, Alloc >::set().

virtual size_t plist::DictionaryBase::size (  )  const [virtual]
bool plist::DictionaryBase::swapEntry ( const std::string &  a,
const std::string &  b 
) [virtual]

exchange the values for a pair of keys -- if either key doesn't exist, forwards call to renameEntry()

returns true if the swap was successful, only returns false if both keys are invalid

Definition at line 339 of file plistCollections.cc.

void plist::DictionaryBase::takeObject ( const std::string &  name,
ObjectBase obj 
) [protected, virtual]

indicates that the storage implementation should mark this as an externally supplied heap reference, which needs to be deleted on removal/destruction

Definition at line 627 of file plistCollections.cc.

Referenced by plist::DictionaryOf< PO, Alloc >::addEntry(), and plist::DictionaryOf< PO, Alloc >::setEntry().

std::string plist::DictionaryBase::toString (  )  const [virtual]

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  os,
const DictionaryBase d 
) [friend]

provides textual output

Definition at line 1578 of file plistCollections.h.


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 477 of file plistCollections.h.

Referenced by plist::DictionaryOf< PO, Alloc >::addEntry(), clear(), getComment(), removeEntry(), renameEntry(), saveOverXMLNode(), saveXMLNode(), setComment(), and swapEntry().


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

Tekkotsu v5.1CVS
Generated Mon May 9 04:59:24 2016 by Doxygen 1.6.3