opynsim
Unofficial C++ Documentation
Loading...
Searching...
No Matches
object.h
Go to the documentation of this file.
1#pragma once
2
5
6#include <cstddef>
7#include <iosfwd>
8#include <memory>
9#include <optional>
10#include <string>
11
12namespace osc { class StringName; }
13
14namespace osc
15{
16 class Object {
17 protected:
18 explicit Object(const Class&);
19 Object(const Object&) = default;
23
24 // directly sets a property's value in this object
25 //
26 // mostly useful for `impl_custom_setter`, because it allows implementations
27 // to (e.g.) coerce property values
29 public:
30
31 // gets the `Class` (osc) of the `Object` type (C++)
32 //
33 // derived types that inherit from `Object` (C++) should ensure that
34 // their associated `Class` (osc) this `Class` as the parent.
36
38
39 std::string to_string() const
40 {
41 return impl_to_string();
42 }
43
44 std::unique_ptr<Object> clone() const
45 {
46 return impl_clone();
47 }
48
49 const Class& klass() const
50 {
51 return klass_;
52 }
53
54 size_t num_properties() const;
56
57 std::optional<size_t> property_index(const StringName& property_name) const;
64
65 private:
66 virtual std::string impl_to_string() const;
67 virtual std::unique_ptr<Object> impl_clone() const = 0;
68
69 // override this method to implement custom behavior when a property is set on
70 // this object
71 //
72 // - return `true` if your implementation has "handled" the `set` call (i.e. so
73 // that `Object` knows that it does not need to do anything further)
74 //
75 // - return `false` if your implementation did not handle the `set` call and, therefore,
76 // `Object` should handle it instead
77 virtual bool impl_custom_property_setter(const StringName& property_name, const Variant& value);
78
79 Class klass_;
80 std::vector<Variant> property_values_;
81 };
82
83 std::ostream& operator<<(std::ostream&, const Object&);
84}
Definition class.h:23
Definition object.h:16
std::string to_string() const
Definition object.h:39
std::optional< size_t > property_index(const StringName &property_name) const
const Variant * property_value(const StringName &property_name) const
const StringName & property_name(size_t property_index) const
virtual bool impl_custom_property_setter(const StringName &property_name, const Variant &value)
const Class & klass() const
Definition object.h:49
static const Class & klass_static()
virtual std::unique_ptr< Object > impl_clone() const =0
size_t num_properties() const
bool set_property_value(const StringName &property_name, const Variant &value)
const Variant & property_value_or_throw(const StringName &property_name) const
void set_property_value_raw(const StringName &property_name, const Variant &value)
std::unique_ptr< Object > clone() const
Definition object.h:44
const Variant * property_default_value(const StringName &property_name) const
const Variant & property_default_value_or_throw(const StringName &property_name) const
Object(const Object &)=default
Object(const Class &)
Object(Object &&) noexcept=default
virtual std::string impl_to_string() const
void set_property_value_or_throw(const StringName &property_name, const Variant &value)
Definition string_name.h:14
Definition variant.h:18
Definition custom_decoration_generator.h:5
std::ostream & operator<<(std::ostream &, const Object &)
constexpr U to(T &&value)
Definition conversion.h:56