summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@gmail.com>2025-05-12 17:53:49 +0200
committerFelix Morgner <felix.morgner@gmail.com>2025-05-12 17:53:49 +0200
commitfb015121f064f2be12d1e28cdc7c54e074ed0411 (patch)
tree8e4577e5166af0ab01931243a25cc2f02b909e22
parenta1e345d62f143c3ef22e73eb51ac55fef27cf2da (diff)
downloadturns-fb015121f064f2be12d1e28cdc7c54e074ed0411.tar.xz
turns-fb015121f064f2be12d1e28cdc7c54e074ed0411.zip
lib: begin basic C++ wrapper
-rw-r--r--lib/CMakeLists.txt53
-rw-r--r--lib/src/turnsmm.hpp6
-rw-r--r--lib/src/turnsmm/participant.cpp142
-rw-r--r--lib/src/turnsmm/participant.hpp53
-rw-r--r--lib/src/turnsmm/private/participant_p.hpp31
5 files changed, 285 insertions, 0 deletions
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index 783700e..0fd7aa0 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -61,6 +61,59 @@ install(TARGETS "lib"
FILE_SET HEADERS DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/turns"
)
+# C++ Wrapper
+
+set(CXX_HEADERS
+ "src/turnsmm/participant.hpp"
+ "src/turnsmm.hpp"
+
+ "src/turnsmm/private/participant_p.hpp"
+)
+
+set(CXX_SOURCES
+ "src/turnsmm/participant.cpp"
+)
+
+add_library("libmm"
+ ${CXX_SOURCES}
+)
+
+add_library("turns::mm" ALIAS "libmm")
+
+target_sources("libmm" PUBLIC
+ FILE_SET HEADERS
+ BASE_DIRS "src"
+ FILES
+ ${CXX_HEADERS}
+)
+
+target_compile_options("libmm" PUBLIC
+ "$<$<CXX_COMPILER_ID:GNU,Clang>:-Wall>"
+ "$<$<CXX_COMPILER_ID:GNU,Clang>:-Wextra>"
+ "$<$<CXX_COMPILER_ID:GNU,Clang>:-Werror>"
+ "$<$<CXX_COMPILER_ID:GNU,Clang>:-pedantic-errors>"
+)
+
+target_include_directories("libmm" PUBLIC
+ "src"
+)
+
+target_link_libraries("libmm" PUBLIC
+ "PkgConfig::glibmm"
+
+ "turns::lib"
+)
+
+set_target_properties("libmm" PROPERTIES
+ OUTPUT_NAME "turnsmm"
+)
+
+enable_coverage("libmm")
+
+install(TARGETS "libmm"
+ FILE_SET HEADERS DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/turnsmm"
+)
+
# Tests
add_executable("lib-tests"
diff --git a/lib/src/turnsmm.hpp b/lib/src/turnsmm.hpp
new file mode 100644
index 0000000..122a5c9
--- /dev/null
+++ b/lib/src/turnsmm.hpp
@@ -0,0 +1,6 @@
+#ifndef TURNSMM_HPP
+#define TURNSMM_HPP
+
+#include "turnsmm/participant.hpp" // IWYU pragma: export
+
+#endif \ No newline at end of file
diff --git a/lib/src/turnsmm/participant.cpp b/lib/src/turnsmm/participant.cpp
new file mode 100644
index 0000000..0086ada
--- /dev/null
+++ b/lib/src/turnsmm/participant.cpp
@@ -0,0 +1,142 @@
+#include "turnsmm/participant.hpp"
+
+#include "turns-disposition.h"
+#include "turns-participant.h"
+#include "turnsmm/private/participant_p.hpp"
+
+#include <glibmm/class.h>
+#include <glibmm/object.h>
+#include <glibmm/objectbase.h>
+#include <glibmm/private/object_p.h>
+#include <glibmm/refptr.h>
+#include <glibmm/ustring.h>
+#include <glibmm/utility.h>
+#include <glibmm/wrap.h>
+
+#include <glib-object.h>
+
+#include <bit>
+
+namespace Turns
+{
+
+ namespace
+ {
+ auto constinit _class = Participant_Class{};
+
+ auto constexpr type_name = "TurnsParticipant";
+ } // namespace
+
+ auto Participant_Class::init() -> Glib::Class const &
+ {
+ if (!gtype_)
+ {
+ class_init_func_ = &class_init_function;
+ gtype_ = turns_participant_get_type();
+ }
+ return *this;
+ }
+
+ auto Participant_Class::class_init_function(void * gclass, void * data) -> void
+ {
+ auto const klass = static_cast<BaseClassType *>(gclass);
+ CppClassParent::class_init_function(klass, data);
+ }
+
+ auto Participant_Class::wrap_new(GObject * object) -> Glib::ObjectBase *
+ {
+ return new Participant(TURNS_PARTICIPANT(object));
+ }
+
+ Participant::Participant()
+ : Glib::ObjectBase{type_name}
+ , Glib::Object{Glib::ConstructParams{_class.init()}}
+ {
+ }
+
+ Participant::Participant(Glib::ustring const & name, float priority, int disposition)
+ : Glib::ObjectBase{type_name}
+ , Glib::Object{Glib::ConstructParams{_class.init(), "name", name.c_str(), "priority", priority, "disposition", disposition, nullptr}}
+ {
+ }
+
+ auto Participant::gobj() noexcept -> BaseObjectType *
+ {
+ return std::bit_cast<BaseObjectType *>(gobject_);
+ }
+
+ auto Participant::gobj() const -> BaseObjectType const *
+ {
+ return std::bit_cast<BaseObjectType const *>(gobject_);
+ }
+
+ auto Participant::gobj_copy() noexcept -> BaseObjectType *
+ {
+ reference();
+ return gobj();
+ }
+
+ auto Participant::get_active() const noexcept -> bool
+ {
+ return turns_participant_get_active(const_cast<BaseObjectType *>(unwrap(this)));
+ }
+
+ auto Participant::get_defeated() const noexcept -> bool
+ {
+ return turns_participant_get_defeated(const_cast<BaseObjectType *>(unwrap(this)));
+ }
+
+ auto Participant::get_disposition() const noexcept -> int
+ {
+ return turns_participant_get_disposition(const_cast<BaseObjectType *>(unwrap(this)));
+ }
+
+ auto Participant::get_name() const -> Glib::ustring
+ {
+ return turns_participant_get_name(const_cast<BaseObjectType *>(unwrap(this)));
+ }
+
+ auto Participant::get_priority() const noexcept -> float
+ {
+ return turns_participant_get_priority(const_cast<BaseObjectType *>(unwrap(this)));
+ }
+
+ auto Participant::set_active(bool value) noexcept -> void
+ {
+ return turns_participant_set_active(unwrap(this), value);
+ }
+
+ auto Participant::set_defeated(bool value) noexcept -> void
+ {
+ return turns_participant_set_defeated(unwrap(this), value);
+ }
+
+ auto Participant::set_disposition(int value) noexcept -> void
+ {
+ return turns_participant_set_disposition(unwrap(this), static_cast<TurnsDisposition>(value));
+ }
+
+ auto Participant::set_name(Glib::ustring const & value) noexcept -> void
+ {
+ return turns_participant_set_name(unwrap(this), value.c_str());
+ }
+
+ auto Participant::set_priority(float value) noexcept -> void
+ {
+ return turns_participant_set_priority(unwrap(this), value);
+ }
+
+ Participant::Participant(BaseObjectType * gobj)
+ : Glib::Object((GObject *)gobj)
+ {
+ }
+
+} // namespace Turns
+
+namespace Glib
+{
+ auto wrap(TurnsParticipant * object, bool copy) -> Glib::RefPtr<Turns::Participant>
+ {
+ return Glib::make_refptr_for_instance<Turns::Participant>(dynamic_cast<Turns::Participant *>(Glib::wrap_auto(G_OBJECT(object), copy)));
+ }
+} // namespace Glib \ No newline at end of file
diff --git a/lib/src/turnsmm/participant.hpp b/lib/src/turnsmm/participant.hpp
new file mode 100644
index 0000000..1eb5c1e
--- /dev/null
+++ b/lib/src/turnsmm/participant.hpp
@@ -0,0 +1,53 @@
+#ifndef TURNSMM_PARTICIPANT_HPP
+#define TURNSMM_PARTICIPANT_HPP
+
+#include "turns-participant.h"
+
+#include <glibmm/object.h>
+#include <glibmm/refptr.h>
+#include <glibmm/ustring.h>
+
+namespace Turns
+{
+
+ class Participant final : public Glib::Object
+ {
+ public:
+ using BaseClassType = TurnsParticipantClass;
+ using BaseObjectType = TurnsParticipant;
+ using CppClassType = class Participant_Class;
+ using CppObjectType = Participant;
+
+ Participant();
+ Participant(Glib::ustring const & name, float priority, int disposition);
+
+ [[nodiscard]] auto gobj() noexcept -> BaseObjectType *;
+ [[nodiscard]] auto gobj() const -> BaseObjectType const *;
+ [[nodiscard]] auto gobj_copy() noexcept -> BaseObjectType *;
+
+ [[nodiscard]] auto get_active() const noexcept -> bool;
+ [[nodiscard]] auto get_defeated() const noexcept -> bool;
+ [[nodiscard]] auto get_disposition() const noexcept -> int;
+ [[nodiscard]] auto get_name() const -> Glib::ustring;
+ [[nodiscard]] auto get_priority() const noexcept -> float;
+
+ auto set_active(bool value) noexcept -> void;
+ auto set_defeated(bool value) noexcept -> void;
+ auto set_disposition(int value) noexcept -> void;
+ auto set_name(Glib::ustring const & value) noexcept -> void;
+ auto set_priority(float value) noexcept -> void;
+
+ protected:
+ friend Participant_Class;
+
+ explicit Participant(BaseObjectType * gobj);
+ };
+
+} // namespace Turns
+
+namespace Glib
+{
+ auto wrap(TurnsParticipant * object, bool copy = false) -> Glib::RefPtr<Turns::Participant>;
+} // namespace Glib
+
+#endif \ No newline at end of file
diff --git a/lib/src/turnsmm/private/participant_p.hpp b/lib/src/turnsmm/private/participant_p.hpp
new file mode 100644
index 0000000..e3f4ce8
--- /dev/null
+++ b/lib/src/turnsmm/private/participant_p.hpp
@@ -0,0 +1,31 @@
+#ifndef TURNSMM_PARTICIPANT_P_HPP
+#define TURNSMM_PARTICIPANT_P_HPP
+
+#include "turns-participant.h"
+
+#include <glibmm/class.h>
+#include <glibmm/object.h>
+#include <glibmm/objectbase.h>
+
+#include <glib-object.h>
+
+namespace Turns
+{
+
+ class Participant_Class : Glib::Class
+ {
+ public:
+ using BaseClassParent = GObjectClass;
+ using BaseClassType = TurnsParticipantClass;
+ using BaseObjectType = TurnsParticipant;
+ using CppClassParent = Glib::Object_Class;
+ using CppObjectType = class Participant;
+
+ 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