GVectors::VectorStore Class Reference

Class for storing VisualVector object in a hierarchical manner. More...

#include <vectorstore.h>

List of all members.

Public Member Functions

 VectorStore (bool use_e=true)
 Constructor.
 ~VectorStore ()
 Destructor.
void use_exceptions (bool ue)
 Set the use of exceptions.
vv_ptr_t id_get (gvid_t id)
 id.
vv_ptr_t operator[] (gvid_t id)
 id.
gvid_t add (const vv_ref_t v)
 Add a VisualVector to the VectorStore.
gvid_t add (vv_ptr_t v, bool managed=true)
 Add a VisualVector to the VectorStore.
void replace (gvid_t id, vv_ptr_t v, bool managed=true)
 vector store id.
void replace (gvid_t id, vv_ref_t v)
 vector store id.
gvid_t add_child (gvid_t id, const vv_ref_t v)
 Add a child to the given vector store id.
gvid_t add_child (gvid_t id, vv_ptr_t v, bool managed=true)
 Add a child to the given vector store id.
void remove (gvid_t id)
 Remove the given id from store.
void clear ()
 Clear the store.
vssize_t size () const
 Get the size of the store in terms of items stored.
void set_origin (const Coordinates &co)
 Set the origin of the top level VisualVectors.
void set_scale (double sc)
 Set the scale of the VisualVectors.
void set_arrow_length (double arl)
 Set the arrow length of all VisualVectors.
void set_rotation (const Rotation &r)
 Set the rotation of all VisualVectors.
void draw (Drawer &d)
 Draw all VisualVectors.
void save (FileWriter &fw) const
 Save all VisualVectors using the given FileWriter.
void sum_up (gvid_t id, GVector &vec) const
 associated with the given id.
void dimension (Coordinates &min, Coordinates &max) const
 plane.

Protected Member Functions

vsi_ptr_t get_item (gvid_t id) const
 Retrieves a VStoreItem by its id.

Private Attributes

std::map< gvid_t, vsi_ptr_tlookup
 Map used for fast access to vector store items.
std::list< vsi_ptr_tvector_items
 List used to represent the item tree.
std::list< gvid_tremoved
 Used to keep lookup map in sync.
bool useexceptions
 Flag indicating whether or not exceptions should be used for indicating error conditions.


Detailed Description

The VectorStore class stores VisualVector objects in a hierarchical manner.

A VectorStore can be drawn and written to disk.

It allows to set a common origin, rotation, and scale to all items stored.

Children will take the head of the parent VisualVector as their tail.


Constructor & Destructor Documentation

VectorStore::VectorStore ( bool  use_e = true  ) 

Constructor.

Parameters:
use_e Flag indicating whether or not exceptions should be used to indicate error conditions. Pass true to enable exceptions, false to disable exceptions (see also VectorStore::use_exceptions()).

VectorStore::~VectorStore (  ) 

Destructor. Removes the items from memory.


Member Function Documentation

vsi_ptr_t VectorStore::get_item ( gvid_t  id  )  const [protected]

Retrieves the pointer to the VStoreItem associated with the given id.

Parameters:
id The id of the VStoreItem to be retrieved.
Returns:
The pointer to the VStoreItem.
Return values:
0 If the id could not be found, and use of exceptions has been disabled (see VectorStore::use_exceptions()).
Exceptions:
GVEItemNotFound if the id could not be found, and the use of exceptions has been enabled (see VectorStore::use_exceptions()).

void VectorStore::use_exceptions ( bool  ue  ) 

Enables or disables the use exceptions when error conditions occur. If enabled, exceptions are thrown upon error condition. If disabled, the return value of the method is used, where possible, to indicate error conditions.

Parameters:
ue Pass true to enable the use of exceptions. If false is passed, the use of exceptions is disabled.

vv_ptr_t VectorStore::id_get ( gvid_t  id  ) 

Retrieves the pointer to the VisualVector associated with the item matching the id provided.

Parameters:
id The id to look up.
Returns:
The pointer to the VisualVector.
Return values:
0 if the id could not be found and the use of exceptions has been disabled.
Exceptions:
GVEItemNotFound if the id could not be found and the use of exceptions has been enabled.

gvid_t VectorStore::add ( const vv_ref_t  v  ) 

Adds the given VisualVector to the vector store. A copy of it is made, so there is no need to keep the original VisualVector.

Parameters:
v A const reference to the VisualVector to be added to the store.
Returns:
The id of the item the VisualVector is associated with. This id can be used to retrieve the pointer to the VisualVector.

gvid_t VectorStore::add ( vv_ptr_t  v,
bool  managed = true 
)

Adds the given VisualVector to the vector store. Depending on the value passed to managed, the VisualVector is either destroyed upon the destruction of the vector store, or the user is responsible for released the memory occupied by the visual vector.

Parameters:
v The pointer to the VisualVector to be added to the store.
managed If this is set to true, then the memory occupied by the VisualVector is released by VectorStore upon destruction, thus it is managed by VectorStore. If it is set to false, the user is responsible for releasing the memory occupied by the VisualVector.
Returns:
The id of the item the VisualVector is associated with. This id can be used to retrieve the pointer to the VisualVector.

void VectorStore::replace ( gvid_t  id,
vv_ptr_t  v,
bool  managed = true 
)

Replaces the VisualVector associated with the id id. If the VisualVector was previously added as managed, the memory is released, else the user is responsible for releasing the memory.

Parameters:
id The id of the VisualVector to be replaced by a new one.
v The pointer to the VisualVector replacing the current VisualVector associated with the id.
managed If this is set to true, then the memory occupied by the VisualVector is released by VectorStore upon destruction, thus it is managed by VectorStore. If it is set to false, the user is responsible for releasing the memory occupied by the VisualVector.

void VectorStore::replace ( gvid_t  id,
vv_ref_t  v 
)

Replaces the VisualVector associated with the id id. Memory management is taken care of by VectorStore.

Parameters:
id The id of the VisualVector to be replaced by a new one.
v A reference to the VisualVector replacing the current VisualVector. A copy of the VisualVector referenced is made, and the memory management is taken care of by VectorStore.

gvid_t VectorStore::add_child ( gvid_t  id,
const vv_ref_t  v 
)

Adds a child to the VisualVector associated with the id id. Children of a VisualVector have the head of the parent as their start point.

Parameters:
id The id of the parent VisualVector.
v A reference to the VisualVector to be added as child. A copy of the VisualVector referenced is made, and the memory management is taken care of by VectorStore.
Returns:
The id which is associated with the newly added child.
Return values:
GVID_NONE if the given id of the parent could not be found, and the use of exceptions has been disabled.
Exceptions:
GVEItemNotFound if the given id of the parent could not be found, and the use of exceptions has been enabled.

gvid_t VectorStore::add_child ( gvid_t  id,
vv_ptr_t  v,
bool  managed = true 
)

Adds a child to the VisualVector associated with the id id. Children of a VisualVector have the head of the parent as their start point.

Parameters:
id The id of the parent VisualVector.
v The pointer to the VisualVector to be added as child.
managed If this is set to true, then the memory occupied by the VisualVector is released by VectorStore upon destruction, thus it is managed by VectorStore. If it is set to false, the user is responsible for releasing the memory occupied by the VisualVector.
Returns:
The id which is associated with the newly added child.
Return values:
GVID_NONE if the given id of the parent could not be found, and the use of exceptions has been disabled.
Exceptions:
GVEItemNotFound if the given id of the parent could not be found, and the use of exceptions has been enabled.

void VectorStore::remove ( gvid_t  id  ) 

Removes the VisualVector with the given id from the store. Depending on the method used to add it to the store, the memory occupied by the VisualVector will be released, e.g. if it was added as 'managed', else the user is responsible for freeing the memory occupied by the VisualVector. In any case, the VisualVector and its id are no longer known to the VectorStore.

If the use of exceptions has been disabled in VectorStore, there is no way of knowing whether or not the item has been successfully removed, e.g. the id has been found.

Parameters:
id The id to be removed from the VectorStore.
Exceptions:
GVEItemNotFound if the id provided is not associated with a VisualVector, and the use of exceptions has been enabled.

void VectorStore::clear (  ) 

Removes all VisualVectorS from the store and release the memory of those added as 'managed'.

vssize_t VectorStore::size (  )  const

Returns the size of the VectorStore in terms of items stored.

As a side effect, it compares the number of item referenced in the lookup map with the count of items obtained by recursively traveling the tree. If those numbers do not match, and the use of exceptions is enabled, it throws an exception.

Returns:
The size of the VectorStore in terms of items stored.
Exceptions:
GVEStoreCorrupt if the number of items referenced in the lookup map do not match the number of items obtained by traveling the tree. This is only thrown, if the use of exceptions has been enabled.

void VectorStore::set_origin ( const Coordinates co  ) 

Sets the origin of the top level items. The origins of the children are calculated based on the head of the parents.

Parameters:
co A const reference to the two dimensional coordinate serving as origin for the top level VisualVectorS.

void VectorStore::set_scale ( double  sc  ) 

Sets the scale of all VisualVectorS.

Parameters:
sc The scale to set.

void VectorStore::set_arrow_length ( double  arl  ) 

Sets the length of the arrow to indicate the head of the VisualVectorS.

Parameters:
arl The length of the arrow.

void VectorStore::set_rotation ( const Rotation r  ) 

Sets the given Rotation on all VisualVectors.

Parameters:
r A const reference to the Rotation object to be set on the VisualVectorS.

void VectorStore::draw ( Drawer d  ) 

Draws all VisualVectorS using the given Drawer.

Parameters:
d A reference to the Drawer to be used to draw the VisualVectorS.

void VectorStore::save ( FileWriter fw  )  const

Save the VectorStore using the FileWriter provided.

Parameters:
fw A reference to a FileWriter used to save to VectorStore.

void VectorStore::sum_up ( gvid_t  id,
GVector vec 
) const

Sums up all VisualVectorS leading to and including the one specified by id.

Parameters:
id The id of the VisualVector.
vec The GVector referenced will receive the sum.

void VectorStore::dimension ( Coordinates min,
Coordinates max 
) const

Gets the dimension of the 2D projection.

Parameters:
min A reference to the Coordinates receiving the minimum x and y values.
max A reference to the Coordinates receiving the maximum x and y values.


Member Data Documentation

std::map<gvid_t, vsi_ptr_t> GVectors::VectorStore::lookup [private]

The map is used for fast access to vector store items. It keeps all pointers to vector store items.

Because it serves only for lookup purpose, it has to kept explicitely in sync with the actual vector store items stored.

std::list<vsi_ptr_t> GVectors::VectorStore::vector_items [private]

This list holds the pointers to the top level items of the vector store. Each item can hold further pointers to items in turen, thus forming a tree.

std::list<gvid_t> GVectors::VectorStore::removed [private]

Since the lookup map is not the primary data structure for storing pointers to items, it has to explicitely kept in sync with the tree, when items are removed.

Every method removing items is expected to keep track of the removed items by putting their pointers into this list.

bool GVectors::VectorStore::useexceptions [private]

This flag determines whether or not exceptions are used when error conditions are encountered. Alternatively, when no exceptions are used, the return value of certain methods indicate an error condition.


The documentation for this class was generated from the following files:
Generated on Sat Sep 8 19:37:30 2007 for libgvectors by  doxygen 1.4.7