frepple::utils::HasHierarchy< T > Class Template Reference

This is a base class for the main objects. More...

#include <utils.h>

Inheritance diagram for frepple::utils::HasHierarchy< T >:

List of all members.

Classes

class  memberIterator
 This class models an STL-like iterator that allows us to iterate over the members. More...

Public Member Functions

void beginElement (XMLInput &, const Attribute &)
memberIterator beginMember () const
void endElement (XMLInput &, const Attribute &, const DataElement &)
unsigned short getHierarchyLevel () const
T * getOwner () const
 HasHierarchy (const string &n)
bool hasOwner () const
bool isGroup () const
void setOwner (T *f)
void writeElement (XMLOutput *, const Keyword &, mode=DEFAULT) const
 ~HasHierarchy ()
- Public Member Functions inherited from frepple::utils::HasName< T >
int compare (const PyObject *other) const
 HasName (const string &n)
 HasName (const char *n)
void setName (const string &newname)
virtual PyObject * str () const
 ~HasName ()
- Public Member Functions inherited from frepple::utils::Tree::TreeNode
TreeNodedecrement () const
const string & getName () const
TreeNodeincrement () const
bool operator< (const TreeNode &o)
 TreeNode (const string &n)
virtual ~TreeNode ()
- Public Member Functions inherited from frepple::utils::Object
virtual bool getHidden () const
virtual size_t getSize () const =0
virtual const MetaClassgetType () const =0
 Object ()
virtual void setHidden (bool b)
virtual ~Object ()
- Public Member Functions inherited from frepple::utils::PythonExtensionBase
virtual PyObject * call (const PythonObject &args, const PythonObject &kwds)
virtual PyObject * getattro (const Attribute &attr)
Py_ssize_t getReferenceCount () const
void initType (const MetaClass *t)
void initType (PyTypeObject *t)
virtual PyObject * iternext ()
 PythonExtensionBase ()
void resetReferenceCount ()
virtual int setattro (const Attribute &attr, const PythonObject &field)
virtual ~PythonExtensionBase ()

Friends

class memberIterator

Additional Inherited Members

- Static Public Member Functions inherited from frepple::utils::HasName< T >
static T * add (const string &k, const MetaClass &cls)
static T * add (T *t)
static T * add (T *t, T *hint)
static iterator begin ()
static void clear ()
static bool empty ()
static iterator end ()
static T * find (const string &k)
static T * findLowerBound (const string &k, bool *f=NULL)
static Objectreader (const MetaClass *cat, const AttributeList &in)
static size_t size ()
static void verify ()
static void writer (const MetaCategory *c, XMLOutput *o)
- Static Public Member Functions inherited from frepple::utils::Object
template<class T >
static PyObject * create (PyTypeObject *pytype, PyObject *args, PyObject *kwds)
template<class T >
static ObjectcreateDefault ()
template<class T >
static ObjectcreateString (const string &n)
static PyObject * toXML (PyObject *, PyObject *)

Detailed Description

template<class T>
class frepple::utils::HasHierarchy< T >

This is a base class for the main objects.

Instances of this class have the following properties:

  • Unique name and global hashtable are inherited from the class HasName.
  • Instances build up hierarchical trees of arbitrary depth.
  • Each object can have a single parent only.
  • Each object has a parent and can have children. This class thus implements the 'composite' design pattern. The internal data structure is a singly linked linear list, which is efficient provided the number of childre remains limited.

Definition at line 4904 of file utils.h.


Constructor & Destructor Documentation

template<class T>
frepple::utils::HasHierarchy< T >::HasHierarchy ( const string &  n)
inline

The one and only constructor.

Definition at line 4984 of file utils.h.

template<class T >
frepple::utils::HasHierarchy< T >::~HasHierarchy ( )

Destructor. When deleting a node of the hierarchy, the children will get the current parent as the new parent. In this way the deletion of nodes doesn't create "dangling branches" in the hierarchy. We just "collapse" a certain level.

Definition at line 134 of file utils.h.


Member Function Documentation

template<class T >
void frepple::utils::HasHierarchy< T >::beginElement ( XMLInput ,
const Attribute  
)
virtual

Called while restoring the model from an XML-file.
This is called for each element within the "this" element, for which the "this" element is immediate parent.
It is called when the open element tag is encountered.

Reimplemented from frepple::utils::Object.

Reimplemented in frepple::Demand, frepple::Resource, frepple::Buffer, frepple::Item, frepple::Customer, and frepple::Location.

Definition at line 104 of file utils.h.

template<class T>
memberIterator frepple::utils::HasHierarchy< T >::beginMember ( ) const
inline

Return a member iterator.

Definition at line 4996 of file utils.h.

template<class T >
void frepple::utils::HasHierarchy< T >::endElement ( XMLInput ,
const Attribute ,
const DataElement  
)
virtual

Called while restoring the model from an XML-file.
This is called when the corresponding close element tag is encountered, and the Data() member of pElement is valid.

Reimplemented from frepple::utils::HasName< T >.

Reimplemented in frepple::Demand, frepple::Resource, frepple::BufferProcure, frepple::Buffer, frepple::Item, frepple::Customer, and frepple::Location.

Definition at line 114 of file utils.h.

template<class T >
unsigned short frepple::utils::HasHierarchy< T >::getHierarchyLevel ( ) const

Returns the level in the hierarchy.
Level 0 means the entity doesn't have any parent.
Level 1 means the entity has a parent entity with level 0.
Level "x" means the entity has a parent entity whose level is "x-1".

Definition at line 168 of file utils.h.

template<class T>
T* frepple::utils::HasHierarchy< T >::getOwner ( ) const
inline

Returns the owning entity.

Definition at line 5015 of file utils.h.

template<class T>
bool frepple::utils::HasHierarchy< T >::hasOwner ( ) const
inline

Returns true if this entity belongs to a higher hierarchical level.
An entity can have only a single owner, and can't belong to multiple hierarchies.

Definition at line 5002 of file utils.h.

template<class T>
bool frepple::utils::HasHierarchy< T >::isGroup ( ) const
inline

Returns true if this entity has lower level entities belonging to it.

Definition at line 5006 of file utils.h.

template<class T>
void frepple::utils::HasHierarchy< T >::setOwner ( T *  f)

Changes the owner of the entity.
The argument must be a valid pointer to an entity of the same type.
A NULL pointer can be passed to clear the existing owner.

Definition at line 35 of file utils.h.

template<class T >
void frepple::utils::HasHierarchy< T >::writeElement ( XMLOutput ,
const Keyword ,
mode  = DEFAULT 
) const
virtual

Called while writing the model into an XML-file. The user class should write itself out, using the IOutStream members for its "simple" members and calling writeElement recursively for any contained objects. Not all classes are expected to implement this method. In instances of such a class can be created but can't be persisted. E.g. Command

Note that this function is never called on its own. It is always called from the writeElement() method of a subclass. Therefore we don't need to worry about the refOnly or incHeader parameters.

Reimplemented from frepple::utils::Object.

Reimplemented in frepple::Demand, frepple::ResourceInfinite, frepple::Resource, frepple::BufferProcure, frepple::BufferInfinite, frepple::Buffer, frepple::Item, frepple::Customer, and frepple::Location.

Definition at line 84 of file utils.h.


Friends And Related Function Documentation

template<class T>
friend class memberIterator
friend

Definition at line 4907 of file utils.h.


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