diff options
| author | Felix Morgner <felix.morgner@gmail.com> | 2025-05-13 15:59:02 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@gmail.com> | 2025-05-13 15:59:02 +0200 |
| commit | 9513f7303ffde9fbda869e346523a23197f4ece9 (patch) | |
| tree | f35ab8afa3273d1a8c4da2fc2ac9580a157a3a2c /lib/src/turnsmm | |
| parent | 661e98cf8bb61f29049d405aef9cdaace1449ac8 (diff) | |
| download | turns-9513f7303ffde9fbda869e346523a23197f4ece9.tar.xz turns-9513f7303ffde9fbda869e346523a23197f4ece9.zip | |
lib: begin TurnOrder implementation
Diffstat (limited to 'lib/src/turnsmm')
| -rw-r--r-- | lib/src/turnsmm/init.cpp | 5 | ||||
| -rw-r--r-- | lib/src/turnsmm/private/turn-order_p.hpp | 31 | ||||
| -rw-r--r-- | lib/src/turnsmm/turn-order.cpp | 92 | ||||
| -rw-r--r-- | lib/src/turnsmm/turn-order.hpp | 45 |
4 files changed, 172 insertions, 1 deletions
diff --git a/lib/src/turnsmm/init.cpp b/lib/src/turnsmm/init.cpp index 77c217b..3104b1d 100644 --- a/lib/src/turnsmm/init.cpp +++ b/lib/src/turnsmm/init.cpp @@ -1,9 +1,10 @@ #include "turnsmm/init.hpp" #include "turns-init.h" -#include "turnsmm/enums.hpp" #include "turnsmm/participant.hpp" #include "turnsmm/private/participant_p.hpp" // IWYU pragma: keep +#include "turnsmm/private/turn-order_p.hpp" // IWYU pragma: keep +#include "turnsmm/turn-order.hpp" #include <glibmm/value.h> #include <glibmm/wrap.h> @@ -21,8 +22,10 @@ namespace Turns turns_init(); WRAP_CLASS(Participant, participant); + WRAP_CLASS(TurnOrder, turn_order); ENSURE_TYPE(Participant); + ENSURE_TYPE(TurnOrder); } } // namespace Turns
\ No newline at end of file diff --git a/lib/src/turnsmm/private/turn-order_p.hpp b/lib/src/turnsmm/private/turn-order_p.hpp new file mode 100644 index 0000000..b128fd4 --- /dev/null +++ b/lib/src/turnsmm/private/turn-order_p.hpp @@ -0,0 +1,31 @@ +#ifndef TURNSMM_TURN_ORDER_P_HPP +#define TURNSMM_TURN_ORDER_P_HPP + +#include "turns-turn-order.h" + +#include <glibmm/class.h> +#include <glibmm/object.h> +#include <glibmm/objectbase.h> + +#include <glib-object.h> + +namespace Turns +{ + + class TurnOrder_Class : Glib::Class + { + public: + using BaseClassParent = GObjectClass; + using BaseClassType = TurnsTurnOrderClass; + using BaseObjectType = TurnsTurnOrder; + using CppClassParent = Glib::Object_Class; + using CppObjectType = class TURN_ORDER; + + auto init() -> Glib::Class const &; + auto static class_init_function(void * gclass, void * data) -> void; + auto static wrap_new(GObject * object) -> Glib::ObjectBase *; + }; + +} // namespace Turns + +#endif
\ No newline at end of file diff --git a/lib/src/turnsmm/turn-order.cpp b/lib/src/turnsmm/turn-order.cpp new file mode 100644 index 0000000..8dbcd9c --- /dev/null +++ b/lib/src/turnsmm/turn-order.cpp @@ -0,0 +1,92 @@ +#include "turnsmm/turn-order.hpp" + +#include "turns-turn-order.h" +#include "turnsmm/private/turn-order_p.hpp" + +#include <glibmm/class.h> +#include <glibmm/object.h> +#include <glibmm/objectbase.h> +#include <glibmm/private/object_p.h> +#include <glibmm/propertyproxy.h> +#include <glibmm/refptr.h> +#include <glibmm/wrap.h> + +#include <glib-object.h> + +#include <bit> + +namespace Turns +{ + + namespace + { + auto constinit _class = TurnOrder_Class{}; + } // namespace + + auto TurnOrder_Class::init() -> Glib::Class const & + { + if (!gtype_) + { + class_init_func_ = &class_init_function; + gtype_ = turns_turn_order_get_type(); + } + return *this; + } + + auto TurnOrder_Class::class_init_function(void * gclass, void * data) -> void + { + auto const klass = static_cast<BaseClassType *>(gclass); + CppClassParent::class_init_function(klass, data); + } + + auto TurnOrder_Class::wrap_new(GObject * object) -> Glib::ObjectBase * + { + return new TurnOrder(TURNS_TURN_ORDER(object)); + } + + TurnOrder::TurnOrder() + : Glib::ObjectBase{nullptr} + , Glib::Object{Glib::ConstructParams{_class.init()}} + { + } + + auto TurnOrder::gobj() noexcept -> BaseObjectType * + { + return std::bit_cast<BaseObjectType *>(gobject_); + } + + auto TurnOrder::gobj() const -> BaseObjectType const * + { + return std::bit_cast<BaseObjectType const *>(gobject_); + } + + auto TurnOrder::gobj_copy() noexcept -> BaseObjectType * + { + reference(); + return gobj(); + } + + auto TurnOrder::get_running() const noexcept -> bool + { + return turns_turn_order_get_running(const_cast<BaseObjectType *>(unwrap(this))); + } + + auto TurnOrder::property_running() const noexcept -> Glib::PropertyProxy_ReadOnly<bool> + { + return {this, "running"}; + } + + TurnOrder::TurnOrder(BaseObjectType * gobj) + : Glib::Object(G_OBJECT(gobj)) + { + } + +} // namespace Turns + +namespace Glib +{ + auto wrap(TurnsTurnOrder * object, bool copy) -> Glib::RefPtr<Turns::TurnOrder> + { + return Glib::make_refptr_for_instance<Turns::TurnOrder>(dynamic_cast<Turns::TurnOrder *>(Glib::wrap_auto(G_OBJECT(object), copy))); + } +} // namespace Glib
\ No newline at end of file diff --git a/lib/src/turnsmm/turn-order.hpp b/lib/src/turnsmm/turn-order.hpp new file mode 100644 index 0000000..822e879 --- /dev/null +++ b/lib/src/turnsmm/turn-order.hpp @@ -0,0 +1,45 @@ +#ifndef TURNSMM_TURN_ORDER_HPP +#define TURNSMM_TURN_ORDER_HPP + +#include "turns-turn-order.h" + +#include <glibmm/object.h> +#include <glibmm/propertyproxy.h> +#include <glibmm/refptr.h> +#include <glibmm/ustring.h> + +namespace Turns +{ + + class TurnOrder final : public Glib::Object + { + public: + using BaseClassType = TurnsTurnOrderClass; + using BaseObjectType = TurnsTurnOrder; + using CppClassType = class TurnOrder_Class; + using CppObjectType = TurnOrder; + + TurnOrder(); + + [[nodiscard]] auto gobj() noexcept -> BaseObjectType *; + [[nodiscard]] auto gobj() const -> BaseObjectType const *; + [[nodiscard]] auto gobj_copy() noexcept -> BaseObjectType *; + + [[nodiscard]] auto get_running() const noexcept -> bool; + + [[nodiscard]] auto property_running() const noexcept -> Glib::PropertyProxy_ReadOnly<bool>; + + protected: + friend TurnOrder_Class; + + explicit TurnOrder(BaseObjectType * gobj); + }; + +} // namespace Turns + +namespace Glib +{ + auto wrap(TurnsTurnOrder * object, bool copy = false) -> Glib::RefPtr<Turns::TurnOrder>; +} // namespace Glib + +#endif
\ No newline at end of file |
