summaryrefslogtreecommitdiff
path: root/glib/src/variant.ccg
blob: c30275af7e2c2ccc830287355763f134af9b0383 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/* Copyright 2010 The glibmm Development Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include <glibmm/variant.h>
#include <glibmm/utility.h>
#include <glib/gvariant.h>

namespace Glib
{

void VariantBase::get_normal_form(VariantBase& result) const
{
  GVariant* const g_value =
    g_variant_get_normal_form(const_cast<GVariant*>(gobj()));

  result.init(g_value); // g_value is already referenced.
}

void VariantBase::byteswap(VariantBase& result) const
{
  GVariant* const g_value = g_variant_byteswap(const_cast<GVariant*>(gobj()));
  result.init(g_value); // g_value is already referenced.
}


/****************** Specializations ***********************************/

void VariantBase::init(const GVariant* cobject, bool take_a_reference)
{
  if(gobject_)
    g_variant_unref(gobject_);

  gobject_ = const_cast<GVariant*>(cobject);
  if(take_a_reference)
    g_variant_ref(gobject_);
}

// static
const GVariantType* Variant<VariantBase>::variant_type()
{
  return G_VARIANT_TYPE_VARIANT;
}

Variant<VariantBase> Variant<VariantBase>::create(const VariantBase& data)
{
  return Variant<VariantBase>(g_variant_new_variant(const_cast<GVariant*>(data.gobj())));
}

VariantBase Variant<VariantBase>::get() const
{
  return VariantBase(g_variant_get_variant(gobject_));
}

// static
const GVariantType* Variant<Glib::ustring>::variant_type()
{
  return G_VARIANT_TYPE_STRING;
}

Variant<Glib::ustring>
Variant<Glib::ustring>::create(const Glib::ustring& data)
{
  return Variant<Glib::ustring>(g_variant_new_string(data.c_str()));
}

Glib::ustring Variant<Glib::ustring>::get() const
{
  return Glib::ustring(g_variant_get_string(gobject_, 0));
}

} // namespace Glib