diff --git a/src/lib/Application.cpp b/src/lib/Application.cpp index fa133d82..5f8ac3c4 100644 --- a/src/lib/Application.cpp +++ b/src/lib/Application.cpp @@ -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::create(ViewFactory* viewFactory) @@ -17,11 +16,9 @@ std::shared_ptr Application::create(ViewFactory* viewFactory) std::shared_ptr ptr(new Application()); - ptr->m_graphAccessProxy = std::make_shared(); - ptr->m_locationAccessProxy = std::make_shared(); + ptr->m_storageAccessProxy = std::make_shared(); - 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) { diff --git a/src/lib/Application.h b/src/lib/Application.h index 96647dbd..89a34c6b 100644 --- a/src/lib/Application.h +++ b/src/lib/Application.h @@ -14,8 +14,7 @@ class ViewFactory; class MainView; -class GraphAccessProxy; -class LocationAccessProxy; +class StorageAccessProxy; class Application : public MessageListener @@ -44,8 +43,7 @@ private: virtual void handleMessage(MessageSaveProject* message); std::shared_ptr m_project; - std::shared_ptr m_graphAccessProxy; - std::shared_ptr m_locationAccessProxy; + std::shared_ptr m_storageAccessProxy; std::shared_ptr m_mainView; std::shared_ptr m_componentManager; diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index 090d0297..d2b4db2e 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -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 diff --git a/src/lib/Project.cpp b/src/lib/Project.cpp index 844be464..75fa16ae 100644 --- a/src/lib/Project.cpp +++ b/src/lib/Project.cpp @@ -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::create(GraphAccessProxy* graphAccessProxy, LocationAccessProxy* locationAccessProxy) +std::shared_ptr Project::create(StorageAccessProxy* storageAccessProxy) { - std::shared_ptr ptr(new Project(graphAccessProxy, locationAccessProxy)); + std::shared_ptr 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(); - - 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) { } diff --git a/src/lib/Project.h b/src/lib/Project.h index 571bff9b..6ac97830 100644 --- a/src/lib/Project.h +++ b/src/lib/Project.h @@ -7,13 +7,12 @@ #include "data/Storage.h" -class GraphAccessProxy; -class LocationAccessProxy; +class StorageAccessProxy; class Project { public: - static std::shared_ptr create(GraphAccessProxy* graphAccessProxy, LocationAccessProxy* locationAccessProxy); + static std::shared_ptr 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 m_storage; std::shared_ptr m_fileManager; diff --git a/src/lib/component/ComponentFactory.cpp b/src/lib/component/ComponentFactory.cpp index fb599a18..ab2cda98 100644 --- a/src/lib/component/ComponentFactory.cpp +++ b/src/lib/component/ComponentFactory.cpp @@ -15,14 +15,12 @@ #include "component/view/UndoRedoView.h" #include "component/view/ViewFactory.h" -std::shared_ptr ComponentFactory::create( - ViewFactory* viewFactory, GraphAccess* graphAccess, LocationAccess* locationAccess -){ +std::shared_ptr ComponentFactory::create(ViewFactory* viewFactory, StorageAccess* storageAccess) +{ std::shared_ptr 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 ComponentFactory::createCodeComponent(ViewLayout* viewLayout) { std::shared_ptr view = m_viewFactory->createCodeView(viewLayout); - std::shared_ptr controller = std::make_shared(m_graphAccess, m_locationAccess); + std::shared_ptr controller = std::make_shared(m_storageAccess); return std::make_shared(view, controller); } @@ -47,7 +45,7 @@ std::shared_ptr ComponentFactory::createCodeComponent(ViewLayout* vie std::shared_ptr ComponentFactory::createGraphComponent(ViewLayout* viewLayout) { std::shared_ptr view = m_viewFactory->createGraphView(viewLayout); - std::shared_ptr controller = std::make_shared(m_graphAccess); + std::shared_ptr controller = std::make_shared(m_storageAccess); return std::make_shared(view, controller); } @@ -63,7 +61,7 @@ std::shared_ptr ComponentFactory::createRefreshComponent(ViewLayout* std::shared_ptr ComponentFactory::createSearchComponent(ViewLayout* viewLayout) { std::shared_ptr view = m_viewFactory->createSearchView(viewLayout); - std::shared_ptr controller = std::make_shared(m_graphAccess); + std::shared_ptr controller = std::make_shared(m_storageAccess); return std::make_shared(view, controller); } diff --git a/src/lib/component/ComponentFactory.h b/src/lib/component/ComponentFactory.h index 26a1707d..544710a2 100644 --- a/src/lib/component/ComponentFactory.h +++ b/src/lib/component/ComponentFactory.h @@ -3,8 +3,7 @@ #include -#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 create( - ViewFactory* viewFactory, GraphAccess* graphAccess, LocationAccess* locationAccess - ); + static std::shared_ptr 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 diff --git a/src/lib/component/ComponentManager.cpp b/src/lib/component/ComponentManager.cpp index 2dcbea8d..14b7ad54 100644 --- a/src/lib/component/ComponentManager.cpp +++ b/src/lib/component/ComponentManager.cpp @@ -8,12 +8,11 @@ #include "component/view/UndoRedoView.h" #include "component/view/ViewFactory.h" -std::shared_ptr ComponentManager::create( - ViewFactory* viewFactory, GraphAccess* graphAccess, LocationAccess* locationAccess -){ +std::shared_ptr ComponentManager::create(ViewFactory* viewFactory, StorageAccess* storageAccess) +{ std::shared_ptr ptr(new ComponentManager()); - ptr->m_componentFactory = ComponentFactory::create(viewFactory, graphAccess, locationAccess); + ptr->m_componentFactory = ComponentFactory::create(viewFactory, storageAccess); return ptr; } diff --git a/src/lib/component/ComponentManager.h b/src/lib/component/ComponentManager.h index 52f9db8e..49b2cb43 100644 --- a/src/lib/component/ComponentManager.h +++ b/src/lib/component/ComponentManager.h @@ -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 create( - ViewFactory* viewFactory, GraphAccess* graphAccess, LocationAccess* locationAccess - ); + static std::shared_ptr create(ViewFactory* viewFactory, StorageAccess* graphAccess); ~ComponentManager(); diff --git a/src/lib/component/controller/CodeController.cpp b/src/lib/component/controller/CodeController.cpp index e2d9f383..5a2896cf 100644 --- a/src/lib/component/controller/CodeController.cpp +++ b/src/lib/component/controller/CodeController.cpp @@ -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 activeTokenIds = m_graphAccess->getActiveTokenIdsForLocationId(message->locationId); + std::vector 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 errorMessages; - TokenLocationCollection errorCollection = m_locationAccess->getErrorTokenLocations(&errorMessages); + TokenLocationCollection errorCollection = m_storageAccess->getErrorTokenLocations(&errorMessages); std::vector 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 CodeController::getSnippetsForActiveTokenIds( const std::vector& ids, Id declarationId ) const { - TokenLocationCollection collection = m_locationAccess->getTokenLocationsForTokenIds(ids); + TokenLocationCollection collection = m_storageAccess->getTokenLocationsForTokenIds(ids); std::vector snippets; @@ -107,7 +105,7 @@ std::vector CodeController::getSnippetsForActiveTok for (CodeView::CodeSnippetParams& params : fileSnippets) { - params.locationFile = m_locationAccess->getTokenLocationsForLinesInFile( + params.locationFile = m_storageAccess->getTokenLocationsForLinesInFile( file->getFilePath().str(), params.startLineNumber, params.endLineNumber); } diff --git a/src/lib/component/controller/CodeController.h b/src/lib/component/controller/CodeController.h index a4692db4..38dc4151 100644 --- a/src/lib/component/controller/CodeController.h +++ b/src/lib/component/controller/CodeController.h @@ -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 { public: - CodeController(GraphAccess* graphAccess, LocationAccess* locationAccess); + CodeController(StorageAccess* storageAccess); ~CodeController(); private: @@ -45,8 +44,7 @@ private: std::vector getSnippetsForFile(const TokenLocationFile* file) const; std::vector> getSnippetRangesForFile(const TokenLocationFile* file) const; - GraphAccess* m_graphAccess; - LocationAccess* m_locationAccess; + StorageAccess* m_storageAccess; }; #endif // CODE_CONTROLLER_H diff --git a/src/lib/component/controller/GraphController.cpp b/src/lib/component/controller/GraphController.cpp index ad7745a1..c5dc9dba 100644 --- a/src/lib/component/controller/GraphController.cpp +++ b/src/lib/component/controller/GraphController.cpp @@ -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& tokenId return; } - std::shared_ptr graph = m_graphAccess->getGraphForActiveTokenIds(tokenIds); + std::shared_ptr graph = m_storageAccess->getGraphForActiveTokenIds(tokenIds); m_dummyEdges.clear(); diff --git a/src/lib/component/controller/GraphController.h b/src/lib/component/controller/GraphController.h index 5f12d881..644b63b2 100644 --- a/src/lib/component/controller/GraphController.h +++ b/src/lib/component/controller/GraphController.h @@ -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& nodes, Id tokenId); DummyNode* findDummyNodeAccessRecursive(std::vector& nodes, Id parentId, TokenComponentAccess::AccessType type); - GraphAccess* m_graphAccess; + StorageAccess* m_storageAccess; GraphView::Metrics m_viewMetrics; std::vector m_dummyNodes; diff --git a/src/lib/component/controller/SearchController.cpp b/src/lib/component/controller/SearchController.cpp index ed561a72..69e9c9ac 100644 --- a/src/lib/component/controller/SearchController.cpp +++ b/src/lib/component/controller/SearchController.cpp @@ -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 ids = m_graphAccess->getTokenIdsForQuery(query); + std::vector 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() diff --git a/src/lib/component/controller/SearchController.h b/src/lib/component/controller/SearchController.h index 131ea26b..3912d55e 100644 --- a/src/lib/component/controller/SearchController.h +++ b/src/lib/component/controller/SearchController.h @@ -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 { 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; }; diff --git a/src/lib/data/Storage.h b/src/lib/data/Storage.h index 649a2dcb..d6c09f39 100644 --- a/src/lib/data/Storage.h +++ b/src/lib/data/Storage.h @@ -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 getTokenIdsForQuery(std::string query) const; - // LocationAccess implementation virtual TokenLocationCollection getTokenLocationsForTokenIds(const std::vector& tokenIds) const; virtual TokenLocationFile getTokenLocationsForFile(const std::string& filePath) const; virtual TokenLocationFile getTokenLocationsForLinesInFile( diff --git a/src/lib/data/access/GraphAccess.cpp b/src/lib/data/access/GraphAccess.cpp deleted file mode 100644 index 1ef17825..00000000 --- a/src/lib/data/access/GraphAccess.cpp +++ /dev/null @@ -1,5 +0,0 @@ -#include "data/access/GraphAccess.h" - -GraphAccess::~GraphAccess() -{ -} diff --git a/src/lib/data/access/GraphAccessProxy.cpp b/src/lib/data/access/GraphAccessProxy.cpp deleted file mode 100644 index 4156c518..00000000 --- a/src/lib/data/access/GraphAccessProxy.cpp +++ /dev/null @@ -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 GraphAccessProxy::getAutocompletionMatches( - const std::string& query, - const std::string& word -) const { - if (hasSubject()) - { - return m_subject->getAutocompletionMatches(query, word); - } - - return std::vector(); -} - -std::shared_ptr GraphAccessProxy::getGraphForActiveTokenIds(const std::vector& tokenIds) const -{ - if (hasSubject()) - { - return m_subject->getGraphForActiveTokenIds(tokenIds); - } - - return std::make_shared(); -} - -std::vector GraphAccessProxy::getActiveTokenIdsForId(Id tokenId, Id* delcarationId) const -{ - if (hasSubject()) - { - return m_subject->getActiveTokenIdsForId(tokenId, delcarationId); - } - - return std::vector(); -} - -std::vector GraphAccessProxy::getActiveTokenIdsForLocationId(Id locationId) const -{ - if (hasSubject()) - { - return m_subject->getActiveTokenIdsForLocationId(locationId); - } - - return std::vector(); -} - -std::vector GraphAccessProxy::getTokenIdsForQuery(std::string query) const -{ - if (hasSubject()) - { - return m_subject->getTokenIdsForQuery(query); - } - - return std::vector(); -} diff --git a/src/lib/data/access/GraphAccessProxy.h b/src/lib/data/access/GraphAccessProxy.h deleted file mode 100644 index 9a05b52b..00000000 --- a/src/lib/data/access/GraphAccessProxy.h +++ /dev/null @@ -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 getAutocompletionMatches( - const std::string& query, const std::string& word) const; - - virtual std::shared_ptr getGraphForActiveTokenIds(const std::vector& tokenIds) const; - - virtual std::vector getActiveTokenIdsForId(Id tokenId, Id* declarationId) const; - virtual std::vector getActiveTokenIdsForLocationId(Id locationId) const; - - virtual std::vector getTokenIdsForQuery(std::string query) const; - -private: - GraphAccess* m_subject; -}; - -#endif // GRAPH_ACCESS_PROXY_H diff --git a/src/lib/data/access/LocationAccess.cpp b/src/lib/data/access/LocationAccess.cpp deleted file mode 100644 index a8cd1451..00000000 --- a/src/lib/data/access/LocationAccess.cpp +++ /dev/null @@ -1,5 +0,0 @@ -#include "data/access/LocationAccess.h" - -LocationAccess::~LocationAccess() -{ -} diff --git a/src/lib/data/access/LocationAccess.h b/src/lib/data/access/LocationAccess.h deleted file mode 100644 index 2ca2f3a4..00000000 --- a/src/lib/data/access/LocationAccess.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef LOCATION_ACCESS_H -#define LOCATION_ACCESS_H - -#include -#include - -#include "utility/types.h" - -class TokenLocationCollection; -class TokenLocationFile; - -class LocationAccess -{ -public: - virtual ~LocationAccess(); - virtual TokenLocationCollection getTokenLocationsForTokenIds(const std::vector& 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* errorMessages) const = 0; -}; - - -#endif // LOCATION_ACCESS_H diff --git a/src/lib/data/access/LocationAccessProxy.cpp b/src/lib/data/access/LocationAccessProxy.cpp deleted file mode 100644 index 97d05e53..00000000 --- a/src/lib/data/access/LocationAccessProxy.cpp +++ /dev/null @@ -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& 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* errorMessages) const -{ - if (hasSubject()) - { - return m_subject->getErrorTokenLocations(errorMessages); - } - - return TokenLocationCollection(); -} diff --git a/src/lib/data/access/LocationAccessProxy.h b/src/lib/data/access/LocationAccessProxy.h deleted file mode 100644 index e87caf36..00000000 --- a/src/lib/data/access/LocationAccessProxy.h +++ /dev/null @@ -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& 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* errorMessages) const; - -private: - LocationAccess* m_subject; -}; - -#endif // LOCATION_ACCESS_PROXY_H diff --git a/src/lib/data/access/StorageAccess.cpp b/src/lib/data/access/StorageAccess.cpp new file mode 100644 index 00000000..7e5df89d --- /dev/null +++ b/src/lib/data/access/StorageAccess.cpp @@ -0,0 +1,5 @@ +#include "data/access/StorageAccess.h" + +StorageAccess::~StorageAccess() +{ +} diff --git a/src/lib/data/access/GraphAccess.h b/src/lib/data/access/StorageAccess.h similarity index 54% rename from src/lib/data/access/GraphAccess.h rename to src/lib/data/access/StorageAccess.h index 1d59f743..7a36f92c 100644 --- a/src/lib/data/access/GraphAccess.h +++ b/src/lib/data/access/StorageAccess.h @@ -1,18 +1,23 @@ -#ifndef GRAPH_ACCESS_H -#define GRAPH_ACCESS_H +#ifndef STORAGE_ACCESS_H +#define STORAGE_ACCESS_H #include #include #include -#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 getActiveTokenIdsForLocationId(Id locationId) const = 0; virtual std::vector getTokenIdsForQuery(std::string query) const = 0; + + virtual TokenLocationCollection getTokenLocationsForTokenIds(const std::vector& 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* errorMessages) const = 0; }; -#endif // GRAPH_ACCESS_H +#endif // STORAGE_ACCESS_H diff --git a/src/lib/data/access/StorageAccessProxy.cpp b/src/lib/data/access/StorageAccessProxy.cpp new file mode 100644 index 00000000..764abdf1 --- /dev/null +++ b/src/lib/data/access/StorageAccessProxy.cpp @@ -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 StorageAccessProxy::getAutocompletionMatches( + const std::string& query, + const std::string& word +) const { + if (hasSubject()) + { + return m_subject->getAutocompletionMatches(query, word); + } + + return std::vector(); +} + +std::shared_ptr StorageAccessProxy::getGraphForActiveTokenIds(const std::vector& tokenIds) const +{ + if (hasSubject()) + { + return m_subject->getGraphForActiveTokenIds(tokenIds); + } + + return std::make_shared(); +} + +std::vector StorageAccessProxy::getActiveTokenIdsForId(Id tokenId, Id* delcarationId) const +{ + if (hasSubject()) + { + return m_subject->getActiveTokenIdsForId(tokenId, delcarationId); + } + + return std::vector(); +} + +std::vector StorageAccessProxy::getActiveTokenIdsForLocationId(Id locationId) const +{ + if (hasSubject()) + { + return m_subject->getActiveTokenIdsForLocationId(locationId); + } + + return std::vector(); +} + +std::vector StorageAccessProxy::getTokenIdsForQuery(std::string query) const +{ + if (hasSubject()) + { + return m_subject->getTokenIdsForQuery(query); + } + + return std::vector(); +} + +TokenLocationCollection StorageAccessProxy::getTokenLocationsForTokenIds(const std::vector& 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* errorMessages) const +{ + if (hasSubject()) + { + return m_subject->getErrorTokenLocations(errorMessages); + } + + return TokenLocationCollection(); +} diff --git a/src/lib/data/access/StorageAccessProxy.h b/src/lib/data/access/StorageAccessProxy.h new file mode 100644 index 00000000..c83ecacd --- /dev/null +++ b/src/lib/data/access/StorageAccessProxy.h @@ -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 getAutocompletionMatches( + const std::string& query, const std::string& word) const; + + virtual std::shared_ptr getGraphForActiveTokenIds(const std::vector& tokenIds) const; + + virtual std::vector getActiveTokenIdsForId(Id tokenId, Id* declarationId) const; + virtual std::vector getActiveTokenIdsForLocationId(Id locationId) const; + + virtual std::vector getTokenIdsForQuery(std::string query) const; + + virtual TokenLocationCollection getTokenLocationsForTokenIds(const std::vector& 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* errorMessages) const; + +private: + StorageAccess* m_subject; +}; + +#endif // STORAGE_ACCESS_PROXY_H