[Lemon-commits] ladanyi: r3349 - glemon/branches/akos
Lemon SVN
svn at lemon.cs.elte.hu
Fri Oct 26 16:09:06 CEST 2007
Author: ladanyi
Date: Fri Oct 26 16:09:05 2007
New Revision: 3349
Modified:
glemon/branches/akos/gui_reader.cc
glemon/branches/akos/gui_reader.h
glemon/branches/akos/gui_writer.cc
glemon/branches/akos/mapstorage.cc
glemon/branches/akos/mapstorage.h
Log:
Loading saved files really works now.
Modified: glemon/branches/akos/gui_reader.cc
==============================================================================
--- glemon/branches/akos/gui_reader.cc (original)
+++ glemon/branches/akos/gui_reader.cc Fri Oct 26 16:09:05 2007
@@ -60,16 +60,16 @@
{
case MapValue::NUMERIC:
{
- vector<pair<int, double> >* p_map_data =
- new vector<pair<int, double> >;
+ map<int, double>* p_map_data =
+ new map<int, double>;
gui_data.numeric_node_maps[*it] = p_map_data;
{ x(*it, *p_map_data); }
}
break;
case MapValue::STRING:
{
- vector<pair<int, string> >* p_map_data =
- new vector<pair<int, string> >;
+ map<int, string>* p_map_data =
+ new map<int, string>;
gui_data.string_node_maps[*it] = p_map_data;
{ x(*it, *p_map_data); }
}
@@ -85,16 +85,16 @@
{
case MapValue::NUMERIC:
{
- vector<pair<int, double> >* p_map_data =
- new vector<pair<int, double> >;
+ map<int, double>* p_map_data =
+ new map<int, double>;
gui_data.numeric_edge_maps[*it] = p_map_data;
{ x(*it, *p_map_data); }
}
break;
case MapValue::STRING:
{
- vector<pair<int, string> >* p_map_data =
- new vector<pair<int, string> >;
+ map<int, string>* p_map_data =
+ new map<int, string>;
gui_data.string_edge_maps[*it] = p_map_data;
{ x(*it, *p_map_data); }
}
@@ -102,10 +102,13 @@
}
}
+ // read the node coorinates
+ { x("node_coord_map", gui_data.node_coord_map); }
+ // read the arrow coorinates
+ { x("arrow_coord_map", gui_data.arrow_coord_map); }
- /*
std::map<int, std::string> nm;
x("active_nodemaps", nm);
@@ -134,11 +137,12 @@
mapstorage->set_iteration(iteration);
mapstorage->redesign_data_changed();
- */
}
-GuiReader::GuiReader(LemonReader& reader, MapStorage::GUISectData& _gui_data) :
+GuiReader::GuiReader(LemonReader& reader, MapStorage* _mapstorage,
+ MapStorage::GUISectData& _gui_data) :
Parent(reader),
+ mapstorage(_mapstorage),
gui_data(_gui_data)
{
}
Modified: glemon/branches/akos/gui_reader.h
==============================================================================
--- glemon/branches/akos/gui_reader.h (original)
+++ glemon/branches/akos/gui_reader.h Fri Oct 26 16:09:05 2007
@@ -27,13 +27,14 @@
class GuiReader : public LemonReader::SectionReader
{
private:
+ MapStorage* mapstorage;
MapStorage::GUISectData& gui_data;
protected:
virtual bool header(const std::string&);
virtual void read(std::istream&);
public:
typedef LemonReader::SectionReader Parent;
- GuiReader(LemonReader&, MapStorage::GUISectData&);
+ GuiReader(LemonReader&, MapStorage*, MapStorage::GUISectData&);
};
#endif
Modified: glemon/branches/akos/gui_writer.cc
==============================================================================
--- glemon/branches/akos/gui_writer.cc (original)
+++ glemon/branches/akos/gui_writer.cc Fri Oct 26 16:09:05 2007
@@ -111,24 +111,24 @@
{
case MapValue::NUMERIC:
{
- std::vector<std::pair<int, double> > map_data;
+ std::map<int, double> map_data;
MapStorage::NumericNodeMap& map =
mapstorage->getNumericNodeMap(*it);
for (NodeIt n(mapstorage->getGraph()); n != INVALID; ++n)
{
- map_data.push_back(std::make_pair(labels[n], map[n]));
+ map_data[labels[n]] = map[n];
}
{ x(*it, map_data); }
}
break;
case MapValue::STRING:
{
- std::vector<std::pair<int, std::string> > map_data;
+ std::map<int, std::string> map_data;
MapStorage::StringNodeMap& map =
mapstorage->getStringNodeMap(*it);
for (NodeIt n(mapstorage->getGraph()); n != INVALID; ++n)
{
- map_data.push_back(std::make_pair(labels[n], map[n]));
+ map_data[labels[n]] = map[n];
}
{ x(*it, map_data); }
}
@@ -146,24 +146,24 @@
{
case MapValue::NUMERIC:
{
- std::vector<std::pair<int, double> > map_data;
+ std::map<int, double> map_data;
MapStorage::NumericEdgeMap& map =
mapstorage->getNumericEdgeMap(*it);
for (EdgeIt e(mapstorage->getGraph()); e != INVALID; ++e)
{
- map_data.push_back(std::make_pair(labels[e], map[e]));
+ map_data[labels[e]] = map[e];
}
{ x(*it, map_data); }
}
break;
case MapValue::STRING:
{
- std::vector<std::pair<int, std::string> > map_data;
+ std::map<int, std::string> map_data;
MapStorage::StringEdgeMap& map =
mapstorage->getStringEdgeMap(*it);
for (EdgeIt e(mapstorage->getGraph()); e != INVALID; ++e)
{
- map_data.push_back(std::make_pair(labels[e], map[e]));
+ map_data[labels[e]] = map[e];
}
{ x(*it, map_data); }
}
@@ -171,6 +171,30 @@
}
}
+ // write the node coorinates
+ {
+ const MapStorage::NodeLabelMap& labels = mapstorage->getNodeLabelMap();
+ std::map<int, XY> node_coord_map;
+ MapStorage::NodeCoordMap& map = mapstorage->getNodeCoordMap();
+ for (NodeIt n(mapstorage->getGraph()); n != INVALID; ++n)
+ {
+ node_coord_map[labels[n]] = map[n];
+ }
+ { x("node_coord_map", node_coord_map); }
+ }
+ // write the arrow coorinates
+ {
+ const MapStorage::EdgeLabelMap& labels = mapstorage->getEdgeLabelMap();
+ std::map<int, XY> arrow_coord_map;
+ MapStorage::ArrowCoordMap& map = mapstorage->getArrowCoordMap();
+ for (EdgeIt e(mapstorage->getGraph()); e != INVALID; ++e)
+ {
+ arrow_coord_map[labels[e]] = map[e];
+ }
+ { x("arrow_coord_map", arrow_coord_map); }
+ }
+
+
std::map<int, std::string> nm;
for(int i=0;i<NODE_PROPERTY_NUM;i++)
Modified: glemon/branches/akos/mapstorage.cc
==============================================================================
--- glemon/branches/akos/mapstorage.cc (original)
+++ glemon/branches/akos/mapstorage.cc Fri Oct 26 16:09:05 2007
@@ -41,19 +41,11 @@
iterations(i_d),
attraction(a_d),
propulsation(p_d),
- node_x_coord(graph),
- node_y_coord(graph),
- arrow_x_coord(graph),
- arrow_y_coord(graph),
+ node_coords(graph),
+ arrow_coords(graph),
node_label(graph),
edge_label(graph)
{
- node_coords.setXMap(node_x_coord);
- node_coords.setYMap(node_y_coord);
-
- arrow_coords.setXMap(arrow_x_coord);
- arrow_coords.setYMap(arrow_y_coord);
-
active_nodemaps.resize(NODE_PROPERTY_NUM);
for(int i=0;i<NODE_PROPERTY_NUM;i++)
{
@@ -220,6 +212,7 @@
int MapStorage::readFromFile(const std::string &filename)
{
using std::vector;
+ using std::map;
using std::string;
// check whether the .conf file exists
@@ -256,9 +249,9 @@
}
if (gui_data_in_lgf)
- std::cerr << "found gui section in " << filename << ".lgf" << std::endl;
+ std::cerr << "found gui section in " << filename << std::endl;
else
- std::cerr << "no gui section in " << filename << ".lgf" << std::endl;
+ std::cerr << "no gui section in " << filename << std::endl;
bool gui_data_found = gui_data_in_lgf || gui_data_in_conf;
@@ -305,7 +298,7 @@
{
std::cerr << "reading gui section form file " << filename << std::endl;
LemonReader lreader(filename);
- GuiReader gui_reader(lreader, gui_data);
+ GuiReader gui_reader(lreader, this, gui_data);
lreader.run();
}
catch (Exception& error)
@@ -323,7 +316,7 @@
{
std::cerr << "reading " << filename << ".conf file" << std::endl;
LemonReader lreader(filename + ".conf");
- GuiReader gui_reader(lreader, gui_data);
+ GuiReader gui_reader(lreader, this, gui_data);
lreader.run();
}
catch (Exception& error)
@@ -338,8 +331,12 @@
try
{
std::cerr << "reading the graph and maps form " << filename
- << ".lgf file" << std::endl;
+ << " file" << std::endl;
GraphReader<Graph> greader(filename, graph);
+
+ greader.readNodeMap("label", node_label);
+ greader.readEdgeMap("label", edge_label);
+
for (vector<string>::const_iterator
it = gui_data.main_node_map_names.begin();
it != gui_data.main_node_map_names.end(); ++it)
@@ -360,6 +357,7 @@
}
}
}
+
for (vector<string>::const_iterator
it = gui_data.main_edge_map_names.begin();
it != gui_data.main_edge_map_names.end(); ++it)
@@ -380,6 +378,7 @@
}
}
}
+
greader.run();
}
catch (Exception& error)
@@ -387,6 +386,76 @@
clear();
return 1;
}
+
+ // add the maps from the gui section
+ for (vector<string>::const_iterator
+ it = gui_data.gui_node_map_names.begin();
+ it != gui_data.gui_node_map_names.end(); ++it)
+ {
+ string map_name = *it;
+ switch (gui_data.node_map_types[map_name])
+ {
+ case MapValue::NUMERIC:
+ {
+ createNodeMap(map_name, MapValue::NUMERIC, double());
+ NumericNodeMap& dmap = getNumericNodeMap(map_name);
+ map<int, double>& smap = *gui_data.numeric_node_maps[map_name];
+ for (NodeIt n(graph); n != INVALID; ++n)
+ {
+ dmap[n] = smap[node_label[n]];
+ }
+ }
+ case MapValue::STRING:
+ {
+ createNodeMap(map_name, MapValue::STRING, string());
+ StringNodeMap& dmap = getStringNodeMap(map_name);
+ map<int, string>& smap = *gui_data.string_node_maps[map_name];
+ for (NodeIt n(graph); n != INVALID; ++n)
+ {
+ dmap[n] = smap[node_label[n]];
+ }
+ }
+ }
+ }
+ for (vector<string>::const_iterator
+ it = gui_data.gui_edge_map_names.begin();
+ it != gui_data.gui_edge_map_names.end(); ++it)
+ {
+ string map_name = *it;
+ switch (gui_data.edge_map_types[map_name])
+ {
+ case MapValue::NUMERIC:
+ {
+ createEdgeMap(map_name, MapValue::NUMERIC, double());
+ NumericEdgeMap& dmap = getNumericEdgeMap(map_name);
+ map<int, double>& smap = *gui_data.numeric_edge_maps[map_name];
+ for (EdgeIt e(graph); e != INVALID; ++e)
+ {
+ dmap[e] = smap[edge_label[e]];
+ }
+ }
+ case MapValue::STRING:
+ {
+ createEdgeMap(map_name, MapValue::STRING, string());
+ StringEdgeMap& dmap = getStringEdgeMap(map_name);
+ map<int, string>& smap = *gui_data.string_edge_maps[map_name];
+ for (EdgeIt e(graph); e != INVALID; ++e)
+ {
+ dmap[e] = smap[edge_label[e]];
+ }
+ }
+ }
+ }
+
+ // restore the node and arrow coordinate maps
+ for (NodeIt n(graph); n != INVALID; ++n)
+ {
+ node_coords[n] = gui_data.node_coord_map[node_label[n]];
+ }
+ for (EdgeIt e(graph); e != INVALID; ++e)
+ {
+ arrow_coords[e] = gui_data.arrow_coord_map[edge_label[e]];
+ }
}
else
{
@@ -656,16 +725,23 @@
{
GraphWriter<Graph> gwriter(filename, graph);
- std::list<MapValueNodeMap> MapValueNodeMaps;
- std::list<MapValueEdgeMap> MapValueEdgeMaps;
+ gwriter.writeNodeMap("label", node_label);
+ gwriter.writeEdgeMap("label", edge_label);
for (NodeMapStore::const_iterator it = nodemaps.begin();
it != nodemaps.end(); ++it)
{
if (it->second->save_dest == NESET_SECT)
{
- MapValueNodeMaps.push_back(MapValueNodeMap(it->first, this));
- gwriter.writeNodeMap(it->first, MapValueNodeMaps.back());
+ switch (it->second->type())
+ {
+ case MapValue::NUMERIC:
+ gwriter.writeNodeMap(it->first, getNumericNodeMap(it->first));
+ break;
+ case MapValue::STRING:
+ gwriter.writeNodeMap(it->first, getStringNodeMap(it->first));
+ break;
+ }
}
}
@@ -674,8 +750,15 @@
{
if (it->second->save_dest == NESET_SECT)
{
- MapValueEdgeMaps.push_back(MapValueEdgeMap(it->first, this));
- gwriter.writeEdgeMap(it->first, MapValueEdgeMaps.back());
+ switch (it->second->type())
+ {
+ case MapValue::NUMERIC:
+ gwriter.writeEdgeMap(it->first, getNumericEdgeMap(it->first));
+ break;
+ case MapValue::STRING:
+ gwriter.writeEdgeMap(it->first, getStringEdgeMap(it->first));
+ break;
+ }
}
}
@@ -1143,3 +1226,13 @@
}
return maps;
}
+
+MapStorage::NodeCoordMap& MapStorage::getNodeCoordMap()
+{
+ return node_coords;
+}
+
+MapStorage::ArrowCoordMap& MapStorage::getArrowCoordMap()
+{
+ return arrow_coords;
+}
Modified: glemon/branches/akos/mapstorage.h
==============================================================================
--- glemon/branches/akos/mapstorage.h (original)
+++ glemon/branches/akos/mapstorage.h Fri Oct 26 16:09:05 2007
@@ -61,12 +61,17 @@
};
enum MapSaveDestination { GUI_SECT, NESET_SECT, DONT_SAVE };
+ enum GuiSectSaveDestination { LGF_FILE, CONF_FILE };
+
typedef Graph::NodeMap<double> NumericNodeMap;
typedef Graph::NodeMap<std::string> StringNodeMap;
typedef Graph::EdgeMap<double> NumericEdgeMap;
typedef Graph::EdgeMap<std::string> StringEdgeMap;
typedef Graph::NodeMap<int> NodeLabelMap;
typedef Graph::EdgeMap<int> EdgeLabelMap;
+ typedef Graph::NodeMap<XY> NodeCoordMap;
+ typedef Graph::EdgeMap<XY> ArrowCoordMap;
+
struct EdgeMapData
{
/// where to save the map
@@ -84,6 +89,7 @@
default_value(def_val)
{}
};
+
struct NumericEdgeMapData : public EdgeMapData
{
NumericEdgeMap map;
@@ -95,6 +101,7 @@
map(g, def_val)
{}
};
+
struct StringEdgeMapData : public EdgeMapData
{
StringEdgeMap map;
@@ -106,6 +113,7 @@
map(g, def_val)
{}
};
+
struct NodeMapData
{
/// where to save the map
@@ -123,6 +131,7 @@
default_value(def_val)
{}
};
+
struct NumericNodeMapData : public NodeMapData
{
NumericNodeMap map;
@@ -134,6 +143,7 @@
map(g, def_val)
{}
};
+
struct StringNodeMapData : public NodeMapData
{
StringNodeMap map;
@@ -145,7 +155,10 @@
map(g, def_val)
{}
};
- enum GuiSectSaveDestination { LGF_FILE, CONF_FILE };
+
+ typedef std::map<std::string, NodeMapData*> NodeMapStore;
+ typedef std::map<std::string, EdgeMapData*> EdgeMapStore;
+
struct GUISectData
{
std::vector<std::string> main_node_map_names;
@@ -157,15 +170,14 @@
std::map<std::string, MapValue::Type> node_map_types;
std::map<std::string, MapValue::Type> edge_map_types;
- std::map<std::string,
- std::vector<std::pair<int, double> >* > numeric_node_maps;
- std::map<std::string,
- std::vector<std::pair<int, std::string> >* > string_node_maps;
-
- std::map<std::string,
- std::vector<std::pair<int, double> >* > numeric_edge_maps;
- std::map<std::string,
- std::vector<std::pair<int, std::string> >* > string_edge_maps;
+ std::map<std::string, std::map<int, double>* > numeric_node_maps;
+ std::map<std::string, std::map<int, std::string>* > string_node_maps;
+
+ std::map<std::string, std::map<int, double>* > numeric_edge_maps;
+ std::map<std::string, std::map<int, std::string>* > string_edge_maps;
+
+ std::map<int, XY> node_coord_map;
+ std::map<int, XY> arrow_coord_map;
~GUISectData()
{
@@ -174,22 +186,22 @@
using std::pair;
using std::string;
- for (map<string, vector<pair<int, double> >* >::iterator it =
+ for (map<string, map<int, double>* >::iterator it =
numeric_node_maps.begin(); it != numeric_node_maps.end(); ++it)
{
delete it->second;
}
- for (map<string, vector<pair<int, string> >* >::iterator it =
+ for (map<string, map<int, string>* >::iterator it =
string_node_maps.begin(); it != string_node_maps.end(); ++it)
{
delete it->second;
}
- for (map<string, vector<pair<int, double> >* >::iterator it =
+ for (map<string, map<int, double>* >::iterator it =
numeric_edge_maps.begin(); it != numeric_edge_maps.end(); ++it)
{
delete it->second;
}
- for (map<string, vector<pair<int, string> >* >::iterator it =
+ for (map<string, map<int, string>* >::iterator it =
string_edge_maps.begin(); it != string_edge_maps.end(); ++it)
{
delete it->second;
@@ -204,25 +216,17 @@
private:
GuiSectSaveDestination gui_sect_save_dest;
- typedef std::map<std::string, NodeMapData*> NodeMapStore;
NodeMapStore nodemaps;
- typedef std::map<std::string, EdgeMapData*> EdgeMapStore;
EdgeMapStore edgemaps;
- Graph::NodeMap<double> node_x_coord;
- Graph::NodeMap<double> node_y_coord;
-
- Graph::EdgeMap<double> arrow_x_coord;
- Graph::EdgeMap<double> arrow_y_coord;
-
NodeLabelMap node_label;
EdgeLabelMap edge_label;
/// the coordinates of the nodes
- XYMap<Graph::NodeMap<double> > node_coords;
+ NodeCoordMap node_coords;
/// the coordinates of the arrows on the edges
- XYMap<Graph::EdgeMap<double> > arrow_coords;
+ ArrowCoordMap arrow_coords;
///The content of the object has changed, update is needed.
bool modified;
@@ -427,6 +431,9 @@
std::vector<std::string> getEdgeMaps(MapType type = ALL);
std::vector<std::string> getNodeMaps(MapType type = ALL);
+ NodeCoordMap& getNodeCoordMap();
+ ArrowCoordMap& getArrowCoordMap();
+
void dumpMaps();
private:
EdgeMapData* getEdgeMapData(std::string name) const;
More information about the Lemon-commits
mailing list