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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
|
// -*- c++ -*-
/* $Id$ */
/* Copyright 2002 The gtkmm Development Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library 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/value.h>
#include <glibmm/objectbase.h>
#include <glibmm/utility.h>
#include <glibmm/wrap.h>
namespace Glib
{
/**** Glib::ValueBase ******************************************************/
ValueBase::ValueBase()
{
GLIBMM_INITIALIZE_STRUCT(gobject_, GValue);
}
void ValueBase::init(GType type)
{
g_value_init(&gobject_, type);
}
ValueBase::ValueBase(const ValueBase& other)
{
GLIBMM_INITIALIZE_STRUCT(gobject_, GValue);
g_value_init(&gobject_, G_VALUE_TYPE(&other.gobject_));
g_value_copy(&other.gobject_, &gobject_);
}
ValueBase& ValueBase::operator=(const ValueBase& other)
{
// g_value_copy() prevents self-assignment and deletes the destination.
g_value_copy(&other.gobject_, &gobject_);
return *this;
}
ValueBase::~ValueBase()
{
g_value_unset(&gobject_);
}
void ValueBase::reset()
{
g_value_reset(&gobject_);
}
/**** Glib::ValueBase_Boxed ************************************************/
// static
GType ValueBase_Boxed::value_type()
{
return G_TYPE_BOXED;
}
void ValueBase_Boxed::set_boxed(const void* data)
{
g_value_set_boxed(&gobject_, data);
}
void* ValueBase_Boxed::get_boxed() const
{
return g_value_get_boxed(&gobject_);
}
GParamSpec* ValueBase_Boxed::create_param_spec(const Glib::ustring& name) const
{
return g_param_spec_boxed(
name.c_str(), 0, 0, G_VALUE_TYPE(&gobject_),
GParamFlags(G_PARAM_READABLE | G_PARAM_WRITABLE));
}
/**** Glib::ValueBase_Object ***********************************************/
// static
GType ValueBase_Object::value_type()
{
return G_TYPE_OBJECT;
}
void ValueBase_Object::set_object(Glib::ObjectBase* data)
{
g_value_set_object(&gobject_, (data) ? data->gobj() : 0);
}
Glib::ObjectBase* ValueBase_Object::get_object() const
{
GObject *const data = static_cast<GObject*>(g_value_get_object(&gobject_));
return Glib::wrap_auto(data, false);
}
Glib::RefPtr<Glib::ObjectBase> ValueBase_Object::get_object_copy() const
{
GObject *const data = static_cast<GObject*>(g_value_get_object(&gobject_));
return Glib::RefPtr<Glib::ObjectBase>(Glib::wrap_auto(data, true));
}
GParamSpec* ValueBase_Object::create_param_spec(const Glib::ustring& name) const
{
// Glib::Value_Pointer<> derives from Glib::ValueBase_Object, because
// we don't know beforehand whether a certain type is derived from
// Glib::Object or not. To keep create_param_spec() out of the template
// struggle, we dispatch here at runtime.
if(G_VALUE_HOLDS_OBJECT(&gobject_))
{
return g_param_spec_object(
name.c_str(), 0, 0, G_VALUE_TYPE(&gobject_),
GParamFlags(G_PARAM_READABLE | G_PARAM_WRITABLE));
}
else
{
g_return_val_if_fail(G_VALUE_HOLDS_POINTER(&gobject_), 0);
return g_param_spec_pointer(
name.c_str(), 0, 0,
GParamFlags(G_PARAM_READABLE | G_PARAM_WRITABLE));
}
}
/**** Glib::ValueBase_Enum *************************************************/
// static
GType ValueBase_Enum::value_type()
{
return G_TYPE_ENUM;
}
void ValueBase_Enum::set_enum(int data)
{
g_value_set_enum(&gobject_, data);
}
int ValueBase_Enum::get_enum() const
{
return g_value_get_enum(&gobject_);
}
GParamSpec* ValueBase_Enum::create_param_spec(const Glib::ustring& name) const
{
return g_param_spec_enum(
name.c_str(), 0, 0,
G_VALUE_TYPE(&gobject_), g_value_get_enum(&gobject_),
GParamFlags(G_PARAM_READABLE | G_PARAM_WRITABLE));
}
/**** Glib::ValueBase_Flags ************************************************/
// static
GType ValueBase_Flags::value_type()
{
return G_TYPE_FLAGS;
}
void ValueBase_Flags::set_flags(unsigned int data)
{
g_value_set_flags(&gobject_, data);
}
unsigned int ValueBase_Flags::get_flags() const
{
return g_value_get_flags(&gobject_);
}
GParamSpec* ValueBase_Flags::create_param_spec(const Glib::ustring& name) const
{
return g_param_spec_flags(
name.c_str(), 0, 0,
G_VALUE_TYPE(&gobject_), g_value_get_flags(&gobject_),
GParamFlags(G_PARAM_READABLE | G_PARAM_WRITABLE));
}
/**** Glib::ValueBase_String ***********************************************/
// static
GType ValueBase_String::value_type()
{
return G_TYPE_STRING;
}
void ValueBase_String::set_cstring(const char* data)
{
g_value_set_string(&gobject_, data);
}
const char* ValueBase_String::get_cstring() const
{
if(const char *const data = g_value_get_string(&gobject_))
return data;
else
return "";
}
GParamSpec* ValueBase_String::create_param_spec(const Glib::ustring& name) const
{
return g_param_spec_string(
name.c_str(), 0, 0, get_cstring(),
GParamFlags(G_PARAM_READABLE | G_PARAM_WRITABLE));
}
/**** Glib::Value<std::string> *********************************************/
void Value<std::string>::set(const std::string& data)
{
g_value_set_string(&gobject_, data.c_str());
}
/**** Glib::Value<Glib::ustring> *******************************************/
void Value<Glib::ustring>::set(const Glib::ustring& data)
{
g_value_set_string(&gobject_, data.c_str());
}
} // namespace Glib
|