~vcs-imports/gconfmm/main

« back to all changes in this revision

Viewing changes to gconf/src/value.hg

  • Committer: murrayc
  • Date: 2007-01-09 15:43:50 UTC
  • Revision ID: vcs-imports@canonical.com-20070109154350-lczyek6p0f2bqgva
moving

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- Mode: C++; c-basic-offset: 4  -*-
 
2
/* $Id: value.hg,v 1.3 2004/12/12 22:04:01 murrayc Exp $ */
 
3
 
 
4
/* value.hg
 
5
 * 
 
6
 * Copyright (C) 2000-2002 GConfmm Development Team
 
7
 *
 
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.
 
12
 *
 
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.
 
17
 *
 
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.
 
21
 */
 
22
 
 
23
#include <glibmm/ustring.h>
 
24
#include <gconfmm/value_listhelpers.h>
 
25
 
 
26
_DEFS(gconfmm,gconf)
 
27
 
 
28
namespace Gnome
 
29
{
 
30
 
 
31
namespace Conf
 
32
{
 
33
 
 
34
_WRAP_ENUM(ValueType,GConfValueType)
 
35
 
 
36
typedef std::pair<Value, Value> ValuePair;    
 
37
typedef std::pair<ValueType, ValueType> ValueTypePair;
 
38
 
 
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
 
46
 * behaviour.
 
47
 *
 
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.
 
50
 *
 
51
 * The Value class has copy-by-value semantics - all arguments to the
 
52
 * set methods are copied.
 
53
 * 
 
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 
 
56
 * accuracy.
 
57
 */
 
58
class Value 
 
59
{
 
60
  _CLASS_OPAQUE_COPYABLE(Value,GConfValue,NONE,gconf_value_copy,gconf_value_free)
 
61
  _CUSTOM_DEFAULT_CTOR
 
62
  _IGNORE(gconf_value_free, gconf_value_copy, gconf_value_compare)
 
63
public:
 
64
 
 
65
  /** Create a Value.
 
66
   * You should call a set() method before using the Value.
 
67
   * @param type: The type of the produced value.
 
68
   */
 
69
  Value(ValueType type = VALUE_INVALID);
 
70
 
 
71
  /** Set the integer value of a Value whose type is VALUE_INT
 
72
   */
 
73
  _WRAP_METHOD(void set(gint val), gconf_value_set_int)
 
74
 
 
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.
 
77
   */
 
78
  _WRAP_METHOD(void set(gdouble val), gconf_value_set_float)
 
79
 
 
80
  /** Set the boolean value of a Value whose type is VALUE_BOOL */
 
81
  _WRAP_METHOD(void set(bool val), gconf_value_set_bool)
 
82
 
 
83
  /** Set the Schema of a Value whose type is VALUE_SCHEMA */
 
84
  _WRAP_METHOD(void set(const Schema& sc), gconf_value_set_schema)
 
85
 
 
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)
 
88
 
 
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)
 
91
 
 
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)
 
95
 
 
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)
 
98
 
 
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
 
102
   */
 
103
  _WRAP_METHOD(void set_int_list(const SListHandle_ValueInt& list), gconf_value_set_list_nocopy)
 
104
 
 
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)
 
108
 
 
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)
 
112
 
 
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)
 
116
 
 
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)
 
121
 
 
122
  /** Get the type of the Value.
 
123
   * @return the type of the Value
 
124
   */
 
125
  ValueType get_type() const;
 
126
  _IGNORE(gconf_value_get_type)
 
127
 
 
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.
 
131
   */
 
132
  _WRAP_METHOD(ValueType get_list_type() const, gconf_value_get_list_type)
 
133
 
 
134
  /** Get the integer that the Value contains */
 
135
  _WRAP_METHOD(int get_int() const, gconf_value_get_int)
 
136
 
 
137
  /** Get the boolean that the Value contains */
 
138
  _WRAP_METHOD(bool get_bool() const, gconf_value_get_bool)
 
139
 
 
140
  /** Get the double that the Value contains */
 
141
  _WRAP_METHOD(double get_float() const, gconf_value_get_float)
 
142
 
 
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)
 
146
 
 
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)
 
150
 
 
151
  /** Get a copy of the car of a VALUE_PAIR Value */
 
152
  Value get_car() const;
 
153
 
 
154
  /** Get a copy of the cdr of a VALUE_PAIR Value */
 
155
  Value get_cdr() const;
 
156
 
 
157
  /** Gets a list of doubles from the Value.
 
158
   * Typical usage is
 
159
   * @code
 
160
   * std::vector<double> foo = value.get_float_list();
 
161
   * @endcode.
 
162
   * @return: an STL-compatible container with doubles as its value type.
 
163
   * Assign to an std::vector, list or deque for proper use.
 
164
   */
 
165
  _WRAP_METHOD(SListHandle_ValueFloat  get_float_list() const, gconf_value_get_list)
 
166
 
 
167
  /** Retrieves the list of integers from the Value.
 
168
   * @see get_float_list
 
169
   */
 
170
  _WRAP_METHOD(SListHandle_ValueInt    get_int_list() const, gconf_value_get_list)
 
171
 
 
172
  /** Retrieves the list of booleans from the Value.
 
173
   * @see get_float_list
 
174
   */
 
175
  _WRAP_METHOD(SListHandle_ValueBool   get_bool_list() const, gconf_value_get_list)
 
176
 
 
177
  /** Retrieves the list of strings from the Value.
 
178
   * @see get_float_list
 
179
   */
 
180
  _WRAP_METHOD(SListHandle_ValueString get_string_list() const, gconf_value_get_list)
 
181
 
 
182
  /** Retrieves the list of Schemas from the Value.
 
183
   * @See get_float_list
 
184
   */
 
185
  _WRAP_METHOD(SListHandle_ValueSchema get_schema_list() const, gconf_value_get_list)
 
186
 
 
187
  /** Convert the Value to a string.
 
188
   * The string is not machine-parseable. Do not depend on the
 
189
   * format of the string.
 
190
   */
 
191
  _WRAP_METHOD(Glib::ustring to_string() const, gconf_value_to_string)
 
192
};
 
193
 
 
194
} /* namespace Conf */
 
195
} /* namespace Gnome */