proland::LazyGraph Class Reference
[graph]

A Graph that will only load the offsets of each elements (node/curve/area) in the input file. More...

#include <LazyGraph.h>

Inheritance diagram for proland::LazyGraph:
proland::Graph

List of all members.

Classes

class  GraphCache
 Templated cache used to store unused graph items (nodes, curves, areas. More...
class  LazyGraphIterator
 LazyGraph implementation for the abstract class GraphIterator. More...

Public Member Functions

 LazyGraph ()
 Creates a new LazyGraph.
virtual ~LazyGraph ()
 Deletes this LazyGraph.
virtual void clear ()
 Clears the cache, and deletes every element of this graph.
virtual void init ()
 Initializes LazyGraph's cache and vectors.
int getCurveCount () const
 Returns the number of curves in this graph.
int getNodeCount () const
 Returns the number of nodes in this graph.
int getAreaCount () const
 Returns the number of areas in this graph.
void setNodeCacheSize (int size)
 Sets the Node Cache size, i.e.
void setCurveCacheSize (int size)
 Sets the Curve Cache size, i.e.
void setAreaCacheSize (int size)
 Sets the Area Cache size, i.e.
void load (const string &file, bool loadSubgraphs=0)
 Loads a graph.
void load (bool loadSubgraphs=0)
 Loads a graph from a basic file, using fileReader.
void loadIndexed (bool loadSubgraphs=0)
 Loads a graph from an indexed file, using fileReader.
void load (FileReader *fileReader, bool loadsubgraphs=0)
 Loads a graph from a basic file.
NodePtr get (NodeId id)
 Calls the getNode() method.
CurvePtr get (CurveId id)
 Calls the getCurve-) method.
AreaPtr get (AreaId id)
 Calls the getArea() method.
NodePtr getNode (NodeId id)
 Will get the Node corresponding to the given Id.
CurvePtr getCurve (CurveId id)
 Will get the Curve corresponding to the given Id.
AreaPtr getArea (AreaId id)
 Will get the Area corresponding to the given Id.
GraphPtr getSubgraph (AreaId id)
 Will get the subgraph corresponding to the given AreaId.
ptr< CurveIteratorgetChildCurves (CurveId parentId)
 Returns the childs of a given curve.
AreaPtr getChildArea (AreaId parentId)
 Returns the child of a given area.
NodePtr newNode (const vec2d &p)
 Adds a node to this graph.
CurvePtr newCurve (CurvePtr parent, bool setParent)
 Adds a curve to this graph.
CurvePtr newCurve (CurvePtr model, NodePtr start, NodePtr end)
 Adds a curve to this graph.
AreaPtr newArea (AreaPtr parent, bool setParent)
 Adds an area to this graph.
virtual void movePoint (CurvePtr c, int i, const vec2d &p)
 Moves a control point or a node on a given curve.
void deleteNode (NodeId id)
 Deletes a resource from this graph.
void deleteCurve (CurveId id)
 See deleteNode(NodeId id).
void deleteArea (AreaId id)
 See deleteNode(NodeId id).
GraphCache< Node > * getNodeCache ()
 Returns the Node Cache.
GraphCache< Curve > * getCurveCache ()
 Returns the Curve Cache.
GraphCache< Area > * getAreaCache ()
 Returns the Area Cache.
void releaseNode (NodeId id)
 Releases an unused resource.
void releaseCurve (CurveId id)
 see releaseNode(NodeId id)
void releaseArea (AreaId id)
 see releaseNode(NodeId id)

Protected Member Functions

virtual NodePtr loadNode (long int offset, NodeId id)
 Loads the Node corresponding to the given Id.
virtual CurvePtr loadCurve (long int offset, CurveId id)
 Loads the Curve corresponding to the given Id.
virtual AreaPtr loadArea (long int offset, AreaId id)
 Loads the Area corresponding to the given Id.
virtual GraphPtr loadSubgraph (long int offset, AreaId id)
 Loads a subgraph corresponding to a given AreaId.
void removeNode (NodeId id)
 Removes a Node from this graph.
void removeCurve (CurveId id)
 Removes a Curve from this graph.
void removeArea (AreaId id)
 Removes an Area from this graph.
void remove (Node *n)
 Calls removeNode().
void remove (Curve *c)
 Calls removeCurve().
void remove (Area *a)
 Calls removeArea().
virtual void clean ()
 Clean method to erase the changes in the graph.
void readSubgraph ()
 Reads the data file to pass through a given graph.
map< NodeId, long int > getNodeOffsets () const
 Returns the list of offsets for each node.
map< CurveId, long int > getCurveOffsets () const
 Returns the list of offsets for each curve.
map< AreaId, long int > getAreaOffsets () const
 Returns the list of offsets for each area.
ptr< NodeIteratorgetNodes ()
 Returns an iterator containing the Nodes of this Graph.
ptr< CurveIteratorgetCurves ()
 Returns an iterator containing the Curves of this Graph.
ptr< AreaIteratorgetAreas ()
 Returns an iterator containing the Areas of this Graph.

Protected Attributes

map< CurveId, Curve * > curves
 The entire list of curves in this graph.
map< NodeId, Node * > nodes
 The entire list of nodes in this graph.
map< AreaId, Area * > areas
 The entire list of areas in this graph.
NodeId nextNodeId
 Id of the next node that will be created.
CurveId nextCurveId
 Id of the next curve that will be created.
AreaId nextAreaId
 Id of the next area that will be created.
map< NodeId, long int > nodeOffsets
 The offsets of each Node in the input file.
map< CurveId, long int > curveOffsets
 The offsets of each Curve in the input file.
map< AreaId, long int > areaOffsets
 The offsets of each Area in the input file.
map< AreaId, long int > subgraphOffsets
 The offsets of each subgraph in the input file.
GraphCache< Node > * nodeCache
 Cache of unused and modified Nodes.
GraphCache< Curve > * curveCache
 Cache of unused and modified Curves.
GraphCache< Area > * areaCache
 Cache of unused and modified Areas.
FileReaderfileReader
 File descriptor for loading graph elements.

Detailed Description

A Graph that will only load the offsets of each elements (node/curve/area) in the input file.

It will then fetch the element directly in the file if a required element isn't already loaded. It keeps track of the resources it has loaded, and automatically deletes them when they are unused (i.e. unreferenced). Alternatively, a lazygraph can cache unused resources so that they can be loaded quickly if they are needed again. LazyGraph contains a list for each kind of resource which maps the Id of the resource to the position where the data of that resource can be found in the file used in fileReader. LazyGraph can then just move the get pointer of the file in fileReader to be able to retrieve the info about a selected resource.

Author:
Antoine Begault, Guillaume Piolat

Constructor & Destructor Documentation

proland::LazyGraph::LazyGraph (  ) 

Creates a new LazyGraph.

virtual proland::LazyGraph::~LazyGraph (  )  [virtual]

Deletes this LazyGraph.


Member Function Documentation

virtual void proland::LazyGraph::clean (  )  [protected, virtual]

Clean method to erase the changes in the graph.

Implements proland::Graph.

virtual void proland::LazyGraph::clear (  )  [virtual]

Clears the cache, and deletes every element of this graph.

Necessary when deleting the LazyGraph or when loading new data.

Implements proland::Graph.

void proland::LazyGraph::deleteArea ( AreaId  id  ) 
void proland::LazyGraph::deleteCurve ( CurveId  id  ) 
void proland::LazyGraph::deleteNode ( NodeId  id  ) 

Deletes a resource from this graph.

This method is called from the resource destructor when a resource gets deleted (for example when a node is deleted in the releaseNode method).

Parameters:
*Id a resource's Id which is currently being deleted.
AreaPtr proland::LazyGraph::get ( AreaId  id  ) 

Calls the getArea() method.

Used for generic Iterators.

Parameters:
id the id of the area we want to get/load.
CurvePtr proland::LazyGraph::get ( CurveId  id  ) 

Calls the getCurve-) method.

Used for generic Iterators.

Parameters:
id the id of the curve we want to get/load.
NodePtr proland::LazyGraph::get ( NodeId  id  ) 

Calls the getNode() method.

Used for generic Iterators.

Parameters:
id the id of the node we want to get/load.
AreaPtr proland::LazyGraph::getArea ( AreaId  id  )  [virtual]

Will get the Area corresponding to the given Id.

If has already been loaded, it will only get it from the cache. Otherwise, it will load it.

Parameters:
id the AreaId of the desired Area.
Returns:
the corresponding Area.

Implements proland::Graph.

GraphCache<Area>* proland::LazyGraph::getAreaCache (  ) 

Returns the Area Cache.

int proland::LazyGraph::getAreaCount (  )  const [virtual]

Returns the number of areas in this graph.

Implements proland::Graph.

map<AreaId, long int> proland::LazyGraph::getAreaOffsets (  )  const [protected]

Returns the list of offsets for each area.

See LazyGraph description.

ptr<AreaIterator> proland::LazyGraph::getAreas (  )  [protected, virtual]

Returns an iterator containing the Areas of this Graph.

Implements proland::Graph.

AreaPtr proland::LazyGraph::getChildArea ( AreaId  parentId  )  [virtual]

Returns the child of a given area.

A child Area is an area that was created from another area by clipping.

Parameters:
parentId the parent area.
Returns:
the child area.

Implements proland::Graph.

ptr<CurveIterator> proland::LazyGraph::getChildCurves ( CurveId  parentId  )  [virtual]

Returns the childs of a given curve.

Child Curves are the curves that were created from another curve by clipping.

Parameters:
parentId the parent curve.
Returns:
a CurveIterator containing the child curves.

Implements proland::Graph.

CurvePtr proland::LazyGraph::getCurve ( CurveId  id  )  [virtual]

Will get the Curve corresponding to the given Id.

If has already been loaded, it will only get it from the cache. Otherwise, it will load it.

Parameters:
id the CurveId of the desired Curve.
Returns:
the corresponding Curve.

Implements proland::Graph.

GraphCache<Curve>* proland::LazyGraph::getCurveCache (  ) 

Returns the Curve Cache.

int proland::LazyGraph::getCurveCount (  )  const [virtual]

Returns the number of curves in this graph.

Implements proland::Graph.

map<CurveId, long int> proland::LazyGraph::getCurveOffsets (  )  const [protected]

Returns the list of offsets for each curve.

See LazyGraph description.

ptr<CurveIterator> proland::LazyGraph::getCurves (  )  [protected, virtual]

Returns an iterator containing the Curves of this Graph.

Implements proland::Graph.

NodePtr proland::LazyGraph::getNode ( NodeId  id  )  [virtual]

Will get the Node corresponding to the given Id.

If has already been loaded, it will only get it from the cache. Otherwise, it will load it.

Parameters:
id the NodeId of the desired Node.
Returns:
the corresponding Node.

Implements proland::Graph.

GraphCache<Node>* proland::LazyGraph::getNodeCache (  ) 

Returns the Node Cache.

int proland::LazyGraph::getNodeCount (  )  const [virtual]

Returns the number of nodes in this graph.

Implements proland::Graph.

map<NodeId, long int> proland::LazyGraph::getNodeOffsets (  )  const [protected]

Returns the list of offsets for each node.

See LazyGraph description.

ptr<NodeIterator> proland::LazyGraph::getNodes (  )  [protected, virtual]

Returns an iterator containing the Nodes of this Graph.

Implements proland::Graph.

GraphPtr proland::LazyGraph::getSubgraph ( AreaId  id  ) 

Will get the subgraph corresponding to the given AreaId.

Only used when loading an area.

Parameters:
id the Id of the area containing the subgraph.
Returns:
the corresponding subgraph.
virtual void proland::LazyGraph::init (  )  [virtual]

Initializes LazyGraph's cache and vectors.

void proland::LazyGraph::load ( FileReader fileReader,
bool  loadsubgraphs = 0 
) [virtual]

Loads a graph from a basic file.

This method is only used for loading subgraphs. Empty implementation for LazyGraph.

Parameters:
the stream to read the data from.
loadSubgraphs if true, will load the subgraphs.

Implements proland::Graph.

void proland::LazyGraph::load ( bool  loadSubgraphs = 0  ) 

Loads a graph from a basic file, using fileReader.

Parameters:
loadSubgraphs if true, will load the subgraphs.
void proland::LazyGraph::load ( const string &  file,
bool  loadSubgraphs = 0 
) [virtual]

Loads a graph.

This method determines whether to call load() or loadIndexed() method.

Parameters:
file the file to load from.
loadSubgraphs if true, will load the subgraphs.

Implements proland::Graph.

virtual AreaPtr proland::LazyGraph::loadArea ( long int  offset,
AreaId  id 
) [protected, virtual]

Loads the Area corresponding to the given Id.

The Area description will be fetched via fileReader at the offset given as parameter.

Parameters:
offset the offset of this Area in the file.
id the id of this Area.
Returns:
the loaded Area.
virtual CurvePtr proland::LazyGraph::loadCurve ( long int  offset,
CurveId  id 
) [protected, virtual]

Loads the Curve corresponding to the given Id.

The Curve description will be fetched via fileReader at the offset given as parameter.

Parameters:
offset the offset of this Curve in the file.
id the id of this Curve.
Returns:
the loaded Curve.
void proland::LazyGraph::loadIndexed ( bool  loadSubgraphs = 0  ) 

Loads a graph from an indexed file, using fileReader.

Indexed files are used to load LazyGraphs faster. It contains the indexes of each element in the file.

Parameters:
loadSubgraphs if true, will load the subgraphs.
virtual NodePtr proland::LazyGraph::loadNode ( long int  offset,
NodeId  id 
) [protected, virtual]

Loads the Node corresponding to the given Id.

The Node description will be fetched via fileReader at the offset given as parameter.

Parameters:
offset the offset of this Node in the file.
id the id of this Node.
Returns:
the loaded Node.
virtual GraphPtr proland::LazyGraph::loadSubgraph ( long int  offset,
AreaId  id 
) [protected, virtual]

Loads a subgraph corresponding to a given AreaId.

Only used when loading an Area. The Graph description will be fetched via fileReader at the offset given as parameter.

Parameters:
offset the offset of this Graph in the file.
the id of the Area containing this Graph.
Returns:
the loaded Graph.
virtual void proland::LazyGraph::movePoint ( CurvePtr  c,
int  i,
const vec2d &  p 
) [virtual]

Moves a control point or a node on a given curve.

Parameters:
c the curve to edit.
i the index of the control point (or node, if i is 0 or c->getSize()-1) to move on c.
p the new control point or node position.

Reimplemented from proland::Graph.

AreaPtr proland::LazyGraph::newArea ( AreaPtr  parent,
bool  setParent 
) [virtual]

Adds an area to this graph.

Parameters:
parent the parent area (NULL if none).
setParent if true, the new area's parent will be s et to the 'parent' parameter.

Implements proland::Graph.

CurvePtr proland::LazyGraph::newCurve ( CurvePtr  model,
NodePtr  start,
NodePtr  end 
) [virtual]

Adds a curve to this graph.

Parameters:
model a model curve : the new curve will have the same vertices, if any.
start the start node.
end the end node.
Returns:
the new curve.

Implements proland::Graph.

CurvePtr proland::LazyGraph::newCurve ( CurvePtr  parent,
bool  setParent 
) [virtual]

Adds a curve to this graph.

Parameters:
parent the parent curve (NULL if none).
setParent if true, the new curve's parent will be set to the 'parent' parameter.
Returns:
the new curve.

Implements proland::Graph.

NodePtr proland::LazyGraph::newNode ( const vec2d &  p  )  [virtual]

Adds a node to this graph.

Parameters:
p a vector containing the coordinates of the new node.
Returns:
the new node.

Implements proland::Graph.

void proland::LazyGraph::readSubgraph (  )  [protected]

Reads the data file to pass through a given graph.

Used for loading : we only want to get the offset of graphs, So, we keep it, and then directly jump to the next subgraph.

void proland::LazyGraph::releaseArea ( AreaId  id  ) 
void proland::LazyGraph::releaseCurve ( CurveId  id  ) 
void proland::LazyGraph::releaseNode ( NodeId  id  ) 

Releases an unused resource.

If there is a cache of unused resource then this resource is put in this cache (the oldest resource in the cache is evicted if the cache is full). Otherwise if there is no cache, the resource is deleted directly.

Parameters:
NodeId an unused Node Id, i.e. an unreferenced resource (See ptr class).
void proland::LazyGraph::remove ( Area a  )  [protected]

Calls removeArea().

Parameters:
a an Area to remove.
void proland::LazyGraph::remove ( Curve c  )  [protected]

Calls removeCurve().

Parameters:
c a Curve to remove.
void proland::LazyGraph::remove ( Node n  )  [protected]

Calls removeNode().

Parameters:
n a Node to remove.
void proland::LazyGraph::removeArea ( AreaId  id  )  [protected, virtual]

Removes an Area from this graph.

This method is called when editing the Graph.

Parameters:
id the id of an Area that is currently being deleted.

Implements proland::Graph.

void proland::LazyGraph::removeCurve ( CurveId  id  )  [protected, virtual]

Removes a Curve from this graph.

This method is called when editing the Graph.

Parameters:
id the id of a Curve that is currently being deleted.

Implements proland::Graph.

void proland::LazyGraph::removeNode ( NodeId  id  )  [protected, virtual]

Removes a Node from this graph.

This method is called when editing the Graph.

Parameters:
id the id of a Node that is currently being deleted.

Implements proland::Graph.

void proland::LazyGraph::setAreaCacheSize ( int  size  ) 

Sets the Area Cache size, i.e.

the number of areas that can be kept in memory at the same time.

Parameters:
size the size.
void proland::LazyGraph::setCurveCacheSize ( int  size  ) 

Sets the Curve Cache size, i.e.

the number of curves that can be kept in memory at the same time.

Parameters:
size the size.
void proland::LazyGraph::setNodeCacheSize ( int  size  ) 

Sets the Node Cache size, i.e.

the number of nodes that can be kept in memory at the same time.

Parameters:
size the size.

Member Data Documentation

Cache of unused and modified Areas.

map<AreaId, long int> proland::LazyGraph::areaOffsets [protected]

The offsets of each Area in the input file.

Loaded in the load() function.

The entire list of areas in this graph.

Cache of unused and modified Curves.

map<CurveId, long int> proland::LazyGraph::curveOffsets [protected]

The offsets of each Curve in the input file.

Loaded in the load() function.

The entire list of curves in this graph.

File descriptor for loading graph elements.

Id of the next area that will be created.

Initialized at 0.

Id of the next curve that will be created.

Initialized at 0.

Id of the next node that will be created.

Initialized at 0.

Cache of unused and modified Nodes.

map<NodeId, long int> proland::LazyGraph::nodeOffsets [protected]

The offsets of each Node in the input file.

Loaded in the load() function.

The entire list of nodes in this graph.

map<AreaId, long int> proland::LazyGraph::subgraphOffsets [protected]

The offsets of each subgraph in the input file.

Loaded in the load() function.


Generated on Sat May 12 09:42:48 2012 for proland by  doxygen 1.6.1