# HG changeset patch # User hegyi # Date 1136906157 0 # Node ID eed01ce27087f69254ea75cf619fe6638c9d8fcc # Parent 22fdc00894aa2264c0a64886b4faafbff0db3f6d If default value of a new map is constant, the newly created elements will get that value as well. Documentation is added to BrokenEdge, MapStorage and GraphDisplazCanvas classes. diff -r 22fdc00894aa -r eed01ce27087 gui/graph_displayer_canvas.cc --- a/gui/graph_displayer_canvas.cc Mon Jan 09 12:41:06 2006 +0000 +++ b/gui/graph_displayer_canvas.cc Tue Jan 10 15:15:57 2006 +0000 @@ -59,9 +59,9 @@ } } -void GraphDisplayerCanvas::propertyUpdate(Node node, int prop, int dummy) +void GraphDisplayerCanvas::propertyUpdate(Node node, int prop) { - dummy=dummy; + //dummy=dummy; std::string mapname=mytab.getActiveNodeMap(prop); @@ -106,9 +106,9 @@ } -void GraphDisplayerCanvas::propertyUpdate(Edge edge, int prop, int dummy) +void GraphDisplayerCanvas::propertyUpdate(Edge edge, int prop) { - dummy=dummy; + //dummy=dummy; std::string mapname=mytab.getActiveEdgeMap(prop); diff -r 22fdc00894aa -r eed01ce27087 gui/graph_displayer_canvas.h --- a/gui/graph_displayer_canvas.h Mon Jan 09 12:41:06 2006 +0000 +++ b/gui/graph_displayer_canvas.h Tue Jan 10 15:15:57 2006 +0000 @@ -16,67 +16,180 @@ { friend class BrokenEdge; + ///Edge displayer class + + ///This class is responsible for displaying edges in graph. + ///The displayed edge is broken in the middle. The + ///aim of this is to be able to indicate direction of edges + ///and to be able to display more then one edges between the + ///same source and target class BrokenEdge : public Gnome::Canvas::Line { + ///The edge that the class displays. + + ///It is needed, because some datas needed from + ///graph can be accessed by this or should be sent + ///as parameter, but it would be complicated Edge edge; + + ///Reference to the canvas, on which the graph is drawn. + + ///It is needed, because some datas needed from + ///graph can be accessed by this or should be sent + ///as parameter, but it would be complicated GraphDisplayerCanvas & gdc; + + ///An arrow that indicates the direction of the edges + + ///in case of directional graph direction can be indicated + ///by this polygon. The polygon formulates a red arrow. Gnome::Canvas::Polygon * arrow; - ///Indicates whether the button of mouse is pressed or not + ///Indicates whether the button of mouse is pressed or not at the moment. bool isbutton; - ///At this location was the mousebutton pressed. - ///It helps to calculate the distance of dragging. - double clicked_x, clicked_y; + ///At this location was the mousebutton pressed. Horizontal component. - ///event handler for forming edges - bool edgeFormerEventHandler(GdkEvent*); + ///It helps to calculate the + ///distance of dragging. + double clicked_x; + + ///At this location was the mousebutton pressed. Vertical component. + + ///It helps to calculate the + ///distance of dragging. + double clicked_y; + + ///event handler for forming broken edges + + ///\param event the + ///event to handle + bool edgeFormerEventHandler(GdkEvent* event); public: - BrokenEdge(Gnome::Canvas::Group &, Edge, GraphDisplayerCanvas &); + + ///Constructor of broken edge class. + + ///\param g the group to which the edge belongs + ///\param _edge the represented edge + ///\param gc the canvas + BrokenEdge(Gnome::Canvas::Group & g, Edge _edge, GraphDisplayerCanvas & gc); + + ///Destructor of broken edge class + + ///Frees up + ///reserved memory ~BrokenEdge(); + + ///The function that draws the edge based on collected data void draw(); }; + + ///Type of canvas, on which the graph is drawn typedef Gnome::Canvas::CanvasAA Parent; public: - GraphDisplayerCanvas(NoteBookTab &); + ///Constructor + + ///\param nbt the tab of the window, in which the graph is displayed + GraphDisplayerCanvas(NoteBookTab & nbt); + + ///destructor of the class virtual ~GraphDisplayerCanvas(); - ///Changes the linewidth attribute according to the given map. + ///Changes the width of edge(s) according to the given map. + + ///\param mapname is the name of the map which contains the values to be set + ///\param edge if it is given, only the width of the given edge will be set, instead of all of them. + int changeEdgeWidth (std::string mapname, Edge edge=INVALID); + + ///Resets width of edge(s) to the default value + + ///\param edge if it is given, only the width of the + ///given edge will be reset, instead of all of them. + int resetEdgeWidth (Edge edge=INVALID); + + ///Changes the color of edge(s) according to the given map. + ///\param mapname is the name of the map which contains the new values - int changeEdgeWidth (std::string mapname, Edge new_item=INVALID); - int resetEdgeWidth (Edge new_item=INVALID); + ///\param edge if it is given, only the color of the given edge will be set, instead of all of them. + int changeEdgeColor (std::string mapname, Edge edge=INVALID); - ///Changes the linecolor attribute according to the given map. + ///Resets color of edge(s) to the default value + + ///\param edge if it is given, only the color of the + ///given edge will be reset, instead of all of them. + int resetEdgeColor (Edge edge=INVALID); + + ///Changes the label of edge(s) according to the given map. + ///\param mapname is the name of the map which contains the new values - int changeEdgeColor (std::string mapname, Edge new_item=INVALID); - int resetEdgeColor (Edge new_item=INVALID); + ///\param edge if it is given, only the label of the given edge will be set, instead of all of them. + int changeEdgeText (std::string mapname, Edge edge=INVALID); - ///Changes the text of line attribute according to the given map. + ///Resets label of edge(s) to the default value + + ///\param edge if it is given, only the color of the + ///given edge will be reset, instead of all of them. + int resetEdgeText (Edge edge=INVALID); + + ///Changes the radius of node(s) according to the given map. + ///\param mapname is the name of the map which contains the new values - int changeEdgeText (std::string mapname, Edge new_item=INVALID); - int resetEdgeText (Edge new_item=INVALID); + ///\param node if it is given, only the radius of the given node will be set, instead of all of them. + int changeNodeRadius (std::string mapname, Node node=INVALID); - ///Changes the linewidth attribute according to the given map. + ///Resets radius of node(s) to the default value + + ///\param node if it is given, only the radius of the + ///given node will be reset, instead of all of them. + int resetNodeRadius (Node node=INVALID); + + ///Changes the color of node(s) according to the given map. + ///\param mapname is the name of the map which contains the new values - int changeNodeRadius (std::string mapname, Node new_item=INVALID); - int resetNodeRadius (Node new_item=INVALID); + ///\param node if it is given, only the color of the given node will be set, instead of all of them. + int changeNodeColor (std::string mapname, Node node=INVALID); - ///Changes the linecolor attribute according to the given map. + ///Resets color of node(s) to the default value + + ///\param node if it is given, only the color of the + ///given node will be reset, instead of all of them. + int resetNodeColor (Node node=INVALID); + + ///Changes the label of node(s) according to the given map. + ///\param mapname is the name of the map which contains the new values - int changeNodeColor (std::string mapname, Node new_item=INVALID); - int resetNodeColor (Node new_item=INVALID); + ///\param node if it is given, only the label of the given node will be set, instead of all of them. + int changeNodeText (std::string mapname, Node node=INVALID); - ///Changes the text of line attribute according to the given map. - ///\param mapname is the name of the map which contains the new values - int changeNodeText (std::string mapname, Node new_item=INVALID); - int resetNodeText (Node new_item=INVALID); + ///Resets label of node(s) to the default value - void propertyChange(bool, int); - void propertyUpdate(Edge, int, int dummy=0); - void propertyUpdate(Node, int, int dummy=0); + ///\param node if it is given, only the label of the + ///given node will be reset, instead of all of them. + int resetNodeText (Node node=INVALID); + ///This function is called, when any of the displayed attributes have to be updated, or changed + + ///\param itisedge if true, edge property has to be changed, else node property + ///\param prop the id of property that has to changed or updated + void propertyChange(bool itisedge, int prop); + + ///updates the given property + + ///\param edge if it is not INVALID, only the property of the given edge will be updated, instead of all of them + ///\param prop the property to update + void propertyUpdate(Edge edge, int prop); + + ///updates the given property + + ///\param node if it is not INVALID, only the property of the given node will be updated, instead of all of them + ///\param prop the property to update + void propertyUpdate(Node node, int prop); + + ///updates all the property for the given edge void propertyUpdate(Edge); + + ///updates all the property for the given node void propertyUpdate(Node); ///Callback for 'ViewZoomIn' action. @@ -95,7 +208,7 @@ protected: - //maximizing, minimizing, restoring window, etc. + //maximizing, minimizing, restoring window, etc. virtual bool on_expose_event(GdkEventExpose *); private: @@ -127,26 +240,42 @@ public: ///Moves the text to new place void textReposition(xy); + ///Activates an edge belonging to a BrokenEdge - /// + ///After we have activated an edge this way, ///the GDC object will know, which edge is under forming - ///therefore it can redraw the necessarz elementy on the canvas, + ///therefore it can redraw the necessary elements on the canvas, ///for example the text belonging to the \ref BrokenEdge can be ///redrawn (\ref textReposition). void toggleEdgeActivity(BrokenEdge*, bool); public: - ///\return the actual tool in hand + + ///Returns the actual tool in hand int getActualTool(); + ///draws the graph + + ///Called when opening a file. void drawGraph(); + + ///Clears the canvas + + ///It achieves this by deleting all data + ///structure used to help handle the displayed graph. void clear(); ///creates a new Nodemap - int addNewNodeMap(double,std::string); + + ///\param init initial value of the map + ///\param mapname name of new map + int addNewNodeMap(double init,std::string mapname); ///creates a new Edgemap - int addNewEdgeMap(double,std::string); + + ///\param init initial value of the map + ///\param mapname name of new map + int addNewEdgeMap(double init,std::string mapname); private: ///Deletes the given element. @@ -183,21 +312,43 @@ double clicked_x, clicked_y; ///Remembers which Gnome::Canvas::Item was pressed. - ///this variable is needed, because - ///1. we cannot query the item at he cursor as fast as it could not cause a Segmentation Fault - ///2. we would like to handle only ony item per movement, therefore quering it is not a working solution - Gnome::Canvas::Item * active_item, * target_item; + + ///this variable is needed, to work on it after selection + Gnome::Canvas::Item * active_item; + + ///Remembers which Gnome::Canvas::Item was pressed. + + ///this variable is used at edge creation, it will + ///be the secondly selected node. No local variable + ///can be used for this purpose inside the function, + ///because the node selected by button press, and + ///the edge is created by button release. Both of + ///them is different function call. + Gnome::Canvas::Item * target_item; + + ///selected node (for any editing) Node active_node; + + ///selected edge (for any editing) Edge active_edge; + + ///the edge that is selected by clicking on the red arrow in the middle of it + + ///This edge is stored only for the purpose of reshape it. + ///That is why it is selected in a different manner. Edge forming_edge; - std::string nodemap_to_edit, edgemap_to_edit; + ///Map displayed by label can be edited. + std::string nodemap_to_edit; + + ///Map displayed by label can be edited. + std::string edgemap_to_edit; static const int zoom_step = 5; private: - ///reference to the parent window + ///reference to the container, in which the canvas is NoteBookTab & mytab; XY GraphDisplayerCanvas::calcArrowPos(XY, XY, XY, XY, bool); diff -r 22fdc00894aa -r eed01ce27087 gui/mapstorage.cc --- a/gui/mapstorage.cc Mon Jan 09 12:41:06 2006 +0000 +++ b/gui/mapstorage.cc Tue Jan 10 15:15:57 2006 +0000 @@ -51,8 +51,9 @@ } } -int MapStorage::addNodeMap(const std::string & name, Graph::NodeMap *nodemap, double default_value = 0.0) +int MapStorage::addNodeMap(const std::string & name, Graph::NodeMap *nodemap, double default_value) { + std::cout << default_value << std::endl; if( nodemap_storage.find(name) == nodemap_storage.end() ) { nodemap_storage[name]=nodemap; @@ -122,7 +123,7 @@ return signal_prop; } -int MapStorage::addEdgeMap(const std::string & name, Graph::EdgeMap *edgemap, double default_value = 0.0) +int MapStorage::addEdgeMap(const std::string & name, Graph::EdgeMap *edgemap, double default_value) { if( edgemap_storage.find(name) == edgemap_storage.end() ) { diff -r 22fdc00894aa -r eed01ce27087 gui/mapstorage.h --- a/gui/mapstorage.h Mon Jan 09 12:41:06 2006 +0000 +++ b/gui/mapstorage.h Tue Jan 10 15:15:57 2006 +0000 @@ -9,6 +9,8 @@ #include "xymap.h" #include +///class MapStorage handles NodeMaps and EdgeMaps. + ///Class MapStorage is responsible for storing ///NodeMaps and EdgeMaps that can be shown later ///on GUI. Therefore maps can be added to it, @@ -22,13 +24,17 @@ { public: + ///The graph for which the datas are stored. Graph graph; /// the coordinates of the nodes XYMap > coords; /// the coordinates of the arrows on the edges XYMap > arrow_pos; + ///The content of the object has changed, update is needed. bool modified; + + ///Name of file loaded in object. std::string file_name; ///Stores double type NodeMaps @@ -37,67 +43,119 @@ ///Stores double type EdgeMaps std::map< std::string,Graph::EdgeMap * > edgemap_storage; - //Stores the default values for the different visualization node attributes + ///Stores the default values for the different visualization node attributes std::vector > default_nodemaps; - //Stores the default values for the different visualization edge attributes + ///Stores the default values for the different visualization edge attributes std::vector > default_edgemaps; - //Stores the active maps for the different visualization node attributes + ///Stores the active maps for the different visualization node attributes std::vector< std::string > active_nodemaps; - //Stores the active maps for the different visualization edge attributes + /// Stores the active maps for the different visualization edge attributes std::vector< std::string > active_edgemaps; - // Default values for the maps + /// Default values for the maps std::map< std::string, double > nodemap_default; - // Default values for the maps + /// Default values for the maps std::map< std::string, double > edgemap_default; bool arrow_pos_read_ok; protected: + /// type of the signal emitted if the visualization of the maps might have to be updated. + + /// bool shows us whether the changed map is edge or nodemap. + /// int tells us the refreshed property typedef sigc::signal Signal_Prop; + + /// Signal emitted on any change made on map values Signal_Prop signal_prop; + + /// Signal emitted in the case of nodemap addition + + /// std::string is the + ///name of the new map sigc::signal signal_node_map; + + /// Signal emitted in the case of edgemap addition + + /// std::string is the + ///name of the new map sigc::signal signal_edge_map; public: - ///Constructor of MapStorage. Expects the Graph of - ///which maps will be stored in it. + ///Constructor of MapStorage. + ///Its all activity is initializing default values - ///for different visualization attributes - /// - ///\param graph is the graph for which the maps are stored in this object. + ///for different visualization attributes. MapStorage(); + ///Destructor of MapStorage + + ///Maps stored here are created with new. Destructor + ///deletes them to free up the reserved memory. ~MapStorage(); - void changeActiveMap(bool, int, std::string); + /// Registrates if the shown map by any attribute has changed to another. - std::string getActiveEdgeMap(int); - std::string getActiveNodeMap(int); + ///It handles the \ref active_edgemaps and + ///\ref active_nodemaps vectors. It also emits \ref signal_prop signal to let + ///know the interested objects that the visible map of a certain + ///attribute has changed. + ///\param itisedge edgemap or nodemap has changed + ///\param prop the property of which the map is changed + ///\param mapname the visible map + void changeActiveMap(bool itisedge , int prop , std::string mapname); + /// Returns the active edgemap shown by a visualization property. + + /// \param prop is the property + ///that shows the requested map. + std::string getActiveEdgeMap(int prop); + + /// Returns the active nodemap shown by a visualization property. + + /// \param prop is the property + ///that shows the requested map. + std::string getActiveNodeMap(int prop); + + /// Returns the names of the edgemaps stored here. std::vector getEdgeMapList(); + + /// Returns the names of the nodemaps stored here. std::vector getNodeMapList(); + ///returns \ref signal_prop to be able to connect functions to it Signal_Prop signal_prop_ch(); + ///returns \ref signal_node_map to be able to connect functions to it sigc::signal signal_node_map_ch(){return signal_node_map;}; + + ///returns \ref signal_edge_map to be able to connect functions to it sigc::signal signal_edge_map_ch(){return signal_edge_map;}; - ///Adds given map to storage. A name and the map itself has to be provided. - ///\param name is the name of map - ///\nodemap is the pointer of the given nodemap + ///Adds given map to storage. + + ///A name and the map itself has to be provided. + ///\param mapname is the name of map + ///\param nodemap is the pointer of the given nodemap + ///\param def the default value of the map. If not given, it will be 0. + ///If new edge is added to graph the value of it in the map will be this. ///\todo map should be given by reference! - int addNodeMap(const std::string &,Graph::NodeMap *, double); + ///\todo why is default value stored? + int addNodeMap(const std::string & mapname,Graph::NodeMap * nodemap, double def=0.0); ///Adds given map to storage. A name and the map itself has to be provided. - ///\param name is the name of map - ///\edgemap is the pointer of the given edgemap + + ///A name and the map itself has to be provided. + ///\param mapname is the name of map + ///\param edgemap is the pointer of the given edgemap + ///\param def the default value of the map. If not given, it will be 0. + ///If new edge is added to graph the value of it in the map will be this. ///\todo map should be given by reference! - int addEdgeMap(const std::string &,Graph::EdgeMap *, double); + int addEdgeMap(const std::string & mapname,Graph::EdgeMap * edgemap, double def=0.0); ///Returns how much nodemaps is stored in \ref MapStorage int numOfNodeMaps() {return nodemap_storage.size();}; @@ -105,39 +163,74 @@ ///Returns how much edgemaps is stored in \ref MapStorage int numOfEdgeMaps() {return edgemap_storage.size();}; - ///Returns the maximum value of the given NodeMap. NodeMap has to be given by its name. - ///\param name is the name of map of which maximum is searched - double maxOfNodeMap(const std::string &); + ///Returns the maximum value of the given NodeMap. - ///Returns the maximum value of the given EdgeMap. EdgeMap has to be given by its name. - ///\param name is the name of map of which maximum is searched - double maxOfEdgeMap(const std::string &); + ///NodeMap has to be given by its name. + ///\param name the name of map of which maximum is searched + double maxOfNodeMap(const std::string & name); - ///Returns the minimum value of the given NodeMap. NodeMap has to be given by its name. - ///\param name is the name of map of which minimum is searched - double minOfNodeMap(const std::string &); + ///Returns the maximum value of the given EdgeMap. - ///Returns the minimum value of the given EdgeMap. EdgeMap has to be given by its name. - ///\param name is the name of map of which minimum is searched - double minOfEdgeMap(const std::string &); + ///EdgeMap has to be given by its name. + ///\param name the name of map of which maximum is searched + double maxOfEdgeMap(const std::string & name); - ///To be able to iterate through each maps this function returns an iterator pointing to the first nodemap in the storage. + ///Returns the minimum value of the given NodeMap. + + ///NodeMap has to be given by its name. + ///\param name the name of map of which minimum is searched + double minOfNodeMap(const std::string & name); + + ///Returns the minimum value of the given EdgeMap. + + ///EdgeMap has to be given by its name. + ///\param name the name of map of which minimum is searched + double minOfEdgeMap(const std::string & name); + + ///Returns iterator pointing to the first NodeMap in storage. + + ///To be able to iterate through each maps this function + ///returns an iterator pointing to the first nodemap in + ///the storage. std::map< std::string,Graph::NodeMap * >::iterator beginOfNodeMaps(){return nodemap_storage.begin();}; - ///To be able to iterate through each maps this function returns an iterator pointing to the first edgemap in the storage. + ///Returns iterator pointing to the first EdgeMap in storage. + + ///To be able to iterate through each maps this function + ///returns an iterator pointing to the first edgemap in + ///the storage. std::map< std::string,Graph::EdgeMap * >::iterator beginOfEdgeMaps(){return edgemap_storage.begin();}; - ///To be able to iterate through each maps this function returns an iterator pointing to the last nodemap in the storage. + ///Returns iterator pointing after the last NodeMap in storage. + + ///To be able to iterate through each maps this function + ///returns an iterator pointing to the last nodemap in the storage. std::map< std::string,Graph::NodeMap * >::iterator endOfNodeMaps(){return nodemap_storage.end();}; - ///To be able to iterate through each maps this function returns an iterator pointing to the last edgemap in the storage. + ///Returns iterator pointing after the last EdgeMap in storage. + + ///To be able to iterate through each maps this function + ///returns an iterator pointing to the last edgemap in the storage. std::map< std::string,Graph::EdgeMap * >::iterator endOfEdgeMaps(){return edgemap_storage.end();}; - void mapChanged(bool, std::string); + ///Emits \ref signal_prop if mapvalues have changed, and MapStorage gets to know it. + ///If values in a map have changed, this function checks, whether it is displayed. + ///This check means searching the given mapname between active maps + ///(\ref active_nodemaps, \ref active_edgemaps). If it is there at a certain property, + ///it emits a signal with the property, where the gotten mapname was found. One signal + ///is emitted for each property displaying the given map. + ///\param itisedge whether the map an edgemap or nodemap + ///\param mapname name of map to visualize + void mapChanged(bool itisedge, std::string mapname); + + ///Read datas from the given filename. int readFromFile(const std::string &); + + ///Save datas to the given filename. void writeToFile(const std::string &); + ///Deletes all datastructures stored here. void clear(); void ArrowPosReadOK(); diff -r 22fdc00894aa -r eed01ce27087 gui/new_map_win.cc --- a/gui/new_map_win.cc Mon Jan 09 12:41:06 2006 +0000 +++ b/gui/new_map_win.cc Tue Jan 10 15:15:57 2006 +0000 @@ -72,79 +72,100 @@ //get and formulate text std::string def_val_str=default_value.get_text(); - std::string polishform=string2Polishform(def_val_str,edge.get_active()); + + bool only_nums=true; + for(int i=0;i<(int)def_val_str.size() && only_nums;i++) + { + if( def_val_str[i]<'0' || def_val_str[i]>'9' ) + { + only_nums=false; + } + } + std::string polishform; + + if(only_nums) + { + def_val=atof(def_val_str.c_str()); + } + else + { + polishform=string2Polishform(def_val_str,edge.get_active()); + } //get name of text std::string mapname=name.get_text(); - - if(!mapname.empty()&&!polishform.empty()) + + if(!mapname.empty()&&(!polishform.empty()||only_nums)) { int abortion=0; if(edge.get_active()) { //create the new map - Graph::EdgeMap * emptr=new Graph::EdgeMap (mytab.mapstorage.graph); - - std::stack polishstack; - - for(EdgeIt k(mytab.mapstorage.graph); k!=INVALID; ++k) + Graph::EdgeMap * emptr=new Graph::EdgeMap (mytab.mapstorage.graph, def_val); + + if(!only_nums) { - for(int i=0;i<(int)polishform.size();i++) + std::stack polishstack; + + for(EdgeIt k(mytab.mapstorage.graph); k!=INVALID; ++k) { - double op1, op2; - 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::map< std::string,Graph::EdgeMap * > ems=mytab.mapstorage.edgemap_storage; - bool itisvar=(ems.find(ch2var[ polishform[i] ])!=ems.end()); - if(itisvar) - { - polishstack.push( (*(mytab.mapstorage.edgemap_storage[ ch2var[ polishform[i] ] ]))[k]); - } - else - { - polishstack.push(atof(ch2var[ polishform[i] ].c_str())); - } - operation=false; - break; - } - if(operation) - { - 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::map< std::string,Graph::EdgeMap * > ems=mytab.mapstorage.edgemap_storage; + bool itisvar=(ems.find(ch2var[ polishform[i] ])!=ems.end()); + if(itisvar) + { + polishstack.push( (*(mytab.mapstorage.edgemap_storage[ ch2var[ polishform[i] ] ]))[k]); + } + else + { + polishstack.push(atof(ch2var[ polishform[i] ].c_str())); + } + operation=false; break; } - polishstack.push(res); - } - } - (*emptr)[k]=polishstack.top(); - } + 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 + (*emptr)[k]=polishstack.top(); + }//foreach edge + }//!only_nums //if addition was not successful addEdgeMap returns one. //cause can be that there is already a map named like the new one @@ -163,68 +184,70 @@ else //!edge.get_active() { //create the new map - Graph::NodeMap * emptr=new Graph::NodeMap (mytab.mapstorage.graph); + Graph::NodeMap * emptr=new Graph::NodeMap (mytab.mapstorage.graph, def_val); - std::stack polishstack; + if(!only_nums) + { + std::stack polishstack; - for(NodeIt k(mytab.mapstorage.graph); k!=INVALID; ++k) - { - for(int i=0;i<(int)polishform.size();i++) + for(NodeIt k(mytab.mapstorage.graph); k!=INVALID; ++k) { - double op1, op2; - 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: - std::map< std::string,Graph::NodeMap * > nms=mytab.mapstorage.nodemap_storage; - bool itisvar=(nms.find(ch2var[ polishform[i] ])!=nms.end()); - if(itisvar) - { - polishstack.push( (*(mytab.mapstorage.nodemap_storage[ ch2var[ polishform[i] ] ]))[k]); - } - else - { - polishstack.push(atof(ch2var[ polishform[i] ].c_str())); - } - operation=false; - break; - } - if(operation) - { - 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; + std::map< std::string,Graph::NodeMap * > nms=mytab.mapstorage.nodemap_storage; + bool itisvar=(nms.find(ch2var[ polishform[i] ])!=nms.end()); + if(itisvar) + { + polishstack.push( (*(mytab.mapstorage.nodemap_storage[ ch2var[ polishform[i] ] ]))[k]); + } + else + { + polishstack.push(atof(ch2var[ polishform[i] ].c_str())); + } + operation=false; break; } - polishstack.push(res); + 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); + } } + (*emptr)[k]=polishstack.top(); } - (*emptr)[k]=polishstack.top(); } - //if addition was not successful addNodeMap returns one. //cause can be that there is already a map named like the new one if(mytab.mapstorage.addNodeMap(mapname,emptr, def_val))