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
+7 -50
View File
@@ -7,7 +7,8 @@
#include "data/graph/Token.h"
class Node;
class EdgeComponent;
class TokenComponentAccess;
class TokenComponentDataType;
class Edge: public Token
{
@@ -24,19 +25,10 @@ public:
EDGE_TYPEDEF_OF
};
enum AccessType
{
ACCESS_PUBLIC,
ACCESS_PROTECTED,
ACCESS_PRIVATE,
ACCESS_NONE
};
Edge(EdgeType type, Node* from, Node* to);
Edge(const Edge& other, Node* from, Node* to);
virtual ~Edge();
std::shared_ptr<Edge> createPlainCopy(Node* from, Node* to) const;
EdgeType getType() const;
Node* getFrom() const;
@@ -46,58 +38,23 @@ public:
virtual bool isNode() const;
virtual bool isEdge() const;
// Additional field accessors for different EdgeTypes.
AccessType getAccess() const;
void setAccess(AccessType access);
// Component setters
void addComponentAccess(std::shared_ptr<TokenComponentAccess> component);
void addComponentDataType(std::shared_ptr<TokenComponentDataType> component);
// Logging.
std::string getTypeString() const;
std::string getAccessString() const;
std::string getAsString() const;
void addComponent(std::shared_ptr<EdgeComponent> component);
template <typename ComponentType>
std::shared_ptr<ComponentType> getComponent() const;
template <typename ComponentType>
bool hasComponent() const;
private:
// Constructor for plain copies.
Edge(Id id, EdgeType type, Node* from, Node* to);
void operator=(const Node&);
const EdgeType m_type;
Node* const m_from;
Node* const m_to;
// Additional fields for different EdgeTypes.
AccessType m_access;
std::vector<std::shared_ptr<EdgeComponent>> m_components;
};
template <typename ComponentType>
std::shared_ptr<ComponentType> Edge::getComponent() const
{
std::shared_ptr<ComponentType> component;
for (std::shared_ptr<EdgeComponent> c: m_components)
{
component = std::dynamic_pointer_cast<ComponentType>(c);
if (component)
break;
}
return component;
}
template <typename ComponentType>
bool Edge::hasComponent() const
{
return (getComponent<ComponentType>());
}
std::ostream& operator<<(std::ostream& ostream, const Edge& edge);
#endif // EDGE_H