diff MemoryDBLink.cpp @ 1:aae83c0a771d

Refactor: -Rename all Db to DB. Add setup script Add support for Sqlite3 in configuration.
author Tom Fredrik Blenning Klaussen <bfg@blenning.no>
date Mon, 20 Aug 2012 17:32:58 +0200
parents MemoryDbLink.cpp@a3834af36579
children d6fdca3bf24e
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MemoryDBLink.cpp	Mon Aug 20 17:32:58 2012 +0200
@@ -0,0 +1,41 @@
+#include "MemoryDBLink.hpp"
+
+#include <QtCore/QStringList>
+
+void MemoryDBLink::addFile(const QString& path, qint64 size, const QDateTime& dtime, const QCryptographicHash& hash)
+{
+  addFile(DBInfo(path, size, dtime, hash.result()));
+}
+
+bool MemoryDBLink::tryAddFile(const DBInfo& dbinfo)
+{
+  QMap<QString, QSharedPointer<DBInfo> >::iterator pos;
+  pos = entries.find(dbinfo.path());
+  if (pos == entries.end()) {
+    entries.insert(dbinfo.path(), QSharedPointer<DBInfo>(new DBInfo(dbinfo)));
+    return true;
+  }
+  return false;
+}
+
+void MemoryDBLink::addFile(const DBInfo& dbinfo)
+{
+  if (!tryAddFile(dbinfo)) {
+    abort(); //Should throw exception
+  }
+}
+
+
+QStringList MemoryDBLink::toStringList()
+{
+  QStringList list;
+  foreach(QSharedPointer<DBInfo> info, entries) {
+    list << info->serialize();
+  }
+  return list;
+}
+
+const QList<QSharedPointer<FileDBLink::DBInfo> > MemoryDBLink::values() const
+{
+  return entries.values();
+}