data: Moved EdgeComponent system to Token and extended it to cover all type specific Edge and Token fields

This change moves the EdgeComponent system to Token and redefines them as TokenComponents.
* Performance tests on the side showed that using typeid() in getComponent() is faster than dynamically casting every
pointer.
* The hasComponent() method was deliberately left out in the implementation, because it used to look up the right
component and discard it again. This check for presence can also be achieved by just using getComponent().
* The method addComponent() is protected in Token, so that Node and Edge can guard which Component is set on which type
by implementing specific setters for each Component.
* The GraphTestSuite was extended to include tests for the Component implementation (and missing tests for locationIds
in Token and copying of Node and Edge were added).
This commit is contained in:
Eberhard Graether
2014-07-26 02:26:59 +02:00
parent 4262be133a
commit 641acc2bde
29 changed files with 711 additions and 443 deletions
+10 -21
View File
@@ -9,6 +9,10 @@
#include "data/graph/Edge.h"
#include "data/graph/Token.h"
class TokenComponentConst;
class TokenComponentStatic;
class TokenComponentSignature;
class Node: public Token
{
public:
@@ -27,10 +31,9 @@ public:
};
Node(NodeType type, const std::string& name);
Node(const Node& other);
virtual ~Node();
std::shared_ptr<Node> createPlainCopy() const;
NodeType getType() const;
void setType(NodeType type);
@@ -54,36 +57,22 @@ public:
virtual bool isNode() const;
virtual bool isEdge() const;
// Additional field accessors for different NodeTypes.
void setAccess(Edge::AccessType access);
bool isConst() const;
void setConst(bool isConst);
bool isStatic() const;
void setStatic(bool isStatic);
std::string getSignature() const;
void setSignature(const std::string& signature);
// Component setters.
void addComponentConst(std::shared_ptr<TokenComponentConst> component);
void addComponentStatic(std::shared_ptr<TokenComponentStatic> component);
void addComponentSignature(std::shared_ptr<TokenComponentSignature> component);
// Logging.
std::string getTypeString(NodeType type) const;
std::string getAsString() const;
private:
// Constructor for plain copies.
Node(Id id, NodeType type, const std::string& name);
void operator=(const Node&);
NodeType m_type;
std::string m_name;
std::vector<Edge*> m_edges;
// Additional fields for different NodeTypes.
bool m_isConst;
bool m_isStatic;
std::string m_signature;
};
std::ostream& operator<<(std::ostream& ostream, const Node& node);