Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

plist::Collection Class Reference

#include <plistCollections.h>

Inheritance diagram for plist::Collection:

Inheritance graph
[legend]
List of all members.

Detailed Description

Provides a common base class for the collection-oriented primitives, Dictionary and Array.

When a collection, you can call addEntry() or setEntry() you can 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

This class supports callbacks upon modification through the use of the CollectionListener interface. Note that we only store a pointer to the listener list, which is typically unallocated when no listeners are active. This should ensure minimal memory usage per object, as well as support safe storage of plist objects in inter-process shared memory regions.

If you are using these in a shared memory region, just be sure that only the process with listeners does any and all modifications, and that it unsubscribes before detaching from the region (or else destroys the region itself)

There isn't a callback if entries themselves are modified, only when new entries are added, or old ones removed. If you want to know any time any aspect of any entry is modified, listen for the add and remove callbacks, and then add yourself as a listener to each entry individually.

Definition at line 37 of file plistCollections.h.

Public Member Functions

virtual ObjectBaseresolveEntry (const std::string &path) const =0
 recursively resolves path interpreted as a series of collection entry names separated by '.', returns NULL if it doesn't exist
virtual void clear ()=0
 remove all entries in one fell swoop
virtual size_t size () const =0
 return the size of the collection
virtual void addCollectionListener (CollectionListener *l)
 get notified of changes; be sure to call removeCollectionListener() before destructing l!
virtual void removeCollectionListener (CollectionListener *l)
 no longer take notification of changes to this object's value
virtual bool isCollectionListener (CollectionListener *l)
 test if l is currently registered as a listener
void setUnusedWarning (bool b)
 set warnUnused
bool getUnusedWarning ()
 returns warnUnused
virtual bool getTrimExtraLoad () const
 returns trimExtraLoad
virtual bool getTrimExtraSave () const
 returns trimExtraSave
virtual void setTrimExtra (bool trim)
 sets trimExtraLoad and trimExtraSave to the save value
virtual void setTrimExtra (bool trimLoad, bool trimSave)
 sets trimExtraLoad and trimExtraSave
virtual unsigned int getLongestKeyLen () const =0
 return the length of the longest key for formatting purposes
virtual bool canContain (const ObjectBase &obj)=0
 returns true if the Collection subclass allows storage of the argument

Static Public Member Functions

static const std::string & subCollectionSep ()
 defines separator between sub-collections

Protected Member Functions

 Collection (bool bl, bool bs)
 constructor
 Collection (const Collection &d)
 copy constructor (don't assign listeners)
Collectionoperator= (const Collection &d)
 assignment (don't assign listeners); subclass should call fireEntriesChanged after calling this (and updating its own storage)
 ~Collection ()
 destructor
virtual void fireEntryAdded (ObjectBase &val)
 run through collectionListeners, calling CollectionListener::plistCollectionEntryAdded(*this,val)
virtual void fireEntryRemoved (ObjectBase &val)
 run through collectionListeners, calling CollectionListener::plistCollectionEntryRemoved(*this,val)
virtual void fireEntriesChanged ()
 run through collectionListeners, calling CollectionListener::plistCollectionEntriesChanged(*this)

Static Protected Member Functions

static size_t getIndex (const std::string &name)
 returns index corresponding to name, which should encode an integer value less than or equal to the current size
static std::string getIndentationPrefix (xmlNode *node)
 returns a prefix for items within the collection
static const std::string & emptyStr ()
 when an empty string is needed for not found items
static const std::string & perIndent ()
 how much to indent each sub-collection

Protected Attributes

std::list< CollectionListener * > * collectionListeners
 stores a list of the current listeners
bool warnUnused
 if true (the default) loadXML will give warnings if there are unused entries in the node it is passed (can only happen if trimExtraLoad is false), or extra values in a file being saved into (can only happen if trimExtraSave is false)
bool trimExtraLoad
 if true, unloaded items in the collection will be removed after a load, and new entries will be created for extras in the source (brings storage into complete sync with input)
bool trimExtraSave
 if true, unsaved items in the destination will be removed after a save (brings output XML tree into complete sync with storage)

Static Protected Attributes

static const unsigned int KEY_IN_COMMENT_MAX_POS = 10

Classes

struct  conversion_policy


Member Function Documentation

static const std::string& plist::Collection::emptyStr (  )  [inline, static, protected]

when an empty string is needed for not found items

(defined as a function instead of just a constant member so there's no issues with initialization order)

Definition at line 103 of file plistCollections.h.

Referenced by plist::ArrayBase::getComment(), and plist::Dictionary::getComment().

static const std::string& plist::Collection::perIndent (  )  [inline, static, protected]

how much to indent each sub-collection

(defined as a function instead of just a constant member so there's no issues with initialization order)

Definition at line 109 of file plistCollections.h.

Referenced by getIndentationPrefix(), plist::ArrayBase::saveXML(), plist::Dictionary::saveXML(), and OutputConfig< T >::saveXML().

static const std::string& plist::Collection::subCollectionSep (  )  [inline, static]

defines separator between sub-collections

(defined as a function instead of just a constant member so there's no issues with initialization order)

Definition at line 65 of file plistCollections.h.

Referenced by plist::ArrayBase::getLongestKeyLen(), plist::Dictionary::getLongestKeyLen(), plist::ArrayBase::getSubEntry(), plist::Dictionary::getSubEntry(), plist::operator<<(), and ConfigurationEditor::refresh().


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