logic: combined GraphAccess and LocationAccess to StorageAccess
Having only one access point to the Storage will simplify caching and parallelisation in the future. Also the two accesses were never really independent of each other anyways, because in some cases they had to access both data sets.
This commit is contained in:
@@ -6,8 +6,7 @@
|
||||
|
||||
#include "utility/file/FilePath.h"
|
||||
|
||||
#include "data/access/GraphAccess.h"
|
||||
#include "data/access/LocationAccess.h"
|
||||
#include "data/access/StorageAccess.h"
|
||||
#include "data/graph/StorageGraph.h"
|
||||
#include "data/graph/token_component/TokenComponentAbstraction.h"
|
||||
#include "data/graph/token_component/TokenComponentAccess.h"
|
||||
@@ -17,8 +16,7 @@
|
||||
|
||||
class Storage
|
||||
: public ParserClient
|
||||
, public GraphAccess
|
||||
, public LocationAccess
|
||||
, public StorageAccess
|
||||
{
|
||||
public:
|
||||
Storage();
|
||||
@@ -107,7 +105,7 @@ public:
|
||||
virtual Id onFileIncludeParsed(
|
||||
const ParseLocation& location, const std::string& filePath, const std::string& includedPath);
|
||||
|
||||
// GraphAccess implementation
|
||||
// StorageAccess implementation
|
||||
virtual Id getIdForNodeWithName(const std::string& fullName) const;
|
||||
virtual std::string getNameForNodeWithId(Id id) const;
|
||||
virtual Node::NodeType getNodeTypeForNodeWithId(Id id) const;
|
||||
@@ -121,7 +119,6 @@ public:
|
||||
|
||||
virtual std::vector<Id> getTokenIdsForQuery(std::string query) const;
|
||||
|
||||
// LocationAccess implementation
|
||||
virtual TokenLocationCollection getTokenLocationsForTokenIds(const std::vector<Id>& tokenIds) const;
|
||||
virtual TokenLocationFile getTokenLocationsForFile(const std::string& filePath) const;
|
||||
virtual TokenLocationFile getTokenLocationsForLinesInFile(
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
#include "data/access/GraphAccess.h"
|
||||
|
||||
GraphAccess::~GraphAccess()
|
||||
{
|
||||
}
|
||||
@@ -1,109 +0,0 @@
|
||||
#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;
|
||||
}
|
||||
|
||||
Node::NodeType GraphAccessProxy::getNodeTypeForNodeWithId(Id id) const
|
||||
{
|
||||
if(hasSubject())
|
||||
{
|
||||
return m_subject->getNodeTypeForNodeWithId(id);
|
||||
}
|
||||
return Node::NODE_UNDEFINED;
|
||||
}
|
||||
|
||||
std::string GraphAccessProxy::getNameForNodeWithId(Id id) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getNameForNodeWithId(id);
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
std::vector<SearchMatch> GraphAccessProxy::getAutocompletionMatches(
|
||||
const std::string& query,
|
||||
const std::string& word
|
||||
) const {
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getAutocompletionMatches(query, word);
|
||||
}
|
||||
|
||||
return std::vector<SearchMatch>();
|
||||
}
|
||||
|
||||
std::shared_ptr<Graph> GraphAccessProxy::getGraphForActiveTokenIds(const std::vector<Id>& tokenIds) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getGraphForActiveTokenIds(tokenIds);
|
||||
}
|
||||
|
||||
return std::make_shared<Graph>();
|
||||
}
|
||||
|
||||
std::vector<Id> GraphAccessProxy::getActiveTokenIdsForId(Id tokenId, Id* delcarationId) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getActiveTokenIdsForId(tokenId, delcarationId);
|
||||
}
|
||||
|
||||
return std::vector<Id>();
|
||||
}
|
||||
|
||||
std::vector<Id> GraphAccessProxy::getActiveTokenIdsForLocationId(Id locationId) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getActiveTokenIdsForLocationId(locationId);
|
||||
}
|
||||
|
||||
return std::vector<Id>();
|
||||
}
|
||||
|
||||
std::vector<Id> GraphAccessProxy::getTokenIdsForQuery(std::string query) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getTokenIdsForQuery(query);
|
||||
}
|
||||
|
||||
return std::vector<Id>();
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
#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 Node::NodeType getNodeTypeForNodeWithId(Id id) const;
|
||||
virtual std::vector<SearchMatch> getAutocompletionMatches(
|
||||
const std::string& query, const std::string& word) const;
|
||||
|
||||
virtual std::shared_ptr<Graph> getGraphForActiveTokenIds(const std::vector<Id>& tokenIds) const;
|
||||
|
||||
virtual std::vector<Id> getActiveTokenIdsForId(Id tokenId, Id* declarationId) const;
|
||||
virtual std::vector<Id> getActiveTokenIdsForLocationId(Id locationId) const;
|
||||
|
||||
virtual std::vector<Id> getTokenIdsForQuery(std::string query) const;
|
||||
|
||||
private:
|
||||
GraphAccess* m_subject;
|
||||
};
|
||||
|
||||
#endif // GRAPH_ACCESS_PROXY_H
|
||||
@@ -1,5 +0,0 @@
|
||||
#include "data/access/LocationAccess.h"
|
||||
|
||||
LocationAccess::~LocationAccess()
|
||||
{
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
#ifndef LOCATION_ACCESS_H
|
||||
#define LOCATION_ACCESS_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "utility/types.h"
|
||||
|
||||
class TokenLocationCollection;
|
||||
class TokenLocationFile;
|
||||
|
||||
class LocationAccess
|
||||
{
|
||||
public:
|
||||
virtual ~LocationAccess();
|
||||
virtual TokenLocationCollection getTokenLocationsForTokenIds(const std::vector<Id>& tokenIds) const = 0;
|
||||
virtual TokenLocationFile getTokenLocationsForFile(const std::string& filePath) const = 0;
|
||||
virtual TokenLocationFile getTokenLocationsForLinesInFile(
|
||||
const std::string& filePath, uint firstLineNumber, uint lastLineNumber
|
||||
) const = 0;
|
||||
|
||||
virtual TokenLocationCollection getErrorTokenLocations(std::vector<std::string>* errorMessages) const = 0;
|
||||
};
|
||||
|
||||
|
||||
#endif // LOCATION_ACCESS_H
|
||||
@@ -1,72 +0,0 @@
|
||||
#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::getTokenLocationsForTokenIds(const std::vector<Id>& tokenIds) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getTokenLocationsForTokenIds(tokenIds);
|
||||
}
|
||||
|
||||
return TokenLocationCollection();
|
||||
}
|
||||
|
||||
TokenLocationFile LocationAccessProxy::getTokenLocationsForFile(const std::string& filePath) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getTokenLocationsForFile(filePath);
|
||||
}
|
||||
|
||||
return TokenLocationFile("");
|
||||
}
|
||||
|
||||
TokenLocationFile LocationAccessProxy::getTokenLocationsForLinesInFile(
|
||||
const std::string& filePath, uint firstLineNumber, uint lastLineNumber
|
||||
) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getTokenLocationsForLinesInFile(filePath, firstLineNumber, lastLineNumber);
|
||||
}
|
||||
|
||||
return TokenLocationFile("");
|
||||
}
|
||||
|
||||
TokenLocationCollection LocationAccessProxy::getErrorTokenLocations(std::vector<std::string>* errorMessages) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getErrorTokenLocations(errorMessages);
|
||||
}
|
||||
|
||||
return TokenLocationCollection();
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
#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 getTokenLocationsForTokenIds(const std::vector<Id>& tokenIds) const;
|
||||
virtual TokenLocationFile getTokenLocationsForFile(const std::string& filePath) const;
|
||||
virtual TokenLocationFile getTokenLocationsForLinesInFile(
|
||||
const std::string& filePath, uint firstLineNumber, uint lastLineNumber
|
||||
) const;
|
||||
|
||||
virtual TokenLocationCollection getErrorTokenLocations(std::vector<std::string>* errorMessages) const;
|
||||
|
||||
private:
|
||||
LocationAccess* m_subject;
|
||||
};
|
||||
|
||||
#endif // LOCATION_ACCESS_PROXY_H
|
||||
@@ -0,0 +1,5 @@
|
||||
#include "data/access/StorageAccess.h"
|
||||
|
||||
StorageAccess::~StorageAccess()
|
||||
{
|
||||
}
|
||||
@@ -1,18 +1,23 @@
|
||||
#ifndef GRAPH_ACCESS_H
|
||||
#define GRAPH_ACCESS_H
|
||||
#ifndef STORAGE_ACCESS_H
|
||||
#define STORAGE_ACCESS_H
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "data/graph/Graph.h"
|
||||
#include "data/search/SearchMatch.h"
|
||||
#include "utility/types.h"
|
||||
|
||||
class GraphAccess
|
||||
#include "data/graph/Node.h"
|
||||
#include "data/search/SearchMatch.h"
|
||||
|
||||
class Graph;
|
||||
class TokenLocationCollection;
|
||||
class TokenLocationFile;
|
||||
|
||||
class StorageAccess
|
||||
{
|
||||
public:
|
||||
virtual ~GraphAccess();
|
||||
virtual ~StorageAccess();
|
||||
|
||||
virtual Id getIdForNodeWithName(const std::string& name) const = 0;
|
||||
virtual std::string getNameForNodeWithId(Id id) const = 0;
|
||||
@@ -26,6 +31,13 @@ public:
|
||||
virtual std::vector<Id> getActiveTokenIdsForLocationId(Id locationId) const = 0;
|
||||
|
||||
virtual std::vector<Id> getTokenIdsForQuery(std::string query) const = 0;
|
||||
|
||||
virtual TokenLocationCollection getTokenLocationsForTokenIds(const std::vector<Id>& tokenIds) const = 0;
|
||||
virtual TokenLocationFile getTokenLocationsForFile(const std::string& filePath) const = 0;
|
||||
virtual TokenLocationFile getTokenLocationsForLinesInFile(
|
||||
const std::string& filePath, uint firstLineNumber, uint lastLineNumber) const = 0;
|
||||
|
||||
virtual TokenLocationCollection getErrorTokenLocations(std::vector<std::string>* errorMessages) const = 0;
|
||||
};
|
||||
|
||||
#endif // GRAPH_ACCESS_H
|
||||
#endif // STORAGE_ACCESS_H
|
||||
@@ -0,0 +1,155 @@
|
||||
#include "data/access/StorageAccessProxy.h"
|
||||
|
||||
#include "utility/logging/logging.h"
|
||||
|
||||
#include "data/graph/Graph.h"
|
||||
#include "data/location/TokenLocationCollection.h"
|
||||
#include "data/location/TokenLocationFile.h"
|
||||
|
||||
StorageAccessProxy::StorageAccessProxy()
|
||||
: m_subject(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
StorageAccessProxy::~StorageAccessProxy()
|
||||
{
|
||||
}
|
||||
|
||||
bool StorageAccessProxy::hasSubject() const
|
||||
{
|
||||
if (m_subject)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
LOG_ERROR("StorageAccessProxy has no subject.");
|
||||
return false;
|
||||
}
|
||||
|
||||
void StorageAccessProxy::setSubject(StorageAccess* subject)
|
||||
{
|
||||
m_subject = subject;
|
||||
}
|
||||
|
||||
Id StorageAccessProxy::getIdForNodeWithName(const std::string& name) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getIdForNodeWithName(name);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Node::NodeType StorageAccessProxy::getNodeTypeForNodeWithId(Id id) const
|
||||
{
|
||||
if(hasSubject())
|
||||
{
|
||||
return m_subject->getNodeTypeForNodeWithId(id);
|
||||
}
|
||||
return Node::NODE_UNDEFINED;
|
||||
}
|
||||
|
||||
std::string StorageAccessProxy::getNameForNodeWithId(Id id) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getNameForNodeWithId(id);
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
std::vector<SearchMatch> StorageAccessProxy::getAutocompletionMatches(
|
||||
const std::string& query,
|
||||
const std::string& word
|
||||
) const {
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getAutocompletionMatches(query, word);
|
||||
}
|
||||
|
||||
return std::vector<SearchMatch>();
|
||||
}
|
||||
|
||||
std::shared_ptr<Graph> StorageAccessProxy::getGraphForActiveTokenIds(const std::vector<Id>& tokenIds) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getGraphForActiveTokenIds(tokenIds);
|
||||
}
|
||||
|
||||
return std::make_shared<Graph>();
|
||||
}
|
||||
|
||||
std::vector<Id> StorageAccessProxy::getActiveTokenIdsForId(Id tokenId, Id* delcarationId) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getActiveTokenIdsForId(tokenId, delcarationId);
|
||||
}
|
||||
|
||||
return std::vector<Id>();
|
||||
}
|
||||
|
||||
std::vector<Id> StorageAccessProxy::getActiveTokenIdsForLocationId(Id locationId) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getActiveTokenIdsForLocationId(locationId);
|
||||
}
|
||||
|
||||
return std::vector<Id>();
|
||||
}
|
||||
|
||||
std::vector<Id> StorageAccessProxy::getTokenIdsForQuery(std::string query) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getTokenIdsForQuery(query);
|
||||
}
|
||||
|
||||
return std::vector<Id>();
|
||||
}
|
||||
|
||||
TokenLocationCollection StorageAccessProxy::getTokenLocationsForTokenIds(const std::vector<Id>& tokenIds) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getTokenLocationsForTokenIds(tokenIds);
|
||||
}
|
||||
|
||||
return TokenLocationCollection();
|
||||
}
|
||||
|
||||
TokenLocationFile StorageAccessProxy::getTokenLocationsForFile(const std::string& filePath) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getTokenLocationsForFile(filePath);
|
||||
}
|
||||
|
||||
return TokenLocationFile("");
|
||||
}
|
||||
|
||||
TokenLocationFile StorageAccessProxy::getTokenLocationsForLinesInFile(
|
||||
const std::string& filePath, uint firstLineNumber, uint lastLineNumber
|
||||
) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getTokenLocationsForLinesInFile(filePath, firstLineNumber, lastLineNumber);
|
||||
}
|
||||
|
||||
return TokenLocationFile("");
|
||||
}
|
||||
|
||||
TokenLocationCollection StorageAccessProxy::getErrorTokenLocations(std::vector<std::string>* errorMessages) const
|
||||
{
|
||||
if (hasSubject())
|
||||
{
|
||||
return m_subject->getErrorTokenLocations(errorMessages);
|
||||
}
|
||||
|
||||
return TokenLocationCollection();
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
#ifndef STORAGE_ACCESS_PROXY_H
|
||||
#define STORAGE_ACCESS_PROXY_H
|
||||
|
||||
#include "data/access/StorageAccess.h"
|
||||
|
||||
class StorageAccessProxy: public StorageAccess
|
||||
{
|
||||
public:
|
||||
StorageAccessProxy();
|
||||
virtual ~StorageAccessProxy();
|
||||
|
||||
bool hasSubject() const;
|
||||
void setSubject(StorageAccess* subject);
|
||||
|
||||
// StorageAccess implementation
|
||||
virtual Id getIdForNodeWithName(const std::string& name) const;
|
||||
virtual std::string getNameForNodeWithId(Id id) const;
|
||||
virtual Node::NodeType getNodeTypeForNodeWithId(Id id) const;
|
||||
virtual std::vector<SearchMatch> getAutocompletionMatches(
|
||||
const std::string& query, const std::string& word) const;
|
||||
|
||||
virtual std::shared_ptr<Graph> getGraphForActiveTokenIds(const std::vector<Id>& tokenIds) const;
|
||||
|
||||
virtual std::vector<Id> getActiveTokenIdsForId(Id tokenId, Id* declarationId) const;
|
||||
virtual std::vector<Id> getActiveTokenIdsForLocationId(Id locationId) const;
|
||||
|
||||
virtual std::vector<Id> getTokenIdsForQuery(std::string query) const;
|
||||
|
||||
virtual TokenLocationCollection getTokenLocationsForTokenIds(const std::vector<Id>& tokenIds) const;
|
||||
virtual TokenLocationFile getTokenLocationsForFile(const std::string& filePath) const;
|
||||
virtual TokenLocationFile getTokenLocationsForLinesInFile(
|
||||
const std::string& filePath, uint firstLineNumber, uint lastLineNumber
|
||||
) const;
|
||||
|
||||
virtual TokenLocationCollection getErrorTokenLocations(std::vector<std::string>* errorMessages) const;
|
||||
|
||||
private:
|
||||
StorageAccess* m_subject;
|
||||
};
|
||||
|
||||
#endif // STORAGE_ACCESS_PROXY_H
|
||||
Reference in New Issue
Block a user