db/simple: throw C++ exception on init error

This commit is contained in:
Max Kellermann 2016-10-28 23:05:13 +02:00
parent e17805f208
commit 7e5ce623fe
2 changed files with 13 additions and 25 deletions

View File

@ -51,14 +51,20 @@
static constexpr Domain simple_db_domain("simple_db");
inline SimpleDatabase::SimpleDatabase()
inline SimpleDatabase::SimpleDatabase(const ConfigBlock &block)
:Database(simple_db_plugin),
path(AllocatedPath::Null()),
path(block.GetPath("path")),
#ifdef ENABLE_ZLIB
compress(true),
compress(block.GetBlockValue("compress", true)),
#endif
cache_path(AllocatedPath::Null()),
prefixed_light_song(nullptr) {}
cache_path(block.GetPath("cache_directory")),
prefixed_light_song(nullptr)
{
if (path.IsNull())
throw std::runtime_error("No \"path\" parameter specified");
path_utf8 = path.ToUTF8();
}
inline SimpleDatabase::SimpleDatabase(AllocatedPath &&_path,
#ifndef ENABLE_ZLIB
@ -80,25 +86,7 @@ SimpleDatabase::Create(gcc_unused EventLoop &loop,
gcc_unused DatabaseListener &listener,
const ConfigBlock &block, Error &)
{
SimpleDatabase *db = new SimpleDatabase();
db->Configure(block);
return db;
}
void
SimpleDatabase::Configure(const ConfigBlock &block)
{
path = block.GetPath("path");
if (path.IsNull())
throw std::runtime_error("No \"path\" parameter specified");
path_utf8 = path.ToUTF8();
cache_path = block.GetPath("cache_directory");
#ifdef ENABLE_ZLIB
compress = block.GetBlockValue("compress", compress);
#endif
return new SimpleDatabase(block);
}
void

View File

@ -67,7 +67,7 @@ class SimpleDatabase : public Database {
mutable unsigned borrowed_song_count;
#endif
SimpleDatabase();
SimpleDatabase(const ConfigBlock &block);
SimpleDatabase(AllocatedPath &&_path, bool _compress);