summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEnrico Zini <enrico@enricozini.org>2015-06-18 10:13:30 +0200
committerEnrico Zini <enrico@enricozini.org>2015-06-18 10:13:30 +0200
commit5016e42155f25dbf851e60f66400f74b8e0f35f1 (patch)
treef0bf7831fa2bb270366c77c0e389c0f9a1e190df
parent8fe03e279c54384ec491aa3c14cc51758c4459fe (diff)
downloadlibept-5016e42155f25dbf851e60f66400f74b8e0f35f1.tar.gz
Allow to load a custom database
-rw-r--r--ept/debtags/debtags.cc16
-rw-r--r--ept/debtags/debtags.h17
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<std::string, std::string> coll_type;
typedef std::pair< std::string, std::set<std::string> > 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; }