[Lemon-commits] ladanyi: r3407 - glemon/branches/akos
Lemon SVN
svn at lemon.cs.elte.hu
Tue Dec 4 02:10:41 CET 2007
Author: ladanyi
Date: Tue Dec 4 02:10:40 2007
New Revision: 3407
Modified:
glemon/branches/akos/mapstorage.cc
glemon/branches/akos/mapstorage.h
glemon/branches/akos/new_map_win.cc
glemon/branches/akos/new_map_win.h
Log:
Bugfix.
Modified: glemon/branches/akos/mapstorage.cc
==============================================================================
--- glemon/branches/akos/mapstorage.cc (original)
+++ glemon/branches/akos/mapstorage.cc Tue Dec 4 02:10:40 2007
@@ -87,7 +87,7 @@
{
NodeMapStore::const_iterator it = nodemaps.find(name);
if (it != nodemaps.end())
- throw MapAlreadyExists(name);
+ throw Error("Node map " + name + " already exists.");
switch (type)
{
@@ -109,7 +109,7 @@
{
EdgeMapStore::const_iterator it = edgemaps.find(name);
if (it != edgemaps.end())
- throw MapAlreadyExists(name);
+ throw Error("Edge map " + name + " already exists.");
switch (type)
{
@@ -1028,28 +1028,32 @@
MapStorage::NumericNodeMap& MapStorage::getNumericNodeMap(const std::string& name)
{
NodeMapData* data = getNodeMapData(name);
- if (data->type() != MapValue::NUMERIC) throw NonexistentMap(name);
+ if (data->type() != MapValue::NUMERIC)
+ throw Error("Numeric node map " + name + " does not exists.");
return static_cast<NumericNodeMapData*>(data)->map;
}
MapStorage::StringNodeMap& MapStorage::getStringNodeMap(const std::string& name)
{
NodeMapData* data = getNodeMapData(name);
- if (data->type() != MapValue::STRING) throw NonexistentMap(name);
+ if (data->type() != MapValue::STRING)
+ throw Error("String node map " + name + " does not exists.");
return static_cast<StringNodeMapData*>(data)->map;
}
MapStorage::NumericEdgeMap& MapStorage::getNumericEdgeMap(const std::string& name)
{
EdgeMapData* data = getEdgeMapData(name);
- if (data->type() != MapValue::NUMERIC) throw NonexistentMap(name);
+ if (data->type() != MapValue::NUMERIC)
+ throw Error("Numeric edge map " + name + " does not exists.");
return static_cast<NumericEdgeMapData*>(data)->map;
}
MapStorage::StringEdgeMap& MapStorage::getStringEdgeMap(const std::string& name)
{
EdgeMapData* data = getEdgeMapData(name);
- if (data->type() != MapValue::STRING) throw NonexistentMap(name);
+ if (data->type() != MapValue::STRING)
+ throw Error("String edge map " + name + " does not exists.");
return static_cast<StringEdgeMapData*>(data)->map;
}
@@ -1113,7 +1117,7 @@
if (it != edgemaps.end())
return it->second;
else
- throw NonexistentMap(name);
+ throw Error("Edge map " + name + " does not exists.");
}
MapStorage::NodeMapData* MapStorage::getNodeMapData(std::string name) const
@@ -1122,7 +1126,7 @@
if (it != nodemaps.end())
return it->second;
else
- throw NonexistentMap(name);
+ throw Error("Node map " + name + " does not exists.");
}
MapValue::Type MapStorage::getNodeMapElementType(std::string name) const
Modified: glemon/branches/akos/mapstorage.h
==============================================================================
--- glemon/branches/akos/mapstorage.h (original)
+++ glemon/branches/akos/mapstorage.h Tue Dec 4 02:10:40 2007
@@ -48,18 +48,17 @@
bool background_set;
double background_scaling;
public:
- class NonexistentMap : public std::exception
+ class Error : public std::exception
{
private:
std::string message;
public:
- NonexistentMap(const std::string& name) :
- message("Map '" + name + "' does not exist.") {}
+ Error(const std::string& msg) : message(msg) {}
virtual const char* what() const throw()
{
return message.c_str();
}
- ~NonexistentMap() throw() {}
+ ~Error() throw() {}
};
void setBackground(const std::string& file_name);
@@ -67,19 +66,6 @@
bool isBackgroundSet();
double getBackgroundScaling();
void setBackgroundScaling(double scaling);
- class MapAlreadyExists : public std::exception
- {
- private:
- std::string message;
- public:
- MapAlreadyExists(const std::string& name) :
- message("Map '" + name + "' already exists.") {}
- virtual const char* what() const throw()
- {
- return message.c_str();
- }
- ~MapAlreadyExists() throw() {}
- };
enum MapSaveDest { GUI_SECT, NESET_SECT, DONT_SAVE };
enum GuiSectSaveDest { LGF_FILE, CONF_FILE };
Modified: glemon/branches/akos/new_map_win.cc
==============================================================================
--- glemon/branches/akos/new_map_win.cc (original)
+++ glemon/branches/akos/new_map_win.cc Tue Dec 4 02:10:40 2007
@@ -101,72 +101,135 @@
lblErrorMsg.set_markup("<i><small>" + msg + "</small></i>");
}
-std::vector<double>* NewMapWin::evaluate_expr(const std::string polishform)
+std::vector<double>* NewMapWin::evaluate_expr(const std::string polishform, bool itisedge)
{
MapStorage& ms = *mytab.mapstorage;
std::vector<double>* ret = new std::vector<double>;
std::stack<double> polishstack;
- for(EdgeIt k(ms.graph); k!=INVALID; ++k)
+ if (itisedge)
{
- for(int i=0;i<(int)polishform.size();i++)
+ for(EdgeIt k(ms.graph); k!=INVALID; ++k)
{
- double op1=0, op2=0;
- bool operation=true;
- switch(polishform[i])
+ for(int i=0;i<(int)polishform.size();i++)
{
- case '+':
- case '-':
- case '/':
- case '*':
- op1=polishstack.top();
- polishstack.pop();
- op2=polishstack.top();
- polishstack.pop();
- break;
- default:
- //substitute variable
- std::vector<std::string> ems =
- ms.getEdgeMapList(NUM);
- bool itisvar=(std::find(ems.begin(), ems.end(), ch2var[ polishform[i] ]) != ems.end());
- if(itisvar)
- {
- polishstack.push(ms.get(ch2var[ polishform[i] ], k));
- }
- else
+ double op1=0, op2=0;
+ bool operation=true;
+ switch(polishform[i])
+ {
+ case '+':
+ case '-':
+ case '/':
+ case '*':
+ op1=polishstack.top();
+ polishstack.pop();
+ op2=polishstack.top();
+ polishstack.pop();
+ break;
+ default:
+ //substitute variable
+ std::vector<std::string> maps = ms.getEdgeMapList(NUM);
+ bool itisvar=(std::find(maps.begin(), maps.end(), ch2var[ polishform[i] ]) != maps.end());
+ if(itisvar)
+ {
+ polishstack.push(ms.get(ch2var[ polishform[i] ], k));
+ }
+ else
+ {
+ polishstack.push(atof(ch2var[ polishform[i] ].c_str()));
+ }
+ operation=false;
+ break;
+ }
+ if(operation)
+ {
+ double res;
+ switch(polishform[i])
{
- polishstack.push(atof(ch2var[ polishform[i] ].c_str()));
+ case '+':
+ res=op1+op2;
+ break;
+ case '-':
+ res=op2-op1;
+ break;
+ case '/':
+ res=op2/op1;
+ break;
+ case '*':
+ res=op1*op2;
+ break;
+ default:
+ std::cout << "How could we get here?" << std::endl;
+ break;
}
- operation=false;
- break;
- }
- if(operation)
+ polishstack.push(res);
+ }
+ }//foreach letter in polishform
+ ret->push_back(polishstack.top());
+ }//foreach edge
+ }
+ else
+ {
+ for(NodeIt k(ms.graph); k!=INVALID; ++k)
+ {
+ for(int i=0;i<(int)polishform.size();i++)
{
- double res;
+ double op1=0, op2=0;
+ bool operation=true;
switch(polishform[i])
{
case '+':
- res=op1+op2;
- break;
case '-':
- res=op2-op1;
- break;
case '/':
- res=op2/op1;
- break;
case '*':
- res=op1*op2;
+ op1=polishstack.top();
+ polishstack.pop();
+ op2=polishstack.top();
+ polishstack.pop();
break;
default:
- std::cout << "How could we get here?" << std::endl;
+ //substitute variable
+ std::vector<std::string> maps = ms.getNodeMapList(NUM);
+ bool itisvar=(std::find(maps.begin(), maps.end(), ch2var[ polishform[i] ]) != maps.end());
+ if(itisvar)
+ {
+ polishstack.push(ms.get(ch2var[ polishform[i] ], k));
+ }
+ else
+ {
+ polishstack.push(atof(ch2var[ polishform[i] ].c_str()));
+ }
+ operation=false;
break;
}
- polishstack.push(res);
- }
- }//foreach letter in polishform
- ret->push_back(polishstack.top());
- }//foreach edge
+ if(operation)
+ {
+ double res;
+ switch(polishform[i])
+ {
+ case '+':
+ res=op1+op2;
+ break;
+ case '-':
+ res=op2-op1;
+ break;
+ case '/':
+ res=op2/op1;
+ break;
+ case '*':
+ res=op1*op2;
+ break;
+ default:
+ std::cout << "How could we get here?" << std::endl;
+ break;
+ }
+ polishstack.push(res);
+ }
+ }//foreach letter in polishform
+ ret->push_back(polishstack.top());
+ }//foreach edge
+ }
return ret;
}
@@ -222,8 +285,12 @@
else
{
// let't try to evaluate the string as an arithmetic expression
- std::vector<double>* values;
- values = evaluate_expr(string2Polishform(def_val, edge.get_active()));
+ std::string polishform =
+ string2Polishform(def_val, edge.get_active());
+ if (polishform.empty())
+ return;
+ std::vector<double>* values =
+ evaluate_expr(polishform, edge.get_active());
if (edge.get_active())
{
ms.createEdgeMap(map_name, MapValue::NUMERIC,
Modified: glemon/branches/akos/new_map_win.h
==============================================================================
--- glemon/branches/akos/new_map_win.h (original)
+++ glemon/branches/akos/new_map_win.h Tue Dec 4 02:10:40 2007
@@ -42,7 +42,7 @@
Gtk::Label lblErrorMsg;
void setErrorMsg(const Glib::ustring& msg);
- std::vector<double>* evaluate_expr(const std::string polishform);
+ std::vector<double>* evaluate_expr(const std::string polishform, bool itisedge);
public:
More information about the Lemon-commits
mailing list