Sound Bakery  v0.1.0
Open-source audio middleware for games
Loading...
Searching...
No Matches
object.h
1#pragma once
2
3#include "sound_bakery/pch.h"
4#include "sound_bakery/util/macros.h"
5
6namespace SB::Engine
7{
8 class System;
9}
10
11namespace SB::Core
12{
16 class SB_CLASS ObjectUtilities
17 {
18 public:
19 SB::Engine::System* getSystem() const;
20 sc_system* getChef() const;
21 ma_engine* getMini() const;
22
23 std::string m_debugName;
24
25 REGISTER_REFLECTION(ObjectUtilities)
26 };
27
32 class SB_CLASS Object : public ObjectUtilities
33 {
34 REGISTER_REFLECTION(Object, ObjectUtilities)
35
36 public:
37 Object() = default;
38 virtual ~Object();
39
40 NOT_COPYABLE(Object)
41
42
47 template <typename T>
49 {
50 if (getType().is_derived_from(T::type()) || getType() == T::type())
51 {
52 return SB::Reflection::cast<T*, Object*>(this);
53 }
54 return nullptr;
55 }
56
57 template <typename T>
58 const T* tryConvertObject() const noexcept
59 {
60 if (getType().is_derived_from(T::type()) || getType() == T::type())
61 {
62 return SB::Reflection::cast<const T*, const Object*>(this);
63 }
64 return nullptr;
65 }
66
67 rttr::type getType() const
68 {
69 if (this == nullptr)
70 {
71 return rttr::type::get<void>();
72 }
73
74 if (!m_type.has_value())
75 {
76 m_type = get_type();
77 }
78
79 assert(m_type.has_value());
80 assert(m_type.value().is_valid());
81
82 return m_type.value();
83 }
84
85 private:
90 mutable std::optional<rttr::type> m_type = std::nullopt;
91 };
92} // namespace SB::Core
Definition database_ptr.h:23
Provides basic helper functions. Not meant to be used directly.
Definition object.h:17
Simple base Object that all Sound Bakery objects should inherit from.
Definition object.h:33
T * tryConvertObject() noexcept
Gets the most derived type of this object and upcasts it to T.
Definition object.h:48
Manager of the whole Sound Bakery.
Definition system.h:34
Object that manages the node graph, sounds, output etc.
Definition sound_chef_common.h:198