summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKjell Ahlstedt <kjell.ahlstedt@bredband.net>2015-04-27 09:37:25 +0200
committerKjell Ahlstedt <kjell.ahlstedt@bredband.net>2015-04-27 09:37:25 +0200
commite89b9ab99416ec328e81668c1e097c63394462f1 (patch)
tree7826ea8b20cad8ec32d57b4277a64750e94e4ba3
parentf23d78236a236ec8206236d5e43a250ac828116a (diff)
downloadglibmm-e89b9ab99416ec328e81668c1e097c63394462f1.tar.gz
Glib::Variant: Wrap handles, add get_data_as_bytes()
* glib/src/variant.[hg|ccg]: VariantBase::is_castable_to(): Accept casts of handles to Variant<gint32>. Add VariantBase::get_data_as_bytes(). Deprecate the non-const get_data() and add a const one. * glib/src/variant_basictypes.[h|cc].m4: Add Variant<gint32>::create_handle().
-rw-r--r--glib/src/variant.ccg13
-rw-r--r--glib/src/variant.hg18
-rw-r--r--glib/src/variant_basictypes.cc.m430
-rw-r--r--glib/src/variant_basictypes.h.m424
4 files changed, 61 insertions, 24 deletions
diff --git a/glib/src/variant.ccg b/glib/src/variant.ccg
index fe835400..fd47549c 100644
--- a/glib/src/variant.ccg
+++ b/glib/src/variant.ccg
@@ -66,10 +66,12 @@ bool VariantBase::is_castable_to(const VariantType& supertype) const
// - Both types are assumed to be definite types (no indefinite types,
// no 'r', '?' or '*').
// - VARIANT_TYPE_OBJECT_PATH (o) and VARIANT_TYPE_SIGNATURE (g) can be cast to
- // VARIANT_TYPE_STRING (s), the type of Glib::ustring.
+ // VARIANT_TYPE_STRING (s), (Variant<Glib::ustring>::variant_type()).
// - VARIANT_TYPE_STRING (s), VARIANT_TYPE_OBJECT_PATH (o) and
- // VARIANT_TYPE_SIGNATURE (g) can be cast to
- // VARIANT_TYPE_BYTESTRING (ay), the type of std::string.
+ // VARIANT_TYPE_SIGNATURE (g) can be cast to VARIANT_TYPE_BYTESTRING (ay),
+ // (Variant<std::string>::variant_type()).
+ // - VARIANT_TYPE_HANDLE (h) can be cast to VARIANT_TYPE_INT32 (i),
+ // (Variant<gint32>::variant_type()).
std::size_t subtype_index = 0;
std::size_t supertype_index = 0;
@@ -96,6 +98,11 @@ bool VariantBase::is_castable_to(const VariantType& supertype) const
supertype_index++;
break;
+ case 'i':
+ if (!(subtype_char == 'h'))
+ return false;
+ break;
+
default:
return false;
}
diff --git a/glib/src/variant.hg b/glib/src/variant.hg
index 5bf3af46..604b195f 100644
--- a/glib/src/variant.hg
+++ b/glib/src/variant.hg
@@ -20,6 +20,7 @@ _DEFS(glibmm,glib)
#include <glibmmconfig.h>
#include <glibmm/varianttype.h>
#include <glibmm/variantiter.h>
+#include <glibmm/refptr.h>
#include <glibmm/ustring.h>
#include <glibmm/error.h>
#include <utility>
@@ -30,6 +31,7 @@ _DEFS(glibmm,glib)
namespace Glib
{
+class Bytes;
/** @defgroup Variant Variant Data Types
*
@@ -38,7 +40,7 @@ namespace Glib
* information about the type of that value. The range of possible
* values is determined by the type. The type system used is VariantType.
*
- * See the VariantBase class and it's derived types, such as VariantContainerBase,
+ * See the VariantBase class and its derived types, such as VariantContainerBase,
* and the Variant<> template type.
*
* Variant instances always have a type and a value (which are given
@@ -58,14 +60,14 @@ namespace Glib
*
* There is a Python-inspired text language for describing Variant
* values. Variant includes a printer for this language and a parser
- * with type inferencing.</a>.
+ * with type inferencing.
*/
//Note: We wrap this because it is thrown by GtkBuilder's functions.
// See https://bugzilla.gnome.org/show_bug.cgi?id=708206
// It would also be thrown by parse() if we wrap g_variant_parse().
// Now (2014-01-30) it's also thrown by Gio::Action::parse_detailed_name().
-/** Exception class for Variant parse errors.
+/** %Exception class for Variant parse errors.
*/
_WRAP_GERROR(VariantParseError, GVariantParseError, G_VARIANT_PARSE_ERROR, NO_GTYPE)
@@ -132,7 +134,9 @@ public:
_WRAP_METHOD(GVariantClass classify() const, g_variant_classify)
_WRAP_METHOD(gsize get_size() const, g_variant_get_size)
- _WRAP_METHOD(gconstpointer get_data(), g_variant_get_data)
+ _WRAP_METHOD(gconstpointer get_data(), g_variant_get_data, deprecated "Use the const version instead.")
+ _WRAP_METHOD(gconstpointer get_data() const, g_variant_get_data)
+ _WRAP_METHOD(Glib::RefPtr<const Glib::Bytes> get_data_as_bytes() const, g_variant_get_data_as_bytes)
_WRAP_METHOD(void store(gpointer data) const, g_variant_store)
_WRAP_METHOD(Glib::ustring print(bool type_annotate = false) const, g_variant_print)
@@ -221,6 +225,7 @@ protected:
* VARIANT_TYPE_STRING (Glib::ustring).
* - VARIANT_TYPE_STRING, VARIANT_TYPE_OBJECT_PATH and VARIANT_TYPE_SIGNATURE
* can be cast to VARIANT_TYPE_BYTESTRING (std::string).
+ * - VARIANT_TYPE_HANDLE can be cast to VARIANT_TYPE_INT32.
*
* These casts are possible also when they are parts of a more complicated type.
* E.g. in Variant<std::map<Glib::ustring, std::vector<std::string> > > the map's keys
@@ -964,11 +969,12 @@ public:
_IGNORE(
g_variant_get_boolean,
g_variant_get_byte,
+ g_variant_get_int16,
g_variant_get_uint16,
- g_variant_get_int64,
g_variant_get_int32,
- g_variant_get_int16,
+ g_variant_get_handle,
g_variant_get_uint32,
+ g_variant_get_int64,
g_variant_get_uint64,
g_variant_get_double,
g_variant_iter_new
diff --git a/glib/src/variant_basictypes.cc.m4 b/glib/src/variant_basictypes.cc.m4
index ba79a204..92e50a30 100644
--- a/glib/src/variant_basictypes.cc.m4
+++ b/glib/src/variant_basictypes.cc.m4
@@ -23,11 +23,14 @@ dnl Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
include(template.macros.m4)
dnl
-dnl For instance, GLIB_VARIANT_BASIC(c++ type, c type, c type name)
-dnl parameters:
-dnl c++ type: The C++ type for the specialization, such as bool
-dnl c type: The C type used by the C API, such as gboolean.
-dnl c type name: The text used in the C API functions and macros, such as boolean, in g_variant_get_boolean() and G_VARIANT_TYPE_BOOLEAN.
+dnl For instance, GLIB_VARIANT_BASIC(C++ type, C type, C type name [,C type name 2])
+dnl Parameters:
+dnl C++ type: The C++ type for the specialization, such as bool.
+dnl C type: The C type used by the C API, such as gboolean.
+dnl C type name: The text used in the C API functions and macros, such as boolean
+dnl in g_variant_get_boolean() and G_VARIANT_TYPE_BOOLEAN.
+dnl C type name 2: Optional second text, such as handle in g_variant_get_handle()
+dnl and G_VARIANT_TYPE_HANDLE.
dnl
define([GLIB_VARIANT_BASIC],[dnl
LINE(]__line__[)dnl
@@ -47,10 +50,24 @@ Variant<$1> Variant<$1>::create($1 data)
Variant<$1> result = Variant<$1>(g_variant_new_$3(data));
return result;
}
+ifelse($4,,,[
+Variant<$1> Variant<$1>::create_$4($1 data)
+{
+ Variant<$1> result = Variant<$1>(g_variant_new_$4(data));
+ return result;
+}
+])dnl
$1 Variant<$1>::get() const
{
+ifelse($4,,[dnl
return g_variant_get_$3(gobject_);
+],[dnl
+ if (get_type().equal(VARIANT_TYPE_[]UPPER($3)))
+ return g_variant_get_$3(gobject_);
+ else
+ return g_variant_get_$4(gobject_);
+])dnl
}
])
@@ -66,11 +83,10 @@ GLIB_VARIANT_BASIC(bool, gboolean, boolean)
GLIB_VARIANT_BASIC(unsigned char, guchar, byte)
GLIB_VARIANT_BASIC(gint16, gint16, int16)
GLIB_VARIANT_BASIC(guint16, guint16, uint16)
-GLIB_VARIANT_BASIC(gint32, gint32, int32)
+GLIB_VARIANT_BASIC(gint32, gint32, int32, handle)
GLIB_VARIANT_BASIC(guint32, guint32, uint32)
GLIB_VARIANT_BASIC(gint64, gint64, int64)
GLIB_VARIANT_BASIC(guint64, guint64, uint64)
-dnl This would redeclare the <int> GLIB_VARIANT_BASIC(gint32, guint32, handle)
GLIB_VARIANT_BASIC(double, gdouble, double)
} // namespace Glib
diff --git a/glib/src/variant_basictypes.h.m4 b/glib/src/variant_basictypes.h.m4
index 2f11a521..a6b6ec06 100644
--- a/glib/src/variant_basictypes.h.m4
+++ b/glib/src/variant_basictypes.h.m4
@@ -23,11 +23,14 @@ dnl Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
include(template.macros.m4)
dnl
-dnl For instance, GLIB_VARIANT_BASIC(c++ type, c type, c type name)
-dnl parameters:
-dnl c++ type: The C++ type for the specialization, such as bool
-dnl c type: The C type used by the C API, such as gboolean.
-dnl c type name: The text used in the C API functions and macros, such as boolean, in g_variant_get_boolean() and G_VARIANT_TYPE_BOOLEAN.
+dnl For instance, GLIB_VARIANT_BASIC(C++ type, C type, C type name [,C type name 2])
+dnl Parameters:
+dnl C++ type: The C++ type for the specialization, such as bool.
+dnl C type: The C type used by the C API, such as gboolean.
+dnl C type name: The text used in the C API functions and macros, such as boolean
+dnl in g_variant_get_boolean() and G_VARIANT_TYPE_BOOLEAN.
+dnl C type name 2: Optional second text, such as handle in g_variant_get_handle()
+dnl and G_VARIANT_TYPE_HANDLE.
dnl
define([GLIB_VARIANT_BASIC],[dnl
LINE(]__line__[)dnl
@@ -67,7 +70,13 @@ public:
* @return The new Glib::Variant<$1>.
*/
static Variant<$1> create($1 data);
-
+ifelse($4,,,[
+ /** Creates a new Glib::Variant<$1> of type VARIANT_TYPE_[]UPPER($4).
+ * @param data The value of the new Glib::Variant<$1>.
+ * @return The new Glib::Variant<$1>.
+ */
+ static Variant<$1> create_$4($1 data);
+])
/** Gets the value of the Glib::Variant<$1>.
* @return The $1 value of the Glib::Variant<$1>.
*/
@@ -90,10 +99,9 @@ GLIB_VARIANT_BASIC(bool, gboolean, boolean)
GLIB_VARIANT_BASIC(unsigned char, guchar, byte)
GLIB_VARIANT_BASIC(gint16, gint16, int16)
GLIB_VARIANT_BASIC(guint16, guint16, uint16)
-GLIB_VARIANT_BASIC(gint32, gint32, int32)
+GLIB_VARIANT_BASIC(gint32, gint32, int32, handle)
GLIB_VARIANT_BASIC(guint32, guint32, uint32)
GLIB_VARIANT_BASIC(gint64, gint64, int64)
GLIB_VARIANT_BASIC(guint64, guint64, uint64)
-dnl This would redeclare the <int> specialization: GLIB_VARIANT_BASIC(gint32, guint32, handle)
GLIB_VARIANT_BASIC(double, gdouble, double)
} // namespace Glib