COIN-OR::LEMON - Graph Library

source: glemon-0.x/mapstorage.h @ 174:95872af46fc4

Last change on this file since 174:95872af46fc4 was 174:95872af46fc4, checked in by Alpar Juttner, 14 years ago

Add copyright headers

File size: 9.4 KB
RevLine 
[174]1/* -*- C++ -*-
2 *
3 * This file is a part of LEMON, a generic C++ optimization library
4 *
5 * Copyright (C) 2003-2006
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 *
9 * Permission to use, modify and distribute this software is granted
10 * provided that this copyright notice appears in all copies. For
11 * precise terms see the accompanying LICENSE file.
12 *
13 * This software is provided "AS IS" with no warranty of any kind,
14 * express or implied, and with no claim as to its suitability for any
15 * purpose.
16 *
17 */
[6]18
19#ifndef MAPSTORAGE_H
20#define MAPSTORAGE_H
21
[94]22class Mapstorage;
23
[53]24#include "all_include.h"
25#include "xymap.h"
[94]26#include <libgnomecanvasmm.h>
[6]27
[118]28///class MapStorage handles NodeMaps and EdgeMaps.
29
[6]30///Class MapStorage is responsible for storing
31///NodeMaps and EdgeMaps that can be shown later
32///on GUI. Therefore maps can be added to it,
33///and datas over the added maps can be queried.
34///The maps will be stored in an std::map,
35///referenced with their names. Unfortunately at
36///the moment it works only with double type maps
37///
38///\todo too many things are public!!
39class MapStorage
40{
41public:
[173]42  enum value {DOUBLE, STRING};
43  enum type {NORMAL, GUI};
[6]44
[118]45  ///The graph for which the datas are stored.
[53]46  Graph graph;
[98]47  /// the coordinates of the nodes
[53]48  XYMap<Graph::NodeMap<double> > coords;
[98]49  /// the coordinates of the arrows on the edges
50  XYMap<Graph::EdgeMap<double> > arrow_pos;
[53]51
[118]52  ///The content of the object has changed, update is needed.
[53]53  bool modified;
[118]54
55  ///Name of file loaded in object.
[53]56  std::string file_name;
[6]57
58  ///Stores double type NodeMaps
59  std::map< std::string,Graph::NodeMap<double> * > nodemap_storage;
60
61  ///Stores double type EdgeMaps
62  std::map< std::string,Graph::EdgeMap<double> * > edgemap_storage;
63
[118]64  ///Stores the default values for the different visualization node attributes
[6]65  std::vector<Graph::NodeMap<double> > default_nodemaps;
66
[118]67  ///Stores the default values for the different visualization edge attributes
[6]68  std::vector<Graph::EdgeMap<double> > default_edgemaps;
69
[118]70  ///Stores the active maps for the different visualization node attributes
[94]71  std::vector< std::string > active_nodemaps;
72
[118]73  /// Stores the active maps for the different visualization edge attributes
[94]74  std::vector< std::string > active_edgemaps;
75
[118]76  /// Default values for the maps
[63]77  std::map< std::string, double > nodemap_default;
78
[118]79  /// Default values for the maps
[63]80  std::map< std::string, double > edgemap_default;
81
[98]82  bool arrow_pos_read_ok;
83
[94]84protected:
[118]85  /// type of the signal emitted if the visualization of the maps might have to be updated.
86
87  /// bool shows us whether the changed map is edge or nodemap.
88  /// int tells us the refreshed property
[94]89  typedef sigc::signal<void, bool, int> Signal_Prop;
[118]90
91  /// Signal emitted on any change made on map values
[94]92  Signal_Prop signal_prop;
[118]93
94  /// Signal emitted in the case of nodemap addition
95
96  /// std::string is the
97  ///name of the new map
[108]98  sigc::signal<void, std::string> signal_node_map;
[118]99
100  /// Signal emitted in the case of edgemap addition
101
102  /// std::string is the
103  ///name of the new map
[108]104  sigc::signal<void, std::string> signal_edge_map;
[94]105
[172]106  /// Signal emitted, when entry in \ref MapWin should be changed.
107  sigc::signal<void, bool, int, std::string> signal_map_win;
108
[6]109public:
[118]110  ///Constructor of MapStorage.
111
[6]112  ///Its all activity is initializing default values
[118]113  ///for different visualization attributes.
[53]114  MapStorage();
115
[118]116  ///Destructor of MapStorage
117
118  ///Maps stored here are created with new. Destructor
119  ///deletes them to free up the reserved memory.
[53]120  ~MapStorage();
[6]121
[118]122  /// Registrates if the shown map by any attribute has changed to another.
[94]123
[118]124  ///It handles the \ref active_edgemaps and
125  ///\ref active_nodemaps vectors. It also emits \ref signal_prop signal to let
126  ///know the interested objects that the visible map of a certain
127  ///attribute has changed.
128  ///\param itisedge edgemap or nodemap has changed
129  ///\param prop the property of which the map is changed
130  ///\param mapname the visible map
131  void changeActiveMap(bool itisedge , int prop , std::string mapname);
[94]132
[172]133  ///Emits signals that let change the active maps in \ref MapWin.
134  void broadcastActiveMaps();
135
[118]136  /// Returns the active edgemap shown by a visualization property.
137
138  /// \param prop is the property
139  ///that shows the requested map.
140  std::string getActiveEdgeMap(int prop);
141
142  /// Returns the active nodemap shown by a visualization property.
143
144  /// \param prop is the property
145  ///that shows the requested map.
146  std::string getActiveNodeMap(int prop);
147
148  /// Returns the names of the edgemaps stored here.
[94]149  std::vector<std::string> getEdgeMapList();
[118]150
151  /// Returns the names of the nodemaps stored here.
[94]152  std::vector<std::string> getNodeMapList();
153
[118]154  ///returns \ref signal_prop to be able to connect functions to it
[94]155  Signal_Prop signal_prop_ch();
156
[118]157  ///returns \ref signal_node_map to be able to connect functions to it
[108]158  sigc::signal<void, std::string> signal_node_map_ch(){return signal_node_map;};
[118]159
160  ///returns \ref signal_edge_map to be able to connect functions to it
[108]161  sigc::signal<void, std::string> signal_edge_map_ch(){return signal_edge_map;};
162
[172]163  ///returns \ref signal_map_win to be able to connect functions to it
164  sigc::signal<void, bool, int, std::string> signal_map_win_ch(){return signal_map_win;};
165
[118]166  ///Adds given map to storage.
167
168  ///A name and the map itself has to be provided.
169  ///\param mapname is the name of map
170  ///\param nodemap is the pointer of the given nodemap
171  ///\param def the default value of the map. If not given, it will be 0.
172  ///If new edge is added to graph the value of it in the map will be this.
[6]173  ///\todo map should be given by reference!
[118]174  ///\todo why is default value stored?
175  int addNodeMap(const std::string & mapname,Graph::NodeMap<double> * nodemap, double def=0.0);
[6]176
177  ///Adds given map to storage. A name and the map itself has to be provided.
[118]178
179  ///A name and the map itself has to be provided.
180  ///\param mapname is the name of map
181  ///\param edgemap is the pointer of the given edgemap
182  ///\param def the default value of the map. If not given, it will be 0.
183  ///If new edge is added to graph the value of it in the map will be this.
[6]184  ///\todo map should be given by reference!
[118]185  int addEdgeMap(const std::string & mapname,Graph::EdgeMap<double> * edgemap, double def=0.0);
[6]186
187  ///Returns how much nodemaps is stored in \ref MapStorage
188  int numOfNodeMaps() {return nodemap_storage.size();};
189
190  ///Returns how much edgemaps is stored in \ref MapStorage
191  int numOfEdgeMaps() {return edgemap_storage.size();};
192
[118]193  ///Returns the maximum value of the given NodeMap.
[6]194
[118]195  ///NodeMap has to be given by its name.
196  ///\param name the name of map of which maximum is searched
197  double maxOfNodeMap(const std::string & name);
[6]198
[118]199  ///Returns the maximum value of the given EdgeMap.
[6]200
[118]201  ///EdgeMap has to be given by its name.
202  ///\param name the name of map of which maximum is searched
203  double maxOfEdgeMap(const std::string & name);
[6]204
[118]205  ///Returns the minimum value of the given NodeMap.
206
207  ///NodeMap has to be given by its name.
208  ///\param name the name of map of which minimum is searched
209  double minOfNodeMap(const std::string & name);
210
211  ///Returns the minimum value of the given EdgeMap.
212
213  ///EdgeMap has to be given by its name.
214  ///\param name the name of map of which minimum is searched
215  double minOfEdgeMap(const std::string & name);
216
217  ///Returns iterator pointing to the first NodeMap in storage.
218
219  ///To be able to iterate through each maps this function
220  ///returns an iterator pointing to the first nodemap in
221  ///the storage.
[6]222  std::map< std::string,Graph::NodeMap<double> * >::iterator beginOfNodeMaps(){return nodemap_storage.begin();};
223
[118]224  ///Returns iterator pointing to the first EdgeMap in storage.
225
226  ///To be able to iterate through each maps this function
227  ///returns an iterator pointing to the first edgemap in
228  ///the storage.
[6]229  std::map< std::string,Graph::EdgeMap<double> * >::iterator beginOfEdgeMaps(){return edgemap_storage.begin();};
[26]230
[118]231  ///Returns iterator pointing after the last NodeMap in storage.
232
233  ///To be able to iterate through each maps this function
234  ///returns an iterator pointing to the last nodemap in the storage.
[31]235  std::map< std::string,Graph::NodeMap<double> * >::iterator endOfNodeMaps(){return nodemap_storage.end();};
236
[118]237  ///Returns iterator pointing after the last EdgeMap in storage.
238
239  ///To be able to iterate through each maps this function
240  ///returns an iterator pointing to the last edgemap in the storage.
[31]241  std::map< std::string,Graph::EdgeMap<double> * >::iterator endOfEdgeMaps(){return edgemap_storage.end();};
242
[118]243  ///Emits \ref signal_prop if mapvalues have changed, and MapStorage gets to know it.
[111]244
[118]245  ///If values in a map have changed, this function checks, whether it is displayed.
246  ///This check means searching the given mapname between active maps
247  ///(\ref active_nodemaps, \ref active_edgemaps). If it is there at a certain property,
248  ///it emits a signal with the property, where the gotten mapname was found. One signal
249  ///is emitted for each property displaying the given map.
250  ///\param itisedge whether the map an edgemap or nodemap
251  ///\param mapname name of map to visualize
252  void mapChanged(bool itisedge, std::string mapname);
253
254  ///Read datas from the given filename.
[63]255  int readFromFile(const std::string &);
[118]256
257  ///Save datas to the given filename.
[53]258  void writeToFile(const std::string &);
259
[118]260  ///Deletes all datastructures stored here.
[53]261  void clear();
[98]262
263  void ArrowPosReadOK();
[6]264};
265
266#endif //MAPSTORAGE_H
Note: See TracBrowser for help on using the repository browser.