diff --git a/src/lib/Application.cpp b/src/lib/Application.cpp index 6d55dcfd..9be0f9d2 100644 --- a/src/lib/Application.cpp +++ b/src/lib/Application.cpp @@ -270,7 +270,7 @@ void Application::handleMessage(MessageLoadProject* message) updateRecentProjects(projectSettingsFilePath); m_storageCache->clear(); - m_storageCache->setSubject(nullptr); + m_storageCache->setSubject(std::weak_ptr()); // TODO: check if this is really required. m_project = std::make_shared( std::make_shared(projectSettingsFilePath), m_storageCache.get(), getUUID(), hasGUI()); diff --git a/src/lib/data/access/StorageAccessProxy.cpp b/src/lib/data/access/StorageAccessProxy.cpp index f2351802..ebbf739c 100644 --- a/src/lib/data/access/StorageAccessProxy.cpp +++ b/src/lib/data/access/StorageAccessProxy.cpp @@ -9,384 +9,108 @@ #include "utility/file/FilePath.h" #include "utility/logging/logging.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) +void StorageAccessProxy::setSubject(std::weak_ptr subject) { m_subject = subject; } -Id StorageAccessProxy::getNodeIdForFileNode(const FilePath& filePath) const -{ - if (hasSubject()) - { - return m_subject->getNodeIdForFileNode(filePath); +#define UNWRAP(...) __VA_ARGS__ + +#define DEF_GETTER_0(_METHOD_NAME_, _RETURN_TYPE_, _DEFAULT_VALUE_) \ + UNWRAP(_RETURN_TYPE_) StorageAccessProxy::_METHOD_NAME_() const \ + { \ + if (std::shared_ptr subject = m_subject.lock()) \ + { \ + return subject->_METHOD_NAME_(); \ + } \ + return _DEFAULT_VALUE_; \ } - return 0; -} - -Id StorageAccessProxy::getNodeIdForNameHierarchy(const NameHierarchy& nameHierarchy) const -{ - if (hasSubject()) - { - return m_subject->getNodeIdForNameHierarchy(nameHierarchy); +#define DEF_GETTER_1(_METHOD_NAME_, _PATAMETER_1_TYPE_, _RETURN_TYPE_, _DEFAULT_VALUE_) \ + UNWRAP(_RETURN_TYPE_) StorageAccessProxy::_METHOD_NAME_(_PATAMETER_1_TYPE_ p1) const \ + { \ + if (std::shared_ptr subject = m_subject.lock()) \ + { \ + return subject->_METHOD_NAME_(p1); \ + } \ + return _DEFAULT_VALUE_; \ } - return 0; -} - -std::vector StorageAccessProxy::getNodeIdsForNameHierarchies(const std::vector nameHierarchies) const -{ - if (hasSubject()) - { - return m_subject->getNodeIdsForNameHierarchies(nameHierarchies); - } - return std::vector(); -} - -NameHierarchy StorageAccessProxy::getNameHierarchyForNodeId(Id id) const -{ - if (hasSubject()) - { - return m_subject->getNameHierarchyForNodeId(id); +#define DEF_GETTER_2(_METHOD_NAME_, _PATAMETER_1_TYPE_, _PATAMETER_2_TYPE_, _RETURN_TYPE_, _DEFAULT_VALUE_) \ + UNWRAP(_RETURN_TYPE_) StorageAccessProxy::_METHOD_NAME_(_PATAMETER_1_TYPE_ p1, _PATAMETER_2_TYPE_ p2) const \ + { \ + if (std::shared_ptr subject = m_subject.lock()) \ + { \ + return subject->_METHOD_NAME_(p1, p2); \ + } \ + return _DEFAULT_VALUE_; \ } - return NameHierarchy(NAME_DELIMITER_UNKNOWN); -} - -std::vector StorageAccessProxy::getNameHierarchiesForNodeIds(const std::vector& nodeIds) const -{ - if (hasSubject()) - { - return m_subject->getNameHierarchiesForNodeIds(nodeIds); - } - return std::vector(); -} - -std::map> StorageAccessProxy::getNodeIdToParentFileMap(const std::vector& nodeIds) const -{ - if (hasSubject()) - { - return m_subject->getNodeIdToParentFileMap(nodeIds); +#define DEF_GETTER_3(_METHOD_NAME_, _PATAMETER_1_TYPE_, _PATAMETER_2_TYPE_, _PATAMETER_3_TYPE_, _RETURN_TYPE_, _DEFAULT_VALUE_) \ + UNWRAP(_RETURN_TYPE_) StorageAccessProxy::_METHOD_NAME_(_PATAMETER_1_TYPE_ p1, _PATAMETER_2_TYPE_ p2, _PATAMETER_3_TYPE_ p3) const \ + { \ + if (std::shared_ptr subject = m_subject.lock()) \ + { \ + return subject->_METHOD_NAME_(p1, p2, p3); \ + } \ + return _DEFAULT_VALUE_; \ } - return { }; -} - -NodeType StorageAccessProxy::getNodeTypeForNodeWithId(Id id) const -{ - if (hasSubject()) - { - return m_subject->getNodeTypeForNodeWithId(id); - } - return NodeType(NodeType::NODE_SYMBOL); -} - -Id StorageAccessProxy::getIdForEdge( - Edge::EdgeType type, const NameHierarchy& fromNameHierarchy, const NameHierarchy& toNameHierarchy -) const { - if (hasSubject()) - { - return m_subject->getIdForEdge(type, fromNameHierarchy, toNameHierarchy); +#define DEF_GETTER_4(_METHOD_NAME_, _PATAMETER_1_TYPE_, _PATAMETER_2_TYPE_, _PATAMETER_3_TYPE_, _PATAMETER_4_TYPE_, _RETURN_TYPE_, _DEFAULT_VALUE_) \ + UNWRAP(_RETURN_TYPE_) StorageAccessProxy::_METHOD_NAME_(_PATAMETER_1_TYPE_ p1, _PATAMETER_2_TYPE_ p2, _PATAMETER_3_TYPE_ p3, _PATAMETER_4_TYPE_ p4) const \ + { \ + if (std::shared_ptr subject = m_subject.lock()) \ + { \ + return subject->_METHOD_NAME_(p1, p2, p3, p4); \ + } \ + return _DEFAULT_VALUE_; \ } - return 0; -} - -StorageEdge StorageAccessProxy::getEdgeById(Id edgeId) const -{ - if (hasSubject()) - { - return m_subject->getEdgeById(edgeId); - } - - return StorageEdge(); -} - -std::shared_ptr StorageAccessProxy::getFullTextSearchLocations( - const std::wstring &searchTerm, bool caseSensitive) const -{ - if (hasSubject()) - { - return m_subject->getFullTextSearchLocations(searchTerm, caseSensitive); - } - - return std::make_shared(); -} - -std::vector StorageAccessProxy::getAutocompletionMatches(const std::wstring& query, NodeTypeSet acceptedNodeTypes) const -{ - if (hasSubject()) - { - return m_subject->getAutocompletionMatches(query, acceptedNodeTypes); - } - - return std::vector(); -} - -std::vector StorageAccessProxy::getSearchMatchesForTokenIds(const std::vector& tokenIds) const -{ - if (hasSubject()) - { - return m_subject->getSearchMatchesForTokenIds(tokenIds); - } - - return std::vector(); -} - -std::shared_ptr StorageAccessProxy::getGraphForAll() const -{ - if (hasSubject()) - { - return m_subject->getGraphForAll(); - } - - return std::make_shared(); -} - -std::shared_ptr StorageAccessProxy::getGraphForNodeTypes(NodeTypeSet nodeTypes) const -{ - if (hasSubject()) - { - return m_subject->getGraphForNodeTypes(nodeTypes); - } - - return std::make_shared(); -} - -std::shared_ptr StorageAccessProxy::getGraphForActiveTokenIds( - const std::vector& tokenIds, const std::vector& expandedNodeIds, bool* isActiveNamespace) const -{ - if (hasSubject()) - { - return m_subject->getGraphForActiveTokenIds(tokenIds, expandedNodeIds, isActiveNamespace); - } - - return std::make_shared(); -} - -std::shared_ptr StorageAccessProxy::getGraphForChildrenOfNodeId(Id nodeId) const -{ - if (hasSubject()) - { - return m_subject->getGraphForChildrenOfNodeId(nodeId); - } - - return std::make_shared(); -} - -std::shared_ptr StorageAccessProxy::getGraphForTrail(Id originId, Id targetId, Edge::TypeMask trailType, size_t depth) const -{ - if (hasSubject()) - { - return m_subject->getGraphForTrail(originId, targetId, trailType, depth); - } - - 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::getNodeIdsForLocationIds(const std::vector& locationIds) const -{ - if (hasSubject()) - { - return m_subject->getNodeIdsForLocationIds(locationIds); - } - - return std::vector(); -} - -std::shared_ptr StorageAccessProxy::getSourceLocationsForTokenIds( - const std::vector& tokenIds) const -{ - if (hasSubject()) - { - return m_subject->getSourceLocationsForTokenIds(tokenIds); - } - - return std::make_shared(); -} - -std::shared_ptr StorageAccessProxy::getSourceLocationsForLocationIds( - const std::vector& locationIds) const -{ - if (hasSubject()) - { - return m_subject->getSourceLocationsForLocationIds(locationIds); - } - - return std::make_shared(); -} - -std::shared_ptr StorageAccessProxy::getSourceLocationsForFile(const FilePath& filePath) const -{ - if (hasSubject()) - { - return m_subject->getSourceLocationsForFile(filePath); - } - - return std::make_shared(FilePath(), false, false, false); -} - -std::shared_ptr StorageAccessProxy::getSourceLocationsForLinesInFile( - const FilePath& filePath, size_t startLine, size_t endLine -) const -{ - if (hasSubject()) - { - return m_subject->getSourceLocationsForLinesInFile(filePath, startLine, endLine); - } - - return std::make_shared(FilePath(), false, false, false); -} - -std::shared_ptr StorageAccessProxy::getSourceLocationsOfTypeInFile( - const FilePath& filePath, LocationType type -) const -{ - if (hasSubject()) - { - return m_subject->getSourceLocationsOfTypeInFile(filePath, type); - } - - return std::make_shared(FilePath(), false, false, false); -} - -std::shared_ptr StorageAccessProxy::getCommentLocationsInFile(const FilePath& filePath) const -{ - if (hasSubject()) - { - return m_subject->getCommentLocationsInFile(filePath); - } - - return std::make_shared(FilePath(), false, false, false); -} - -std::shared_ptr StorageAccessProxy::getFileContent(const FilePath& filePath) const -{ - if (hasSubject()) - { - return m_subject->getFileContent(filePath); - } - - return nullptr; -} - -FileInfo StorageAccessProxy::getFileInfoForFileId(Id id) const -{ - if (hasSubject()) - { - return m_subject->getFileInfoForFileId(id); - } - - return FileInfo(); -} - -FileInfo StorageAccessProxy::getFileInfoForFilePath(const FilePath& filePath) const -{ - if (hasSubject()) - { - return m_subject->getFileInfoForFilePath(filePath); - } - - return FileInfo(); -} - -std::vector StorageAccessProxy::getFileInfosForFilePaths(const std::vector& filePaths) const -{ - if (hasSubject()) - { - return m_subject->getFileInfosForFilePaths(filePaths); - } - - return std::vector(); -} - -StorageStats StorageAccessProxy::getStorageStats() const -{ - if (hasSubject()) - { - return m_subject->getStorageStats(); - } - - return StorageStats(); -} -ErrorCountInfo StorageAccessProxy::getErrorCount() const -{ - if (hasSubject()) - { - return m_subject->getErrorCount(); - } +DEF_GETTER_1(getNodeIdForFileNode, const FilePath&, Id, 0) +DEF_GETTER_1(getNodeIdForNameHierarchy, const NameHierarchy&, Id, 0) +DEF_GETTER_1(getNodeIdsForNameHierarchies, const std::vector, std::vector, {}) +DEF_GETTER_1(getNameHierarchyForNodeId, Id, NameHierarchy, NameHierarchy(NAME_DELIMITER_UNKNOWN)) +DEF_GETTER_1(getNameHierarchiesForNodeIds, const std::vector&, std::vector, {}) - return ErrorCountInfo(); -} +typedef std::map> NodeIdToParentFileMap; +DEF_GETTER_1(getNodeIdToParentFileMap, const std::vector&, NodeIdToParentFileMap, {}) -std::vector StorageAccessProxy::getErrorsLimited(const ErrorFilter& filter) const -{ - if (hasSubject()) - { - return m_subject->getErrorsLimited(filter); - } - - return std::vector(); -} - -std::vector StorageAccessProxy::getErrorsForFileLimited(const ErrorFilter& filter, const FilePath& filePath) const -{ - if (hasSubject()) - { - return m_subject->getErrorsForFileLimited(filter, filePath); - } - - return std::vector(); -} - -std::shared_ptr StorageAccessProxy::getErrorSourceLocations( - const std::vector& errors) const -{ - if (hasSubject()) - { - return m_subject->getErrorSourceLocations(errors); - } - - return std::make_shared(); -} +DEF_GETTER_1(getNodeTypeForNodeWithId, Id, NodeType, NodeType(NodeType::NODE_SYMBOL)) +DEF_GETTER_3(getIdForEdge, Edge::EdgeType, const NameHierarchy&, const NameHierarchy&, Id, 0) +DEF_GETTER_1(getEdgeById, Id, StorageEdge, StorageEdge()) +DEF_GETTER_2(getFullTextSearchLocations, const std::wstring &, bool, std::shared_ptr, std::make_shared()) +DEF_GETTER_2(getAutocompletionMatches, const std::wstring &, NodeTypeSet, std::vector, std::vector()) +DEF_GETTER_1(getSearchMatchesForTokenIds, const std::vector&, std::vector, std::vector()) +DEF_GETTER_0(getGraphForAll, std::shared_ptr, std::make_shared()) +DEF_GETTER_1(getGraphForNodeTypes, NodeTypeSet, std::shared_ptr, std::make_shared()) +DEF_GETTER_3(getGraphForActiveTokenIds, const std::vector&, const std::vector&, bool*, std::shared_ptr, std::make_shared()) +DEF_GETTER_1(getGraphForChildrenOfNodeId, Id, std::shared_ptr, std::make_shared()) +DEF_GETTER_4(getGraphForTrail, Id, Id, Edge::TypeMask, size_t, std::shared_ptr, std::make_shared()) +DEF_GETTER_2(getActiveTokenIdsForId, Id, Id*, std::vector, {}) +DEF_GETTER_1(getNodeIdsForLocationIds, const std::vector&, std::vector, {}) +DEF_GETTER_1(getSourceLocationsForTokenIds, const std::vector&, std::shared_ptr, std::make_shared()) +DEF_GETTER_1(getSourceLocationsForLocationIds, const std::vector&, std::shared_ptr, std::make_shared()) +DEF_GETTER_1(getSourceLocationsForFile, const FilePath&, std::shared_ptr, std::make_shared(FilePath(), false, false, false)) +DEF_GETTER_3(getSourceLocationsForLinesInFile, const FilePath&, size_t, size_t, std::shared_ptr, std::make_shared(FilePath(), false, false, false)) +DEF_GETTER_2(getSourceLocationsOfTypeInFile, const FilePath&, LocationType, std::shared_ptr, std::make_shared(FilePath(), false, false, false)) +DEF_GETTER_1(getCommentLocationsInFile, const FilePath&, std::shared_ptr, std::make_shared(FilePath(), false, false, false)) +DEF_GETTER_1(getFileContent, const FilePath&, std::shared_ptr, nullptr) +DEF_GETTER_1(getFileInfoForFileId, Id, FileInfo, FileInfo()) +DEF_GETTER_1(getFileInfoForFilePath, const FilePath&, FileInfo, FileInfo()) +DEF_GETTER_1(getFileInfosForFilePaths, const std::vector&, std::vector, {}) +DEF_GETTER_0(getStorageStats, StorageStats, StorageStats()) +DEF_GETTER_0(getErrorCount, ErrorCountInfo, ErrorCountInfo()) +DEF_GETTER_1(getErrorsLimited, const ErrorFilter&, std::vector, {}) +DEF_GETTER_2(getErrorsForFileLimited, const ErrorFilter&, const FilePath&, std::vector, {}) +DEF_GETTER_1(getErrorSourceLocations, const std::vector&, std::shared_ptr, std::make_shared()) Id StorageAccessProxy::addNodeBookmark(const NodeBookmark& bookmark) { - if (hasSubject()) + if (std::shared_ptr subject = m_subject.lock()) { - return m_subject->addNodeBookmark(bookmark); + return subject->addNodeBookmark(bookmark); } return -1; @@ -394,9 +118,9 @@ Id StorageAccessProxy::addNodeBookmark(const NodeBookmark& bookmark) Id StorageAccessProxy::addEdgeBookmark(const EdgeBookmark& bookmark) { - if (hasSubject()) + if (std::shared_ptr subject = m_subject.lock()) { - return m_subject->addEdgeBookmark(bookmark); + return subject->addEdgeBookmark(bookmark); } return -1; @@ -404,9 +128,9 @@ Id StorageAccessProxy::addEdgeBookmark(const EdgeBookmark& bookmark) Id StorageAccessProxy::addBookmarkCategory(const std::wstring& categoryName) { - if (hasSubject()) + if (std::shared_ptr subject = m_subject.lock()) { - return m_subject->addBookmarkCategory(categoryName); + return subject->addBookmarkCategory(categoryName); } return -1; @@ -414,75 +138,30 @@ Id StorageAccessProxy::addBookmarkCategory(const std::wstring& categoryName) void StorageAccessProxy::updateBookmark(const Id bookmarkId, const std::wstring& name, const std::wstring& comment, const std::wstring& categoryName) { - if (hasSubject()) + if (std::shared_ptr subject = m_subject.lock()) { - m_subject->updateBookmark(bookmarkId, name, comment, categoryName); + subject->updateBookmark(bookmarkId, name, comment, categoryName); } } void StorageAccessProxy::removeBookmark(const Id id) { - if (hasSubject()) + if (std::shared_ptr subject = m_subject.lock()) { - m_subject->removeBookmark(id); + subject->removeBookmark(id); } } void StorageAccessProxy::removeBookmarkCategory(const Id id) { - if (hasSubject()) + if (std::shared_ptr subject = m_subject.lock()) { - m_subject->removeBookmarkCategory(id); + subject->removeBookmarkCategory(id); } } -std::vector StorageAccessProxy::getAllNodeBookmarks() const -{ - if (hasSubject()) - { - return m_subject->getAllNodeBookmarks(); - } - - return std::vector(); -} - -std::vector StorageAccessProxy::getAllEdgeBookmarks() const -{ - if (hasSubject()) - { - return m_subject->getAllEdgeBookmarks(); - } - - return std::vector(); -} - -std::vector StorageAccessProxy::getAllBookmarkCategories() const -{ - if (hasSubject()) - { - return m_subject->getAllBookmarkCategories(); - } - - return std::vector(); -} - -TooltipInfo StorageAccessProxy::getTooltipInfoForTokenIds(const std::vector& tokenIds, TooltipOrigin origin) const -{ - if (hasSubject()) - { - return m_subject->getTooltipInfoForTokenIds(tokenIds, origin); - } - - return TooltipInfo(); -} - -TooltipInfo StorageAccessProxy::getTooltipInfoForSourceLocationIdsAndLocalSymbolIds( - const std::vector& locationIds, const std::vector& localSymbolIds) const -{ - if (hasSubject()) - { - return m_subject->getTooltipInfoForSourceLocationIdsAndLocalSymbolIds(locationIds, localSymbolIds); - } - - return TooltipInfo(); -} +DEF_GETTER_0(getAllNodeBookmarks, std::vector, {}) +DEF_GETTER_0(getAllEdgeBookmarks, std::vector, {}) +DEF_GETTER_0(getAllBookmarkCategories, std::vector, {}) +DEF_GETTER_2(getTooltipInfoForTokenIds, const std::vector&, TooltipOrigin, TooltipInfo, TooltipInfo()) +DEF_GETTER_2(getTooltipInfoForSourceLocationIdsAndLocalSymbolIds, const std::vector&, const std::vector&, TooltipInfo, TooltipInfo()) diff --git a/src/lib/data/access/StorageAccessProxy.h b/src/lib/data/access/StorageAccessProxy.h index 6b041fa7..429a00ad 100644 --- a/src/lib/data/access/StorageAccessProxy.h +++ b/src/lib/data/access/StorageAccessProxy.h @@ -1,100 +1,100 @@ #ifndef STORAGE_ACCESS_PROXY_H #define STORAGE_ACCESS_PROXY_H +#include + #include "data/access/StorageAccess.h" class StorageAccessProxy : public StorageAccess { public: - StorageAccessProxy(); - virtual ~StorageAccessProxy(); + StorageAccessProxy() = default; - bool hasSubject() const; - void setSubject(StorageAccess* subject); + void setSubject(std::weak_ptr subject); // StorageAccess implementation - virtual Id getNodeIdForFileNode(const FilePath& filePath) const override; - virtual Id getNodeIdForNameHierarchy(const NameHierarchy& nameHierarchy) const override; - virtual std::vector getNodeIdsForNameHierarchies(const std::vector nameHierarchies) const override; + Id getNodeIdForFileNode(const FilePath& filePath) const override; + Id getNodeIdForNameHierarchy(const NameHierarchy& nameHierarchy) const override; + std::vector getNodeIdsForNameHierarchies(const std::vector nameHierarchies) const override; - virtual NameHierarchy getNameHierarchyForNodeId(Id id) const override; - virtual std::vector getNameHierarchiesForNodeIds(const std::vector& nodeIds) const override; - virtual std::map> getNodeIdToParentFileMap(const std::vector& nodeIds) const override; + NameHierarchy getNameHierarchyForNodeId(Id id) const override; + std::vector getNameHierarchiesForNodeIds(const std::vector& nodeIds) const override; + std::map> getNodeIdToParentFileMap(const std::vector& nodeIds) const override; - virtual NodeType getNodeTypeForNodeWithId(Id id) const override; + NodeType getNodeTypeForNodeWithId(Id id) const override; - virtual Id getIdForEdge( + Id getIdForEdge( Edge::EdgeType type, const NameHierarchy& fromNameHierarchy, const NameHierarchy& toNameHierarchy) const override; - virtual StorageEdge getEdgeById(Id edgeId) const override; + StorageEdge getEdgeById(Id edgeId) const override; - virtual std::shared_ptr getFullTextSearchLocations( + std::shared_ptr getFullTextSearchLocations( const std::wstring& searchTerm, bool caseSensitive) const override; - virtual std::vector getAutocompletionMatches(const std::wstring& query, NodeTypeSet acceptedNodeTypes) const override; - virtual std::vector getSearchMatchesForTokenIds(const std::vector& tokenIds) const override; + std::vector getAutocompletionMatches(const std::wstring& query, NodeTypeSet acceptedNodeTypes) const override; + std::vector getSearchMatchesForTokenIds(const std::vector& tokenIds) const override; - virtual std::shared_ptr getGraphForAll() const override; - virtual std::shared_ptr getGraphForNodeTypes(NodeTypeSet nodeTypes) const override; - virtual std::shared_ptr getGraphForActiveTokenIds( + std::shared_ptr getGraphForAll() const override; + std::shared_ptr getGraphForNodeTypes(NodeTypeSet nodeTypes) const override; + std::shared_ptr getGraphForActiveTokenIds( const std::vector& tokenIds, const std::vector& expandedNodeIds, bool* isActiveNamespace = nullptr) const override; - virtual std::shared_ptr getGraphForChildrenOfNodeId(Id nodeId) const override; - virtual std::shared_ptr getGraphForTrail(Id originId, Id targetId, Edge::TypeMask trailType, size_t depth) const override; + std::shared_ptr getGraphForChildrenOfNodeId(Id nodeId) const override; + std::shared_ptr getGraphForTrail(Id originId, Id targetId, Edge::TypeMask trailType, size_t depth) const override; - virtual std::vector getActiveTokenIdsForId(Id tokenId, Id* declarationId) const override; - virtual std::vector getNodeIdsForLocationIds(const std::vector& locationIds) const override; + std::vector getActiveTokenIdsForId(Id tokenId, Id* declarationId) const override; + std::vector getNodeIdsForLocationIds(const std::vector& locationIds) const override; - virtual std::shared_ptr getSourceLocationsForTokenIds( + std::shared_ptr getSourceLocationsForTokenIds( const std::vector& tokenIds ) const override; - virtual std::shared_ptr getSourceLocationsForLocationIds( + std::shared_ptr getSourceLocationsForLocationIds( const std::vector& locationIds ) const override; - virtual std::shared_ptr getSourceLocationsForFile(const FilePath& filePath) const override; - virtual std::shared_ptr getSourceLocationsForLinesInFile( + std::shared_ptr getSourceLocationsForFile(const FilePath& filePath) const override; + std::shared_ptr getSourceLocationsForLinesInFile( const FilePath& filePath, size_t startLine, size_t endLine) const override; - virtual std::shared_ptr getSourceLocationsOfTypeInFile( + std::shared_ptr getSourceLocationsOfTypeInFile( const FilePath& filePath, LocationType type) const override; - virtual std::shared_ptr getCommentLocationsInFile(const FilePath& filePath) const override; + std::shared_ptr getCommentLocationsInFile(const FilePath& filePath) const override; - virtual std::shared_ptr getFileContent(const FilePath& filePath) const override; + std::shared_ptr getFileContent(const FilePath& filePath) const override; - virtual FileInfo getFileInfoForFileId(Id id) const override; + FileInfo getFileInfoForFileId(Id id) const override; - virtual FileInfo getFileInfoForFilePath(const FilePath& filePath) const override; - virtual std::vector getFileInfosForFilePaths(const std::vector& filePaths) const override; + FileInfo getFileInfoForFilePath(const FilePath& filePath) const override; + std::vector getFileInfosForFilePaths(const std::vector& filePaths) const override; - virtual StorageStats getStorageStats() const override; + StorageStats getStorageStats() const override; - virtual ErrorCountInfo getErrorCount() const override; - virtual std::vector getErrorsLimited(const ErrorFilter& filter) const override; - virtual std::vector getErrorsForFileLimited( + ErrorCountInfo getErrorCount() const override; + std::vector getErrorsLimited(const ErrorFilter& filter) const override; + std::vector getErrorsForFileLimited( const ErrorFilter& filter, const FilePath& filePath) const override; - virtual std::shared_ptr getErrorSourceLocations( + std::shared_ptr getErrorSourceLocations( const std::vector& errors) const override; // TODO: remove these from access because it's not a getter! - virtual Id addNodeBookmark(const NodeBookmark& bookmark) override; - virtual Id addEdgeBookmark(const EdgeBookmark& bookmark) override; - virtual Id addBookmarkCategory(const std::wstring& categoryName) override; + Id addNodeBookmark(const NodeBookmark& bookmark) override; + Id addEdgeBookmark(const EdgeBookmark& bookmark) override; + Id addBookmarkCategory(const std::wstring& categoryName) override; - virtual void updateBookmark( + void updateBookmark( const Id bookmarkId, const std::wstring& name, const std::wstring& comment, const std::wstring& categoryName) override; - virtual void removeBookmark(const Id id) override; - virtual void removeBookmarkCategory(const Id id) override; + void removeBookmark(const Id id) override; + void removeBookmarkCategory(const Id id) override; // END TODO - virtual std::vector getAllNodeBookmarks() const override; - virtual std::vector getAllEdgeBookmarks() const override; - virtual std::vector getAllBookmarkCategories() const override; + std::vector getAllNodeBookmarks() const override; + std::vector getAllEdgeBookmarks() const override; + std::vector getAllBookmarkCategories() const override; - virtual TooltipInfo getTooltipInfoForTokenIds(const std::vector& tokenIds, TooltipOrigin origin) const override; - virtual TooltipInfo getTooltipInfoForSourceLocationIdsAndLocalSymbolIds( + TooltipInfo getTooltipInfoForTokenIds(const std::vector& tokenIds, TooltipOrigin origin) const override; + TooltipInfo getTooltipInfoForSourceLocationIdsAndLocalSymbolIds( const std::vector& locationIds, const std::vector& localSymbolIds) const override; private: - StorageAccess* m_subject; + std::weak_ptr m_subject; }; #endif // STORAGE_ACCESS_PROXY_H diff --git a/src/lib/project/Project.cpp b/src/lib/project/Project.cpp index b3962edb..2c1b3029 100644 --- a/src/lib/project/Project.cpp +++ b/src/lib/project/Project.cpp @@ -98,7 +98,7 @@ void Project::load(std::shared_ptr dialogView) } m_storageCache->clear(); - m_storageCache->setSubject(nullptr); + m_storageCache->setSubject(std::weak_ptr()); // TODO: check if this is really required. if (!m_settings->reload()) { @@ -192,7 +192,7 @@ void Project::load(std::shared_ptr dialogView) { m_storage->setMode(SqliteStorage::STORAGE_MODE_READ); m_storage->buildCaches(); - m_storageCache->setSubject(m_storage.get()); + m_storageCache->setSubject(m_storage); if (m_hasGUI) { @@ -408,7 +408,7 @@ void Project::buildIndex(const RefreshInfo& info, std::shared_ptr di MessageIndexingStatus(true, 0).dispatch(); m_storageCache->clear(); - m_storageCache->setSubject(m_storage.get()); + m_storageCache->setSubject(m_storage); const FilePath indexDbFilePath = m_storage->getIndexDbFilePath(); const FilePath tempIndexDbFilePath = indexDbFilePath.replaceExtension(TEMP_INDEX_DB_FILE_EXTENSION); @@ -596,7 +596,7 @@ void Project::swapToTempStorage() m_storage->buildCaches(); //dialogView->hideUnknownProgressDialog(); - m_storageCache->setSubject(m_storage.get()); + m_storageCache->setSubject(m_storage); } void Project::discardTempStorage()