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
@@ -0,0 +1,5 @@
#include "data/graph/token_component/TokenComponent.h"
TokenComponent::~TokenComponent()
{
}
@@ -0,0 +1,13 @@
#ifndef TOKEN_COMPONENT_H
#define TOKEN_COMPONENT_H
#include <memory>
class TokenComponent
{
public:
virtual ~TokenComponent();
virtual std::shared_ptr<TokenComponent> copy() const = 0;
};
#endif // TOKEN_COMPONENT_H
@@ -0,0 +1,36 @@
#include "data/graph/token_component/TokenComponentAccess.h"
TokenComponentAccess::TokenComponentAccess(AccessType access)
: m_access(access)
{
}
TokenComponentAccess::~TokenComponentAccess()
{
}
std::shared_ptr<TokenComponent> TokenComponentAccess::copy() const
{
return std::make_shared<TokenComponentAccess>(*this);
}
TokenComponentAccess::AccessType TokenComponentAccess::getAccess() const
{
return m_access;
}
std::string TokenComponentAccess::getAccessString() const
{
switch (m_access)
{
case ACCESS_PUBLIC:
return "public";
case ACCESS_PROTECTED:
return "protected";
case ACCESS_PRIVATE:
return "private";
case ACCESS_NONE:
return "";
}
return "";
}
@@ -0,0 +1,33 @@
#ifndef TOKEN_COMPONENT_ACCESS
#define TOKEN_COMPONENT_ACCESS
#include <string>
#include "data/graph/token_component/TokenComponent.h"
class TokenComponentAccess
: public TokenComponent
{
public:
enum AccessType
{
ACCESS_PUBLIC,
ACCESS_PROTECTED,
ACCESS_PRIVATE,
ACCESS_NONE
};
TokenComponentAccess(AccessType access);
virtual ~TokenComponentAccess();
virtual std::shared_ptr<TokenComponent> copy() const;
AccessType getAccess() const;
std::string getAccessString() const;
private:
const AccessType m_access;
};
#endif // TOKEN_COMPONENT_ACCESS
@@ -0,0 +1,6 @@
#include "data/graph/token_component/TokenComponentConst.h"
std::shared_ptr<TokenComponent> TokenComponentConst::copy() const
{
return std::make_shared<TokenComponentConst>(*this);
}
@@ -0,0 +1,13 @@
#ifndef TOKEN_COMPONENT_CONST
#define TOKEN_COMPONENT_CONST
#include "data/graph/token_component/TokenComponent.h"
class TokenComponentConst
: public TokenComponent
{
public:
virtual std::shared_ptr<TokenComponent> copy() const;
};
#endif // TOKEN_COMPONENT_CONST
@@ -0,0 +1,30 @@
#include "data/graph/token_component/TokenComponentDataType.h"
#include "data/type/DataType.h"
TokenComponentDataType::TokenComponentDataType(
const DataTypeQualifierList qualifierList, const DataTypeModifierStack modifierStack
)
: m_qualifierList(qualifierList)
, m_modifierStack(modifierStack)
{
}
TokenComponentDataType::~TokenComponentDataType()
{
}
std::shared_ptr<TokenComponent> TokenComponentDataType::copy() const
{
return std::make_shared<TokenComponentDataType>(*this);
}
DataType TokenComponentDataType::getDataType(const std::string& typeName) const
{
return DataType(typeName, m_qualifierList, m_modifierStack);
}
std::string TokenComponentDataType::getQualifiedTypeName(const std::string& typeName) const
{
return m_modifierStack.applyTo(m_qualifierList.applyTo(typeName));
}
@@ -0,0 +1,27 @@
#ifndef TOKEN_COMPONENT_DATA_TYPE
#define TOKEN_COMPONENT_DATA_TYPE
#include "data/graph/token_component/TokenComponent.h"
#include "data/type/DataTypeModifierStack.h"
#include "data/type/DataTypeQualifierList.h"
class DataType;
class TokenComponentDataType
: public TokenComponent
{
public:
TokenComponentDataType(const DataTypeQualifierList qualifierList, const DataTypeModifierStack modifierStack);
virtual ~TokenComponentDataType();
virtual std::shared_ptr<TokenComponent> copy() const;
DataType getDataType(const std::string& typeName) const;
std::string getQualifiedTypeName(const std::string& typeName) const;
private:
const DataTypeQualifierList m_qualifierList;
const DataTypeModifierStack m_modifierStack;
};
#endif // TOKEN_COMPONENT_DATA_TYPE
@@ -0,0 +1,20 @@
#include "data/graph/token_component/TokenComponentSignature.h"
TokenComponentSignature::TokenComponentSignature(std::string signature)
: m_signature(signature)
{
}
TokenComponentSignature::~TokenComponentSignature()
{
}
std::shared_ptr<TokenComponent> TokenComponentSignature::copy() const
{
return std::make_shared<TokenComponentSignature>(*this);
}
const std::string& TokenComponentSignature::getSignature() const
{
return m_signature;
}
@@ -0,0 +1,23 @@
#ifndef TOKEN_COMPONENT_SIGNATURE
#define TOKEN_COMPONENT_SIGNATURE
#include <string>
#include "data/graph/token_component/TokenComponent.h"
class TokenComponentSignature
: public TokenComponent
{
public:
TokenComponentSignature(std::string signature);
virtual ~TokenComponentSignature();
virtual std::shared_ptr<TokenComponent> copy() const;
const std::string& getSignature() const;
private:
const std::string m_signature;
};
#endif // TOKEN_COMPONENT_SIGNATURE
@@ -0,0 +1,6 @@
#include "data/graph/token_component/TokenComponentStatic.h"
std::shared_ptr<TokenComponent> TokenComponentStatic::copy() const
{
return std::make_shared<TokenComponentStatic>(*this);
}
@@ -0,0 +1,13 @@
#ifndef TOKEN_COMPONENT_STATIC
#define TOKEN_COMPONENT_STATIC
#include "data/graph/token_component/TokenComponent.h"
class TokenComponentStatic
: public TokenComponent
{
public:
virtual std::shared_ptr<TokenComponent> copy() const;
};
#endif // TOKEN_COMPONENT_STATIC