]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/database-leveldb.cpp
Conf.example: Update using auto-generation
[dragonfireclient.git] / src / database-leveldb.cpp
index de510e5336382f8e2d723add6df9762de4d7167d..4a4904c6a0b122f58a5ee217577236b22cf767fb 100644 (file)
@@ -22,78 +22,72 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #if USE_LEVELDB
 
 #include "database-leveldb.h"
-#include "leveldb/db.h"
 
-#include "map.h"
-#include "mapsector.h"
-#include "mapblock.h"
-#include "serialization.h"
-#include "main.h"
-#include "settings.h"
 #include "log.h"
 #include "filesys.h"
+#include "exceptions.h"
+#include "util/string.h"
+
+#include "leveldb/db.h"
+
 
 #define ENSURE_STATUS_OK(s) \
        if (!(s).ok()) { \
-               throw FileNotGoodException(std::string("LevelDB error: ") + (s).ToString()); \
+               throw DatabaseException(std::string("LevelDB error: ") + \
+                               (s).ToString()); \
        }
 
-Database_LevelDB::Database_LevelDB(ServerMap *map, std::string savedir)
+
+Database_LevelDB::Database_LevelDB(const std::string &savedir)
 {
        leveldb::Options options;
        options.create_if_missing = true;
-       leveldb::Status status = leveldb::DB::Open(options, savedir + DIR_DELIM + "map.db", &m_database);
+       leveldb::Status status = leveldb::DB::Open(options,
+               savedir + DIR_DELIM + "map.db", &m_database);
        ENSURE_STATUS_OK(status);
-       srvmap = map;
 }
 
-int Database_LevelDB::Initialized(void)
+Database_LevelDB::~Database_LevelDB()
 {
-       return 1;
+       delete m_database;
 }
 
-void Database_LevelDB::beginSave() {}
-void Database_LevelDB::endSave() {}
-
-bool Database_LevelDB::saveBlock(v3s16 blockpos, std::string &data)
+bool Database_LevelDB::saveBlock(const v3s16 &pos, const std::string &data)
 {
        leveldb::Status status = m_database->Put(leveldb::WriteOptions(),
-                       i64tos(getBlockAsInteger(blockpos)), data);
+                       i64tos(getBlockAsInteger(pos)), data);
        if (!status.ok()) {
-               errorstream << "WARNING: saveBlock: LevelDB error saving block "
-                       << PP(blockpos) << ": " << status.ToString() << std::endl;
+               warningstream << "saveBlock: LevelDB error saving block "
+                       << PP(pos) << ": " << status.ToString() << std::endl;
                return false;
        }
 
        return true;
 }
 
-std::string Database_LevelDB::loadBlock(v3s16 blockpos)
+void Database_LevelDB::loadBlock(const v3s16 &pos, std::string *block)
 {
        std::string datastr;
        leveldb::Status status = m_database->Get(leveldb::ReadOptions(),
-               i64tos(getBlockAsInteger(blockpos)), &datastr);
+               i64tos(getBlockAsInteger(pos)), &datastr);
 
-       if(status.ok())
-               return datastr;
-       else
-               return "";
+       *block = (status.ok()) ? datastr : "";
 }
 
-bool Database_LevelDB::deleteBlock(v3s16 blockpos)
+bool Database_LevelDB::deleteBlock(const v3s16 &pos)
 {
        leveldb::Status status = m_database->Delete(leveldb::WriteOptions(),
-                       i64tos(getBlockAsInteger(blockpos)));
+                       i64tos(getBlockAsInteger(pos)));
        if (!status.ok()) {
-               errorstream << "WARNING: deleteBlock: LevelDB error deleting block "
-                       << PP(blockpos) << ": " << status.ToString() << std::endl;
+               warningstream << "deleteBlock: LevelDB error deleting block "
+                       << PP(pos) << ": " << status.ToString() << std::endl;
                return false;
        }
 
        return true;
 }
 
-void Database_LevelDB::listAllLoadableBlocks(std::list<v3s16> &dst)
+void Database_LevelDB::listAllLoadableBlocks(std::vector<v3s16> &dst)
 {
        leveldb::Iterator* it = m_database->NewIterator(leveldb::ReadOptions());
        for (it->SeekToFirst(); it->Valid(); it->Next()) {
@@ -103,8 +97,5 @@ void Database_LevelDB::listAllLoadableBlocks(std::list<v3s16> &dst)
        delete it;
 }
 
-Database_LevelDB::~Database_LevelDB()
-{
-       delete m_database;
-}
-#endif
+#endif // USE_LEVELDB
+