#include <PropertyFacility.hpp>
The properties are all templated ancestors of the abstract Property class, so that they can be stored in an untyped list.
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> | |
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. |
|
Type for the Map.
|
|
PropertyIterator type.
|
|
Type for the Property Map.
|
|
Constructor.
|
|
Copy Constructor. Will hold the same properties for the same nodes. |
|
Destructor.
|
|
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 )
|
|
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; }
|
|
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.
|
|
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) )
|
|
Returns an iterator pointing after the end of the properties of an IDnode. For an example, see PropertyFacility::begin()
|
|
Get the property of an ID. Useage example: properties->get<int>(nodeid, "importance"); Complexity: O( log(#properties(id)) )
|
|
Check if a property exists for an ID. Complexity: O( log(#properties(id)) )
|
|
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. |
|
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)) )
|
|
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. |
|
Unset a property of an ID. If the property does not exist, nothing will happen. Complexity: O( log(#properties(id)) )
|
|
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. |
|
Property Map of Nodes Properties.
|
|
Number of users using this Property Facility.
|