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:
Eberhard Graether
2015-03-17 16:38:17 +01:00
parent 52baca3962
commit e3f1f004a0
27 changed files with 290 additions and 387 deletions
+6 -9
View File
@@ -6,8 +6,7 @@
#include "component/view/MainView.h"
#include "component/view/ViewFactory.h"
#include "data/access/GraphAccessProxy.h"
#include "data/access/LocationAccessProxy.h"
#include "data/access/StorageAccessProxy.h"
#include "settings/ApplicationSettings.h"
std::shared_ptr<Application> Application::create(ViewFactory* viewFactory)
@@ -17,11 +16,9 @@ std::shared_ptr<Application> Application::create(ViewFactory* viewFactory)
std::shared_ptr<Application> ptr(new Application());
ptr->m_graphAccessProxy = std::make_shared<GraphAccessProxy>();
ptr->m_locationAccessProxy = std::make_shared<LocationAccessProxy>();
ptr->m_storageAccessProxy = std::make_shared<StorageAccessProxy>();
ptr->m_componentManager = ComponentManager::create(
viewFactory, ptr->m_graphAccessProxy.get(), ptr->m_locationAccessProxy.get());
ptr->m_componentManager = ComponentManager::create(viewFactory, ptr->m_storageAccessProxy.get());
ptr->m_mainView = viewFactory->createMainView();
ptr->m_componentManager->setup(ptr->m_mainView.get());
@@ -53,7 +50,7 @@ Application::~Application()
void Application::loadProject(const std::string& projectSettingsFilePath)
{
m_project = Project::create(m_graphAccessProxy.get(), m_locationAccessProxy.get());
m_project = Project::create(m_storageAccessProxy.get());
m_project->loadProjectSettings(projectSettingsFilePath);
m_project->parseCode();
@@ -61,7 +58,7 @@ void Application::loadProject(const std::string& projectSettingsFilePath)
void Application::loadSource(const std::string& sourceDirectoryPath)
{
m_project = Project::create(m_graphAccessProxy.get(), m_locationAccessProxy.get());
m_project = Project::create(m_storageAccessProxy.get());
m_project->clearProjectSettings();
m_project->setSourceDirectoryPath(sourceDirectoryPath);
@@ -88,7 +85,7 @@ void Application::handleMessage(MessageFinishedParsing* message)
return;
}
Id mainId = m_graphAccessProxy->getIdForNodeWithName("main");
Id mainId = m_storageAccessProxy->getIdForNodeWithName("main");
if (!mainId)
{
+2 -4
View File
@@ -14,8 +14,7 @@
class ViewFactory;
class MainView;
class GraphAccessProxy;
class LocationAccessProxy;
class StorageAccessProxy;
class Application
: public MessageListener<MessageFinishedParsing>
@@ -44,8 +43,7 @@ private:
virtual void handleMessage(MessageSaveProject* message);
std::shared_ptr<Project> m_project;
std::shared_ptr<GraphAccessProxy> m_graphAccessProxy;
std::shared_ptr<LocationAccessProxy> m_locationAccessProxy;
std::shared_ptr<StorageAccessProxy> m_storageAccessProxy;
std::shared_ptr<MainView> m_mainView;
std::shared_ptr<ComponentManager> m_componentManager;
+4 -8
View File
@@ -80,14 +80,10 @@ add_files(
component/ComponentManager.cpp
component/ComponentManager.h
data/access/LocationAccess.cpp
data/access/LocationAccess.h
data/access/LocationAccessProxy.cpp
data/access/LocationAccessProxy.h
data/access/GraphAccess.cpp
data/access/GraphAccess.h
data/access/GraphAccessProxy.cpp
data/access/GraphAccessProxy.h
data/access/StorageAccess.cpp
data/access/StorageAccess.h
data/access/StorageAccessProxy.cpp
data/access/StorageAccessProxy.h
data/graph/filter/GraphFilter.cpp
data/graph/filter/GraphFilter.h
+6 -10
View File
@@ -4,16 +4,15 @@
#include "utility/messaging/type/MessageFinishedParsing.h"
#include "utility/utility.h"
#include "data/access/GraphAccessProxy.h"
#include "data/access/LocationAccessProxy.h"
#include "data/access/StorageAccessProxy.h"
#include "data/graph/Token.h"
#include "data/parser/cxx/CxxParser.h"
#include "settings/ApplicationSettings.h"
#include "settings/ProjectSettings.h"
std::shared_ptr<Project> Project::create(GraphAccessProxy* graphAccessProxy, LocationAccessProxy* locationAccessProxy)
std::shared_ptr<Project> Project::create(StorageAccessProxy* storageAccessProxy)
{
std::shared_ptr<Project> ptr(new Project(graphAccessProxy, locationAccessProxy));
std::shared_ptr<Project> ptr(new Project(storageAccessProxy));
ptr->clearStorage();
return ptr;
}
@@ -66,9 +65,7 @@ bool Project::setSourceDirectoryPath(const std::string& sourceDirectoryPath)
void Project::clearStorage()
{
m_storage = std::make_shared<Storage>();
m_graphAccessProxy->setSubject(m_storage.get());
m_locationAccessProxy->setSubject(m_storage.get());
m_storageAccessProxy->setSubject(m_storage.get());
Token::resetNextId();
}
@@ -149,8 +146,7 @@ void Project::parseCode()
MessageFinishedParsing(filesToParse.size(), duration, m_storage->getErrorCount()).dispatch();
}
Project::Project(GraphAccessProxy* graphAccessProxy, LocationAccessProxy* locationAccessProxy)
: m_graphAccessProxy(graphAccessProxy)
, m_locationAccessProxy(locationAccessProxy)
Project::Project(StorageAccessProxy* storageAccessProxy)
: m_storageAccessProxy(storageAccessProxy)
{
}
+4 -6
View File
@@ -7,13 +7,12 @@
#include "data/Storage.h"
class GraphAccessProxy;
class LocationAccessProxy;
class StorageAccessProxy;
class Project
{
public:
static std::shared_ptr<Project> create(GraphAccessProxy* graphAccessProxy, LocationAccessProxy* locationAccessProxy);
static std::shared_ptr<Project> create(StorageAccessProxy* storageAccessProxy);
~Project();
@@ -27,14 +26,13 @@ public:
void parseCode();
private:
Project(GraphAccessProxy* graphAccessProxy, LocationAccessProxy* locationAccessProxy);
Project(StorageAccessProxy* storageAccessProxy);
Project(const Project&);
Project operator=(const Project&);
std::string m_projectSettingsFilepath;
GraphAccessProxy* const m_graphAccessProxy;
LocationAccessProxy* const m_locationAccessProxy;
StorageAccessProxy* const m_storageAccessProxy;
std::shared_ptr<Storage> m_storage;
std::shared_ptr<FileManager> m_fileManager;
+6 -8
View File
@@ -15,14 +15,12 @@
#include "component/view/UndoRedoView.h"
#include "component/view/ViewFactory.h"
std::shared_ptr<ComponentFactory> ComponentFactory::create(
ViewFactory* viewFactory, GraphAccess* graphAccess, LocationAccess* locationAccess
){
std::shared_ptr<ComponentFactory> ComponentFactory::create(ViewFactory* viewFactory, StorageAccess* storageAccess)
{
std::shared_ptr<ComponentFactory> ptr(new ComponentFactory());
ptr->m_viewFactory = viewFactory;
ptr->m_graphAccess = graphAccess;
ptr->m_locationAccess = locationAccess;
ptr->m_storageAccess = storageAccess;
return ptr;
}
@@ -39,7 +37,7 @@ ViewFactory* ComponentFactory::getViewFactory() const
std::shared_ptr<Component> ComponentFactory::createCodeComponent(ViewLayout* viewLayout)
{
std::shared_ptr<CodeView> view = m_viewFactory->createCodeView(viewLayout);
std::shared_ptr<CodeController> controller = std::make_shared<CodeController>(m_graphAccess, m_locationAccess);
std::shared_ptr<CodeController> controller = std::make_shared<CodeController>(m_storageAccess);
return std::make_shared<Component>(view, controller);
}
@@ -47,7 +45,7 @@ std::shared_ptr<Component> ComponentFactory::createCodeComponent(ViewLayout* vie
std::shared_ptr<Component> ComponentFactory::createGraphComponent(ViewLayout* viewLayout)
{
std::shared_ptr<View> view = m_viewFactory->createGraphView(viewLayout);
std::shared_ptr<GraphController> controller = std::make_shared<GraphController>(m_graphAccess);
std::shared_ptr<GraphController> controller = std::make_shared<GraphController>(m_storageAccess);
return std::make_shared<Component>(view, controller);
}
@@ -63,7 +61,7 @@ std::shared_ptr<Component> ComponentFactory::createRefreshComponent(ViewLayout*
std::shared_ptr<Component> ComponentFactory::createSearchComponent(ViewLayout* viewLayout)
{
std::shared_ptr<SearchView> view = m_viewFactory->createSearchView(viewLayout);
std::shared_ptr<SearchController> controller = std::make_shared<SearchController>(m_graphAccess);
std::shared_ptr<SearchController> controller = std::make_shared<SearchController>(m_storageAccess);
return std::make_shared<Component>(view, controller);
}
+3 -8
View File
@@ -3,8 +3,7 @@
#include <memory>
#include "data/access/LocationAccess.h"
#include "data/access/GraphAccess.h"
#include "data/access/StorageAccess.h"
class Component;
class ViewFactory;
@@ -13,9 +12,7 @@ class ViewLayout;
class ComponentFactory
{
public:
static std::shared_ptr<ComponentFactory> create(
ViewFactory* viewFactory, GraphAccess* graphAccess, LocationAccess* locationAccess
);
static std::shared_ptr<ComponentFactory> create(ViewFactory* viewFactory, StorageAccess* storageAccess);
~ComponentFactory();
@@ -33,9 +30,7 @@ private:
ComponentFactory(const ComponentFactory&);
ViewFactory* m_viewFactory;
GraphAccess* m_graphAccess;
LocationAccess* m_locationAccess;
StorageAccess* m_storageAccess;
};
#endif // COMPONENT_FACTORY_H
+3 -4
View File
@@ -8,12 +8,11 @@
#include "component/view/UndoRedoView.h"
#include "component/view/ViewFactory.h"
std::shared_ptr<ComponentManager> ComponentManager::create(
ViewFactory* viewFactory, GraphAccess* graphAccess, LocationAccess* locationAccess
){
std::shared_ptr<ComponentManager> ComponentManager::create(ViewFactory* viewFactory, StorageAccess* storageAccess)
{
std::shared_ptr<ComponentManager> ptr(new ComponentManager());
ptr->m_componentFactory = ComponentFactory::create(viewFactory, graphAccess, locationAccess);
ptr->m_componentFactory = ComponentFactory::create(viewFactory, storageAccess);
return ptr;
}
+2 -5
View File
@@ -6,10 +6,9 @@
#include "component/Component.h"
#include "component/ComponentFactory.h"
#include "data/access/LocationAccess.h"
#include "data/access/GraphAccess.h"
class CompositeView;
class StorageAccess;
class View;
class ViewFactory;
class ViewLayout;
@@ -17,9 +16,7 @@ class ViewLayout;
class ComponentManager
{
public:
static std::shared_ptr<ComponentManager> create(
ViewFactory* viewFactory, GraphAccess* graphAccess, LocationAccess* locationAccess
);
static std::shared_ptr<ComponentManager> create(ViewFactory* viewFactory, StorageAccess* graphAccess);
~ComponentManager();
@@ -1,15 +1,13 @@
#include "component/controller/CodeController.h"
#include "data/access/GraphAccess.h"
#include "data/access/LocationAccess.h"
#include "data/access/StorageAccess.h"
#include "data/location/TokenLocation.h"
#include "data/location/TokenLocationCollection.h"
#include "data/location/TokenLocationFile.h"
#include "utility/text/TextAccess.h"
CodeController::CodeController(GraphAccess* graphAccess, LocationAccess* locationAccess)
: m_graphAccess(graphAccess)
, m_locationAccess(locationAccess)
CodeController::CodeController(StorageAccess* storageAccess)
: m_storageAccess(storageAccess)
{
}
@@ -23,7 +21,7 @@ void CodeController::handleMessage(MessageActivateTokenLocation* message)
{
if (message->locationId)
{
std::vector<Id> activeTokenIds = m_graphAccess->getActiveTokenIdsForLocationId(message->locationId);
std::vector<Id> activeTokenIds = m_storageAccess->getActiveTokenIdsForLocationId(message->locationId);
MessageActivateTokens(activeTokenIds).dispatch();
}
}
@@ -35,7 +33,7 @@ void CodeController::handleMessage(MessageActivateTokens* message)
if (activeTokenIds.size() == 1)
{
activeTokenIds = m_graphAccess->getActiveTokenIdsForId(activeTokenIds[0], &declarationId);
activeTokenIds = m_storageAccess->getActiveTokenIdsForId(activeTokenIds[0], &declarationId);
}
CodeView* view = getView();
@@ -49,7 +47,7 @@ void CodeController::handleMessage(MessageFinishedParsing* message)
if (message->errorCount > 0)
{
std::vector<std::string> errorMessages;
TokenLocationCollection errorCollection = m_locationAccess->getErrorTokenLocations(&errorMessages);
TokenLocationCollection errorCollection = m_storageAccess->getErrorTokenLocations(&errorMessages);
std::vector<CodeView::CodeSnippetParams> snippets;
@@ -83,7 +81,7 @@ void CodeController::handleMessage(MessageShowFile* message)
params.lineCount = textAccess->getLineCount();
params.code = textAccess->getText();
params.locationFile = m_locationAccess->getTokenLocationsForFile(message->filePath);
params.locationFile = m_storageAccess->getTokenLocationsForFile(message->filePath);
getView()->showCodeFile(params);
}
@@ -96,7 +94,7 @@ CodeView* CodeController::getView()
std::vector<CodeView::CodeSnippetParams> CodeController::getSnippetsForActiveTokenIds(
const std::vector<Id>& ids, Id declarationId
) const {
TokenLocationCollection collection = m_locationAccess->getTokenLocationsForTokenIds(ids);
TokenLocationCollection collection = m_storageAccess->getTokenLocationsForTokenIds(ids);
std::vector<CodeView::CodeSnippetParams> snippets;
@@ -107,7 +105,7 @@ std::vector<CodeView::CodeSnippetParams> CodeController::getSnippetsForActiveTok
for (CodeView::CodeSnippetParams& params : fileSnippets)
{
params.locationFile = m_locationAccess->getTokenLocationsForLinesInFile(
params.locationFile = m_storageAccess->getTokenLocationsForLinesInFile(
file->getFilePath().str(), params.startLineNumber, params.endLineNumber);
}
@@ -13,8 +13,7 @@
#include "utility/messaging/type/MessageShowFile.h"
#include "utility/types.h"
class GraphAccess;
class LocationAccess;
class StorageAccess;
class TokenLocationFile;
class CodeController
@@ -26,7 +25,7 @@ class CodeController
, public MessageListener<MessageShowFile>
{
public:
CodeController(GraphAccess* graphAccess, LocationAccess* locationAccess);
CodeController(StorageAccess* storageAccess);
~CodeController();
private:
@@ -45,8 +44,7 @@ private:
std::vector<CodeView::CodeSnippetParams> getSnippetsForFile(const TokenLocationFile* file) const;
std::vector<std::pair<uint, uint>> getSnippetRangesForFile(const TokenLocationFile* file) const;
GraphAccess* m_graphAccess;
LocationAccess* m_locationAccess;
StorageAccess* m_storageAccess;
};
#endif // CODE_CONTROLLER_H
@@ -7,7 +7,8 @@
#include "component/view/graphElements/GraphEdge.h"
#include "component/view/graphElements/GraphNode.h"
#include "component/view/GraphView.h"
#include "data/access/GraphAccess.h"
#include "data/access/StorageAccess.h"
#include "data/graph/Graph.h"
GraphController::Margins::Margins()
: left(0)
@@ -22,8 +23,8 @@ GraphController::Margins::Margins()
}
GraphController::GraphController(GraphAccess* graphAccess)
: m_graphAccess(graphAccess)
GraphController::GraphController(StorageAccess* storageAccess)
: m_storageAccess(storageAccess)
{
}
@@ -112,7 +113,7 @@ void GraphController::createDummyGraphForTokenIds(const std::vector<Id>& tokenId
return;
}
std::shared_ptr<Graph> graph = m_graphAccess->getGraphForActiveTokenIds(tokenIds);
std::shared_ptr<Graph> graph = m_storageAccess->getGraphForActiveTokenIds(tokenIds);
m_dummyEdges.clear();
@@ -16,8 +16,8 @@
struct DummyNode;
struct DummyEdge;
class Graph;
class GraphAccess;
class Node;
class StorageAccess;
class GraphController
: public Controller
@@ -44,7 +44,7 @@ public:
float charWidth;
};
GraphController(GraphAccess* graphAccess);
GraphController(StorageAccess* storageAccess);
~GraphController();
private:
@@ -74,7 +74,7 @@ private:
DummyNode* findDummyNodeRecursive(std::vector<DummyNode>& nodes, Id tokenId);
DummyNode* findDummyNodeAccessRecursive(std::vector<DummyNode>& nodes, Id parentId, TokenComponentAccess::AccessType type);
GraphAccess* m_graphAccess;
StorageAccess* m_storageAccess;
GraphView::Metrics m_viewMetrics;
std::vector<DummyNode> m_dummyNodes;
@@ -1,10 +1,10 @@
#include "component/controller/SearchController.h"
#include "component/view/SearchView.h"
#include "data/access/GraphAccess.h"
#include "data/access/storageAccess.h"
SearchController::SearchController(GraphAccess* graphAccess)
: m_graphAccess(graphAccess)
SearchController::SearchController(StorageAccess* storageAccess)
: m_storageAccess(storageAccess)
, m_ignoreNextMessageActivateTokens(false)
{
}
@@ -19,8 +19,8 @@ void SearchController::handleMessage(MessageActivateTokens* message)
if (!m_ignoreNextMessageActivateTokens && message->tokenIds.size())
{
SearchMatch match;
match.fullName = m_graphAccess->getNameForNodeWithId(message->tokenIds[0]);
match.nodeType = m_graphAccess->getNodeTypeForNodeWithId(message->tokenIds[0]);
match.fullName = m_storageAccess->getNameForNodeWithId(message->tokenIds[0]);
match.nodeType = m_storageAccess->getNodeTypeForNodeWithId(message->tokenIds[0]);
match.tokenIds.insert(message->tokenIds[0]);
match.queryNodeType = QueryNode::QUERYNODETYPE_TOKEN;
@@ -54,10 +54,10 @@ void SearchController::handleMessage(MessageSearch* message)
m_ignoreNextMessageActivateTokens = true;
std::vector<Id> ids = m_graphAccess->getTokenIdsForQuery(query);
std::vector<Id> ids = m_storageAccess->getTokenIdsForQuery(query);
if (!ids.size())
{
ids.push_back(m_graphAccess->getIdForNodeWithName(query));
ids.push_back(m_storageAccess->getIdForNodeWithName(query));
}
MessageActivateTokens(ids).dispatch();
@@ -66,7 +66,7 @@ void SearchController::handleMessage(MessageSearch* message)
void SearchController::handleMessage(MessageSearchAutocomplete* message)
{
LOG_INFO("autocomplete string: \"" + message->word + "\"");
getView()->setAutocompletionList(m_graphAccess->getAutocompletionMatches(message->query, message->word));
getView()->setAutocompletionList(m_storageAccess->getAutocompletionMatches(message->query, message->word));
}
SearchView* SearchController::getView()
@@ -12,7 +12,7 @@
#include "utility/messaging/type/MessageSearch.h"
#include "utility/messaging/type/MessageSearchAutocomplete.h"
class GraphAccess;
class StorageAccess;
class SearchView;
class SearchController
@@ -25,7 +25,7 @@ class SearchController
, public MessageListener<MessageSearchAutocomplete>
{
public:
SearchController(GraphAccess* graphAccess);
SearchController(StorageAccess* storageAccess);
~SearchController();
private:
@@ -38,7 +38,7 @@ private:
SearchView* getView();
GraphAccess* m_graphAccess;
StorageAccess* m_storageAccess;
bool m_ignoreNextMessageActivateTokens;
};
+3 -6
View File
@@ -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(
-5
View File
@@ -1,5 +0,0 @@
#include "data/access/GraphAccess.h"
GraphAccess::~GraphAccess()
{
}
-109
View File
@@ -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>();
}
-33
View File
@@ -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
-5
View File
@@ -1,5 +0,0 @@
#include "data/access/LocationAccess.h"
LocationAccess::~LocationAccess()
{
}
-26
View File
@@ -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();
}
-28
View File
@@ -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
+5
View File
@@ -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
+155
View File
@@ -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();
}
+41
View File
@@ -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