[gjs] arg: Add a templated static type name function
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs] arg: Add a templated static type name function
- Date: Sun, 4 Oct 2020 23:35:56 +0000 (UTC)
commit 7407548b2c3e74895d8941aa0b38814d6e972654
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date: Thu May 14 20:16:14 2020 +0200
arg: Add a templated static type name function
This allows compile-time computation of the type name as a string.
(Philip: split out from another commit)
gi/arg-types-inl.h | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 90 insertions(+)
---
diff --git a/gi/arg-types-inl.h b/gi/arg-types-inl.h
new file mode 100644
index 00000000..d4758c9a
--- /dev/null
+++ b/gi/arg-types-inl.h
@@ -0,0 +1,90 @@
+/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
+// SPDX-License-Identifier: MIT OR LGPL-2.0-or-later
+// SPDX-FileCopyrightText: 2020 Marco Trevisan <marco trevisan canonical com>
+
+#pragma once
+
+#include <stdint.h>
+
+#include <type_traits>
+
+#include <girepository.h>
+#include <glib-object.h> // for GType
+#include <glib.h> // for gboolean
+
+namespace Gjs {
+
+template <typename T, GITypeTag TAG = GI_TYPE_TAG_VOID>
+constexpr inline const char* static_type_name() = delete;
+
+template <>
+constexpr inline const char* static_type_name<bool>() {
+ return "bool";
+}
+
+template <>
+constexpr inline const char* static_type_name<int8_t>() {
+ return "int8";
+}
+
+template <>
+constexpr inline const char* static_type_name<uint8_t>() {
+ return "uint8";
+}
+
+template <>
+constexpr inline const char* static_type_name<int16_t>() {
+ return "int16";
+}
+
+template <>
+constexpr inline const char* static_type_name<uint16_t>() {
+ return "uint16";
+}
+
+template <>
+constexpr inline const char* static_type_name<int32_t>() {
+ return "int32";
+}
+
+template <>
+constexpr inline const char* static_type_name<uint32_t>() {
+ return "uint32";
+}
+
+template <>
+constexpr inline const char* static_type_name<int64_t>() {
+ return "int64";
+}
+
+template <>
+constexpr inline const char* static_type_name<uint64_t>() {
+ return "uint64";
+}
+
+template <>
+constexpr inline const char* static_type_name<float>() {
+ return "float";
+}
+
+template <>
+constexpr inline const char* static_type_name<double>() {
+ return "double";
+}
+
+template <>
+constexpr inline const char* static_type_name<void*>() {
+ return "pointer";
+}
+
+template <>
+constexpr inline const char* static_type_name<GType, GI_TYPE_TAG_GTYPE>() {
+ return "GType";
+}
+
+template <>
+constexpr inline const char* static_type_name<gboolean, GI_TYPE_TAG_BOOLEAN>() {
+ return "boolean";
+}
+
+} // namespace Gjs
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]