Main Page | Class Hierarchy | Data Structures | File List | Data Fields | Globals

PropertyFacility Class Reference

#include <PropertyFacility.hpp>


Detailed Description

PropertyFacility class. Stores properties.

General
The node and edge properties are all stored in a property facility, which is external to the graph. This allows us to change the implementation of either the properties or the graph without having to change the implementation of the other one. Also, the properties are in a "global" place, which means that if there are, for example, two views of the same hierarchy, they can share the same properties. This helps keeping the properties consistent.

The properties are all templated ancestors of the abstract Property class, so that they can be stored in an untyped list.

Useage
Before a property for a node or an edge can be set, the node or edge has to be inserted into the property facility. When a node or an edge is deleted, the del_node or del_edge method of the property facility has to be called. The default graph implementation of this project already does this autmatically.

Internals
The property facility has a map for the node properties and a map for the edge properties. These maps map the nodes or edges to maps for the properties of the nodes or edges, which map strings (the property names) to the actual properties.

Whenever a Property is inserted into the PropertyFacility which already exists, the old one is updated if the types match, otherwise, an exception is thrown.


Public Types

typedef std::map< std::string,
AbstractProperty * > 
PropertyMap
 Type for the Property Map.
typedef std::hash_map< std::string,
std::pair< int, PropertyMap * > > 
Map
 Type for the Map.
typedef PropertyMap::iterator PropertyIterator
 PropertyIterator type.

Public Member Functions

 PropertyFacility ()
 Constructor.
 PropertyFacility (const PropertyFacility &p)
 Copy Constructor.
 ~PropertyFacility ()
 Destructor.
void register_user ()
 Register as a user of the property facility.
void unregister_user ()
 Unregister as a user of the property facility.
int user_count ()
 Return the user number.
void add_id (std::string id)
 Add an id to the PropertyFacility.
void del_id (std::string id)
 Remove an id from the PropertyFacility.
template<class T>
void set (std::string id, std::string pname, T val)
 Set the property of an ID.
template<class T>
get (std::string id, std::string pname)
 Get the property of an ID.
bool isset (std::string id, std::string pname)
 Check if a property exists for an ID.
void unset (std::string id, std::string pname)
 Unset a property of an ID.
void clone (std::string id1, std::string id2, PropertyFacility *prop2=NULL)
 Copy all properties of id 1 to id 2 (in PropertyFacility prop2).
PropertyIterator begin (std::string id)
 Returns an iterator pointing to the first property of an ID.
PropertyIterator end (std::string id)
 Returns an iterator pointing after the end of the properties of an IDnode.

Private Attributes

Map_m
 Property Map of Nodes Properties.
int users
 Number of users using this Property Facility.


Member Typedef Documentation

typedef std::hash_map<std::string, std::pair<int, PropertyMap*> > Map
 

Type for the Map.

typedef PropertyMap::iterator PropertyIterator
 

PropertyIterator type.

typedef std::map<std::string, AbstractProperty*> PropertyMap
 

Type for the Property Map.


Constructor & Destructor Documentation

PropertyFacility  ) 
 

Constructor.

PropertyFacility const PropertyFacility p  ) 
 

Copy Constructor.

Will hold the same properties for the same nodes.

~PropertyFacility  ) 
 

Destructor.


Member Function Documentation

void add_id std::string  id  ) 
 

Add an id to the PropertyFacility.

This enables the PropertyFacility to store properties for the node. It should be removed from the PropertyFacility once it's not used anymore.

Complexity: O( 1 )

Parameters:
id The ID

PropertyFacility::PropertyMap::iterator begin std::string  id  ) 
 

Returns an iterator pointing to the first property of an ID.

 // PropertyFacility* p is a pointer to a PropertyFacility
 // ID id is a NodeID or EdgeID
 for( PropertyFacility::PropertyIterator it = p->begin(id); it != p->end(id); ++it ) {
   std::cout << "The Property named \"" << it->first << "\" has the value: " << it->second << std::endl;
 }

Exceptions:
GraphException Throws an invalid_id exception if the ID is not in the PropertyFacility.
Parameters:
id The ID

void clone std::string  id1,
std::string  id2,
PropertyFacility prop2 = NULL
 

Copy all properties of id 1 to id 2 (in PropertyFacility prop2).

Existing Properties of id2 with the same name as properties of id1 will be deleted.

Parameters:
id1 ID to copy from
id2 ID to copy to
prop2 PropertyFacility of id2 (NULLL => uses this), defaults to NULL

void del_id std::string  id  ) 
 

Remove an id from the PropertyFacility.

This removes all properties of the node from the PropertyFacility and disables the ability to store properties for the node.

Complexity: O( #properties(id) )

Parameters:
id The ID

PropertyFacility::PropertyMap::iterator end std::string  id  ) 
 

Returns an iterator pointing after the end of the properties of an IDnode.

For an example, see PropertyFacility::begin()

Exceptions:
GraphException Throws an invalid_id exception if the ID is not in the PropertyFacility.
Parameters:
id The ID

T get std::string  id,
std::string  pname
 

Get the property of an ID.

Useage example:

 properties->get<int>(nodeid, "importance");

Complexity: O( log(#properties(id)) )

Exceptions:
GraphException Throws an invalid_id exception if the ID is not in the PropertyFacility, an invalid_property_type if the property is of another type than the expected one and an invalid_property if the property is not set.
Parameters:
id The ID
pname The property name
Returns:
The property

bool isset std::string  id,
std::string  pname
 

Check if a property exists for an ID.

Complexity: O( log(#properties(id)) )

Parameters:
id The ID
pname The name of the property
Returns:
true if the property exists, false otherwise

void register_user  ) 
 

Register as a user of the property facility.

Add one to the user number. This should be called when an object wants to use this property facility: as long as there are registered users, the PropertyFacility should not be destroyed.

void set std::string  id,
std::string  pname,
val
 

Set the property of an ID.

If the property does not yet exist, it will be created. If it exists and the data type is the same, the old value will be overwritten.

This should always be used with the type specialization to prevent unintentional errors and to make clear what you are doing. Example:

 // PropertyFacility* prop, NodeID nodeid
 prop->set<std::string>(nodeid, "weight", "Matthew");

Complexity: O( log(#properties(id)) )

Exceptions:
GraphException Throws an invalid_id exception if the ID is not in the PropertyFacility, and an invalid_property_type if the property exists, but is of another type than the new value.
Parameters:
id The ID
pname The property name
val The property value

void unregister_user  ) 
 

Unregister as a user of the property facility.

Substract one of the user number. This should be called when an object does now want to use this property facility any more.

void unset std::string  id,
std::string  pname
 

Unset a property of an ID.

If the property does not exist, nothing will happen.

Complexity: O( log(#properties(id)) )

Parameters:
id The ID
pname The name of the property

int user_count  ) 
 

Return the user number.

With this, a check can be made if this property facility is still in use by somebody. If not, it can be destroyed.


Field Documentation

Map* _m [private]
 

Property Map of Nodes Properties.

int users [private]
 

Number of users using this Property Facility.


Generated on Sun Nov 5 12:06:31 2006 for Graph by  doxygen 1.4.1