From 5016e42155f25dbf851e60f66400f74b8e0f35f1 Mon Sep 17 00:00:00 2001 From: Enrico Zini Date: Thu, 18 Jun 2015 10:13:30 +0200 Subject: Allow to load a custom database --- ept/debtags/debtags.cc | 16 +++++++++++++--- ept/debtags/debtags.h | 17 +++++++---------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/ept/debtags/debtags.cc b/ept/debtags/debtags.cc index 371dce8..4ebf5bf 100644 --- a/ept/debtags/debtags.cc +++ b/ept/debtags/debtags.cc @@ -49,21 +49,31 @@ using namespace wibble; namespace ept { namespace debtags { -Debtags::Debtags(bool editable) +Debtags::Debtags() : m_timestamp(0) { string src = pathname(); if (!sys::fs::exists(src)) return; + load(src); +} + +Debtags::Debtags(const std::string& pathname) + : m_timestamp(0) +{ + load(pathname); +} +void Debtags::load(const std::string& pathname) +{ // Read uncompressed data - tagcoll::input::Stdio in(src); + tagcoll::input::Stdio in(pathname); // Read the collection tagcoll::textformat::parse(in, inserter(*this)); // Read the timestamp - m_timestamp = sys::fs::timestamp(src, 0); + m_timestamp = sys::fs::timestamp(pathname, 0); } string Debtags::pathname() diff --git a/ept/debtags/debtags.h b/ept/debtags/debtags.h index f51daa0..c908f0d 100644 --- a/ept/debtags/debtags.h +++ b/ept/debtags/debtags.h @@ -60,20 +60,17 @@ protected: // Last modification timestamp of the index time_t m_timestamp; + void load(const std::string& pathname); + public: typedef tagcoll::coll::Fast coll_type; typedef std::pair< std::string, std::set > value_type; - /** - * Create a new accessor for the on-disk Debtags database - * - * \param editable - * Specifies if recording of modifications should be enabled. If editable - * is true, then the local state directory will be created when the object - * is instantiated. - */ - Debtags(bool editable = false); - ~Debtags() {} + /// Create a Debtags object, reading the system database + Debtags(); + /// Create a Debtags object, reading the given database file + Debtags(const std::string& pathname); + ~Debtags() {} /// Get the timestamp of when the index was last updated time_t timestamp() const { return m_timestamp; } -- cgit v1.2.3