Loading...
Searching...
No Matches
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
38namespace 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. */
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 */
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 */
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 */
114
115 /*!
116 \brief Creates a new graph data structure
117
118 \return A pointer to a new graph data
119
120 */
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 */
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 */
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 */
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 */
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 */
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
This class is used to set the main functions of a cache policy.
Class used to manager the graph data elements. This class uses a cache policy to control the elements...
Definition: GraphCache.h:61
GraphDataManager * m_dataManager
Used to load and save GraphData information from a DataSource.
Definition: GraphCache.h:181
void clearCache()
Used to remove from memory all elements loaded.
std::map< int, GraphData * > m_graphDataMap
This map represents all data loaded in cache.
Definition: GraphCache.h:177
GraphMetadata * m_metadata
Graph metadata information.
Definition: GraphCache.h:183
GraphData * getGraphDataByEdgeId(int id)
Get a graph data from vector using a edge id information. if not found a new graph data has to be loa...
GraphData * checkCacheByVertexId(int id)
This functions check in cache if the vertex element with a given id was alredy in memory.
int m_graphDataCounter
Graph data identifier counter.
Definition: GraphCache.h:185
void saveGraphData(GraphData *data)
Save the graph data structure inside a data source.
GraphData * getGraphData()
Get a graph data.
void removeGraphData(int idx)
Used to remove a graph data from cache.
GraphData * createGraphData()
Creates a new graph data structure.
AbstractCachePolicy * m_policy
Cache policy to control the cache in memory.
Definition: GraphCache.h:179
GraphData * getGraphDataByVertexId(int id)
Get a graph data from vector using a vertex id information. if not found a new graph data has to be l...
GraphCache(AbstractCachePolicy *cp, GraphDataManager *dm)
Default constructor.
~GraphCache()
Default destructor.
int getGraphDataId()
Protected function used to define a new value of Id to a graph data.
GraphData * checkCacheByEdgeId(int id)
This functions check in cache if the edge element with a given id was alredy in memory.
This class define a important struct used to group a map of vertex and edges. A flag is used to indic...
Definition: GraphData.h:56
Class used to define the graph metadata informations.
Definition: GraphMetadata.h:57
TerraLib.
#define TEGRAPHEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:178