From 51b586365bc4cbf52dd8f116034c4ca23a2f2eb3 Mon Sep 17 00:00:00 2001 From: Rick Altherr Date: Mon, 20 Nov 2017 16:38:34 -0800 Subject: [PATCH] lib: Wrapper for retrieving info from a database directory Currently provides list of segbits files saved in the database. Signed-off-by: Rick Altherr Signed-off-by: Tim 'mithro' Ansell --- lib/CMakeLists.txt | 1 + lib/database.cc | 37 ++++++++++++++++++++++++++++++++++ lib/include/prjxray/database.h | 25 +++++++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 lib/database.cc create mode 100644 lib/include/prjxray/database.h diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index f99f1771..844a5e84 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -1,4 +1,5 @@ add_library(libprjxray + database.cc memory_mapped_file.cc segbits_file_reader.cc) target_include_directories(libprjxray PUBLIC "include") diff --git a/lib/database.cc b/lib/database.cc new file mode 100644 index 00000000..f0f3eade --- /dev/null +++ b/lib/database.cc @@ -0,0 +1,37 @@ +#include + +#include + +#include + +#include + +namespace prjxray { + +static constexpr const char kSegbitsGlobPattern[] = "segbits_*.db"; + +std::vector> Database::segbits() const { + std::vector> segbits; + + glob_t segbits_glob_results; + int ret = glob(absl::StrCat(db_path_, "/", kSegbitsGlobPattern).c_str(), + GLOB_NOSORT | GLOB_TILDE, + NULL, &segbits_glob_results); + if (ret < 0) { + return {}; + } + + for(size_t idx = 0; idx < segbits_glob_results.gl_pathc; idx++) { + auto this_segbit = SegbitsFileReader::InitWithFile( + segbits_glob_results.gl_pathv[idx]); + if (this_segbit) { + segbits.emplace_back(std::move(this_segbit)); + } + } + + globfree(&segbits_glob_results); + + return segbits; +} + +} // namespace prjxray diff --git a/lib/include/prjxray/database.h b/lib/include/prjxray/database.h new file mode 100644 index 00000000..15b587d5 --- /dev/null +++ b/lib/include/prjxray/database.h @@ -0,0 +1,25 @@ +#ifndef PRJXRAY_LIB_DATABASE_H +#define PRJXRAY_LIB_DATABASE_H + +#include +#include +#include + +#include + +namespace prjxray { + +class Database { + public: + Database(const std::string &path) + : db_path_(path) {} + + std::vector> segbits() const; + + private: + std::string db_path_; +}; + +} // namespace prjxray + +#endif // PRJXRAY_LIB_DATABASE_H