GraphCache.h
Go to the documentation of this file.
1 /* Copyright (C) 2008 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 GraphCache.h
22 
23  \brief Class used to manager the graph data elements.
24  This class uses a cache policy to control the elements in memory.
25  If a element was requested and not found in cache, the
26  GraphDataManager is used to loaded a new GraphData.
27 */
28 
29 #ifndef __TERRALIB_GRAPH_INTERNAL_GRAPHCACHE_H
30 #define __TERRALIB_GRAPH_INTERNAL_GRAPHCACHE_H
31 
32 // Terralib Includes
33 #include "../Config.h"
34 
35 // STL Includes
36 #include <map>
37 
38 namespace te
39 {
40  namespace graph
41  {
42  //forward declarations
43  class AbstractCachePolicy;
44  class AbstractGraphLoaderStrategy;
45  class GraphData;
46  class GraphDataManager;
47  class GraphMetadata;
48 
49  /*!
50  \class GraphCache
51 
52  \brief Class used to manager the graph data elements.
53  This class uses a cache policy to control the elements in memory.
54  If a element was requested and not found in cache, the
55  GraphDataManager is used to loaded a new GraphData.
56 
57  \sa GraphDataManager, GraphData
58  */
59 
61  {
62  public:
63 
64  /*!
65  \brief Default constructor.
66 
67  \param cp Implementation of a cache policy
68 
69  \param dm Data manager pointer
70 
71  */
73 
74  /*! \brief Default destructor. */
75  ~GraphCache();
76 
77  /** @name Graph Cache Manager Methods
78  * Method used to manager a graph data
79  */
80  //@{
81 
82  /*!
83  \brief Get a graph data from vector using a vertex id information.
84  if not found a new graph data has to be loaded using AbstractDataManager
85 
86  \param id The vertex identifier of the desired element.
87 
88  \return A Graph Data that contains the request element.
89 
90  */
91  GraphData* getGraphDataByVertexId(int id);
92 
93  /*!
94  \brief Get a graph data from vector using a edge id information.
95  if not found a new graph data has to be loaded using AbstractDataManager
96 
97  \param id The edge identifier of the desired element.
98 
99  \return A Graph Data that contains the request element.
100 
101  */
102  GraphData* getGraphDataByEdgeId(int id);
103 
104  /*!
105  \brief Get a graph data
106 
107  \note It's always try to return the graph data with the max number of elements that
108  is not already full. If its not possible a new graph data will be created.
109 
110  \return A pointer to a graph data.
111 
112  */
113  GraphData* getGraphData();
114 
115  /*!
116  \brief Creates a new graph data structure
117 
118  \return A pointer to a new graph data
119 
120  */
121  GraphData* createGraphData();
122 
123  /*!
124  \brief Used to remove a graph data from cache
125 
126  \param idx The graph data identifier
127 
128  */
129  void removeGraphData(int idx);
130 
131  /*!
132  \brief Save the graph data structure inside a data source
133 
134  \param data The graph data to be saved
135  */
136  void saveGraphData(GraphData* data);
137 
138  /*!
139  \brief Used to remove from memory all elements loaded.
140 
141  \note The function Flush from AbstractGraph calls this function.
142 
143  */
144  void clearCache();
145 
146  /*!
147  \brief This functions check in cache if the vertex element with a given id was alredy in memory
148 
149  \param id The vertex Id
150 
151  \return If the element was found its returns a pointer to a graph data that contains this element
152  */
153  GraphData* checkCacheByVertexId(int id);
154 
155  /*!
156  \brief This functions check in cache if the edge element with a given id was alredy in memory
157 
158  \param id The edge Id
159 
160  \return If the element was found its returns a pointer to a graph data that contains this element
161  */
162  GraphData* checkCacheByEdgeId(int id);
163 
164  //@}
165 
166  protected:
167 
168  /*!
169  \brief Protected function used to define a new value of Id to a graph data.
170 
171  \return Integer value with the id information
172  */
173  int getGraphDataId();
174 
175  private:
176 
177  std::map<int, GraphData*> m_graphDataMap; //!< This map represents all data loaded in cache
178 
179  AbstractCachePolicy* m_policy; //!< Cache policy to control the cache in memory
180 
181  GraphDataManager* m_dataManager; //!< Used to load and save GraphData information from a DataSource
182 
183  GraphMetadata* m_metadata; //!< Graph metadata information.
184 
185  int m_graphDataCounter; //!< Graph data identifier counter
186  };
187  } // end namespace graph
188 } // end namespace te
189 
190 #endif // __TERRALIB_GRAPH_INTERNAL_GRAPHCACHE_H
#define TEGRAPHEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:178
AbstractCachePolicy * m_policy
Cache policy to control the cache in memory.
Definition: GraphCache.h:179
GraphMetadata * m_metadata
Graph metadata information.
Definition: GraphCache.h:183
This class is used to set the main functions of a cache policy.
URI C++ Library.
Class used to manager the graph data elements. This class uses a cache policy to control the elements...
Definition: GraphCache.h:60
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
std::map< int, GraphData * > m_graphDataMap
This map represents all data loaded in cache.
Definition: GraphCache.h:177
GraphDataManager * m_dataManager
Used to load and save GraphData information from a DataSource.
Definition: GraphCache.h:181
int m_graphDataCounter
Graph data identifier counter.
Definition: GraphCache.h:185
Class used to define the graph metadata informations.
Definition: GraphMetadata.h:56