Modified the NodeTree with a unique id used in construction of the DOT representation, so that two different nodes with the same name don't end up as the same on the graph.
This commit is contained in:
@@ -5,8 +5,11 @@
|
|||||||
#define NULL 0
|
#define NULL 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <util.h>
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
class NodeTree {
|
class NodeTree {
|
||||||
public:
|
public:
|
||||||
@@ -32,9 +35,13 @@ class NodeTree {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
std::string DOTGraphStringHelper();
|
std::string DOTGraphStringHelper();
|
||||||
|
std::string getDOTName();
|
||||||
std::string name;
|
std::string name;
|
||||||
NodeTree* parent;
|
NodeTree* parent;
|
||||||
std::vector<NodeTree*> children;
|
std::vector<NodeTree*> children;
|
||||||
|
|
||||||
|
static int idCounter;
|
||||||
|
int id;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -9,5 +9,7 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
std::string intToString(int theInt);
|
std::string intToString(int theInt);
|
||||||
|
std::string truncateEnd(std::string to_truncate);
|
||||||
|
std::string removeBeginning(std::string to_remove);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -1,13 +1,19 @@
|
|||||||
#include "NodeTree.h"
|
#include "NodeTree.h"
|
||||||
|
|
||||||
|
int NodeTree::idCounter;
|
||||||
|
|
||||||
NodeTree::NodeTree() {
|
NodeTree::NodeTree() {
|
||||||
parent = NULL;
|
parent = NULL;
|
||||||
name = "UnnamedNode";
|
name = "UnnamedNode";
|
||||||
|
|
||||||
|
id = idCounter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeTree::NodeTree(std::string name) {
|
NodeTree::NodeTree(std::string name) {
|
||||||
parent = NULL;
|
parent = NULL;
|
||||||
this->name = name;
|
this->name = name;
|
||||||
|
|
||||||
|
id = idCounter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeTree::~NodeTree() {
|
NodeTree::~NodeTree() {
|
||||||
@@ -78,7 +84,13 @@ std::string NodeTree::DOTGraphString() {
|
|||||||
std::string NodeTree::DOTGraphStringHelper() {
|
std::string NodeTree::DOTGraphStringHelper() {
|
||||||
std::string ourDOTRelation = "";
|
std::string ourDOTRelation = "";
|
||||||
for (int i = 0; i < children.size(); i++) {
|
for (int i = 0; i < children.size(); i++) {
|
||||||
ourDOTRelation += name + " -> " + children[i]->name + ";\n" + children[i]->DOTGraphStringHelper();
|
ourDOTRelation += getDOTName() + " -> " + children[i]->getDOTName() + ";\n" + children[i]->DOTGraphStringHelper();
|
||||||
}
|
}
|
||||||
return(ourDOTRelation);
|
return(ourDOTRelation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string NodeTree::getDOTName() {
|
||||||
|
if (name.at(0) == '\"')
|
||||||
|
return truncateEnd(name) + "_" + intToString(id) + "\""; //Note that terminals already have a quote in the front of their name, so we don't need to add one
|
||||||
|
return "\"" + name + "_" + intToString(id) + "\"";
|
||||||
|
}
|
||||||
15
src/util.cpp
15
src/util.cpp
@@ -5,3 +5,18 @@ std::string intToString(int theInt) {
|
|||||||
converter << theInt;
|
converter << theInt;
|
||||||
return converter.str();
|
return converter.str();
|
||||||
}
|
}
|
||||||
|
std::string truncateEnd(std::string to_truncate)
|
||||||
|
{
|
||||||
|
std::string to_return = "";
|
||||||
|
for (unsigned int i = 0; i < to_truncate.length()-1; i++)
|
||||||
|
to_return = to_return + to_truncate[i];
|
||||||
|
return to_return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string removeBeginning(std::string to_remove)
|
||||||
|
{
|
||||||
|
std::string to_return = "";
|
||||||
|
for (unsigned int i = 1; i < to_remove.length(); i++)
|
||||||
|
to_return = to_return + to_remove[i];
|
||||||
|
return to_return;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user