diff --git a/src/app/qt/view/graphElements/QtGraphEdge.cpp b/src/app/qt/view/graphElements/QtGraphEdge.cpp index 7f702674..c7fd3d49 100644 --- a/src/app/qt/view/graphElements/QtGraphEdge.cpp +++ b/src/app/qt/view/graphElements/QtGraphEdge.cpp @@ -151,7 +151,12 @@ void QtGraphEdge::onClick() } else { - MessageActivateEdge(getData()->getId(), getData()->getType(), getData()->getName()).dispatch(); + MessageActivateEdge( + getData()->getId(), + getData()->getType(), + getData()->getFrom()->getNameHierarchy(), + getData()->getTo()->getNameHierarchy() + ).dispatch(); } } diff --git a/src/lib/Application.cpp b/src/lib/Application.cpp index d03aeaee..945091c6 100644 --- a/src/lib/Application.cpp +++ b/src/lib/Application.cpp @@ -109,7 +109,7 @@ void Application::handleMessage(MessageFinishedParsing* message) m_isInitialParse = false; - Id mainId = m_storageCache->getIdForNodeWithName("main"); + Id mainId = m_storageCache->getIdForNodeWithNameHierarchy(NameHierarchy("main")); if (!mainId) { @@ -122,7 +122,7 @@ void Application::handleMessage(MessageFinishedParsing* message) message.addNode( mainId, m_storageCache->getNodeTypeForNodeWithId(mainId), - m_storageCache->getNameForNodeWithId(mainId) + m_storageCache->getNameHierarchyForNodeWithId(mainId) ); message.isFromSystem = true; message.dispatch(); diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index 43387777..9fddb8d9 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -188,6 +188,8 @@ add_files( data/StorageCache.cpp data/StorageCache.h data/StorageTypes.h + data/TaskCleanStorage.cpp + data/TaskCleanStorage.h settings/ApplicationSettings.cpp settings/ApplicationSettings.h diff --git a/src/lib/Project.cpp b/src/lib/Project.cpp index 547b28f1..6dfbed89 100644 --- a/src/lib/Project.cpp +++ b/src/lib/Project.cpp @@ -7,9 +7,11 @@ #include "data/access/StorageAccessProxy.h" #include "data/graph/Token.h" #include "data/parser/cxx/TaskParseCxx.h" +#include "data/TaskCleanStorage.h" #include "settings/ApplicationSettings.h" #include "settings/ProjectSettings.h" #include "utility/file/FileSystem.h" +#include "utility/scheduling/TaskGroupSequential.h" std::shared_ptr Project::create(StorageAccessProxy* storageAccessProxy) { @@ -103,27 +105,28 @@ void Project::parseCode() std::set removedFilePaths = m_fileManager.getRemovedFilePaths(); utility::append(updatedFilePaths, m_storage->getDependingFilePaths(updatedFilePaths)); - utility::append(removedFilePaths, m_storage->getDependingFilePaths(removedFilePaths)); + utility::append(updatedFilePaths, m_storage->getDependingFilePaths(removedFilePaths)); - MessageStatus("Clearing updated files").dispatch(); - m_storage->clearFileElements(updatedFilePaths); + std::shared_ptr taskGroup = std::make_shared(); - MessageStatus("Clearing removed files").dispatch(); - m_storage->clearFileElements(removedFilePaths); + std::set filesToClean; + utility::append(filesToClean, removedFilePaths); + utility::append(filesToClean, updatedFilePaths); - MessageStatus("Cleaning up names").dispatch(); - m_storage->removeUnusedNames(); + taskGroup->addTask(std::make_shared(m_storage.get(), filesToClean)); std::vector filesToParse; filesToParse.insert(filesToParse.end(), addedFilePaths.begin(), addedFilePaths.end()); filesToParse.insert(filesToParse.end(), updatedFilePaths.begin(), updatedFilePaths.end()); - Task::dispatch(std::make_shared( + taskGroup->addTask(std::make_shared( m_storage.get(), &m_fileManager, getParserArguments(), filesToParse )); + + Task::dispatch(taskGroup); } void Project::logStats() const diff --git a/src/lib/component/controller/CodeController.cpp b/src/lib/component/controller/CodeController.cpp index f48aa887..7a0d0a4e 100644 --- a/src/lib/component/controller/CodeController.cpp +++ b/src/lib/component/controller/CodeController.cpp @@ -270,7 +270,7 @@ std::vector CodeController::getSnippetsForFile(std: m_storageAccess->getTokenLocationOfParentScope(firstUsedLine->getTokenLocations().begin()->second.get())->forEachStartTokenLocation( [&](TokenLocation* location) { - params.title = m_storageAccess->getNameForNodeWithId(location->getTokenId()); + params.title = m_storageAccess->getNameHierarchyForNodeWithId(location->getTokenId()).getFullName(); params.titleId = location->getId(); } ); diff --git a/src/lib/component/controller/FeatureController.cpp b/src/lib/component/controller/FeatureController.cpp index 2a20dc35..d9d39889 100644 --- a/src/lib/component/controller/FeatureController.cpp +++ b/src/lib/component/controller/FeatureController.cpp @@ -19,19 +19,8 @@ void FeatureController::handleMessage(MessageActivateEdge* message) { if (message->type == Edge::EDGE_AGGREGATION) { - const std::string sourceStartDelimiter = ":"; - const std::string sourceEndDelimiter = "->"; - - const int sourceStartPosition = message->name.find(sourceStartDelimiter) + sourceStartDelimiter.size(); - const int sourceEndPosition = message->name.find(sourceEndDelimiter); - const int targetStartPosition = sourceEndPosition + sourceEndDelimiter.size(); - const int targetEndPosition = message->name.size(); - - const std::string sourceName = message->name.substr(sourceStartPosition, sourceEndPosition - sourceStartPosition); - const std::string targetName = message->name.substr(targetStartPosition, targetEndPosition - targetStartPosition); - - const int sourceId = m_storageAccess->getIdForNodeWithName(sourceName); - const int targetId = m_storageAccess->getIdForNodeWithName(targetName); + const Id sourceId = m_storageAccess->getIdForNodeWithNameHierarchy(message->fromNameHierarchy); + const Id targetId = m_storageAccess->getIdForNodeWithNameHierarchy(message->toNameHierarchy); MessageActivateTokens m(m_storageAccess->getTokenIdsForAggregationEdge(sourceId, targetId)); m.isAggregation = true; @@ -44,7 +33,7 @@ void FeatureController::handleMessage(MessageActivateEdge* message) if (!message->isFresh()) { - edgeId = m_storageAccess->getIdForEdgeWithName(message->name); + edgeId = m_storageAccess->getIdForEdge(message->type, message->fromNameHierarchy, message->toNameHierarchy); } if (!edgeId) @@ -80,17 +69,18 @@ void FeatureController::handleMessage(MessageActivateNodes* message) { for (const MessageActivateNodes::ActiveNode& node : message->nodes) { - nodeIds.push_back(m_storageAccess->getIdForNodeWithName(node.name)); + Id nodeId = m_storageAccess->getIdForNodeWithNameHierarchy(node.nameHierarchy); + if (nodeId > 0) + { + nodeIds.push_back(nodeId); + } } } - if (nodeIds.size()) - { - MessageActivateTokens m(nodeIds); - m.isFromSystem = message->isFromSystem; - m.undoRedoType = message->undoRedoType; - m.dispatchImmediately(); - } + MessageActivateTokens m(nodeIds); + m.isFromSystem = message->isFromSystem; + m.undoRedoType = message->undoRedoType; + m.dispatchImmediately(); } void FeatureController::handleMessage(MessageActivateTokenLocations* message) @@ -104,7 +94,7 @@ void FeatureController::handleMessage(MessageActivateTokenLocations* message) msg.addNode( nodeId, m_storageAccess->getNodeTypeForNodeWithId(nodeId), - m_storageAccess->getNameForNodeWithId(nodeId) + m_storageAccess->getNameHierarchyForNodeWithId(nodeId) ); } msg.dispatchImmediately(); diff --git a/src/lib/component/controller/GraphController.cpp b/src/lib/component/controller/GraphController.cpp index 9b348e1e..cd17648d 100644 --- a/src/lib/component/controller/GraphController.cpp +++ b/src/lib/component/controller/GraphController.cpp @@ -43,6 +43,12 @@ void GraphController::handleMessage(MessageActivateTokens* message) m_activeEdgeIds.clear(); } + if (!m_activeNodeIds.size() && !m_activeEdgeIds.size()) + { + clear(); + return; + } + createDummyGraphForTokenIds(utility::concat(m_activeNodeIds, m_activeEdgeIds)); buildGraph(message); @@ -133,6 +139,18 @@ GraphView* GraphController::getView() const return Controller::getView(); } +void GraphController::clear() +{ + m_dummyNodes.clear(); + m_dummyEdges.clear(); + + m_activeNodeIds.clear(); + m_activeEdgeIds.clear(); + + m_graph.reset(); + getView()->clear(); +} + void GraphController::createDummyGraphForTokenIds(const std::vector& tokenIds) { GraphView* view = getView(); diff --git a/src/lib/component/controller/GraphController.h b/src/lib/component/controller/GraphController.h index 72da41a2..357cb0f0 100644 --- a/src/lib/component/controller/GraphController.h +++ b/src/lib/component/controller/GraphController.h @@ -48,6 +48,8 @@ private: GraphView* getView() const; + void clear(); + void createDummyGraphForTokenIds(const std::vector& tokenIds); DummyNode createDummyNodeTopDown(Node* node); diff --git a/src/lib/component/controller/SearchController.cpp b/src/lib/component/controller/SearchController.cpp index d111e2d1..704c83df 100644 --- a/src/lib/component/controller/SearchController.cpp +++ b/src/lib/component/controller/SearchController.cpp @@ -40,7 +40,7 @@ void SearchController::handleMessage(MessageActivateNodes* message) for (const MessageActivateNodes::ActiveNode& node : message->nodes) { SearchMatch match; - match.fullName = node.name; + match.fullName = node.nameHierarchy.getFullName(); match.nodeType = node.type; match.tokenIds.insert(node.nodeId); match.searchType = SearchMatch::SEARCH_TOKEN; diff --git a/src/lib/component/controller/UndoRedoController.cpp b/src/lib/component/controller/UndoRedoController.cpp index c1b7417b..e2a85fba 100644 --- a/src/lib/component/controller/UndoRedoController.cpp +++ b/src/lib/component/controller/UndoRedoController.cpp @@ -28,7 +28,7 @@ UndoRedoController::Command::Command(std::shared_ptr message, size_ void UndoRedoController::handleMessage(MessageActivateEdge* message) { if (m_lastCommand.message && m_lastCommand.message->getType() == message->getType() && - static_cast(m_lastCommand.message.get())->name == message->name) + static_cast(m_lastCommand.message.get())->getFullName() == message->getFullName()) { return; } @@ -53,7 +53,8 @@ void UndoRedoController::handleMessage(MessageActivateNodes* message) { if (m_lastCommand.message && m_lastCommand.message->getType() == message->getType() && message->nodes.size() && static_cast(m_lastCommand.message.get())->nodes.size() == message->nodes.size() && - static_cast(m_lastCommand.message.get())->nodes[0].name == message->nodes[0].name) + static_cast(m_lastCommand.message.get())->nodes[0].nameHierarchy.getFullName() == + message->nodes[0].nameHierarchy.getFullName()) { return; } diff --git a/src/lib/data/Storage.cpp b/src/lib/data/Storage.cpp index e0a70c46..22f0f76f 100644 --- a/src/lib/data/Storage.cpp +++ b/src/lib/data/Storage.cpp @@ -46,24 +46,6 @@ void Storage::clearCaches() m_hierarchyCache.clear(); } -void Storage::clearFileElements(const std::set& filePaths) -{ - for (const FilePath& filePath: filePaths) - { - clearFileElements(filePath); - } -} - -void Storage::clearFileElements(const FilePath& filePath) -{ - Id fileId = m_sqliteStorage.getFileByName(filePath.fileName()).id; - if (fileId != 0) - { - m_sqliteStorage.removeElementsWithLocationInFile(fileId); - m_sqliteStorage.removeFile(fileId); - } -} - std::set Storage::getDependingFilePaths(const std::set& filePaths) { std::set dependingFilePaths; @@ -79,15 +61,12 @@ std::set Storage::getDependingFilePaths(const FilePath& filePath) { std::set dependingFilePaths; - Id fileNodeId = getFileNodeId(filePath); std::vector incomingEdges = m_sqliteStorage.getEdgesByTargetType( - fileNodeId, Edge::typeToInt(Edge::EDGE_INCLUDE) + getFileNodeId(filePath), Edge::typeToInt(Edge::EDGE_INCLUDE) ); - for (StorageEdge incomingEdge: incomingEdges) + for (const StorageEdge& incomingEdge: incomingEdges) { - Id dependingFileId = incomingEdge.sourceNodeId; - FilePath dependingFilePath = FilePath(m_sqliteStorage.getFileById(dependingFileId).filePath); - + FilePath dependingFilePath = getFileNodePath(incomingEdge.sourceNodeId); dependingFilePaths.insert(dependingFilePath); std::set dependingFilePathsSubset = getDependingFilePaths(dependingFilePath); @@ -97,6 +76,16 @@ std::set Storage::getDependingFilePaths(const FilePath& filePath) return dependingFilePaths; } +void Storage::clearFileElement(const FilePath& filePath) +{ + Id fileId = getFileNodeId(filePath); + if (fileId != 0) + { + m_sqliteStorage.removeElementsWithLocationInFile(fileId); + m_sqliteStorage.removeFile(fileId); + } +} + void Storage::removeUnusedNames() { m_sqliteStorage.removeUnusedNameHierarchyElements(); @@ -688,44 +677,30 @@ Id Storage::onMacroExpandParsed(const ParseLocation &location, const NameHierarc return edgeId; } -Id Storage::getIdForNodeWithName(const std::string& fullName) const // use name hierarchy here +Id Storage::getIdForNodeWithNameHierarchy(const NameHierarchy& nameHierarchy) const { - std::vector nameParts = utility::splitToVector(fullName, "::"); + Id currentId = 0; - Id parentId = 0; - for (size_t i = 0; i < nameParts.size(); i++) + for (size_t i = 0; i < nameHierarchy.size(); i++) { - Id currentId = 0; - if (parentId == 0) - { - currentId = m_sqliteStorage.getNameHierarchyElementIdByName(nameParts[i]); - } - else - { - currentId = m_sqliteStorage.getNameHierarchyElementIdByName(nameParts[i], parentId); - } - - parentId = currentId; + Id parentId = currentId; + currentId = m_sqliteStorage.getNameHierarchyElementIdByName(nameHierarchy[i]->getFullName(), parentId); if (currentId == 0) { + currentId = parentId; break; } } - return m_sqliteStorage.getNodeByNameId(parentId).id; + return m_sqliteStorage.getNodeByNameId(currentId).id; } -Id Storage::getIdForEdgeWithName(const std::string& name) const -{ - Edge::EdgeType type; - std::string sourceName; - std::string targetName; - - Edge::splitName(name, &type, &sourceName, &targetName); - - int sourceId = getIdForNodeWithName(sourceName); - int targetId = getIdForNodeWithName(targetName); +Id Storage::getIdForEdge( + Edge::EdgeType type, const NameHierarchy& fromNameHierarchy, const NameHierarchy& toNameHierarchy +) const { + int sourceId = getIdForNodeWithNameHierarchy(fromNameHierarchy); + int targetId = getIdForNodeWithNameHierarchy(toNameHierarchy); return m_sqliteStorage.getEdgeBySourceTargetType(sourceId, targetId, type).id; } @@ -750,10 +725,10 @@ std::vector Storage::getInfoOnAllFiles() const return fileInfos; } -std::string Storage::getNameForNodeWithId(Id nodeId) const +NameHierarchy Storage::getNameHierarchyForNodeWithId(Id nodeId) const { Id nameHierarchyElementId = m_sqliteStorage.getNameHierarchyElementIdByNodeId(nodeId); - return m_sqliteStorage.getNameHierarchyById(nameHierarchyElementId).getFullName(); + return m_sqliteStorage.getNameHierarchyById(nameHierarchyElementId); // return m_tokenIndex.getNameHierarchyForTokenId(nodeId).getFullName(); } @@ -1325,6 +1300,19 @@ Id Storage::getFileNodeId(const FilePath& filePath) const return storageFile.id; } +FilePath Storage::getFileNodePath(Id fileId) const +{ + for (const std::pair& p : m_fileNodeIds) + { + if (p.second == fileId) + { + return p.first; + } + } + + return m_sqliteStorage.getFileById(fileId).filePath; +} + Id Storage::getLastVisibleParentNodeId(const Id nodeId) const { return m_hierarchyCache.getLastVisibleParentNodeId(nodeId); diff --git a/src/lib/data/Storage.h b/src/lib/data/Storage.h index 1c4c695d..e830911f 100644 --- a/src/lib/data/Storage.h +++ b/src/lib/data/Storage.h @@ -26,11 +26,10 @@ public: void clear(); void clearCaches(); - void clearFileElements(const std::set& filePaths); - void clearFileElements(const FilePath& filePath); std::set getDependingFilePaths(const std::set& filePaths); std::set getDependingFilePaths(const FilePath& filePath); + void clearFileElement(const FilePath& filePath); void removeUnusedNames(); void logGraph() const; @@ -123,12 +122,13 @@ public: virtual Id onMacroExpandParsed(const ParseLocation& location, const NameHierarchy& macroNameHierarchy); // StorageAccess implementation - virtual Id getIdForNodeWithName(const std::string& fullName) const; - virtual Id getIdForEdgeWithName(const std::string& name) const; + virtual Id getIdForNodeWithNameHierarchy(const NameHierarchy& nameHierarchy) const; + virtual Id getIdForEdge( + Edge::EdgeType type, const NameHierarchy& fromNameHierarchy, const NameHierarchy& toNameHierarchy) const; virtual std::vector getInfoOnAllFiles() const; - virtual std::string getNameForNodeWithId(Id nodeId) const; + virtual NameHierarchy getNameHierarchyForNodeWithId(Id nodeId) const; virtual Node::NodeType getNodeTypeForNodeWithId(Id nodeId) const; virtual std::vector getAutocompletionMatches( const std::string& query, const std::string& word) const; @@ -168,6 +168,7 @@ private: Id addEdge(Id sourceNodeId, Id targetNodeId, Edge::EdgeType type, ParseLocation location); Id getFileNodeId(const FilePath& filePath) const; + FilePath getFileNodePath(Id fileId) const; Id getLastVisibleParentNodeId(const Id nodeId) const; std::vector getAllChildNodeIds(const Id nodeId) const; diff --git a/src/lib/data/TaskCleanStorage.cpp b/src/lib/data/TaskCleanStorage.cpp new file mode 100644 index 00000000..7bd29db0 --- /dev/null +++ b/src/lib/data/TaskCleanStorage.cpp @@ -0,0 +1,60 @@ +#include "data/TaskCleanStorage.h" + +#include "data/Storage.h" +#include "utility/messaging/type/MessageStatus.h" + +TaskCleanStorage::TaskCleanStorage(Storage* storage, const std::set& filePaths) + : m_storage(storage) + , m_fileCount(filePaths.size()) +{ + for (const FilePath& p : filePaths) + { + m_filePaths.push(p); + } +} + +void TaskCleanStorage::enter() +{ + m_start = utility::durationStart(); +} + +Task::TaskState TaskCleanStorage::update() +{ + if (!m_filePaths.size()) + { + if (m_fileCount) + { + MessageStatus("Cleaning up names", false, true).dispatch(); + m_storage->removeUnusedNames(); + } + + return Task::STATE_FINISHED; + } + + FilePath filePath = m_filePaths.front(); + m_filePaths.pop(); + + std::stringstream ss; + ss << "clearing (ESC to quit): ["; + ss << m_fileCount - m_filePaths.size() - 1 << "/" << m_fileCount << "] "; + ss << filePath.str(); + + MessageStatus(ss.str(), false, true).dispatch(); + + m_storage->clearFileElement(filePath); + + return Task::STATE_RUNNING; +} + +void TaskCleanStorage::exit() +{ + // std::cout << "clean duration: " << utility::duration(m_start) << std::endl; +} + +void TaskCleanStorage::interrupt() +{ +} + +void TaskCleanStorage::revert() +{ +} diff --git a/src/lib/data/TaskCleanStorage.h b/src/lib/data/TaskCleanStorage.h new file mode 100644 index 00000000..3f35dfcd --- /dev/null +++ b/src/lib/data/TaskCleanStorage.h @@ -0,0 +1,37 @@ +#ifndef TASK_CLEAN_STORAGE_H +#define TASK_CLEAN_STORAGE_H + +#include +#include + +#include "utility/file/FilePath.h" +#include "utility/scheduling/Task.h" +#include "utility/utility.h" + +class Storage; + +class TaskCleanStorage + : public Task +{ +public: + TaskCleanStorage( + Storage* storage, + const std::set& filePaths + ); + + virtual void enter(); + virtual TaskState update(); + virtual void exit(); + + virtual void interrupt(); + virtual void revert(); + +private: + Storage* m_storage; + std::queue m_filePaths; + const size_t m_fileCount; + + utility::TimePoint m_start; +}; + +#endif // TASK_PARSE_CXX_H diff --git a/src/lib/data/access/StorageAccess.h b/src/lib/data/access/StorageAccess.h index 78e4e755..5b3cf200 100644 --- a/src/lib/data/access/StorageAccess.h +++ b/src/lib/data/access/StorageAccess.h @@ -23,12 +23,13 @@ class StorageAccess public: virtual ~StorageAccess(); - virtual Id getIdForNodeWithName(const std::string& name) const = 0; - virtual Id getIdForEdgeWithName(const std::string& name) const = 0; + virtual Id getIdForNodeWithNameHierarchy(const NameHierarchy& nameHierarchy) const = 0; + virtual Id getIdForEdge( + Edge::EdgeType type, const NameHierarchy& fromNameHierarchy, const NameHierarchy& toNameHierarchy) const = 0; virtual std::vector getInfoOnAllFiles() const = 0; - virtual std::string getNameForNodeWithId(Id id) const = 0; + virtual NameHierarchy getNameHierarchyForNodeWithId(Id id) const = 0; virtual Node::NodeType getNodeTypeForNodeWithId(Id id) const = 0; virtual std::vector getAutocompletionMatches( const std::string& query, const std::string& word) const = 0; diff --git a/src/lib/data/access/StorageAccessProxy.cpp b/src/lib/data/access/StorageAccessProxy.cpp index 757edbbc..9226836a 100644 --- a/src/lib/data/access/StorageAccessProxy.cpp +++ b/src/lib/data/access/StorageAccessProxy.cpp @@ -32,21 +32,22 @@ void StorageAccessProxy::setSubject(StorageAccess* subject) m_subject = subject; } -Id StorageAccessProxy::getIdForNodeWithName(const std::string& name) const +Id StorageAccessProxy::getIdForNodeWithNameHierarchy(const NameHierarchy& nameHierarchy) const { if (hasSubject()) { - return m_subject->getIdForNodeWithName(name); + return m_subject->getIdForNodeWithNameHierarchy(nameHierarchy); } return 0; } -Id StorageAccessProxy::getIdForEdgeWithName(const std::string& name) const -{ +Id StorageAccessProxy::getIdForEdge( + Edge::EdgeType type, const NameHierarchy& fromNameHierarchy, const NameHierarchy& toNameHierarchy +) const { if (hasSubject()) { - return m_subject->getIdForEdgeWithName(name); + return m_subject->getIdForEdge(type, fromNameHierarchy, toNameHierarchy); } return 0; @@ -71,14 +72,14 @@ Node::NodeType StorageAccessProxy::getNodeTypeForNodeWithId(Id id) const return Node::NODE_UNDEFINED; } -std::string StorageAccessProxy::getNameForNodeWithId(Id id) const +NameHierarchy StorageAccessProxy::getNameHierarchyForNodeWithId(Id id) const { if (hasSubject()) { - return m_subject->getNameForNodeWithId(id); + return m_subject->getNameHierarchyForNodeWithId(id); } - return ""; + return NameHierarchy(); } std::vector StorageAccessProxy::getAutocompletionMatches( diff --git a/src/lib/data/access/StorageAccessProxy.h b/src/lib/data/access/StorageAccessProxy.h index 934872e9..2b8409c3 100644 --- a/src/lib/data/access/StorageAccessProxy.h +++ b/src/lib/data/access/StorageAccessProxy.h @@ -13,12 +13,13 @@ public: void setSubject(StorageAccess* subject); // StorageAccess implementation - virtual Id getIdForNodeWithName(const std::string& name) const; - virtual Id getIdForEdgeWithName(const std::string& name) const; + virtual Id getIdForNodeWithNameHierarchy(const NameHierarchy& nameHierarchy) const; + virtual Id getIdForEdge( + Edge::EdgeType type, const NameHierarchy& fromNameHierarchy, const NameHierarchy& toNameHierarchy) const; virtual std::vector getInfoOnAllFiles() const; - virtual std::string getNameForNodeWithId(Id id) const; + virtual NameHierarchy getNameHierarchyForNodeWithId(Id id) const; virtual Node::NodeType getNodeTypeForNodeWithId(Id id) const; virtual std::vector getAutocompletionMatches( const std::string& query, const std::string& word) const; diff --git a/src/lib/data/graph/Edge.cpp b/src/lib/data/graph/Edge.cpp index 9be01262..17ff3446 100644 --- a/src/lib/data/graph/Edge.cpp +++ b/src/lib/data/graph/Edge.cpp @@ -117,24 +117,6 @@ std::string Edge::getName() const return getTypeString() + ":" + getFrom()->getFullName() + "->" + getTo()->getFullName(); } -void Edge::splitName(const std::string& name, EdgeType* type, std::string* fromName, std::string* toName) -{ - EdgeTypeMask mask = 1; - std::string typeStr = utility::substrBefore(name, ':'); - - while (typeStr != getTypeString(static_cast(mask))) - { - mask = mask << 1; - } - - *type = static_cast(mask); - - std::string names = utility::substrAfter(name, ':'); - - *fromName = utility::substrBefore(names, '-'); - *toName = utility::substrAfter(utility::substrAfter(names, '-'), '>'); -} - bool Edge::isNode() const { return false; diff --git a/src/lib/data/graph/Edge.h b/src/lib/data/graph/Edge.h index 46eae516..38a59e1b 100644 --- a/src/lib/data/graph/Edge.h +++ b/src/lib/data/graph/Edge.h @@ -54,7 +54,6 @@ public: Node* getTo() const; std::string getName() const; - static void splitName(const std::string& name, EdgeType* type, std::string* fromName, std::string* toName); // Token implementation virtual bool isNode() const; diff --git a/src/lib/data/graph/Node.cpp b/src/lib/data/graph/Node.cpp index cba5234a..a8425a79 100644 --- a/src/lib/data/graph/Node.cpp +++ b/src/lib/data/graph/Node.cpp @@ -156,6 +156,11 @@ std::string Node::getFullName() const return m_nameHierarchy.getFullName(); } +NameHierarchy Node::getNameHierarchy() const +{ + return m_nameHierarchy; +} + const std::vector& Node::getEdges() const { return m_edges; diff --git a/src/lib/data/graph/Node.h b/src/lib/data/graph/Node.h index cc4acfd0..e9bc067c 100644 --- a/src/lib/data/graph/Node.h +++ b/src/lib/data/graph/Node.h @@ -62,6 +62,7 @@ public: std::string getName() const; std::string getFullName() const; + NameHierarchy getNameHierarchy() const; const std::vector& getEdges() const; diff --git a/src/lib/utility/messaging/type/MessageActivateEdge.h b/src/lib/utility/messaging/type/MessageActivateEdge.h index 3f13b841..21a8e1cf 100644 --- a/src/lib/utility/messaging/type/MessageActivateEdge.h +++ b/src/lib/utility/messaging/type/MessageActivateEdge.h @@ -5,15 +5,17 @@ #include "utility/types.h" #include "data/graph/Edge.h" +#include "data/name/NameHierarchy.h" class MessageActivateEdge : public Message { public: - MessageActivateEdge(Id tokenId, Edge::EdgeType type, const std::string& name) + MessageActivateEdge(Id tokenId, Edge::EdgeType type, const NameHierarchy& fromName, const NameHierarchy& toName) : tokenId(tokenId) , type(type) - , name(name) + , fromNameHierarchy(fromName) + , toNameHierarchy(toName) { } @@ -27,9 +29,15 @@ public: return type == Edge::EDGE_AGGREGATION; } + std::string getFullName() const + { + return Edge::getTypeString(type) + ":" + fromNameHierarchy.getFullName() + "->" + toNameHierarchy.getFullName(); + } + const Id tokenId; const Edge::EdgeType type; - const std::string name; + const NameHierarchy fromNameHierarchy; + const NameHierarchy toNameHierarchy; }; #endif // MESSAGE_ACTIVATE_EDGE_H diff --git a/src/lib/utility/messaging/type/MessageActivateNodes.h b/src/lib/utility/messaging/type/MessageActivateNodes.h index 89fae329..7d0abc4a 100644 --- a/src/lib/utility/messaging/type/MessageActivateNodes.h +++ b/src/lib/utility/messaging/type/MessageActivateNodes.h @@ -14,7 +14,7 @@ public: { Id nodeId; Node::NodeType type; - std::string name; + NameHierarchy nameHierarchy; }; MessageActivateNodes() @@ -22,12 +22,12 @@ public: { } - void addNode(Id tokenId, Node::NodeType type, const std::string& name) + void addNode(Id tokenId, Node::NodeType type, const NameHierarchy& nameHierarchy) { ActiveNode node; node.nodeId = tokenId; node.type = type; - node.name = name; + node.nameHierarchy = nameHierarchy; nodes.push_back(node); }