aboutsummaryrefslogtreecommitdiff
path: root/src/db.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2003-07-07 09:25:26 +0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2003-07-07 09:25:26 +0000
commit5895c160c466c0a97716ffdf5ef654eb1c3c6009 (patch)
tree8e2756dd75b785f550c00538e4b97570d6a4c1c6 /src/db.cc
parent609a224848dd08cea35a89b03b64274c82f0a2a7 (diff)
* Make dbRefs a mapping from Hash to [Path].
Diffstat (limited to 'src/db.cc')
-rw-r--r--src/db.cc57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/db.cc b/src/db.cc
index b33591c8b..89cee32ba 100644
--- a/src/db.cc
+++ b/src/db.cc
@@ -73,6 +73,40 @@ bool queryDB(const string & filename, const string & dbname,
}
+bool queryListDB(const string & filename, const string & dbname,
+ const string & key, Strings & data)
+{
+ string d;
+
+ if (!queryDB(filename, dbname, key, d))
+ return false;
+
+ string::iterator it = d.begin();
+
+ while (it != d.end()) {
+
+ if (it + 4 > d.end())
+ throw Error(format("short db entry: `%1%'") % d);
+
+ unsigned int len;
+ len = (unsigned char) *it++;
+ len |= ((unsigned char) *it++) << 8;
+ len |= ((unsigned char) *it++) << 16;
+ len |= ((unsigned char) *it++) << 24;
+
+ if (it + len > d.end())
+ throw Error(format("short db entry: `%1%'") % d);
+
+ string s;
+ while (len--) s += *it++;
+
+ data.push_back(s);
+ }
+
+ return true;
+}
+
+
void setDB(const string & filename, const string & dbname,
const string & key, const string & data)
{
@@ -85,6 +119,29 @@ void setDB(const string & filename, const string & dbname,
}
+void setListDB(const string & filename, const string & dbname,
+ const string & key, const Strings & data)
+{
+ string d;
+
+ for (Strings::const_iterator it = data.begin();
+ it != data.end(); it++)
+ {
+ string s = *it;
+ unsigned int len = s.size();
+
+ d += len & 0xff;
+ d += (len >> 8) & 0xff;
+ d += (len >> 16) & 0xff;
+ d += (len >> 24) & 0xff;
+
+ d += s;
+ }
+
+ setDB(filename, dbname, key, d);
+}
+
+
void delDB(const string & filename, const string & dbname,
const string & key)
{