All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Graph.h
Go to the documentation of this file.
1 /* Copyright (C) 2001-2009 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file Graph.h
22 
23  \brief This is the main graph implementation, that uses a
24  cache policy anda graph loader to get all elements
25  inside a data source.
26 
27  All methods to access a graph element (vertex or edge)
28  will use the GraphData instance, if not found the element,
29  the class GraphCache will be consulted.
30 */
31 
32 #ifndef __TERRALIB_GRAPH_INTERNAL_GRAPH_H
33 #define __TERRALIB_GRAPH_INTERNAL_GRAPH_H
34 
35 // Terralib Includes
36 #include "../core/AbstractGraph.h"
37 #include "../Config.h"
38 
39 
40 // STL Includes
41 #include <vector>
42 
43 namespace te
44 {
45  namespace dt { class Property; }
46 
47  namespace graph
48  {
49  //forward declarations
50  class AbstractCachePolicy;
51  class AbstractGraphLoaderStrategy;
52  class GraphData;
53  class GraphDataManager;
54  class GraphCache;
55  class GraphMetadata;
56 
57 
58  /*!
59  \class Graph
60 
61  \brief This is the main graph implementation, that uses a
62  cache policy anda graph loader to get all elements
63  inside a data source.
64 
65  All methods to access a graph element (vertex or edge)
66  will use the GraphData instance, if not found the element,
67  the class GraphCache will be consulted.
68 
69  \sa AbstractGraph, GraphData, GraphCache
70  */
71 
73  {
74  public:
75 
76  /*! \brief constructor. */
77  Graph();
78 
79  /*!
80  \brief Constructor
81 
82  \param cp A pointer to a cache policy implementation
83 
84  \param ls A pointer to a loader strategy implementation
85 
86  */
88 
89  /*! \brief Virtual destructor. */
90  ~Graph();
91 
92 
93  /** @name Vertex Access Methods
94  * Method used to access vertex elements from a graph.
95  */
96  //@{
97 
98  /*!
99  \brief Add a new vertex element to a graph
100 
101  \param v Vertex element
102 
103  \note This function turns the dirty flag of current GraphData to true, the
104  new flag of the vertex turns to true.
105 
106  */
107  virtual void add(Vertex* v);
108 
109  /*!
110  \brief Update the vertex element
111 
112  \param v Vertex element
113 
114  \note This function turns the dirty flag of current GraphData to true and
115  also the dirty flag of the vertex.
116 
117  */
118  virtual void update(Vertex* v);
119 
120  /*!
121  \brief This function removes the vertex element from graph, also was removed
122  in data source.
123 
124  \param id Vertex identification
125 
126  */
127  virtual void removeVertex(int id);
128 
129  /*!
130  \brief It returns the vertex element if it's exist.
131 
132  \param id Vertex identification
133 
134  \return A valid vertex point if the element was found and a null pointer in other case.
135  */
136  virtual te::graph::Vertex* getVertex(int id);
137 
138 
139  /*!
140  \brief Add a new property associated to the vertex element
141 
142  param p New property to be associated with vertex elements.
143 
144  \note It's important before using this function call the flush() function, its necessary
145  to force the memory clear and the elements will be loaded with the right size of
146  properties.
147  */
148  virtual void addVertexProperty(te::dt::Property* p);
149 
150 
151  /*!
152  \brief Remove a property associated to the vertex element
153 
154  \param idx Index of the property
155  */
156  virtual void removeVertexProperty(int idx);
157 
158  /*!
159  \brief Get a vertex property given a index
160 
161  \param idx Index of the property
162 
163  \return A property associated to the vertex element if the index is right and a null pointer in other case.
164 
165  */
166  virtual te::dt::Property* getVertexProperty(int idx);
167 
168  /*!
169  \brief Used to verify the number of properties associated to vertex elements
170 
171  \return Integer value with the number of properties.
172 
173  */
174  virtual int getVertexPropertySize();
175 
176 
177  //@}
178 
179  /** @name Edge Access Methods
180  * Method used to access edge elements from a graph.
181  */
182  //@{
183 
184  /*!
185  \brief Add a new edge element to a graph
186 
187  \param e Edge element
188 
189  \note This function turns the dirty flag of current GraphData to true, the
190  new flag of the edge turns to true.
191 
192  */
193  virtual void add(Edge* e);
194 
195  /*!
196  \brief Update the edge element
197 
198  \param e Edge element
199 
200  \note This function turns the dirty flag of current GraphData to true and
201  also the dirty flag of the edge.
202 
203  */
204  virtual void update(Edge* e);
205 
206  /*!
207  \brief This function removes the edge element from graph, also was removed
208  in data source.
209 
210  \param id Edge identification
211 
212  */
213  virtual void removeEdge(int id);
214 
215  /*!
216  \brief It returns the edge element if it's exist.
217 
218  \param id Vertex identification
219 
220  \return A valid vertex point if the element was found and a null pointer in other case.
221  */
222  virtual te::graph::Edge* getEdge(int id);
223 
224  /*!
225  \brief Add a new property associated to the edge element
226 
227  param p New property to be associated with edge elements.
228 
229  \note It's important before using this function call the flush() function, its necessary
230  to force the memory clear and the elements will be loaded with the right size of
231  properties.
232  */
233  virtual void addEdgeProperty(te::dt::Property* p);
234 
235  /*!
236  \brief Remove a property associated to the edge element
237 
238  \param idx Index of the property
239  */
240  virtual void removeEdgeProperty(int idx);
241 
242  /*!
243  \brief Get a edge property given a index
244 
245  \param idx Index of the property
246 
247  \return A property associated to the edge element if the index is right and a null pointer in other case.
248 
249  */
250  virtual te::dt::Property* getEdgeProperty(int idx);
251 
252  /*!
253  \brief Used to verify the number of properties associated to edge elements
254 
255  \return Integer value with the number of properties.
256 
257  */
258  virtual int getEdgePropertySize();
259 
260  //@}
261 
262  /*!
263  \brief Function used to access the graph metadata
264 
265  \return A pointer to a class that defines the graph metadata
266 
267  */
268  virtual te::graph::GraphMetadata* getMetadata();
269 
270 
271  /*!
272  \brief Function used to clear the memory cache, all elements was released from
273  memory, if any element was changes it will be saved.
274 
275  \return
276 
277  */
278  virtual void flush();
279 
280  protected:
281 
282  GraphData* m_graphData; //!< This class has the graph data and properties
283 
284  GraphDataManager* m_dataManager; //!< Used to load and save GraphData information from a DataSource
285 
286  GraphCache* m_graphCache; //!< Class used to keep all graph data loaded
287 
288  GraphMetadata* m_metadata; //!< Graph Data loader strategy
289  };
290 
291  } // end namespace graph
292 } // end namespace te
293 
294 #endif // __TERRALIB_GRAPH_INTERNAL_ABSTRACTGRAPH_H
GraphDataManager * m_dataManager
Used to load and save GraphData information from a DataSource.
Definition: Graph.h:284
Abstract class used to define the main functions of graph struct. All graph implementations must used...
Definition: AbstractGraph.h:56
Class used to define the edge struct of a graph. Its compose with a identifier, the vertex origin and...
Definition: Edge.h:58
#define TEGRAPHEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:216
This class define the main functions necessary to save and load the graph data and metadata informati...
GraphData * m_graphData
This class has the graph data and properties.
Definition: Graph.h:282
Class used to manager the graph data elements. This class uses a cache policy to control the elements...
Definition: GraphCache.h:60
From the point of view of graph theory, vertices are treated as featureless and indivisible objects...
Definition: Vertex.h:68
GraphCache * m_graphCache
Class used to keep all graph data loaded.
Definition: Graph.h:286
This is the main graph implementation, that uses a cache policy anda graph loader to get all elements...
Definition: Graph.h:72
It models a property definition.
Definition: Property.h:59
This class is used to set the main functions of a cache policy.
Class used to define the graph metadata informations.
Definition: GraphMetadata.h:56
GraphMetadata * m_metadata
Graph Data loader strategy.
Definition: Graph.h:288
This class define a important struct used to group a map of vertex and edges. A flag is used to indic...
Definition: GraphData.h:55