logic: moved Storage into Project
Moved Storage instantiation into the Project. Storage access is still handled via the GraphAccess and LocationAccess interfaces, but the ComponentFactory now only serves proxy implementations of these access classes. Project is responsible for setting the subject of the proxies to the current Storage instance.
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
#include "data/access/GraphAccessProxy.h"
|
||||
|
||||
#include "utility/logging/logging.h"
|
||||
|
||||
GraphAccessProxy::GraphAccessProxy()
|
||||
: m_subject(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
GraphAccessProxy::~GraphAccessProxy()
|
||||
{
|
||||
}
|
||||
|
||||
bool GraphAccessProxy::hasSubject() const
|
||||
{
|
||||
if (m_subject)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
LOG_ERROR("GraphAccessProxy has no subject.");
|
||||
return false;
|
||||
}
|
||||
|
||||
void GraphAccessProxy::setSubject(GraphAccess* subject)
|
||||
{
|
||||
m_subject = subject;
|
||||
}
|
||||
|
||||
Id GraphAccessProxy::getIdForNodeWithName(const std::string& name) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getIdForNodeWithName(name);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string GraphAccessProxy::getNameForNodeWithId(Id id) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getNameForNodeWithId(id);
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
std::vector<std::string> GraphAccessProxy::getNamesForNodesWithNamePrefix(const std::string& prefix) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getNamesForNodesWithNamePrefix(prefix);
|
||||
}
|
||||
|
||||
return std::vector<std::string>();
|
||||
}
|
||||
|
||||
std::vector<Id> GraphAccessProxy::getIdsOfNeighbours(const Id id) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getIdsOfNeighbours(id);
|
||||
}
|
||||
|
||||
return std::vector<Id>();
|
||||
}
|
||||
|
||||
std::vector<std::pair<Id, Id>> GraphAccessProxy::getConnectedEdges(const Id id) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getConnectedEdges(id);
|
||||
}
|
||||
|
||||
return std::vector<std::pair<Id, Id>>();
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
#ifndef GRAPH_ACCESS_PROXY_H
|
||||
#define GRAPH_ACCESS_PROXY_H
|
||||
|
||||
#include "data/access/GraphAccess.h"
|
||||
|
||||
class GraphAccessProxy: public GraphAccess
|
||||
{
|
||||
public:
|
||||
GraphAccessProxy();
|
||||
virtual ~GraphAccessProxy();
|
||||
|
||||
bool hasSubject() const;
|
||||
void setSubject(GraphAccess* subject);
|
||||
|
||||
// GraphAccess implementation
|
||||
virtual Id getIdForNodeWithName(const std::string& name) const;
|
||||
virtual std::string getNameForNodeWithId(Id id) const;
|
||||
virtual std::vector<std::string> getNamesForNodesWithNamePrefix(const std::string& prefix) const;
|
||||
virtual std::vector<Id> getIdsOfNeighbours(const Id id) const;
|
||||
virtual std::vector<std::pair<Id, Id>> getConnectedEdges(const Id id) const;
|
||||
|
||||
private:
|
||||
GraphAccess* m_subject;
|
||||
};
|
||||
|
||||
#endif // GRAPH_ACCESS_PROXY_H
|
||||
@@ -0,0 +1,53 @@
|
||||
#include "data/access/LocationAccessProxy.h"
|
||||
|
||||
#include "data/location/TokenLocationCollection.h"
|
||||
#include "data/location/TokenLocationFile.h"
|
||||
#include "utility/logging/logging.h"
|
||||
|
||||
LocationAccessProxy::LocationAccessProxy()
|
||||
: m_subject(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
LocationAccessProxy::~LocationAccessProxy()
|
||||
{
|
||||
}
|
||||
|
||||
bool LocationAccessProxy::hasSubject() const
|
||||
{
|
||||
if (m_subject)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
LOG_ERROR("LocationAccessProxy has no subject.");
|
||||
return false;
|
||||
}
|
||||
|
||||
void LocationAccessProxy::setSubject(LocationAccess* subject)
|
||||
{
|
||||
m_subject = subject;
|
||||
}
|
||||
|
||||
TokenLocationCollection LocationAccessProxy::getTokenLocationsForTokenId(Id id) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getTokenLocationsForTokenId(id);
|
||||
}
|
||||
|
||||
return TokenLocationCollection();
|
||||
}
|
||||
|
||||
|
||||
TokenLocationFile LocationAccessProxy::getTokenLocationsForLinesInFile(
|
||||
const std::string& fileName, unsigned int firstLineNumber, unsigned int lastLineNumber
|
||||
) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getTokenLocationsForLinesInFile(fileName, firstLineNumber, lastLineNumber);
|
||||
}
|
||||
|
||||
return TokenLocationFile("");
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
#ifndef LOCATION_ACCESS_PROXY_H
|
||||
#define LOCATION_ACCESS_PROXY_H
|
||||
|
||||
#include "data/access/LocationAccess.h"
|
||||
|
||||
class LocationAccessProxy: public LocationAccess
|
||||
{
|
||||
public:
|
||||
LocationAccessProxy();
|
||||
virtual ~LocationAccessProxy();
|
||||
|
||||
bool hasSubject() const;
|
||||
void setSubject(LocationAccess* subject);
|
||||
|
||||
// LocationAccess implementation
|
||||
virtual TokenLocationCollection getTokenLocationsForTokenId(Id id) const;
|
||||
virtual TokenLocationFile getTokenLocationsForLinesInFile(
|
||||
const std::string& fileName, unsigned int firstLineNumber, unsigned int lastLineNumber
|
||||
) const;
|
||||
|
||||
private:
|
||||
LocationAccess* m_subject;
|
||||
};
|
||||
|
||||
#endif // LOCATION_ACCESS_PROXY_H
|
||||
Reference in New Issue
Block a user