view libserver/malikania/database.cpp @ 73:efe1a7fb43f8

Misc: fix some code style
author David Demelier <markand@malikania.fr>
date Thu, 22 Dec 2016 09:27:09 +0100
parents b0593a3e2ca8
children 858621081b95
line wrap: on
line source

/*
 * database.cpp -- generic database loader
 *
 * Copyright (c) 2013-2016 David Demelier <markand@malikania.fr>
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include <boost/filesystem.hpp>

#include <stdexcept>

#include "database.hpp"
#include "util.hpp"

namespace mlk {

namespace {

using load_func = void (const database_settings&);
using unload_func = void ();

boost::filesystem::path path(const database_settings& params)
{
    auto it = params.find("type");

    if (it == params.end()) {
        throw std::runtime_error("missing 'type' property");
    }

    boost::filesystem::path ret(util::basedir());

    ret /= "lib";
    ret /= "malikania";
    ret /= "0.1.0";         // TODO: change this with an appropriate sysconfig.h
    ret /= it->second;

    return ret;
}

} // !namespace

database::database(const database_settings& params)
    : m_dso(path(params), boost::dll::load_mode::append_decorations)
{
    m_dso.get<load_func>("malikania_driver_load")(params);
}

database::~database()
{
    m_dso.get<unload_func>("malikania_driver_unload")();
}

} // !mlk