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:
@@ -2,7 +2,8 @@
|
||||
|
||||
#include "ApplicationSettings.h"
|
||||
#include "component/view/MainView.h"
|
||||
#include "data/Storage.h"
|
||||
#include "data/access/GraphAccessProxy.h"
|
||||
#include "data/access/LocationAccessProxy.h"
|
||||
#include "gui/GuiFactory.h"
|
||||
#include "utility/logging/ConsoleLogger.h"
|
||||
#include "utility/logging/LogManager.h"
|
||||
@@ -17,11 +18,13 @@ std::shared_ptr<Application> Application::create(GuiFactory* guiFactory)
|
||||
ApplicationSettings::getInstance()->load("data/ApplicationSettings.xml");
|
||||
|
||||
std::shared_ptr<Application> ptr(new Application());
|
||||
ptr->m_storage = std::make_shared<Storage>();
|
||||
|
||||
ptr->m_graphAccessProxy = std::make_shared<GraphAccessProxy>();
|
||||
ptr->m_locationAccessProxy = std::make_shared<LocationAccessProxy>();
|
||||
|
||||
ptr->m_mainView = guiFactory->createMainView();
|
||||
ptr->m_componentManager =
|
||||
ComponentManager::create(guiFactory, ptr->m_mainView.get(), ptr->m_storage, ptr->m_storage);
|
||||
ptr->m_componentManager = ComponentManager::create(
|
||||
guiFactory, ptr->m_mainView.get(), ptr->m_graphAccessProxy.get(), ptr->m_locationAccessProxy.get());
|
||||
|
||||
ptr->m_componentManager->setup();
|
||||
|
||||
@@ -40,8 +43,7 @@ Application::~Application()
|
||||
|
||||
void Application::loadProject(const std::string& projectSettingsFilePath)
|
||||
{
|
||||
m_storage->clear();
|
||||
m_project = Project::create(m_storage);
|
||||
m_project = Project::create(m_graphAccessProxy.get(), m_locationAccessProxy.get());
|
||||
|
||||
m_project->loadProjectSettings(projectSettingsFilePath);
|
||||
m_project->parseCode();
|
||||
@@ -52,8 +54,7 @@ void Application::loadProject(const std::string& projectSettingsFilePath)
|
||||
|
||||
void Application::loadSource(const std::string& sourceDirectoryPath)
|
||||
{
|
||||
m_storage->clear();
|
||||
m_project = Project::create(m_storage);
|
||||
m_project = Project::create(m_graphAccessProxy.get(), m_locationAccessProxy.get());
|
||||
|
||||
m_project->clearProjectSettings();
|
||||
m_project->setSourceDirectoryPath(sourceDirectoryPath);
|
||||
|
||||
@@ -11,7 +11,8 @@
|
||||
|
||||
class GuiFactory;
|
||||
class MainView;
|
||||
class Storage;
|
||||
class GraphAccessProxy;
|
||||
class LocationAccessProxy;
|
||||
|
||||
class Application
|
||||
: public MessageListener<MessageLoadProject>
|
||||
@@ -32,7 +33,8 @@ private:
|
||||
virtual void handleMessage(MessageLoadSource* message);
|
||||
|
||||
std::shared_ptr<Project> m_project;
|
||||
std::shared_ptr<Storage> m_storage;
|
||||
std::shared_ptr<GraphAccessProxy> m_graphAccessProxy;
|
||||
std::shared_ptr<LocationAccessProxy> m_locationAccessProxy;
|
||||
|
||||
std::shared_ptr<MainView> m_mainView;
|
||||
std::shared_ptr<ComponentManager> m_componentManager;
|
||||
|
||||
@@ -56,8 +56,12 @@ add_files(
|
||||
|
||||
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/graph/Edge.cpp
|
||||
data/graph/Edge.h
|
||||
|
||||
+16
-10
@@ -3,24 +3,24 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "data/access/GraphAccessProxy.h"
|
||||
#include "data/access/LocationAccessProxy.h"
|
||||
#include "data/parser/cxx/CxxParser.h"
|
||||
#include "utility/FileSystem.h"
|
||||
#include "utility/messaging/type/MessageFinishedParsing.h"
|
||||
#include "utility/logging/logging.h"
|
||||
#include "utility/messaging/type/MessageFinishedParsing.h"
|
||||
|
||||
std::shared_ptr<Project> Project::create(
|
||||
std::shared_ptr<Storage> storage
|
||||
)
|
||||
std::shared_ptr<Project> Project::create(GraphAccessProxy* graphAccessProxy, LocationAccessProxy* locationAccessProxy)
|
||||
{
|
||||
std::shared_ptr<Project> ptr(new Project());
|
||||
ptr->m_storage = storage;
|
||||
std::shared_ptr<Project> ptr(new Project(graphAccessProxy, locationAccessProxy));
|
||||
ptr->m_storage = std::make_shared<Storage>();
|
||||
|
||||
graphAccessProxy->setSubject(ptr->m_storage.get());
|
||||
locationAccessProxy->setSubject(ptr->m_storage.get());
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
Project::Project()
|
||||
{
|
||||
}
|
||||
|
||||
Project::~Project()
|
||||
{
|
||||
}
|
||||
@@ -60,3 +60,9 @@ void Project::parseCode()
|
||||
message.dispatch();
|
||||
}
|
||||
}
|
||||
|
||||
Project::Project(GraphAccessProxy* graphAccessProxy, LocationAccessProxy* locationAccessProxy)
|
||||
: m_graphAccessProxy(graphAccessProxy)
|
||||
, m_locationAccessProxy(locationAccessProxy)
|
||||
{
|
||||
}
|
||||
|
||||
+8
-4
@@ -6,12 +6,13 @@
|
||||
#include "data/Storage.h"
|
||||
#include "ProjectSettings.h"
|
||||
|
||||
class GraphAccessProxy;
|
||||
class LocationAccessProxy;
|
||||
|
||||
class Project
|
||||
{
|
||||
public:
|
||||
static std::shared_ptr<Project> create(
|
||||
std::shared_ptr<Storage> storage
|
||||
);
|
||||
static std::shared_ptr<Project> create(GraphAccessProxy* graphAccessProxy, LocationAccessProxy* locationAccessProxy);
|
||||
|
||||
~Project();
|
||||
|
||||
@@ -23,10 +24,13 @@ public:
|
||||
void parseCode();
|
||||
|
||||
private:
|
||||
Project();
|
||||
Project(GraphAccessProxy* graphAccessProxy, LocationAccessProxy* locationAccessProxy);
|
||||
Project(const Project&);
|
||||
Project operator=(const Project&);
|
||||
|
||||
GraphAccessProxy* const m_graphAccessProxy;
|
||||
LocationAccessProxy* const m_locationAccessProxy;
|
||||
|
||||
std::shared_ptr<Storage> m_storage;
|
||||
};
|
||||
|
||||
|
||||
@@ -11,16 +11,13 @@
|
||||
#include "gui/GuiFactory.h"
|
||||
|
||||
std::shared_ptr<ComponentFactory> ComponentFactory::create(
|
||||
GuiFactory* guiFactory,
|
||||
ViewLayout* viewLayout,
|
||||
std::shared_ptr<LocationAccess> locationAccess,
|
||||
std::shared_ptr<GraphAccess> graphAccess)
|
||||
{
|
||||
GuiFactory* guiFactory, ViewLayout* viewLayout, GraphAccess* graphAccess, LocationAccess* locationAccess
|
||||
){
|
||||
std::shared_ptr<ComponentFactory> ptr(new ComponentFactory());
|
||||
ptr->m_guiFactory = guiFactory;
|
||||
ptr->m_viewLayout = viewLayout;
|
||||
ptr->m_locationAccess = locationAccess;
|
||||
ptr->m_graphAccess = graphAccess;
|
||||
ptr->m_locationAccess = locationAccess;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,10 +14,8 @@ class ComponentFactory
|
||||
{
|
||||
public:
|
||||
static std::shared_ptr<ComponentFactory> create(
|
||||
GuiFactory* guiFactory,
|
||||
ViewLayout* viewLayout,
|
||||
std::shared_ptr<LocationAccess> locationAccess,
|
||||
std::shared_ptr<GraphAccess> graphAccess);
|
||||
GuiFactory* guiFactory, ViewLayout* viewLayout, GraphAccess* graphAccess, LocationAccess* locationAccess
|
||||
);
|
||||
|
||||
~ComponentFactory();
|
||||
|
||||
@@ -32,8 +30,8 @@ private:
|
||||
GuiFactory* m_guiFactory;
|
||||
ViewLayout* m_viewLayout;
|
||||
|
||||
std::shared_ptr<LocationAccess> m_locationAccess;
|
||||
std::shared_ptr<GraphAccess> m_graphAccess;
|
||||
GraphAccess* m_graphAccess;
|
||||
LocationAccess* m_locationAccess;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -7,13 +7,10 @@
|
||||
#include "data/location/TokenLocationFile.h"
|
||||
|
||||
std::shared_ptr<ComponentManager> ComponentManager::create(
|
||||
GuiFactory* guiFactory,
|
||||
ViewLayout* viewLayout,
|
||||
std::shared_ptr<LocationAccess> locationAccess,
|
||||
std::shared_ptr<GraphAccess> graphAccess)
|
||||
{
|
||||
GuiFactory* guiFactory, ViewLayout* viewLayout, GraphAccess* graphAccess, LocationAccess* locationAccess
|
||||
){
|
||||
std::shared_ptr<ComponentManager> ptr(new ComponentManager());
|
||||
ptr->m_componentFactory = ComponentFactory::create(guiFactory, viewLayout, locationAccess, graphAccess);
|
||||
ptr->m_componentFactory = ComponentFactory::create(guiFactory, viewLayout, graphAccess, locationAccess);
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
@@ -16,10 +16,8 @@ class ComponentManager
|
||||
{
|
||||
public:
|
||||
static std::shared_ptr<ComponentManager> create(
|
||||
GuiFactory* guiFactory,
|
||||
ViewLayout* viewLayout,
|
||||
std::shared_ptr<LocationAccess> locationAccess,
|
||||
std::shared_ptr<GraphAccess> graphAccess);
|
||||
GuiFactory* guiFactory, ViewLayout* viewLayout, GraphAccess* graphAccess, LocationAccess* locationAccess
|
||||
);
|
||||
|
||||
~ComponentManager();
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include "utility/logging/logging.h"
|
||||
|
||||
|
||||
CodeController::CodeController(std::shared_ptr<LocationAccess> locationAccess)
|
||||
CodeController::CodeController(LocationAccess* locationAccess)
|
||||
: m_locationAccess(locationAccess)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ class CodeController
|
||||
, public MessageListener<MessageActivateToken>
|
||||
{
|
||||
public:
|
||||
CodeController(std::shared_ptr<LocationAccess> locationAccess);
|
||||
CodeController(LocationAccess* locationAccess);
|
||||
~CodeController();
|
||||
|
||||
void setActiveTokenId(Id id);
|
||||
@@ -31,7 +31,7 @@ private:
|
||||
virtual void handleMessage(MessageActivateToken* message);
|
||||
CodeView* getView();
|
||||
|
||||
std::shared_ptr<LocationAccess> m_locationAccess;
|
||||
LocationAccess* m_locationAccess;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
#include "utility/logging/logging.h"
|
||||
|
||||
GraphController::GraphController(std::shared_ptr<GraphAccess> graphAccess)
|
||||
GraphController::GraphController(GraphAccess* graphAccess)
|
||||
: m_graphAccess(graphAccess)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -14,14 +14,14 @@ class GraphController:
|
||||
public MessageListener<MessageActivateToken>
|
||||
{
|
||||
public:
|
||||
GraphController(std::shared_ptr<GraphAccess> graphAccess);
|
||||
GraphController(GraphAccess* graphAccess);
|
||||
~GraphController();
|
||||
|
||||
private:
|
||||
virtual void handleMessage(MessageActivateToken* message);
|
||||
GraphView* getView();
|
||||
|
||||
std::shared_ptr<GraphAccess> m_graphAccess;
|
||||
GraphAccess* m_graphAccess;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "component/view/SearchView.h"
|
||||
#include "data/access/GraphAccess.h"
|
||||
|
||||
SearchController::SearchController(std::shared_ptr<GraphAccess> graphAccess)
|
||||
SearchController::SearchController(GraphAccess* graphAccess)
|
||||
: m_graphAccess(graphAccess)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ class SearchController
|
||||
, public MessageListener<MessageFinishedParsing>
|
||||
{
|
||||
public:
|
||||
SearchController(std::shared_ptr<GraphAccess> graphAccess);
|
||||
SearchController(GraphAccess* graphAccess);
|
||||
~SearchController();
|
||||
|
||||
void search(const std::string& s);
|
||||
@@ -28,7 +28,7 @@ private:
|
||||
virtual void handleMessage(MessageFinishedParsing* message);
|
||||
SearchView* getView();
|
||||
|
||||
std::shared_ptr<GraphAccess> m_graphAccess;
|
||||
GraphAccess* m_graphAccess;
|
||||
};
|
||||
|
||||
#endif // SEARCH_CONTROLLER_H
|
||||
|
||||
@@ -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