From c4aad954e2d56feaf8a4044334a2056300cfeff3 Mon Sep 17 00:00:00 2001 From: mlangkabel Date: Tue, 26 Mar 2019 10:41:47 +0100 Subject: [PATCH] fix some logic and functional errors in the cpp api example --- examples/cpp_api_example/src/main.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/examples/cpp_api_example/src/main.cpp b/examples/cpp_api_example/src/main.cpp index dd82209..49c1a1c 100644 --- a/examples/cpp_api_example/src/main.cpp +++ b/examples/cpp_api_example/src/main.cpp @@ -4,6 +4,17 @@ #include "SourcetrailDBWriter.h" +void findAndReplaceAll(std::string &data, const std::string &toSearch, const std::string &replaceStr) +{ + size_t pos = data.find(toSearch); + + while (pos != std::string::npos) + { + data.replace(pos, toSearch.size(), replaceStr); + pos = data.find(toSearch, pos + replaceStr.size()); + } +} + int main(int argc, const char *argv[]) { sourcetrail::SourcetrailDBWriter dbWriter; @@ -21,6 +32,7 @@ int main(int argc, const char *argv[]) std::string dbPath = argv[1]; std::string sourcePath = argv[2]; + findAndReplaceAll(sourcePath, "\\", "/"); int dbVersion = 0; if (argc == 4) @@ -44,6 +56,13 @@ int main(int argc, const char *argv[]) return 1; } + std::cout << "Clearing Database... " << std::endl; + if (!dbWriter.clear()) + { + std::cerr << "error: " << dbWriter.getLastError() << std::endl; + return 1; + } + std::cout << "Starting Indexing..." << std::endl; // start recording with faster speed @@ -83,7 +102,7 @@ int main(int argc, const char *argv[]) // record inheritance reference to "BaseType" int baseId = dbWriter.recordSymbol( { "::", { { "", "BaseType", "" } } } ); - int inheritanceId = dbWriter.recordReference(baseId, classId, sourcetrail::ReferenceKind::INHERITANCE); + int inheritanceId = dbWriter.recordReference(classId, baseId, sourcetrail::ReferenceKind::INHERITANCE); dbWriter.recordReferenceLocation(inheritanceId, { fileId, 12, 14, 12, 21 }); @@ -98,7 +117,7 @@ int main(int argc, const char *argv[]) dbWriter.recordSymbolSignatureLocation(methodId, { fileId, 15, 5, 15, 45 }); // used in tooltip - // record parameter type "bool" + // record usage of parameter type "bool" int typeId = dbWriter.recordSymbol({ "::", { { "", "bool", "" } } }); int typeuseId = dbWriter.recordReference(methodId, typeId, sourcetrail::ReferenceKind::TYPE_USAGE); dbWriter.recordReferenceLocation(typeuseId, { fileId, 15, 20, 15, 23 });