mirror of https://github.com/openXC7/prjxray.git
lib: Wrapper for retrieving info from a database directory
Currently provides list of segbits files saved in the database. Signed-off-by: Rick Altherr <kc8apf@kc8apf.net> Signed-off-by: Tim 'mithro' Ansell <mithro@mithis.com>
This commit is contained in:
parent
3e203b956b
commit
51b586365b
|
|
@ -1,4 +1,5 @@
|
||||||
add_library(libprjxray
|
add_library(libprjxray
|
||||||
|
database.cc
|
||||||
memory_mapped_file.cc
|
memory_mapped_file.cc
|
||||||
segbits_file_reader.cc)
|
segbits_file_reader.cc)
|
||||||
target_include_directories(libprjxray PUBLIC "include")
|
target_include_directories(libprjxray PUBLIC "include")
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,37 @@
|
||||||
|
#include <prjxray/database.h>
|
||||||
|
|
||||||
|
#include <glob.h>
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include <absl/strings/str_cat.h>
|
||||||
|
|
||||||
|
namespace prjxray {
|
||||||
|
|
||||||
|
static constexpr const char kSegbitsGlobPattern[] = "segbits_*.db";
|
||||||
|
|
||||||
|
std::vector<std::unique_ptr<prjxray::SegbitsFileReader>> Database::segbits() const {
|
||||||
|
std::vector<std::unique_ptr<prjxray::SegbitsFileReader>> 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
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
#ifndef PRJXRAY_LIB_DATABASE_H
|
||||||
|
#define PRJXRAY_LIB_DATABASE_H
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include <prjxray/segbits_file_reader.h>
|
||||||
|
|
||||||
|
namespace prjxray {
|
||||||
|
|
||||||
|
class Database {
|
||||||
|
public:
|
||||||
|
Database(const std::string &path)
|
||||||
|
: db_path_(path) {}
|
||||||
|
|
||||||
|
std::vector<std::unique_ptr<SegbitsFileReader>> segbits() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string db_path_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace prjxray
|
||||||
|
|
||||||
|
#endif // PRJXRAY_LIB_DATABASE_H
|
||||||
Loading…
Reference in New Issue