data: storing type modifiers in edges
- ASTVisitor uses DataType instead of string to pass on type information. - Edges can have EdgeComponents. - EdgeComponentDataType stores information that modifies the type a ...TYPE_OF edge points to. - EdgeComponentDataType can create a complete DataType using it's internal information. - Fixed a bug where DataTypeModifiers did not apply their qualifiers.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "data/graph/edgeComponent/EdgeComponent.h"
|
||||
#include "data/graph/Node.h"
|
||||
#include "utility/logging/logging.h"
|
||||
|
||||
@@ -33,6 +34,11 @@ std::shared_ptr<Edge> Edge::createPlainCopy(Node* from, Node* to) const
|
||||
|
||||
edge->setAccess(m_access);
|
||||
|
||||
for (std::shared_ptr<EdgeComponent> component: m_components)
|
||||
{
|
||||
edge->addComponent(component); // Todo: create a deep copy here
|
||||
}
|
||||
|
||||
return edge;
|
||||
}
|
||||
|
||||
@@ -132,6 +138,12 @@ std::string Edge::getAsString() const
|
||||
return str.str();
|
||||
}
|
||||
|
||||
void Edge::addComponent(std::shared_ptr<EdgeComponent> component)
|
||||
{
|
||||
m_components.push_back(component);
|
||||
component->setEdge(this);
|
||||
}
|
||||
|
||||
Edge::Edge(Id id, EdgeType type, Node* from, Node* to)
|
||||
: Token(id)
|
||||
, m_type(type)
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "data/graph/Token.h"
|
||||
|
||||
class Node;
|
||||
class EdgeComponent;
|
||||
|
||||
class Edge: public Token
|
||||
{
|
||||
@@ -53,6 +54,15 @@ public:
|
||||
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);
|
||||
@@ -64,8 +74,29 @@ private:
|
||||
|
||||
// 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
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
#include "data/graph/edgeComponent/EdgeComponent.h"
|
||||
|
||||
EdgeComponent::EdgeComponent()
|
||||
{
|
||||
}
|
||||
|
||||
EdgeComponent::~EdgeComponent()
|
||||
{
|
||||
}
|
||||
|
||||
void EdgeComponent::setEdge(Edge* edge)
|
||||
{
|
||||
m_edge = edge;
|
||||
}
|
||||
|
||||
Edge* EdgeComponent::getEdge() const
|
||||
{
|
||||
return m_edge;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
#ifndef EDGE_COMPONENT_H
|
||||
#define EDGE_COMPONENT_H
|
||||
|
||||
#include "data/graph/Edge.h"
|
||||
|
||||
|
||||
class EdgeComponent
|
||||
{
|
||||
public:
|
||||
EdgeComponent();
|
||||
virtual ~EdgeComponent();
|
||||
|
||||
void setEdge(Edge* edge);
|
||||
|
||||
protected:
|
||||
Edge* getEdge() const;
|
||||
|
||||
private:
|
||||
Edge* m_edge;
|
||||
};
|
||||
|
||||
|
||||
#endif // EDGE_COMPONENT_H
|
||||
@@ -0,0 +1,19 @@
|
||||
#include "data/graph/edgeComponent/EdgeComponentDataType.h"
|
||||
|
||||
#include "data/type/DataType.h"
|
||||
#include "data/graph/Node.h"
|
||||
|
||||
EdgeComponentDataType::EdgeComponentDataType(const DataTypeQualifierList qualifierList, const DataTypeModifierStack modifierStack)
|
||||
: m_qualifierList(qualifierList)
|
||||
, m_modifierStack(modifierStack)
|
||||
{
|
||||
}
|
||||
|
||||
EdgeComponentDataType::~EdgeComponentDataType()
|
||||
{
|
||||
}
|
||||
|
||||
DataType EdgeComponentDataType::getDataType() const
|
||||
{
|
||||
return DataType(getEdge()->getTo()->getName(), m_qualifierList, m_modifierStack);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
#ifndef EDGE_COMPONENT_DATA_TYPE_H
|
||||
#define EDGE_COMPONENT_DATA_TYPE_H
|
||||
|
||||
#include "data/graph/edgeComponent/EdgeComponent.h"
|
||||
|
||||
#include "data/type/DataTypeModifierStack.h"
|
||||
#include "data/type/DataTypeQualifierList.h"
|
||||
|
||||
class DataType;
|
||||
|
||||
class EdgeComponentDataType: public EdgeComponent
|
||||
{
|
||||
public:
|
||||
EdgeComponentDataType(const DataTypeQualifierList qualifierList, const DataTypeModifierStack modifierStack);
|
||||
virtual ~EdgeComponentDataType();
|
||||
|
||||
DataType getDataType() const;
|
||||
|
||||
private:
|
||||
const DataTypeQualifierList m_qualifierList;
|
||||
const DataTypeModifierStack m_modifierStack;
|
||||
};
|
||||
|
||||
|
||||
#endif // EDGE_COMPONENT_DATA_TYPE_H
|
||||
Reference in New Issue
Block a user