data: NameHierarchy class

* replaced vector of strings as name hierarchy by a new NameHierarchy class.
* Adjusted code in ASTVisitor, Storage and various test cases.
This commit is contained in:
malte_langkabel
2015-03-28 16:57:30 +01:00
parent 07ca387326
commit bdbd266a67
27 changed files with 485 additions and 283 deletions
+15
View File
@@ -0,0 +1,15 @@
#include "data/name/NameElement.h"
NameElement::NameElement(std::string name)
: m_name(name)
{
}
NameElement::~NameElement()
{
}
std::string NameElement::getFullName() const
{
return m_name;
}
+18
View File
@@ -0,0 +1,18 @@
#ifndef NAME_ELEMENT_H
#define NAME_ELEMENT_H
#include <string>
class NameElement
{
public:
NameElement(std::string name);
~NameElement();
std::string getFullName() const;
private:
std::string m_name;
};
#endif // NAME_ELEMENT_H
+48
View File
@@ -0,0 +1,48 @@
#include "data/name/NameHierarchy.h"
NameHierarchy::NameHierarchy()
{
}
NameHierarchy::~NameHierarchy()
{
}
void NameHierarchy::push(std::shared_ptr<NameElement> element)
{
m_elements.push_back(element);
}
void NameHierarchy::pop()
{
m_elements.pop_back();
}
std::shared_ptr<NameElement> NameHierarchy::back()
{
return m_elements.back();
}
std::shared_ptr<NameElement> NameHierarchy::operator[](size_t pos) const
{
return m_elements[pos];
}
size_t NameHierarchy::size() const
{
return m_elements.size();
}
std::string NameHierarchy::getFullName() const
{
std::string name;
for (int i = 0; i < m_elements.size(); i++)
{
name += m_elements[i]->getFullName();
if (i < m_elements.size() - 1)
{
name += "::";
}
}
return name;
}
+28
View File
@@ -0,0 +1,28 @@
#ifndef NAME_HIERARCHY_H
#define NAME_HIERARCHY_H
#include <memory>
#include <string>
#include <vector>
#include "data/name/NameElement.h"
class NameHierarchy
{
public:
NameHierarchy();
~NameHierarchy();
void push(std::shared_ptr<NameElement> element);
void pop();
std::shared_ptr<NameElement> back();
std::shared_ptr<NameElement> operator[](size_t pos) const;
size_t size() const;
std::string getFullName() const;
private:
std::vector<std::shared_ptr<NameElement>> m_elements;
};
#endif // NAME_ELEMENT_H