2 #ifndef _GLIBMM_PROPERTY_H
3 #define _GLIBMM_PROPERTY_H
4 /* $Id: property.h 291 2006-05-12 08:08:45Z murrayc $ */
6 /* Copyright 2002 The gtkmm 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/propertyproxy.h>
25 #ifdef GLIBMM_PROPERTIES_ENABLED
27 #include <glibmm/value.h>
32 #ifndef DOXYGEN_SHOULD_SKIP_THIS
34 #ifdef GLIBMM_CXX_CAN_USE_NAMESPACES_INSIDE_EXTERNC
35 //For the AIX xlC compiler, I can not find a way to do this without putting the functions in the global namespace. murrayc
38 #endif //GLIBMM_CXX_CAN_USE_NAMESPACES_INSIDE_EXTERNC
40 void custom_get_property_callback(GObject* object, unsigned int property_id,
41 GValue* value, GParamSpec* param_spec);
43 void custom_set_property_callback(GObject* object, unsigned int property_id,
44 const GValue* value, GParamSpec* param_spec);
46 #ifdef GLIBMM_CXX_CAN_USE_NAMESPACES_INSIDE_EXTERNC
48 #endif //GLIBMM_CXX_CAN_USE_NAMESPACES_INSIDE_EXTERNC
50 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
56 Glib::ustring get_name() const;
60 Glib::Object* object_;
61 Glib::ValueBase value_;
62 GParamSpec* param_spec_;
64 PropertyBase(Glib::Object& object, GType value_type);
67 bool lookup_property(const Glib::ustring& name);
68 void install_property(GParamSpec* param_spec);
70 const char* get_name_internal() const;
74 PropertyBase(const PropertyBase&);
75 PropertyBase& operator=(const PropertyBase&);
77 #ifndef DOXYGEN_SHOULD_SKIP_THIS
79 friend void Glib::custom_get_property_callback(GObject* object, unsigned int property_id,
80 GValue* value, GParamSpec* param_spec);
82 friend void Glib::custom_set_property_callback(GObject* object, unsigned int property_id,
83 const GValue* value, GParamSpec* param_spec);
85 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
90 class Property : public PropertyBase
93 typedef T PropertyType;
94 typedef Glib::Value<T> ValueType;
96 Property(Glib::Object& object, const Glib::ustring& name);
97 Property(Glib::Object& object, const Glib::ustring& name, const PropertyType& default_value);
99 inline void set_value(const PropertyType& data);
100 inline PropertyType get_value() const;
102 inline Property<T>& operator=(const PropertyType& data);
103 inline operator PropertyType() const;
105 inline Glib::PropertyProxy<T> get_proxy();
109 #ifndef DOXYGEN_SHOULD_SKIP_THIS
111 /**** Glib::Property<T> ****************************************************/
114 Property<T>::Property(Glib::Object& object, const Glib::ustring& name)
116 PropertyBase(object, ValueType::value_type())
118 if(!lookup_property(name))
119 install_property(static_cast<ValueType&>(value_).create_param_spec(name));
123 Property<T>::Property(Glib::Object& object, const Glib::ustring& name,
124 const typename Property<T>::PropertyType& default_value)
126 PropertyBase(object, ValueType::value_type())
128 static_cast<ValueType&>(value_).set(default_value);
130 if(!lookup_property(name))
131 install_property(static_cast<ValueType&>(value_).create_param_spec(name));
134 template <class T> inline
135 void Property<T>::set_value(const typename Property<T>::PropertyType& data)
137 static_cast<ValueType&>(value_).set(data);
141 template <class T> inline
142 typename Property<T>::PropertyType Property<T>::get_value() const
144 return static_cast<const ValueType&>(value_).get();
147 template <class T> inline
148 Property<T>& Property<T>::operator=(const typename Property<T>::PropertyType& data)
150 static_cast<ValueType&>(value_).set(data);
155 template <class T> inline
156 Property<T>::operator T() const
158 return static_cast<const ValueType&>(value_).get();
161 template <class T> inline
162 Glib::PropertyProxy<T> Property<T>::get_proxy()
164 return Glib::PropertyProxy<T>(object_, get_name_internal());
167 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
171 #endif //GLIBMM_PROPERTIES_ENABLED
173 #endif /* _GLIBMM_PROPERTY_H */