opynsim
Unofficial C++ Documentation
Loading...
Searching...
No Matches
class.h
Go to the documentation of this file.
1#pragma once
2
4
5#include <cstddef>
6#include <memory>
7#include <optional>
8#include <span>
9#include <string_view>
10
11namespace osc { class StringName; }
12
13namespace osc
14{
15 // Represents the shared aspects of `Object`s that are instances on this class.
16 //
17 // In oscar's runtime engine foundation systems, C++ classes should have
18 // a single linear inheritance chain with `Object` at the root. Each
19 // C++ class should also define one of these `Class` objects, usually behind
20 // a static `klass` member function getter. This is so that runtime systems
21 // can "see" the inheritance chain and handle (e.g.) inherited properties
22 // correctly.
23 class Class final {
24 public:
25 // Constructs a `Class` that represents an `Object` (i.e. the "root" `Class`).
27
28 // Constructs a `Class` with the given `name` that inherits from `parent_class`
29 // and has the given `properties`.
30 explicit Class(
31 std::string_view name,
32 const Class& parent_class = Class{},
33 std::span<const PropertyInfo> properties = std::span<const PropertyInfo>{}
34 );
35
36 // Returns the concrete classname of the `Class`.
37 const StringName& name() const;
38
39 // Returns the parent `Class` of this `Class`. If the `Class` has no parent (i.e.
40 // it's the `Class` that represents `Object`) then `std::nullopt` is returned.
41 std::optional<Class> parent_class() const;
42
43 // Returns a read-only view of the `PropertyInfo` for all properties of this `Class`.
44 std::span<const PropertyInfo> properties() const;
45
46 // Returns the index of the `PropertyInfo` that has the given `property_name`, or
47 // `std::nullopt` if no `PropertyInfo` with that name could be found.
48 std::optional<size_t> property_index(const StringName& property_name) const;
49
50 // Checks if the all aspects of the left- and right-hand operands are equal.
51 friend bool operator==(const Class&, const Class&);
52
53 private:
54 class Impl;
55 std::shared_ptr<const Impl> impl_;
56 };
57
58 bool operator==(const Class&, const Class&);
59}
Definition class.h:23
std::optional< size_t > property_index(const StringName &property_name) const
Class(std::string_view name, const Class &parent_class=Class{}, std::span< const PropertyInfo > properties=std::span< const PropertyInfo >{})
const StringName & name() const
friend bool operator==(const Class &, const Class &)
std::span< const PropertyInfo > properties() const
std::optional< Class > parent_class() const
Definition string_name.h:14
Definition custom_decoration_generator.h:5
bool operator==(const Class &, const Class &)
constexpr U to(T &&value)
Definition conversion.h:56