[Lemon-commits] ladanyi: r3255 - glemon/branches/akos
Lemon SVN
svn at lemon.cs.elte.hu
Mon Apr 16 19:43:39 CEST 2007
Author: ladanyi
Date: Mon Apr 16 19:43:38 2007
New Revision: 3255
Modified:
glemon/branches/akos/algobox.cc
glemon/branches/akos/algobox.h
glemon/branches/akos/kruskalbox.cc
glemon/branches/akos/map_value.cc
glemon/branches/akos/mapselector.cc
glemon/branches/akos/mapstorage.cc
glemon/branches/akos/mapstorage.h
glemon/branches/akos/new_map_win.cc
Log:
NewMapWin and other fixes.
Modified: glemon/branches/akos/algobox.cc
==============================================================================
--- glemon/branches/akos/algobox.cc (original)
+++ glemon/branches/akos/algobox.cc Mon Apr 16 19:43:38 2007
@@ -154,11 +154,11 @@
pack_start(*(new Gtk::HSeparator()));
}
-void AlgoBox::addMapSelector(std::string inputname, bool itisedge)
+void AlgoBox::addMapSelector(std::string inputname, bool itisedge, MapType type)
{
std::vector<std::string> empty_vector;
- MapSelector * msp=new MapSelector(empty_vector,"",inputname,itisedge, false);
+ MapSelector * msp=new MapSelector(empty_vector,"",inputname,itisedge, false, type);
if(itisedge)
{
Modified: glemon/branches/akos/algobox.h
==============================================================================
--- glemon/branches/akos/algobox.h (original)
+++ glemon/branches/akos/algobox.h Mon Apr 16 19:43:38 2007
@@ -184,6 +184,6 @@
///\param label label to show in \ref MapSelector
///\param itisedge whether edge or nodemaps stored in \ref MapSelector
- void addMapSelector(std::string label, bool itisedge);
+ void addMapSelector(std::string label, bool itisedge, MapType type = ALL);
};
#endif //ALGOBOX_H
Modified: glemon/branches/akos/kruskalbox.cc
==============================================================================
--- glemon/branches/akos/kruskalbox.cc (original)
+++ glemon/branches/akos/kruskalbox.cc Mon Apr 16 19:43:38 2007
@@ -34,11 +34,31 @@
)
{
- const Graph &g=mapstorage->graph;
- const Graph::EdgeMap<double>& inputmap=
- mapstorage->getEdgeMap(edgemapcbts[INPUT]->get_active_text());
+ const Graph &g=mapstorage->getGraph();
+ std::string input_map_name = edgemapcbts[INPUT]->get_active_text();
Graph::EdgeMap<bool> outputmap(g);
- double res=kruskal(g, inputmap, outputmap);
+ double res;
+ switch (mapstorage->getEdgeMapElementType(input_map_name))
+ {
+ case MapValue::INTEGER:
+ {
+ const MapStorage::IntegerEdgeMap& inputmap=
+ mapstorage->getIntegerEdgeMap(input_map_name);
+ res=kruskal(g, inputmap, outputmap);
+ }
+ break;
+ case MapValue::SCALAR:
+ {
+ const MapStorage::ScalarEdgeMap& inputmap=
+ mapstorage->getScalarEdgeMap(input_map_name);
+ res=kruskal(g, inputmap, outputmap);
+ }
+ break;
+ case MapValue::STRING:
+ std::cerr << "String maps can not be used here." << std::endl;
+ exit(1);
+ break;
+ }
for (EdgeIt i(g); i!=INVALID; ++i)
{
@@ -69,8 +89,8 @@
{
std::vector<std::string> empty_vector;
- addMapSelector("Edgecosts: ", true);
- addMapSelector("Edges of tree here: ", true);
+ addMapSelector("Edgecosts: ", true, MapType(INT | SCAL));
+ addMapSelector("Edges of tree here: ", true, MapType(INT | SCAL));
resultlabel.set_text("Result: algorithm is not run yet.");
pack_start(resultlabel);
Modified: glemon/branches/akos/map_value.cc
==============================================================================
--- glemon/branches/akos/map_value.cc (original)
+++ glemon/branches/akos/map_value.cc Mon Apr 16 19:43:38 2007
@@ -23,6 +23,8 @@
{
if (type == INTEGER)
return *(static_cast<int*>(p_value));
+ if (type == SCALAR)
+ return static_cast<int>(*(static_cast<double*>(p_value)));
else
throw IllegalOperation();
}
@@ -31,6 +33,8 @@
{
if (type == SCALAR)
return *(static_cast<double*>(p_value));
+ if (type == INTEGER)
+ return static_cast<double>(*(static_cast<int*>(p_value)));
else
throw IllegalOperation();
}
Modified: glemon/branches/akos/mapselector.cc
==============================================================================
--- glemon/branches/akos/mapselector.cc (original)
+++ glemon/branches/akos/mapselector.cc Mon Apr 16 19:43:38 2007
@@ -18,7 +18,7 @@
#include "mapselector.h"
-MapSelector::MapSelector(std::vector<std::string> ml, std::string act, std::string labeltext, bool edge, MapType type, bool d):def(d),itisedge(edge),set_new_map(false), map_type(type)
+MapSelector::MapSelector(std::vector<std::string> ml, std::string act, std::string labeltext, bool edge, bool d, MapType type):def(d),itisedge(edge),set_new_map(false), map_type(type)
{
update_list(ml);
Modified: glemon/branches/akos/mapstorage.cc
==============================================================================
--- glemon/branches/akos/mapstorage.cc (original)
+++ glemon/branches/akos/mapstorage.cc Mon Apr 16 19:43:38 2007
@@ -65,36 +65,27 @@
}
}
+// TODO
MapStorage::~MapStorage()
{
- for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it =
- nodemap_storage.begin(); it != nodemap_storage.end(); ++it)
- {
- delete it->second;
- }
- for (std::map<std::string, Graph::EdgeMap<double>*>::const_iterator it =
- edgemap_storage.begin(); it != edgemap_storage.end(); ++it)
- {
- delete it->second;
- }
}
void MapStorage::createNodeMap(const std::string& name, MapValue::Type type,
MapValue def_val)
{
NodeMapStore::const_iterator it = nodemaps.find(name);
- if (it != edgemaps.end())
+ if (it != nodemaps.end())
throw MapAlreadyExists();
switch (type)
{
- case INTEGER:
+ case MapValue::INTEGER:
nodemaps[name] = new IntegerNodeMapData(graph, def_val);
break;
- case SCALAR:
+ case MapValue::SCALAR:
nodemaps[name] = new ScalarNodeMapData(graph, def_val);
break;
- case STRING:
+ case MapValue::STRING:
nodemaps[name] = new StringNodeMapData(graph, def_val);
break;
}
@@ -115,13 +106,13 @@
switch (type)
{
- case INTEGER:
+ case MapValue::INTEGER:
edgemaps[name] = new IntegerEdgeMapData(graph, def_val);
break;
- case SCALAR:
+ case MapValue::SCALAR:
edgemaps[name] = new ScalarEdgeMapData(graph, def_val);
break;
- case STRING:
+ case MapValue::STRING:
edgemaps[name] = new StringEdgeMapData(graph, def_val);
break;
}
@@ -169,9 +160,9 @@
return active_nodemaps[prop];
}
-std::vector<std::string> MapStorage::getEdgeMapList(MapType type = ALL)
+std::vector<std::string> MapStorage::getEdgeMapList(MapType type)
{
- it (type == ALL)
+ if (type == ALL)
{
std::vector<std::string> ret(edgemaps.size());
for (EdgeMapStore::const_iterator it = edgemaps.begin();
@@ -200,7 +191,7 @@
}
}
-std::vector<std::string> MapStorage::getNodeMapList()
+std::vector<std::string> MapStorage::getNodeMapList(MapType type)
{
std::vector<std::string> ret(nodemaps.size());
for (NodeMapStore::const_iterator it = nodemaps.begin();
@@ -767,45 +758,45 @@
return edge;
}
-IntegerNodeMap& MapStorage::getIntegerNodeMap(const std::string& name)
+MapStorage::IntegerNodeMap& MapStorage::getIntegerNodeMap(const std::string& name)
{
NodeMapData* data = getNodeMapData(name);
- if (data->type() != MapStorage::INTEGER) throw NonexistentMap();
+ if (data->type() != MapValue::INTEGER) throw NonexistentMap();
return static_cast<IntegerNodeMapData*>(data)->map;
}
-ScalarNodeMap& MapStorage::getScalarNodeMap(const std::string& name)
+MapStorage::ScalarNodeMap& MapStorage::getScalarNodeMap(const std::string& name)
{
NodeMapData* data = getNodeMapData(name);
- if (data->type() != MapStorage::SCALAR) throw NonexistentMap();
+ if (data->type() != MapValue::SCALAR) throw NonexistentMap();
return static_cast<ScalarNodeMapData*>(data)->map;
}
-StringNodeMap& MapStorage::getStringNodeMap(const std::string& name)
+MapStorage::StringNodeMap& MapStorage::getStringNodeMap(const std::string& name)
{
NodeMapData* data = getNodeMapData(name);
- if (data->type() != MapStorage::STRING) throw NonexistentMap();
+ if (data->type() != MapValue::STRING) throw NonexistentMap();
return static_cast<StringNodeMapData*>(data)->map;
}
-IntegerEdgeMap& MapStorage::getIntegerEdgeMap(const std::string& name)
+MapStorage::IntegerEdgeMap& MapStorage::getIntegerEdgeMap(const std::string& name)
{
EdgeMapData* data = getEdgeMapData(name);
- if (data->type() != MapStorage::INTEGER) throw NonexistentMap();
+ if (data->type() != MapValue::INTEGER) throw NonexistentMap();
return static_cast<IntegerEdgeMapData*>(data)->map;
}
-ScalarEdgeMap& MapStorage::getScalarEdgeMap(const std::string& name)
+MapStorage::ScalarEdgeMap& MapStorage::getScalarEdgeMap(const std::string& name)
{
EdgeMapData* data = getEdgeMapData(name);
- if (data->type() != MapStorage::SCALAR) throw NonexistentMap();
+ if (data->type() != MapValue::SCALAR) throw NonexistentMap();
return static_cast<ScalarEdgeMapData*>(data)->map;
}
-StringEdgeMap& MapStorage::getStringEdgeMap(const std::string& name)
+MapStorage::StringEdgeMap& MapStorage::getStringEdgeMap(const std::string& name)
{
EdgeMapData* data = getEdgeMapData(name);
- if (data->type() != MapStorage::STRING) throw NonexistentMap();
+ if (data->type() != MapValue::STRING) throw NonexistentMap();
return static_cast<StringEdgeMapData*>(data)->map;
}
@@ -883,12 +874,12 @@
return data->type();
}
-const NodeLabelMap& MapStorage::getNodeLabelMap()
+const MapStorage::NodeLabelMap& MapStorage::getNodeLabelMap()
{
return node_label;
}
-const EdgeLabelMap& MapStorage::getEdgeLabelMap()
+const MapStorage::EdgeLabelMap& MapStorage::getEdgeLabelMap()
{
return edge_label;
}
Modified: glemon/branches/akos/mapstorage.h
==============================================================================
--- glemon/branches/akos/mapstorage.h (original)
+++ glemon/branches/akos/mapstorage.h Mon Apr 16 19:43:38 2007
@@ -164,10 +164,9 @@
public:
///The graph for which the datas are stored.
Graph graph;
-
-private:
const Graph& getGraph();
+private:
GuiSectSaveDestination gui_sect_save_dest;
typedef std::map<std::string, NodeMapData*> NodeMapStore;
@@ -293,10 +292,10 @@
std::string getActiveNodeMap(int prop);
/// Returns the names of the edgemaps stored here.
- std::vector<std::string> getEdgeMapList();
+ std::vector<std::string> getEdgeMapList(MapType type = ALL);
/// Returns the names of the nodemaps stored here.
- std::vector<std::string> getNodeMapList();
+ std::vector<std::string> getNodeMapList(MapType type = ALL);
///returns \ref signal_prop to be able to connect functions to it
sigc::signal<void, bool, int> signal_prop_ch();
Modified: glemon/branches/akos/new_map_win.cc
==============================================================================
--- glemon/branches/akos/new_map_win.cc (original)
+++ glemon/branches/akos/new_map_win.cc Mon Apr 16 19:43:38 2007
@@ -124,7 +124,7 @@
break;
default:
//substitute variable
- std::vector<std::string> ems = mytab.mapstorage.getEdgeMapList(map_type);
+ std::vector<std::string> ems = mytab.mapstorage.getEdgeMapList(INT | SCAL);
bool itisvar=(std::find(ems.begin(), ems.end(), ch2var[ polishform[i] ]) != ems.end());
if(itisvar)
{
@@ -179,6 +179,7 @@
return;
}
+ // check whether the map already exists
if (edge.get_active())
{
if (mytab.mapstorage.edgeMapExists(map_name))
@@ -221,6 +222,29 @@
std::vector<double>* values;
values = evaluate_expr(string2Polishform(def_val, edge.get_active()));
// TODO
+ if (edge.get_active())
+ {
+ mytab.mapstorage.createEdgeMap(map_name, MapValue::SCALAR,
+ MapValue(d));
+ std::vector<double>::const_iterator vit = values.begin()
+ for (NodeIt it(mytab.mapstorage.graph); it != INVALID; +it)
+ {
+ mytab.mapstorage.set(map_name, it, MapValue(*vit));
+ ++vit;
+ }
+ }
+ else
+ {
+ mytab.mapstorage.createNodeMap(map_name, MapValue::SCALAR,
+ MapValue(d));
+ std::vector<double>::const_iterator vit = values.begin()
+ for (NodeIt it(mytab.mapstorage.graph); it != INVALID; +it)
+ {
+ mytab.mapstorage.set(map_name, it, MapValue(*vit));
+ ++vit;
+ }
+ }
+ delete values;
}
}
else if (text == "string")
@@ -232,9 +256,16 @@
mytab.mapstorage.createNodeMap(map_name, MapValue::STRING,
MapValue(def_val));
}
+
+ name.set_text("");
+ default_value.set_text("0");
+ edge.show();
+ node.show();
+ hide();
}
}
+/*
void NewMapWin::on_response(int response_id)
{
if(response_id==Gtk::RESPONSE_OK)
@@ -425,20 +456,6 @@
{
abortion=1;
}
- /*
- try
- {
- mytab.mapstorage.createNodeMap(mapname, MapStorage::SCALAR,
- MapValue(def_val));
- for ()
- {
- }
- }
- catch (MapStorage::MapAlreadyExists& e)
- {
- abortion=1;
- }
- */
//add it to the list of the displayable maps
//furthermore it is done by signals
@@ -458,6 +475,7 @@
}
}
}
+*/
std::string NewMapWin::string2Polishform(std::string rawcommand, bool itisedge)
@@ -646,12 +664,12 @@
//is it mapname?
if(itisedge)
{
- std::vector<std::string> edge_maps = mytab.mapstorage.getEdgeMapList();
+ std::vector<std::string> edge_maps = mytab.mapstorage.getEdgeMapList(INT | SCAL);
cancel=(std::find(edge_maps.begin(), edge_maps.end(), variable)==edge_maps.end());
}
else
{
- std::vector<std::string> node_maps = mytab.mapstorage.getNodeMapList();
+ std::vector<std::string> node_maps = mytab.mapstorage.getNodeMapList(INT | SCAL);
cancel=(std::find(node_maps.begin(), node_maps.end(), variable)==node_maps.end());
}
//maybe it is number
More information about the Lemon-commits
mailing list