1
// -*- Mode: C++; c-basic-offset: 4 -*-
2
/* $Id: value.hg,v 1.3 2004/12/12 22:04:01 murrayc Exp $ */
6
* Copyright (C) 2000-2002 GConfmm Development Team
8
* This library is free software; you can redistribute it and/or
9
* modify it under the terms of the GNU Library General Public
10
* License as published by the Free Software Foundation; either
11
* version 2 of the License, or (at your option) any later version.
13
* This library is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
* Library General Public License for more details.
18
* You should have received a copy of the GNU Library General Public
19
* License along with this library; if not, write to the Free
20
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23
#include <glibmm/ustring.h>
24
#include <gconfmm/value_listhelpers.h>
34
_WRAP_ENUM(ValueType,GConfValueType)
36
typedef std::pair<Value, Value> ValuePair;
37
typedef std::pair<ValueType, ValueType> ValueTypePair;
39
/** Wrapper for primitive types.
40
* This class wraps the primitive types that are passed to
41
* and from instances of Gnome::Conf::Client. It has an associated
42
* @c ValueType, which is specified at creation time,
43
* but can be changed with assignment. If the type is @c VALUE_INVALID then the effect
44
* of the set and get methods is undefined. Using a default-constructed
45
* Value without using any of the set methods produces undefined
48
* Compound Values of type VALUE_PAIR and VALUE_LIST can only have
49
* elements whose types are neither VALUE_PAIR or VALUE_LIST - they can only have primitive types.
51
* The Value class has copy-by-value semantics - all arguments to the
52
* set methods are copied.
54
* Note that while the type is named VALUE_FLOAT, the accessors for
55
* floating-point values use @c double, not @c float, to preserve
60
_CLASS_OPAQUE_COPYABLE(Value,GConfValue,NONE,gconf_value_copy,gconf_value_free)
62
_IGNORE(gconf_value_free, gconf_value_copy, gconf_value_compare)
66
* You should call a set() method before using the Value.
67
* @param type: The type of the produced value.
69
Value(ValueType type = VALUE_INVALID);
71
/** Set the integer value of a Value whose type is VALUE_INT
73
_WRAP_METHOD(void set(gint val), gconf_value_set_int)
75
/** Set the float value of a Value whose type is VALUE_FLOAT
76
* @param val: the @c double this Value will be se to.
78
_WRAP_METHOD(void set(gdouble val), gconf_value_set_float)
80
/** Set the boolean value of a Value whose type is VALUE_BOOL */
81
_WRAP_METHOD(void set(bool val), gconf_value_set_bool)
83
/** Set the Schema of a Value whose type is VALUE_SCHEMA */
84
_WRAP_METHOD(void set(const Schema& sc), gconf_value_set_schema)
86
/** Set the car (in a pair, the first element) of a Value whose type is VALUE_PAIR */
87
_WRAP_METHOD(void set_car(const Value& car), gconf_value_set_car)
89
/** Set the cdr (in a pair, the second element) of a Value whose type is VALUE_PAIR */
90
_WRAP_METHOD(void set_cdr(const Value& cdr), gconf_value_set_cdr)
92
/** Set the string of a Value whose type is VALUE_STRING */
93
_WRAP_METHOD(void set(const Glib::ustring& val), gconf_value_set_string)
94
_IGNORE(gconf_value_set_car_nocopy, gconf_value_set_cdr_nocopy, gconf_value_set_schema_nocopy)
96
/** Sets the type of the elements of a Value with type VALUE_LIST */
97
_WRAP_METHOD(void set_list_type(ValueType type), gconf_value_set_list_type)
99
/** Sets the Value to contain a list of integers.
100
* set_list_type(VALUE_INT) must have been called prior this call.
101
* @param list: an STL-compatible container whose value_type is @c int
103
_WRAP_METHOD(void set_int_list(const SListHandle_ValueInt& list), gconf_value_set_list_nocopy)
105
/** Sets the Value to contain a list of bools.
106
* @see set_int_list */
107
_WRAP_METHOD(void set_bool_list(const SListHandle_ValueBool& list), gconf_value_set_list_nocopy)
109
/** Sets the Value to contain a list of doubles.
110
* @see set_int_list */
111
_WRAP_METHOD(void set_float_list(const SListHandle_ValueFloat& list), gconf_value_set_list_nocopy)
113
/** Sets the Value to contain a list of strings.
114
* @see set_int_list */
115
_WRAP_METHOD(void set_string_list(const SListHandle_ValueString& list), gconf_value_set_list_nocopy)
117
/** Sets the Value to contain a list of Schema.
118
* @see set_int_list */
119
_WRAP_METHOD(void set_schema_list(const SListHandle_ValueSchema& list), gconf_value_set_list_nocopy)
120
_IGNORE(gconf_value_set_list)
122
/** Get the type of the Value.
123
* @return the type of the Value
125
ValueType get_type() const;
126
_IGNORE(gconf_value_get_type)
128
/** Get the type of the list elements of the Value.
129
* Do not call this method on non-list Values.
130
* @return the type of the list elements.
132
_WRAP_METHOD(ValueType get_list_type() const, gconf_value_get_list_type)
134
/** Get the integer that the Value contains */
135
_WRAP_METHOD(int get_int() const, gconf_value_get_int)
137
/** Get the boolean that the Value contains */
138
_WRAP_METHOD(bool get_bool() const, gconf_value_get_bool)
140
/** Get the double that the Value contains */
141
_WRAP_METHOD(double get_float() const, gconf_value_get_float)
143
/** Get the string that the Value contains */
144
_WRAP_METHOD(Glib::ustring get_string() const, gconf_value_get_string)
145
_IGNORE(gconf_value_get_schema)
147
/** Get a copy of the Schema of the value.. */
148
Schema get_schema() const;
149
_IGNORE(gconf_value_get_car, gconf_value_get_cdr)
151
/** Get a copy of the car of a VALUE_PAIR Value */
152
Value get_car() const;
154
/** Get a copy of the cdr of a VALUE_PAIR Value */
155
Value get_cdr() const;
157
/** Gets a list of doubles from the Value.
160
* std::vector<double> foo = value.get_float_list();
162
* @return: an STL-compatible container with doubles as its value type.
163
* Assign to an std::vector, list or deque for proper use.
165
_WRAP_METHOD(SListHandle_ValueFloat get_float_list() const, gconf_value_get_list)
167
/** Retrieves the list of integers from the Value.
168
* @see get_float_list
170
_WRAP_METHOD(SListHandle_ValueInt get_int_list() const, gconf_value_get_list)
172
/** Retrieves the list of booleans from the Value.
173
* @see get_float_list
175
_WRAP_METHOD(SListHandle_ValueBool get_bool_list() const, gconf_value_get_list)
177
/** Retrieves the list of strings from the Value.
178
* @see get_float_list
180
_WRAP_METHOD(SListHandle_ValueString get_string_list() const, gconf_value_get_list)
182
/** Retrieves the list of Schemas from the Value.
183
* @See get_float_list
185
_WRAP_METHOD(SListHandle_ValueSchema get_schema_list() const, gconf_value_get_list)
187
/** Convert the Value to a string.
188
* The string is not machine-parseable. Do not depend on the
189
* format of the string.
191
_WRAP_METHOD(Glib::ustring to_string() const, gconf_value_to_string)
194
} /* namespace Conf */
195
} /* namespace Gnome */