Horizon Official Technical Documentation
StorageDB.hpp
Go to the documentation of this file.
1 /***************************************************
2 * _ _ _ *
3 * | | | | (_) *
4 * | |_| | ___ _ __ _ _______ _ __ *
5 * | _ |/ _ \| '__| |_ / _ \| '_ \ *
6 * | | | | (_) | | | |/ / (_) | | | | *
7 * \_| |_/\___/|_| |_/___\___/|_| |_| *
8 ***************************************************
9 * This file is part of Horizon (c).
10 *
11 * Copyright (c) 2019 Sagun K. (sagunxp@gmail.com).
12 * Copyright (c) 2019 Horizon Dev Team.
13 *
14 * Base Author - Sagun K. (sagunxp@gmail.com)
15 *
16 * This library is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation, either version 3 of the License, or
19 * (at your option) any later version.
20 *
21 * This library is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this library. If not, see <http://www.gnu.org/licenses/>.
28 **************************************************/
29
30#ifndef HORIZON_ZONE_STATICDB_STORAGEDB_HPP
31#define HORIZON_ZONE_STATICDB_STORAGEDB_HPP
33#include <cinttypes>
34#include <string>
35#include <memory>
36#include <sol/sol.hpp>
37#include <map>
38
39namespace Horizon
40{
41namespace Zone
42{
44{
45 int32_t storage_id{0};
46 std::string name{""};
47 int32_t capacity{600};
48};
50{
51public:
54
56 {
57 static StorageDatabase instance;
58 return &instance;
59 }
60
61 bool load();
62
63protected:
64 bool load_storage(sol::table const &storage_tbl);
65 bool load_internal(sol::object const &key, sol::object const &value);
66
67public:
68 std::shared_ptr<const storage_config_data> get_storage_by_id(int32_t id) { return _storage_db.at(id); }
69 int32_t get_storage_db_size() { return _storage_db.size(); }
70
71 std::map<uint32_t, std::shared_ptr<const storage_config_data>> const get_storage_db() const { return _storage_db.get_map(); }
72
73private:
75};
76}
77}
78
79#define StorageDB Horizon::Zone::StorageDatabase::get_instance()
80
81#endif /* HORIZON_ZONE_STATICDB_STORAGEDB_HPP */
Definition: StorageDB.hpp:50
StorageDatabase()
Definition: StorageDB.cpp:35
static StorageDatabase * get_instance()
Definition: StorageDB.hpp:55
std::map< uint32_t, std::shared_ptr< const storage_config_data > > const get_storage_db() const
Definition: StorageDB.hpp:71
std::shared_ptr< const storage_config_data > get_storage_by_id(int32_t id)
Definition: StorageDB.hpp:68
~StorageDatabase()
Definition: StorageDB.cpp:39
bool load_internal(sol::object const &key, sol::object const &value)
Definition: StorageDB.cpp:76
int32_t get_storage_db_size()
Definition: StorageDB.hpp:69
bool load()
Definition: StorageDB.cpp:43
bool load_storage(sol::table const &storage_tbl)
Definition: StorageDB.cpp:65
LockedLookupTable< uint32_t, std::shared_ptr< const storage_config_data > > _storage_db
Definition: StorageDB.hpp:74
Definition: LockedLookupTable.hpp:44
Definition: Element.hpp:7
Definition: StorageDB.hpp:44
std::string name
Definition: StorageDB.hpp:46
int32_t storage_id
Definition: StorageDB.hpp:45
int32_t capacity
Definition: StorageDB.hpp:47