ui: bookmarks

can now bookmark tokens
This commit is contained in:
wrongway88
2017-02-12 15:06:07 +01:00
parent e1d2c3a4e0
commit 97fd40fe9b
84 changed files with 5024 additions and 65 deletions
+7
View File
@@ -167,6 +167,13 @@ void IntermediateStorage::addError(const std::string& message, const FilePath& f
));
}
Id IntermediateStorage::addBookmark(const Bookmark& bookmark)
{
m_bookmarks.push_back(bookmark);
return -1;
}
void IntermediateStorage::forEachNode(std::function<void(const Id /*id*/, const StorageNode& /*data*/)> callback) const
{
for (std::map<Id, std::shared_ptr<StorageNode>>::const_iterator it = m_nodeIdsToData.begin(); it != m_nodeIdsToData.end(); it++)
+2
View File
@@ -27,6 +27,7 @@ public:
virtual void addComponentAccess(Id nodeId , int type);
virtual void addCommentLocation(Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol);
virtual void addError(const std::string& message, const FilePath& filePath, uint startLine, uint startCol, bool fatal, bool indexed);
virtual Id addBookmark(const Bookmark& bookmark);
virtual void forEachNode(std::function<void(const Id /*id*/, const StorageNode& /*data*/)> callback) const;
virtual void forEachFile(std::function<void(const StorageFile& /*data*/)> callback) const;
@@ -65,6 +66,7 @@ private:
std::vector<StorageComponentAccess> m_componentAccesses;
std::vector<StorageCommentLocation> m_commentLocations;
std::vector<StorageError> m_errors;
std::vector<Bookmark> m_bookmarks;
Id m_nextId;
};
+95
View File
@@ -149,6 +149,86 @@ void PersistentStorage::addError(
);
}
Id PersistentStorage::addNodeBookmark(const NodeBookmark& bookmark)
{
return m_sqliteStorage.addNodeBookmark(bookmark);
}
Id PersistentStorage::addEdgeBookmark(const EdgeBookmark& bookmark)
{
return m_sqliteStorage.addEdgeBookmark(bookmark);
}
Id PersistentStorage::addBookmarkCategory(const BookmarkCategory& category)
{
return m_sqliteStorage.addBookmarkCategory(category.getName());
}
std::vector<NodeBookmark> PersistentStorage::getAllNodeBookmarks() const
{
return m_sqliteStorage.getAllNodeBookmarks();
}
NodeBookmark PersistentStorage::getNodeBookmarkById(const Id bookmarkId) const
{
return m_sqliteStorage.getNodeBookmarkById(bookmarkId);
}
bool PersistentStorage::checkNodeBookmarkExistsByTokens(const std::vector<std::string>& tokenNames) const
{
return m_sqliteStorage.checkNodeBookmarkExistsByNames(tokenNames);
}
void PersistentStorage::removeNodeBookmark(Id id)
{
m_sqliteStorage.removeNodeBookmark(id);
}
void PersistentStorage::editNodeBookmark(const NodeBookmark& bookmark)
{
m_sqliteStorage.editNodeBookmark(bookmark);
}
std::vector<EdgeBookmark> PersistentStorage::getAllEdgeBookmarks() const
{
return m_sqliteStorage.getAllEdgeBookmarks();
}
EdgeBookmark PersistentStorage::getEdgeBookmarkById(const Id bookmarkId) const
{
return m_sqliteStorage.getEdgeBookmarkById(bookmarkId);
}
bool PersistentStorage::checkEdgeBookmarkExistsByTokens(const std::vector<std::string>& tokenNames) const
{
return m_sqliteStorage.checkEdgeBookmarkExistsByNames(tokenNames);
}
void PersistentStorage::removeEdgeBookmark(Id id)
{
m_sqliteStorage.removeEdgeBookmark(id);
}
void PersistentStorage::editEdgeBookmark(const EdgeBookmark& bookmark)
{
m_sqliteStorage.editEdgeBookmark(bookmark);
}
bool PersistentStorage::checkBookmarkCategoryExists(const std::string& name) const
{
return m_sqliteStorage.checkBookmarkCategoryExists(name);
}
std::vector<BookmarkCategory> PersistentStorage::getAllBookmarkCategories() const
{
return m_sqliteStorage.getAllBookmarkCategories();
}
void PersistentStorage::removeBookmarkCategory(Id id)
{
m_sqliteStorage.removeBookmarkCategory(id);
}
void PersistentStorage::forEachNode(std::function<void(const Id /*id*/, const StorageNode& /*data*/)> callback) const
{
for (StorageNode& node: m_sqliteStorage.getAll<StorageNode>())
@@ -394,6 +474,11 @@ Id PersistentStorage::getIdForEdge(
return m_sqliteStorage.getEdgeBySourceTargetType(sourceId, targetId, type).id;
}
StorageEdge PersistentStorage::getEdgeById(Id edgeId) const
{
return m_sqliteStorage.getEdgeById(edgeId);
}
NameHierarchy PersistentStorage::getNameHierarchyForNodeWithId(Id nodeId) const
{
TRACE();
@@ -907,6 +992,11 @@ std::vector<Id> PersistentStorage::getActiveTokenIdsForId(Id tokenId, Id* declar
return activeTokenIds;
}
bool PersistentStorage::checkEdgeExists(Id edgeId) const
{
return m_sqliteStorage.checkEdgeExists(edgeId);
}
std::vector<Id> PersistentStorage::getNodeIdsForLocationIds(const std::vector<Id>& locationIds) const
{
TRACE();
@@ -975,6 +1065,11 @@ std::vector<Id> PersistentStorage::getLocalSymbolIdsForLocationIds(const std::ve
return utility::toVector(localSymbolIds);
}
bool PersistentStorage::checkNodeExistsByName(const std::string& serializedName) const
{
return m_sqliteStorage.checkNodeExistsByName(serializedName);
}
std::vector<Id> PersistentStorage::getTokenIdsForMatches(const std::vector<SearchMatch>& matches) const
{
FilePath rootPath = getDbFilePath().parentDirectory();
+23
View File
@@ -37,6 +37,25 @@ public:
virtual void addComponentAccess(Id nodeId , int type);
virtual void addCommentLocation(Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol);
virtual void addError(const std::string& message, const FilePath& filePath, uint startLine, uint startCol, bool fatal, bool indexed);
virtual Id addNodeBookmark(const NodeBookmark& bookmark);
virtual Id addEdgeBookmark(const EdgeBookmark& bookmark);
virtual Id addBookmarkCategory(const BookmarkCategory& category);
virtual std::vector<NodeBookmark> getAllNodeBookmarks() const;
virtual NodeBookmark getNodeBookmarkById(const Id bookmarkId) const;
virtual bool checkNodeBookmarkExistsByTokens(const std::vector<std::string>& tokenNames) const;
virtual void removeNodeBookmark(Id id);
virtual void editNodeBookmark(const NodeBookmark& bookmark);
virtual std::vector<EdgeBookmark> getAllEdgeBookmarks() const;
virtual EdgeBookmark getEdgeBookmarkById(const Id bookmarkId) const;
virtual bool checkEdgeBookmarkExistsByTokens(const std::vector<std::string>& tokenNames) const;
virtual void removeEdgeBookmark(Id id);
virtual void editEdgeBookmark(const EdgeBookmark& bookmark);
virtual bool checkBookmarkCategoryExists(const std::string& name) const;
virtual std::vector<BookmarkCategory> getAllBookmarkCategories() const;
virtual void removeBookmarkCategory(Id id);
virtual void forEachNode(std::function<void(const Id /*id*/, const StorageNode& /*data*/)> callback) const;
virtual void forEachFile(std::function<void(const StorageFile& /*data*/)> callback) const;
@@ -80,6 +99,7 @@ public:
virtual Id getIdForNodeWithNameHierarchy(const NameHierarchy& nameHierarchy) const;
virtual Id getIdForEdge(
Edge::EdgeType type, const NameHierarchy& fromNameHierarchy, const NameHierarchy& toNameHierarchy) const;
virtual StorageEdge getEdgeById(Id edgeId) const;
virtual NameHierarchy getNameHierarchyForNodeWithId(Id nodeId) const;
virtual Node::NodeType getNodeTypeForNodeWithId(Id nodeId) const;
@@ -97,8 +117,11 @@ public:
virtual std::vector<Id> getActiveTokenIdsForId(Id tokenId, Id* declarationId) const;
virtual bool checkEdgeExists(Id edgeId) const;
virtual std::vector<Id> getNodeIdsForLocationIds(const std::vector<Id>& locationIds) const;
virtual std::vector<Id> getLocalSymbolIdsForLocationIds(const std::vector<Id>& locationIds) const;
virtual bool checkNodeExistsByName(const std::string& serializedName) const;
virtual std::vector<Id> getTokenIdsForMatches(const std::vector<SearchMatch>& matches) const;
virtual Id getTokenIdForFileNode(const FilePath& filePath) const;
+790
View File
@@ -328,6 +328,203 @@ Id SqliteStorage::addError(const std::string& message, const FilePath& filePath,
return m_database.lastRowId();
}
Id SqliteStorage::addNodeBookmark(const NodeBookmark& bookmark)
{
std::string tokenName = bookmark.getDisplayName();
std::string comment = bookmark.getComment();
std::string timeStamp = bookmark.getTimeStamp().toString();
tokenName = utility::replace(tokenName, "'", "''");
comment = utility::replace(comment, "'", "''");
/*tokenName = utility::replace(tokenName, "\\", "/");
comment = utility::replace(comment, "\\", "/");*/
// for backwards compatibility
m_database.execDML(
"CREATE TABLE IF NOT EXISTS nodeBookmark("
"id INTEGER NOT NULL, "
"name TEXT, "
"comment TEXT, "
"timestamp TEXT, "
"category INTEGER, "
"PRIMARY KEY(id), "
"FOREIGN KEY(category) REFERENCES bookmarkCategory(id));"
);
m_database.execDML(
"CREATE TABLE IF NOT EXISTS nodeBookmarkToken("
"id INTEGER NOT NULL, "
"bookmarkId INTEGER NOT NULL, "
"name TEXT, "
"type INTEGER, "
"PRIMARY KEY(id), "
"FOREIGN KEY(bookmarkId) REFERENCES nodeBookmark(id) ON DELETE CASCADE);"
);
m_database.execDML(
"CREATE TABLE IF NOT EXISTS bookmarkCategory("
"id INTEGER NOT NULL, "
"name TEXT, "
"PRIMARY KEY(id));"
);
std::string statement = "INSERT INTO nodeBookmark(name, comment, timestamp, category) "
"VALUES (?, ?, ?, ?);";
int categoryId = getOrCreateBookmarkCategoryByName(bookmark.getCategory().getName()).getId();
CppSQLite3Statement stmt = m_database.compileStatement(statement.c_str());
stmt.bind(1, tokenName.c_str());
stmt.bind(2, comment.c_str());
stmt.bind(3, timeStamp.c_str());
stmt.bind(4, categoryId);
stmt.execDML();
Id id = m_database.lastRowId();
for (unsigned int i = 0; i < bookmark.getTokenNames().size(); i++)
{
std::string name = bookmark.getTokenNames()[i];
int type = bookmark.getTokenTypes()[i];
statement = "INSERT INTO nodeBookmarkToken(bookmarkId, name, type) "
"VALUES (" + std::to_string(id) + ", ?, " + std::to_string(type) + ");";
stmt = m_database.compileStatement(statement.c_str());
stmt.bind(1, name.c_str());
stmt.execDML();
}
return id;
}
Id SqliteStorage::addEdgeBookmark(const EdgeBookmark& bookmark)
{
std::string tokenName = bookmark.getDisplayName();
std::string comment = bookmark.getComment();
std::string timeStamp = bookmark.getTimeStamp().toString();
tokenName = utility::replace(tokenName, "'", "''");
comment = utility::replace(comment, "'", "''");
// for backwards compatibility
m_database.execDML(
"CREATE TABLE IF NOT EXISTS edgeBookmark("
"id INTEGER NOT NULL, "
"name TEXT, "
"comment TEXT, "
"timestamp TEXT, "
"category INTEGER, "
"PRIMARY KEY(id), "
"FOREIGN KEY(category) REFERENCES bookmarkCategory(id));"
);
m_database.execDML(
"CREATE TABLE IF NOT EXISTS edgeBookmarkToken("
"id INTEGER NOT NULL, "
"bookmarkId INTEGER NOT NULL, "
"name TEXT, "
"type INTEGER, "
"PRIMARY KEY(id), "
"FOREIGN KEY(bookmarkId) REFERENCES edgeBookmark(id) ON DELETE CASCADE);"
);
m_database.execDML(
"CREATE TABLE IF NOT EXISTS edgeBaseBookmark("
"id INTEGER NOT NULL, "
"edgeId INTEGER, "
"PRIMARY KEY(id), "
"FOREIGN KEY(edgeId) REFERENCES edgeBookmark(id) ON DELETE CASCADE);"
);
m_database.execDML(
"CREATE TABLE IF NOT EXISTS edgeBaseBookmarkToken("
"id INTEGER NOT NULL, "
"bookmarkId INTEGER NOT NULL, "
"name TEXT, "
"type INTEGER, "
"PRIMARY KEY(id), "
"FOREIGN KEY(bookmarkId) REFERENCES edgeBaseBookmark(id) ON DELETE CASCADE);"
);
std::string statement = "INSERT INTO edgeBookmark(name, comment, timestamp, category) "
"VALUES (?, ?, ?, ?);";
int categoryId = getOrCreateBookmarkCategoryByName(bookmark.getCategory().getName()).getId();
CppSQLite3Statement stmt = m_database.compileStatement(statement.c_str());
stmt.bind(1, tokenName.c_str());
stmt.bind(2, comment.c_str());
stmt.bind(3, timeStamp.c_str());
stmt.bind(4, categoryId);
stmt.execDML();
Id id = m_database.lastRowId();
for (unsigned int i = 0; i < bookmark.getEdgeTokenNames().size(); i++)
{
std::string name = bookmark.getEdgeTokenNames()[i];
int type = bookmark.getEdgeTokenTypes()[i];
statement = "INSERT INTO edgeBookmarkToken(bookmarkId, name, type) "
"VALUES (" + std::to_string(id) + ", ?, " + std::to_string(type) + ");";
stmt = m_database.compileStatement(statement.c_str());
stmt.bind(1, name.c_str());
stmt.execDML();
}
statement = "INSERT INTO edgeBaseBookmark(edgeId) "
"VALUES (" + std::to_string(id) + ");";
stmt = m_database.compileStatement(statement.c_str());
stmt.execDML();
Id baseId = m_database.lastRowId();
for (unsigned int i = 0; i < bookmark.getTokenNames().size(); i++)
{
std::string name = bookmark.getTokenNames()[i];
int type = bookmark.getTokenTypes()[i];
statement = "INSERT INTO edgeBaseBookmarkToken(bookmarkId, name, type) "
"VALUES (" + std::to_string(baseId) + ", ?, " + std::to_string(bookmark.getTokenTypes()[i]) + ");";
stmt = m_database.compileStatement(statement.c_str());
stmt.bind(1, bookmark.getTokenNames()[i].c_str());
stmt.execDML();
}
return id;
}
Id SqliteStorage::addBookmarkCategory(const std::string& name)
{
// for backwards compatibility
m_database.execDML(
"CREATE TABLE IF NOT EXISTS bookmarkCategory("
"id INTEGER NOT NULL, "
"name TEXT, "
"PRIMARY KEY(id));"
);
std::string statement = "INSERT INTO bookmarkCategory(name) "
"VALUES (?);";
CppSQLite3Statement stmt = m_database.compileStatement(statement.c_str());
stmt.bind(1, name.c_str());
stmt.execDML();
Id id = m_database.lastRowId();
return id;
}
void SqliteStorage::removeElement(Id id)
{
std::vector<Id> ids;
@@ -509,6 +706,18 @@ bool SqliteStorage::isFile(Id elementId) const
return (count > 0);
}
StorageEdge SqliteStorage::getEdgeById(Id edgeId) const
{
std::vector<StorageEdge> candidates = doGetAll<StorageEdge>("WHERE id = " + std::to_string(edgeId));
if (candidates.size() > 0)
{
return candidates[0];
}
return StorageEdge();
}
StorageEdge SqliteStorage::getEdgeBySourceTargetType(Id sourceId, Id targetId, int type) const
{
return doGetFirst<StorageEdge>("WHERE "
@@ -568,6 +777,39 @@ std::vector<StorageEdge> SqliteStorage::getEdgesByTargetsType(const std::vector<
return doGetAll<StorageEdge>("WHERE target_node_id IN (" + utility::join(utility::toStrings(targetIds), ',') + ") AND type == " + std::to_string(type));
}
bool SqliteStorage::checkEdgeExists(Id edgeId) const
{
CppSQLite3Statement stmt = m_database.compileStatement(
("SELECT type FROM edge WHERE id == " + std::to_string(edgeId) + ";").c_str()
);
CppSQLite3Query q = executeQuery(stmt);
if (!q.eof())
{
const int type = q.getIntField(0, -1);
if (type != -1)
{
return true;
}
}
return false;
}
StorageNode SqliteStorage::getNodeById(Id id) const
{
std::vector<StorageNode> candidates = doGetAll<StorageNode>("WHERE id = " + std::to_string(id));
if (candidates.size() > 0)
{
return candidates[0];
}
return StorageNode();
}
StorageNode SqliteStorage::getNodeBySerializedName(const std::string& serializedName) const
{
CppSQLite3Statement stmt = m_database.compileStatement(
@@ -592,6 +834,28 @@ StorageNode SqliteStorage::getNodeBySerializedName(const std::string& serialized
return StorageNode();
}
bool SqliteStorage::checkNodeExistsByName(const std::string& serializedName) const
{
CppSQLite3Statement stmt = m_database.compileStatement(
"SELECT id FROM node WHERE serialized_name == ? LIMIT 1;"
);
stmt.bind(1, serializedName.c_str());
CppSQLite3Query q = executeQuery(stmt);
if (!q.eof())
{
const Id id = q.getIntField(0, 0);
if (id != -1)
{
return true;
}
}
return false;
}
StorageLocalSymbol SqliteStorage::getLocalSymbolByName(const std::string& name) const
{
return doGetFirst<StorageLocalSymbol>("WHERE name == '" + name + "'");
@@ -735,6 +999,278 @@ std::vector<StorageCommentLocation> SqliteStorage::getCommentLocationsInFile(con
return doGetAll<StorageCommentLocation>("WHERE file_node_id == " + std::to_string(fileNodeId));
}
std::vector<NodeBookmark> SqliteStorage::getAllNodeBookmarks() const
{
return doGetAll<NodeBookmark>("");
}
NodeBookmark SqliteStorage::getNodeBookmarkById(const Id bookmarkId) const
{
std::vector<NodeBookmark> candidates = doGetAll<NodeBookmark>("WHERE id = " + std::to_string(bookmarkId));
if (candidates.size() > 0)
{
return candidates[0];
}
return NodeBookmark();
}
bool SqliteStorage::checkNodeBookmarkExistsByNames(const std::vector<std::string>& names) const
{
// bookmarks can only be uniquly identified by their token names.
// therefore, a bookmark exists if there is an exactly matching set of 'bookmarkToken's with a common foreign key
if (names.size() <= 0)
{
return false;
}
std::set<int> bookmarkIds;
bool insert = true;
for (unsigned int i = 0; i < names.size(); i++)
{
CppSQLite3Query q = m_database.execQuery((
"SELECT bookmarkId FROM nodeBookmarkToken WHERE name = '" + names[i] +"';"
).c_str());
bool contains = false;
while (!q.eof())
{
int id = q.getIntField(0, -1);
if (insert)
{
bookmarkIds.insert(id);
}
else
{
if (bookmarkIds.find(id) != bookmarkIds.end())
{
contains = true;
}
}
q.nextRow();
}
if ((contains == false && insert == false)
|| bookmarkIds.size() <= 0)
{
return false;
}
insert = false;
}
return true;
}
void SqliteStorage::removeNodeBookmark(Id id)
{
executeStatement(
"DELETE FROM nodeBookmark WHERE id = (" + std::to_string(id) + ");"
);
}
void SqliteStorage::editNodeBookmark(const NodeBookmark& bookmark)
{
std::string statement = "UPDATE nodeBookmark SET name=?, comment=?, category=? WHERE id=" + std::to_string(bookmark.getId()) + ";";
BookmarkCategory category = getBookmarkCategoryByName(bookmark.getCategory().getName());
if (category.getId() == -1)
{
category.setId(addBookmarkCategory(bookmark.getCategory().getName()));
category.setName(bookmark.getCategory().getName());
}
CppSQLite3Statement stmt = m_database.compileStatement(statement.c_str());
stmt.bind(1, bookmark.getDisplayName().c_str());
stmt.bind(2, bookmark.getComment().c_str());
stmt.bind(3, (int)category.getId());
stmt.execDML();
}
std::vector<EdgeBookmark> SqliteStorage::getAllEdgeBookmarks() const
{
return doGetAll<EdgeBookmark>("");
}
EdgeBookmark SqliteStorage::getEdgeBookmarkById(const Id bookmarkId) const
{
std::vector<EdgeBookmark> candidates = doGetAll<EdgeBookmark>("WHERE id = " + std::to_string(bookmarkId));
if (candidates.size() > 0)
{
return candidates[0];
}
return EdgeBookmark();
}
bool SqliteStorage::checkEdgeBookmarkExistsByNames(const std::vector<std::string>& names) const
{
if (names.size() <= 0)
{
return false;
}
std::set<int> bookmarkIds;
bool insert = true;
for (unsigned int i = 0; i < names.size(); i++)
{
CppSQLite3Query q = m_database.execQuery((
"SELECT bookmarkId FROM edgeBookmarkToken WHERE name = '" + names[i] + "';"
).c_str());
bool contains = false;
while (!q.eof())
{
int id = q.getIntField(0, -1);
if (insert)
{
bookmarkIds.insert(id);
}
else
{
if (bookmarkIds.find(id) != bookmarkIds.end())
{
contains = true;
}
}
q.nextRow();
}
if ((contains == false && insert == false)
|| bookmarkIds.size() <= 0)
{
return false;
}
insert = false;
}
return true;
}
void SqliteStorage::removeEdgeBookmark(Id id)
{
executeStatement(
"DELETE FROM edgeBookmark WHERE id = (" + std::to_string(id) + ");"
);
}
void SqliteStorage::editEdgeBookmark(const EdgeBookmark& bookmark)
{
std::string statement = "UPDATE edgeBookmark SET name=?, comment=?, category=? WHERE id=" + std::to_string(bookmark.getId()) + ";";
BookmarkCategory category = getBookmarkCategoryByName(bookmark.getCategory().getName());
if (category.getId() == -1)
{
category.setId(addBookmarkCategory(bookmark.getCategory().getName()));
category.setName(bookmark.getCategory().getName());
}
CppSQLite3Statement stmt = m_database.compileStatement(statement.c_str());
stmt.bind(1, bookmark.getDisplayName().c_str());
stmt.bind(2, bookmark.getComment().c_str());
stmt.bind(3, (int)category.getId());
stmt.execDML();
}
std::vector<BookmarkCategory> SqliteStorage::getAllBookmarkCategories() const
{
return doGetAll<BookmarkCategory>("");
}
BookmarkCategory SqliteStorage::getBookmarkCategoryByName(const std::string& name) const
{
BookmarkCategory category;
category.setName("");
category.setId(-1);
CppSQLite3Query q = m_database.execQuery((
"SELECT id FROM bookmarkCategory WHERE name = '" + name + "';"
).c_str());
while (!q.eof())
{
int id = q.getIntField(0, -1);
if (id > -1)
{
category.setName(name);
category.setId(id);
}
q.nextRow();
}
return category;
}
BookmarkCategory SqliteStorage::getOrCreateBookmarkCategoryByName(const std::string& name)
{
if (checkBookmarkCategoryExists(name))
{
return getBookmarkCategoryByName(name);
}
else
{
Id id = addBookmarkCategory(name);
BookmarkCategory result;
result.setName(name);
result.setId(id);
return result;
}
}
bool SqliteStorage::checkBookmarkCategoryExists(const std::string& name) const
{
CppSQLite3Query q = m_database.execQuery((
"SELECT id FROM bookmarkCategory WHERE name = '" + name + "';"
).c_str());
while (!q.eof())
{
int id = q.getIntField(0, -1);
if (id > -1)
{
return true;
}
q.nextRow();
}
return false;
}
void SqliteStorage::removeBookmarkCategory(Id id)
{
executeStatement(
"DELETE FROM bookmarkCategory WHERE id = (" + std::to_string(id) + ");"
);
}
Id SqliteStorage::getTokenIdByName(const std::string& name) const
{
/*CppSQLite3Query q = m_database.execQuery((
"SELECT id FROM bookmark WHERE " + " foo " + ";"
).c_str());*/
return -1;
}
int SqliteStorage::getNodeCount() const
{
return executeScalar("SELECT COUNT(*) FROM node;");
@@ -913,10 +1449,81 @@ void SqliteStorage::setupTables()
"column_number INTEGER, "
"PRIMARY KEY(id));"
);
m_database.execDML(
"CREATE TABLE IF NOT EXISTS bookmarkCategory("
"id INTEGER NOT NULL, "
"name TEXT, "
"PRIMARY KEY(id));"
);
m_database.execDML(
"CREATE TABLE IF NOT EXISTS nodeBookmark("
"id INTEGER NOT NULL, "
"name TEXT, "
"comment TEXT, "
"timestamp TEXT, "
"category INTEGER, "
"PRIMARY KEY(id), "
"FOREIGN KEY(category) REFERENCES bookmarkCategory(id));"
);
m_database.execDML(
"CREATE TABLE IF NOT EXISTS edgeBookmark("
"id INTEGER NOT NULL, "
"name TEXT, "
"comment TEXT, "
"timestamp TEXT, "
"category INTEGER, "
"PRIMARY KEY(id), "
"FOREIGN KEY(category) REFERENCES bookmarkCategory(id));"
);
m_database.execDML(
"CREATE TABLE IF NOT EXISTS nodeBookmarkToken("
"id INTEGER NOT NULL, "
"bookmarkId INTEGER NOT NULL, "
"name TEXT, "
"type INTEGER, "
"PRIMARY KEY(id), "
"FOREIGN KEY(bookmarkId) REFERENCES nodeBookmark(id) ON DELETE CASCADE);"
);
m_database.execDML(
"CREATE TABLE IF NOT EXISTS edgeBookmarkToken("
"id INTEGER NOT NULL, "
"bookmarkId INTEGER NOT NULL, "
"name TEXT, "
"type INTEGER, "
"PRIMARY KEY(id), "
"FOREIGN KEY(bookmarkId) REFERENCES edgeBookmark(id) ON DELETE CASCADE);"
);
m_database.execDML(
"CREATE TABLE IF NOT EXISTS edgeBaseBookmark("
"id INTEGER NOT NULL, "
"edgeId INTEGER, "
"PRIMARY KEY(id), "
"FOREIGN KEY(edgeId) REFERENCES edgeBookmark(id) ON DELETE CASCADE);"
);
m_database.execDML(
"CREATE TABLE IF NOT EXISTS edgeBaseBookmarkToken("
"id INTEGER NOT NULL, "
"bookmarkId INTEGER NOT NULL, "
"name TEXT, "
"type INTEGER, "
"PRIMARY KEY(id), "
"FOREIGN KEY(bookmarkId) REFERENCES edgeBaseBookmark(id) ON DELETE CASCADE);"
);
}
catch (CppSQLite3Exception& e)
{
LOG_ERROR(std::to_string(e.errorCode()) + ": " + e.errorMessage());
throw(std::exception("fail"));
// todo: cancel project creation and destroy created files, display message
}
}
@@ -1318,3 +1925,186 @@ std::vector<StorageError> SqliteStorage::doGetAll<StorageError>(const std::strin
return errors;
}
template <>
std::vector<NodeBookmark> SqliteStorage::doGetAll<NodeBookmark>(const std::string& query) const
{
CppSQLite3Query q = m_database.execQuery((
"SELECT id, name, comment, timestamp, category FROM nodeBookmark " + query + ";"
).c_str());
std::vector<NodeBookmark> bookmarks;
bookmarks.clear();
while (!q.eof())
{
const int id = q.getIntField(0, -1);
const std::string name = q.getStringField(1, "");
const std::string comment = q.getStringField(2, "");
const std::string timeStamp = q.getStringField(3, "");
const int categoryId = q.getIntField(4, -1);
CppSQLite3Query qSub = m_database.execQuery((
"SELECT name, type FROM nodeBookmarkToken WHERE bookmarkId = " + std::to_string(id) + ";"
).c_str());
std::vector<std::string> tokenNames;
std::vector<int> tokenTypes;
while (!qSub.eof())
{
const std::string tokenName = qSub.getStringField(0, "");
const int tokenType = qSub.getIntField(1, -1);
tokenNames.push_back(tokenName);
tokenTypes.push_back(tokenType);
qSub.nextRow();
}
NodeBookmark bookmark(name, std::vector<Id>(), tokenNames, comment, TimePoint(timeStamp));
bookmark.setId(id);
bookmark.setTokenTypes(tokenTypes);
qSub = m_database.execQuery((
"SELECT id, name FROM bookmarkCategory WHERE id = " + std::to_string(categoryId) + ";"
).c_str());
while (!qSub.eof())
{
const int categoryId = qSub.getIntField(0, -1);
const std::string name = qSub.getStringField(1, "");
BookmarkCategory category;
category.setId(categoryId);
category.setName(name);
bookmark.setCategory(category);
qSub.nextRow();
}
bookmarks.push_back(bookmark);
q.nextRow();
}
return bookmarks;
}
template <>
std::vector<EdgeBookmark> SqliteStorage::doGetAll<EdgeBookmark>(const std::string& query) const
{
CppSQLite3Query q = m_database.execQuery((
"SELECT id, name, comment, timestamp, category FROM edgeBookmark " + query + ";"
).c_str());
std::vector<EdgeBookmark> bookmarks;
bookmarks.clear();
while (!q.eof())
{
const int id = q.getIntField(0, -1);
const std::string name = q.getStringField(1, "");
const std::string comment = q.getStringField(2, "");
const std::string timeStamp = q.getStringField(3, "");
const int categoryId = q.getIntField(4, -1);
CppSQLite3Query qSub = m_database.execQuery((
"SELECT name, type FROM edgeBookmarkToken WHERE bookmarkId = " + std::to_string(id) + ";"
).c_str());
std::vector<std::string> tokenNames;
std::vector<int> tokenTypes;
while (!qSub.eof())
{
const std::string tokenName = qSub.getStringField(0, "");
const int tokenType = qSub.getIntField(1, -1);
tokenNames.push_back(tokenName);
tokenTypes.push_back(tokenType);
qSub.nextRow();
}
qSub = m_database.execQuery((
"SELECT id FROM edgeBaseBookmark WHERE edgeId = " + std::to_string(id) + ";"
).c_str());
NodeBookmark baseBookmark; // there should only be one base bookmark, if there are more use the last one
while (!qSub.eof())
{
const int baseId = qSub.getIntField(0, -1);
baseBookmark.setId(baseId);
CppSQLite3Query qSubSub = m_database.execQuery((
"SELECT id, name, type FROM edgeBaseBookmarkToken WHERE bookmarkId = " + std::to_string(baseId) + ";"
).c_str());
std::vector<std::string> baseTokenNames;
std::vector<int> baseTokenTypes;
while (!qSubSub.eof())
{
const std::string baseTokenName = qSubSub.getStringField(1, "");
const int baseTokenType = qSubSub.getIntField(2, -1);
baseTokenNames.push_back(baseTokenName);
baseTokenTypes.push_back(baseTokenType);
qSubSub.nextRow();
}
baseBookmark.setTokenNames(baseTokenNames);
baseBookmark.setTokenTypes(baseTokenTypes);
qSub.nextRow();
}
EdgeBookmark bookmark(name, std::vector<Id>(), tokenNames, comment, TimePoint(timeStamp));
bookmark.setTokenTypes(tokenTypes);
bookmark.setBaseBookmark(baseBookmark);
bookmark.setId(id);
qSub = m_database.execQuery((
"SELECT id, name FROM bookmarkCategory WHERE id = " + std::to_string(categoryId) + ";"
).c_str());
while (!qSub.eof())
{
const int categoryId = qSub.getIntField(0, -1);
const std::string name = qSub.getStringField(1, "");
BookmarkCategory category;
category.setId(categoryId);
category.setName(name);
bookmark.setCategory(category);
qSub.nextRow();
}
bookmarks.push_back(bookmark);
q.nextRow();
}
return bookmarks;
}
template <>
std::vector<BookmarkCategory> SqliteStorage::doGetAll<BookmarkCategory>(const std::string& query) const
{
std::vector<BookmarkCategory> categories;
CppSQLite3Query q = m_database.execQuery((
"SELECT id, name FROM bookmarkCategory " + query + ";"
).c_str());
while (!q.eof())
{
const int id = q.getIntField(0, -1);
const std::string name = q.getStringField(1, "");
BookmarkCategory category;
category.setId(id);
category.setName(name);
categories.push_back(category);
q.nextRow();
}
return categories;
}
+39 -1
View File
@@ -7,6 +7,9 @@
#include "sqlite/CppSQLite3.h"
#include "data/bookmark/BookmarkCategory.h"
#include "data/bookmark/EdgeBookmark.h"
#include "data/bookmark/NodeBookmark.h"
#include "data/location/TokenLocationFile.h"
#include "data/location/TokenLocationCollection.h"
#include "data/name/NameHierarchy.h"
@@ -66,6 +69,9 @@ public:
Id addComponentAccess(Id nodeId, int type);
Id addCommentLocation(Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol);
Id addError(const std::string& message, const FilePath& filePath, uint lineNumber, uint columnNumber, bool fatal, bool indexed);
Id addNodeBookmark(const NodeBookmark& bookmark);
Id addEdgeBookmark(const EdgeBookmark& bookmark);
Id addBookmarkCategory(const std::string& name);
void removeElement(Id id);
void removeElements(const std::vector<Id>& ids);
@@ -77,6 +83,7 @@ public:
bool isNode(Id elementId) const;
bool isFile(Id elementId) const;
StorageEdge getEdgeById(Id edgeId) const;
StorageEdge getEdgeBySourceTargetType(Id sourceId, Id targetId, int type) const;
std::vector<StorageEdge> getEdgesBySourceId(Id sourceId) const;
@@ -91,7 +98,11 @@ public:
std::vector<StorageEdge> getEdgesByTargetType(Id targetId, int type) const;
std::vector<StorageEdge> getEdgesByTargetsType(const std::vector<Id>& targetIds, int type) const;
bool checkEdgeExists(Id edgeId) const;
StorageNode getNodeById(Id id) const;
StorageNode getNodeBySerializedName(const std::string& serializedName) const;
bool checkNodeExistsByName(const std::string& serializedName) const;
StorageLocalSymbol getLocalSymbolByName(const std::string& name) const;
@@ -121,6 +132,26 @@ public:
return doGetAll<ResultType>("");
}
std::vector<NodeBookmark> getAllNodeBookmarks() const;
NodeBookmark getNodeBookmarkById(const Id bookmarkId) const;
bool checkNodeBookmarkExistsByNames(const std::vector<std::string>& names) const;
void removeNodeBookmark(Id id);
void editNodeBookmark(const NodeBookmark& bookmark);
std::vector<EdgeBookmark> getAllEdgeBookmarks() const;
EdgeBookmark getEdgeBookmarkById(const Id bookmarkId) const;
bool checkEdgeBookmarkExistsByNames(const std::vector<std::string>& names) const;
void removeEdgeBookmark(Id id);
void editEdgeBookmark(const EdgeBookmark& bookmark);
std::vector<BookmarkCategory> getAllBookmarkCategories() const;
BookmarkCategory getBookmarkCategoryByName(const std::string& name) const;
BookmarkCategory getOrCreateBookmarkCategoryByName(const std::string& name);
bool checkBookmarkCategoryExists(const std::string& name) const;
void removeBookmarkCategory(Id id);
Id getTokenIdByName(const std::string& name) const;
template <typename ResultType>
ResultType getFirstById(const Id id) const
{
@@ -200,6 +231,8 @@ std::vector<StorageLocalSymbol> SqliteStorage::doGetAll<StorageLocalSymbol>(cons
template <>
std::vector<StorageSourceLocation> SqliteStorage::doGetAll<StorageSourceLocation>(const std::string& query) const;
template <>
std::vector<NodeBookmark> SqliteStorage::doGetAll<NodeBookmark>(const std::string& query) const;
template <>
std::vector<StorageOccurrence> SqliteStorage::doGetAll<StorageOccurrence>(const std::string& query) const;
template <>
std::vector<StorageComponentAccess> SqliteStorage::doGetAll<StorageComponentAccess>(const std::string& query) const;
@@ -207,6 +240,11 @@ template <>
std::vector<StorageCommentLocation> SqliteStorage::doGetAll<StorageCommentLocation>(const std::string& query) const;
template <>
std::vector<StorageError> SqliteStorage::doGetAll<StorageError>(const std::string& query) const;
template <>
std::vector<Bookmark> SqliteStorage::doGetAll<Bookmark>(const std::string& query) const;
template <>
std::vector<EdgeBookmark> SqliteStorage::doGetAll<EdgeBookmark>(const std::string& query) const;
template <>
std::vector<BookmarkCategory> SqliteStorage::doGetAll<BookmarkCategory>(const std::string& query) const;
#endif // SQLITE_STORAGE_H
+1
View File
@@ -5,6 +5,7 @@
#include <mutex>
#include <string>
#include "data/bookmark/Bookmark.h"
#include "data/name/NameHierarchy.h"
#include "data/StorageTypes.h"
#include "utility/types.h"
+28
View File
@@ -9,6 +9,10 @@
#include "utility/file/FileInfo.h"
#include "utility/file/FilePath.h"
#include "data/bookmark/Bookmark.h"
#include "data/bookmark/BookmarkCategory.h"
#include "data/bookmark/EdgeBookmark.h"
#include "data/bookmark/NodeBookmark.h"
#include "data/parser/ParseLocation.h"
#include "data/graph/Node.h"
#include "data/search/SearchMatch.h"
@@ -32,9 +36,13 @@ public:
virtual Id getIdForNodeWithNameHierarchy(const NameHierarchy& nameHierarchy) const = 0;
virtual Id getIdForEdge(
Edge::EdgeType type, const NameHierarchy& fromNameHierarchy, const NameHierarchy& toNameHierarchy) const = 0;
virtual StorageEdge getEdgeById(Id edgeId) const = 0;
virtual bool checkEdgeExists(Id edgeId) const = 0;
virtual NameHierarchy getNameHierarchyForNodeWithId(Id id) const = 0;
virtual Node::NodeType getNodeTypeForNodeWithId(Id id) const = 0;
virtual bool checkNodeExistsByName(const std::string& serializedName) const = 0;
virtual std::shared_ptr<TokenLocationCollection> getFullTextSearchLocations(
const std::string& searchTerm, bool caseSensitive) const = 0;
@@ -76,6 +84,26 @@ public:
virtual void setErrorFilter(const ErrorFilter& filter);
virtual Id addNodeBookmark(const NodeBookmark& bookmark) = 0;
virtual Id addEdgeBookmark(const EdgeBookmark& bookmark) = 0;
virtual Id addBookmarkCategory(const BookmarkCategory& category) = 0;
virtual std::vector<NodeBookmark> getAllNodeBookmarks() const = 0;
virtual NodeBookmark getNodeBookmarkById(const Id bookmarkId) const = 0;
virtual bool checkNodeBookmarkExistsByTokens(const std::vector<std::string>& tokenNames) const = 0;
virtual void removeNodeBookmark(Id id) = 0;
virtual void editNodeBookmark(const NodeBookmark& bookmark) = 0;
virtual std::vector<EdgeBookmark> getAllEdgeBookmarks() const = 0;
virtual EdgeBookmark getEdgeBookmarkById(const Id bookmarkId) const = 0;
virtual bool checkEdgeBookmarkExistsByTokens(const std::vector<std::string>& tokenNames) const = 0;
virtual void removeEdgeBookmark(Id id) = 0;
virtual void editEdgeBookmark(const EdgeBookmark& bookmark) = 0;
virtual std::vector<BookmarkCategory> getAllBookmarkCategories() const = 0;
virtual bool checkBookmarkCategoryExists(const std::string& name) const = 0;
virtual void removeBookmarkCategory(Id id) = 0;
protected:
ErrorFilter m_errorFilter;
};
+177
View File
@@ -57,6 +57,24 @@ Id StorageAccessProxy::getIdForEdge(
return 0;
}
StorageEdge StorageAccessProxy::getEdgeById(Id edgeId) const
{
if (hasSubject())
{
return m_subject->getEdgeById(edgeId);
}
}
bool StorageAccessProxy::checkEdgeExists(Id edgeId) const
{
if (hasSubject())
{
return m_subject->checkEdgeExists(edgeId);
}
return false;
}
Node::NodeType StorageAccessProxy::getNodeTypeForNodeWithId(Id id) const
{
if (hasSubject())
@@ -66,6 +84,15 @@ Node::NodeType StorageAccessProxy::getNodeTypeForNodeWithId(Id id) const
return Node::NODE_NON_INDEXED;
}
bool StorageAccessProxy::checkNodeExistsByName(const std::string& serializedName) const
{
if (hasSubject())
{
return m_subject->checkNodeExistsByName(serializedName);
}
return false;
}
NameHierarchy StorageAccessProxy::getNameHierarchyForNodeWithId(Id id) const
{
if (hasSubject())
@@ -302,6 +329,156 @@ std::shared_ptr<TokenLocationCollection> StorageAccessProxy::getErrorTokenLocati
return std::make_shared<TokenLocationCollection>();
}
Id StorageAccessProxy::addNodeBookmark(const NodeBookmark& bookmark)
{
if (hasSubject())
{
return m_subject->addNodeBookmark(bookmark);
}
return -1;
}
Id StorageAccessProxy::addEdgeBookmark(const EdgeBookmark& bookmark)
{
if (hasSubject())
{
return m_subject->addEdgeBookmark(bookmark);
}
return -1;
}
Id StorageAccessProxy::addBookmarkCategory(const BookmarkCategory& category)
{
if (hasSubject())
{
return m_subject->addBookmarkCategory(category);
}
return -1;
}
std::vector<NodeBookmark> StorageAccessProxy::getAllNodeBookmarks() const
{
if (hasSubject())
{
return m_subject->getAllNodeBookmarks();
}
return std::vector<NodeBookmark>();
}
NodeBookmark StorageAccessProxy::getNodeBookmarkById(const Id bookmarkId) const
{
if (hasSubject())
{
return m_subject->getNodeBookmarkById(bookmarkId);
}
return NodeBookmark();
}
bool StorageAccessProxy::checkNodeBookmarkExistsByTokens(const std::vector<std::string>& tokenNames) const
{
if (hasSubject())
{
return m_subject->checkNodeBookmarkExistsByTokens(tokenNames);
}
return false;
}
void StorageAccessProxy::removeNodeBookmark(Id id)
{
if (hasSubject())
{
m_subject->removeNodeBookmark(id);
}
}
void StorageAccessProxy::editNodeBookmark(const NodeBookmark& bookmark)
{
if (hasSubject())
{
m_subject->editNodeBookmark(bookmark);
}
}
std::vector<EdgeBookmark> StorageAccessProxy::getAllEdgeBookmarks() const
{
if (hasSubject())
{
return m_subject->getAllEdgeBookmarks();
}
return std::vector<EdgeBookmark>();
}
EdgeBookmark StorageAccessProxy::getEdgeBookmarkById(const Id bookmarkId) const
{
if (hasSubject())
{
return m_subject->getEdgeBookmarkById(bookmarkId);
}
return EdgeBookmark();
}
bool StorageAccessProxy::checkEdgeBookmarkExistsByTokens(const std::vector<std::string>& tokenNames) const
{
if (hasSubject())
{
return m_subject->checkEdgeBookmarkExistsByTokens(tokenNames);
}
return false;
}
void StorageAccessProxy::removeEdgeBookmark(Id id)
{
if (hasSubject())
{
m_subject->removeEdgeBookmark(id);
}
}
void StorageAccessProxy::editEdgeBookmark(const EdgeBookmark& bookmark)
{
if (hasSubject())
{
m_subject->editEdgeBookmark(bookmark);
}
}
std::vector<BookmarkCategory> StorageAccessProxy::getAllBookmarkCategories() const
{
if (hasSubject())
{
return m_subject->getAllBookmarkCategories();
}
return std::vector<BookmarkCategory>();
}
bool StorageAccessProxy::checkBookmarkCategoryExists(const std::string& name) const
{
if (hasSubject())
{
return m_subject->checkBookmarkCategoryExists(name);
}
return false;
}
void StorageAccessProxy::removeBookmarkCategory(Id id)
{
if (hasSubject())
{
m_subject->removeBookmarkCategory(id);
}
}
void StorageAccessProxy::setErrorFilter(const ErrorFilter& filter)
{
StorageAccess::setErrorFilter(filter);
+24
View File
@@ -21,9 +21,13 @@ public:
virtual Id getIdForNodeWithNameHierarchy(const NameHierarchy& nameHierarchy) const;
virtual Id getIdForEdge(
Edge::EdgeType type, const NameHierarchy& fromNameHierarchy, const NameHierarchy& toNameHierarchy) const;
virtual StorageEdge getEdgeById(Id edgeId) const;
virtual bool checkEdgeExists(Id edgeId) const;
virtual NameHierarchy getNameHierarchyForNodeWithId(Id id) const;
virtual Node::NodeType getNodeTypeForNodeWithId(Id id) const;
virtual bool checkNodeExistsByName(const std::string& serializedName) const;
virtual std::shared_ptr<TokenLocationCollection> getFullTextSearchLocations(
const std::string& searchTerm, bool caseSensitive) const;
@@ -66,6 +70,26 @@ public:
virtual std::shared_ptr<TokenLocationCollection> getErrorTokenLocations(std::vector<ErrorInfo>* errors) const;
virtual Id addNodeBookmark(const NodeBookmark& bookmark);
virtual Id addEdgeBookmark(const EdgeBookmark& bookmark);
virtual Id addBookmarkCategory(const BookmarkCategory& category);
virtual std::vector<NodeBookmark> getAllNodeBookmarks() const;
virtual NodeBookmark getNodeBookmarkById(const Id bookmarkId) const;
virtual bool checkNodeBookmarkExistsByTokens(const std::vector<std::string>& tokenNames) const;
virtual void removeNodeBookmark(Id id);
virtual void editNodeBookmark(const NodeBookmark& bookmark);
virtual std::vector<EdgeBookmark> getAllEdgeBookmarks() const;
virtual EdgeBookmark getEdgeBookmarkById(const Id bookmarkId) const;
virtual bool checkEdgeBookmarkExistsByTokens(const std::vector<std::string>& tokenNames) const;
virtual void removeEdgeBookmark(Id id);
virtual void editEdgeBookmark(const EdgeBookmark& bookmark);
virtual virtual std::vector<BookmarkCategory> getAllBookmarkCategories() const;
virtual bool checkBookmarkCategoryExists(const std::string& name) const;
virtual void removeBookmarkCategory(Id id);
protected:
virtual void setErrorFilter(const ErrorFilter& filter);
+116
View File
@@ -0,0 +1,116 @@
#include "Bookmark.h"
Bookmark::Bookmark()
: m_id(-1)
, m_tokenTypes()
, m_tokenIds()
, m_tokenNames()
, m_comment("")
, m_displayName("")
, m_valid(false)
, m_timeStamp()
, m_category()
{
}
Bookmark::Bookmark(const std::string& displayName, const std::vector<Id>& tokens, const std::vector<std::string>& tokenNames, const std::string& comment, const TimePoint& timeStamp)
: m_id(-1)
, m_tokenTypes()
, m_tokenIds(tokens)
, m_tokenNames(tokenNames)
, m_comment(comment)
, m_displayName(displayName)
, m_valid(false)
, m_timeStamp(timeStamp)
, m_category()
{
}
Bookmark::~Bookmark()
{
}
Id Bookmark::getId() const
{
return m_id;
}
void Bookmark::setId(const Id id)
{
m_id = id;
}
std::vector<int> Bookmark::getTokenTypes() const
{
return m_tokenTypes;
}
void Bookmark::setTokenTypes(const std::vector<int>& types)
{
m_tokenTypes = types;
}
std::vector<Id> Bookmark::getTokenIds() const
{
return m_tokenIds;
}
void Bookmark::setTokenIds(const std::vector<Id>& ids)
{
m_tokenIds = ids;
}
std::vector<std::string> Bookmark::getTokenNames() const
{
return m_tokenNames;
}
void Bookmark::setTokenNames(const std::vector<std::string>& names)
{
m_tokenNames = names;
}
std::string Bookmark::getComment() const
{
return m_comment;
}
void Bookmark::setComment(const std::string& comment)
{
m_comment = comment;
}
std::string Bookmark::getDisplayName() const
{
return m_displayName;
}
void Bookmark::setDisplayName(const std::string& name)
{
m_displayName = name;
}
bool Bookmark::isValid() const
{
return m_valid;
}
void Bookmark::setValid(const bool valid)
{
m_valid = valid;
}
TimePoint Bookmark::getTimeStamp() const
{
return m_timeStamp;
}
BookmarkCategory Bookmark::getCategory() const
{
return m_category;
}
void Bookmark::setCategory(const BookmarkCategory& category)
{
m_category = category;
}
+60
View File
@@ -0,0 +1,60 @@
#ifndef BOOKMARK_H
#define BOOKMARK_H
#include <vector>
#include <string>
#include "utility/TimePoint.h"
#include "utility/types.h"
#include "BookmarkCategory.h"
class Bookmark
{
public:
Bookmark();
Bookmark(const std::string& displayName, const std::vector<Id>& tokens, const std::vector<std::string>& tokenNames, const std::string& comment, const TimePoint& timeStamp);
virtual ~Bookmark();
Id getId() const;
void setId(const Id id);
std::vector<int> getTokenTypes() const;
void setTokenTypes(const std::vector<int>& types);
std::vector<Id> getTokenIds() const;
void setTokenIds(const std::vector<Id>& ids);
std::vector<std::string> getTokenNames() const;
void setTokenNames(const std::vector<std::string>& names);
std::string getComment() const;
void setComment(const std::string& comment);
std::string getDisplayName() const;
void setDisplayName(const std::string& name);
bool isValid() const;
void setValid(const bool valid);
TimePoint getTimeStamp() const;
BookmarkCategory getCategory() const;
void setCategory(const BookmarkCategory& category);
private:
Id m_id;
std::vector<int> m_tokenTypes;
std::vector<Id> m_tokenIds;
std::vector<std::string> m_tokenNames;
std::string m_comment;
std::string m_displayName;
bool m_valid;
TimePoint m_timeStamp;
BookmarkCategory m_category;
};
#endif // BOOKMARK_H
@@ -0,0 +1,31 @@
#include "BookmarkCategory.h"
BookmarkCategory::BookmarkCategory()
: m_id(-1)
, m_name("")
{
}
BookmarkCategory::~BookmarkCategory()
{
}
Id BookmarkCategory::getId() const
{
return m_id;
}
void BookmarkCategory::setId(const Id id)
{
m_id = id;
}
std::string BookmarkCategory::getName() const
{
return m_name;
}
void BookmarkCategory::setName(const std::string& name)
{
m_name = name;
}
+25
View File
@@ -0,0 +1,25 @@
#ifndef BOOKMARK_CATEGORY_H
#define BOOKMARK_CATEGORY_H
#include <string>
#include "utility/types.h"
class BookmarkCategory
{
public:
BookmarkCategory();
~BookmarkCategory();
Id getId() const;
void setId(const Id id);
std::string getName() const;
void setName(const std::string& name);
private:
Id m_id;
std::string m_name;
};
#endif // BOOKMARK_CATEGORY_H
+55
View File
@@ -0,0 +1,55 @@
#include "EdgeBookmark.h"
EdgeBookmark::EdgeBookmark()
: Bookmark()
{
}
EdgeBookmark::EdgeBookmark(const std::string& displayName, const std::vector<Id>& tokens, const std::vector<std::string>& tokenNames, const std::string& comment, const TimePoint& timeStamp)
: Bookmark(displayName, tokens, tokenNames, comment, timeStamp)
{
}
EdgeBookmark::~EdgeBookmark()
{
}
std::vector<int> EdgeBookmark::getEdgeTokenTypes() const
{
return m_edgeTokenTypes;
}
void EdgeBookmark::setEdgeTokenTypes(const std::vector<int>& tokenTypes)
{
m_edgeTokenTypes = tokenTypes;
}
std::vector<Id> EdgeBookmark::getEdgeTokenIds() const
{
return m_edgeTokenIds;
}
void EdgeBookmark::setEdgeTokenIds(const std::vector<Id>& tokenIds)
{
m_edgeTokenIds = tokenIds;
}
std::vector<std::string> EdgeBookmark::getEdgeTokenNames() const
{
return m_edgeTokenNames;
}
void EdgeBookmark::setEdgeTokenNames(const std::vector<std::string>& tokenNames)
{
m_edgeTokenNames = tokenNames;
}
NodeBookmark EdgeBookmark::getBaseBookmark() const
{
return m_baseBookmark;
}
void EdgeBookmark::setBaseBookmark(const NodeBookmark& baseBookmark)
{
m_baseBookmark = baseBookmark;
}
+35
View File
@@ -0,0 +1,35 @@
#ifndef EDGE_BOOKMARK_H
#define EDGE_BOOKMARK_H
#include "Bookmark.h"
#include "NodeBookmark.h"
class EdgeBookmark
: public Bookmark
{
public:
EdgeBookmark();
EdgeBookmark(const std::string& displayName, const std::vector<Id>& tokens, const std::vector<std::string>& tokenNames, const std::string& comment, const TimePoint& timeStamp);
virtual ~EdgeBookmark();
std::vector<int> getEdgeTokenTypes() const;
void setEdgeTokenTypes(const std::vector<int>& tokenTypes);
std::vector<Id> getEdgeTokenIds() const;
void setEdgeTokenIds(const std::vector<Id>& tokenIds);
std::vector<std::string> getEdgeTokenNames() const;
void setEdgeTokenNames(const std::vector<std::string>& tokenNames);
NodeBookmark getBaseBookmark() const;
void setBaseBookmark(const NodeBookmark& baseBookmark);
private:
std::vector<int> m_edgeTokenTypes;
std::vector<Id> m_edgeTokenIds;
std::vector<std::string> m_edgeTokenNames;
NodeBookmark m_baseBookmark;
};
#endif // EDGE_BOOKMARK_H
+15
View File
@@ -0,0 +1,15 @@
#include "NodeBookmark.h"
NodeBookmark::NodeBookmark()
: Bookmark()
{
}
NodeBookmark::NodeBookmark(const std::string& displayName, const std::vector<Id>& tokens, const std::vector<std::string>& tokenNames, const std::string& comment, const TimePoint& timeStamp)
: Bookmark(displayName, tokens, tokenNames, comment, timeStamp)
{
}
NodeBookmark::~NodeBookmark()
{
}
+15
View File
@@ -0,0 +1,15 @@
#ifndef NODE_BOOKMARK_H
#define NODE_BOOKMARK_H
#include "Bookmark.h"
class NodeBookmark
: public Bookmark
{
public:
NodeBookmark();
NodeBookmark(const std::string& displayName, const std::vector<Id>& tokens, const std::vector<std::string>& tokenNames, const std::string& comment, const TimePoint& timeStamp);
virtual ~NodeBookmark();
};
#endif // NODE_BOOKMARK_H