Sound Bakery  v0.1.0
Open-source audio middleware for games
Loading...
Searching...
No Matches
database.h
1#pragma once
2
3#include "sound_bakery/core/database/database_object.h"
4
5namespace sbk::core
6{
14 class SB_CLASS database
15 {
16 public:
17 auto add_object_to_database(const std::shared_ptr<database_object>& object) -> void;
18 auto remove_object_from_database(sbk_id objectID) -> void;
19
20 [[nodiscard]] auto try_find(sbk_id objectID) const -> std::weak_ptr<database_object>;
21 [[nodiscard]] auto try_find(std::string_view name) const -> std::weak_ptr<database_object>;
22 [[nodiscard]] auto get_all() const -> std::vector<std::weak_ptr<database_object>>;
23
24 void clear_database() noexcept;
25
26 private:
27 static auto create_new_id() -> sbk_id;
28 static auto create_new_name(const rttr::type& type) -> std::string;
29
30 auto update_id(sbk_id oldID, sbk_id newID) -> void;
31 auto update_name(std::string_view oldName, std::string_view newName) -> void;
32 auto on_object_destroyed(object* object) -> void;
33
34 std::unordered_map<sbk_id, std::weak_ptr<database_object>> m_idToPointerMap;
35 std::unordered_map<std::string, sbk_id> m_nameToIdMap;
36 };
37} // namespace sbk::core
Runtime lookup of objects, using their ID or name.
Definition database.h:15