[Bf-blender-cvs] [ce5fc090a85] xr-controller-support: Move customdata wrapper to GHOST_Util.h
Peter Kim
noreply at git.blender.org
Tue May 18 15:07:12 CEST 2021
Commit: ce5fc090a85903e0d6b2c11bfff4049963049ac4
Author: Peter Kim
Date: Sun May 16 03:13:07 2021 +0900
Branches: xr-controller-support
https://developer.blender.org/rBce5fc090a85903e0d6b2c11bfff4049963049ac4
Move customdata wrapper to GHOST_Util.h
===================================================================
M intern/ghost/CMakeLists.txt
A intern/ghost/intern/GHOST_Util.h
M intern/ghost/intern/GHOST_XrAction.cpp
M intern/ghost/intern/GHOST_XrAction.h
===================================================================
diff --git a/intern/ghost/CMakeLists.txt b/intern/ghost/CMakeLists.txt
index 45021e3ee01..f90e8a973bf 100644
--- a/intern/ghost/CMakeLists.txt
+++ b/intern/ghost/CMakeLists.txt
@@ -79,6 +79,7 @@ set(SRC
intern/GHOST_SystemPaths.h
intern/GHOST_TimerManager.h
intern/GHOST_TimerTask.h
+ intern/GHOST_Util.h
intern/GHOST_Window.h
intern/GHOST_WindowManager.h
)
diff --git a/intern/ghost/intern/GHOST_Util.h b/intern/ghost/intern/GHOST_Util.h
new file mode 100644
index 00000000000..8be5e373b28
--- /dev/null
+++ b/intern/ghost/intern/GHOST_Util.h
@@ -0,0 +1,45 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+/** \file
+ * \ingroup GHOST
+ */
+
+#pragma once
+
+#include <functional>
+
+/**
+ * RAII wrapper for typical C `void *` custom data.
+ * Used for exception safe custom-data handling during constructor calls.
+ */
+struct GHOST_C_CustomDataWrapper {
+ using FreeFn = std::function<void(void *)>;
+
+ void *custom_data_;
+ FreeFn free_fn_;
+
+ GHOST_C_CustomDataWrapper(void *custom_data, FreeFn free_fn)
+ : custom_data_(custom_data), free_fn_(free_fn)
+ {
+ }
+ ~GHOST_C_CustomDataWrapper()
+ {
+ if (free_fn_ != nullptr && custom_data_ != nullptr) {
+ free_fn_(custom_data_);
+ }
+ }
+};
diff --git a/intern/ghost/intern/GHOST_XrAction.cpp b/intern/ghost/intern/GHOST_XrAction.cpp
index 601f580baa1..2b956c26ca7 100644
--- a/intern/ghost/intern/GHOST_XrAction.cpp
+++ b/intern/ghost/intern/GHOST_XrAction.cpp
@@ -28,32 +28,6 @@
#include "GHOST_XrAction.h"
-/* -------------------------------------------------------------------- */
-/** \name CCustomDataWrapper
- *
- * RAII wrapper for typical C `void *` custom data.
- * Used for exception safe custom-data handling during constructor calls.
- *
- * \{ */
-
-struct CCustomDataWrapper {
- void *custom_data_;
- GHOST_XrCustomdataFreeFn free_fn_;
-
- CCustomDataWrapper(void *custom_data, GHOST_XrCustomdataFreeFn free_fn)
- : custom_data_(custom_data), free_fn_(free_fn)
- {
- }
- ~CCustomDataWrapper()
- {
- if (free_fn_ != nullptr && custom_data_ != nullptr) {
- free_fn_(custom_data_);
- }
- }
-};
-
-/** \} */
-
/* -------------------------------------------------------------------- */
/** \name GHOST_XrActionSpace
*
@@ -179,7 +153,7 @@ GHOST_XrAction::GHOST_XrAction(XrInstance instance,
: m_type(info.type),
m_states(info.states),
m_custom_data_(
- std::make_unique<CCustomDataWrapper>(info.customdata, info.customdata_free_fn))
+ std::make_unique<GHOST_C_CustomDataWrapper>(info.customdata, info.customdata_free_fn))
{
m_subaction_paths.resize(info.count_subaction_paths);
@@ -414,7 +388,7 @@ void GHOST_XrAction::getBindings(
GHOST_XrActionSet::GHOST_XrActionSet(XrInstance instance, const GHOST_XrActionSetInfo &info)
: m_custom_data_(
- std::make_unique<CCustomDataWrapper>(info.customdata, info.customdata_free_fn))
+ std::make_unique<GHOST_C_CustomDataWrapper>(info.customdata, info.customdata_free_fn))
{
XrActionSetCreateInfo action_set_info{XR_TYPE_ACTION_SET_CREATE_INFO};
strcpy(action_set_info.actionSetName, info.name);
diff --git a/intern/ghost/intern/GHOST_XrAction.h b/intern/ghost/intern/GHOST_XrAction.h
index 961e4c8d3ba..b915e1cd316 100644
--- a/intern/ghost/intern/GHOST_XrAction.h
+++ b/intern/ghost/intern/GHOST_XrAction.h
@@ -27,7 +27,7 @@
#include <memory>
#include <string>
-struct CCustomDataWrapper;
+#include "GHOST_Util.h"
/* -------------------------------------------------------------------- */
@@ -106,7 +106,7 @@ class GHOST_XrAction {
/** States for each subaction path. */
void *m_states;
- std::unique_ptr<CCustomDataWrapper> m_custom_data_ = nullptr; /* wmXrAction */
+ std::unique_ptr<GHOST_C_CustomDataWrapper> m_custom_data_ = nullptr; /* wmXrAction */
/* Spaces identified by user (subaction) path. */
std::map<std::string, GHOST_XrActionSpace> m_spaces;
@@ -139,7 +139,7 @@ class GHOST_XrActionSet {
private:
XrActionSet m_action_set = XR_NULL_HANDLE;
- std::unique_ptr<CCustomDataWrapper> m_custom_data_ = nullptr; /* wmXrActionSet */
+ std::unique_ptr<GHOST_C_CustomDataWrapper> m_custom_data_ = nullptr; /* wmXrActionSet */
std::map<std::string, GHOST_XrAction> m_actions;
};
More information about the Bf-blender-cvs
mailing list