Reference Manual
Inti Logo
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

object.h

Go to the documentation of this file.
00001 /*  Inti: Integrated Foundation Classes
00002  *  Copyright (C) 2002 The Inti Development Team.
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU Library General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU Library General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  */
00018 
00023 
00024 #ifndef INTI_G_OBJECT_H
00025 #define INTI_G_OBJECT_H
00026 
00027 #ifndef INTI_MEMORY_HANDLER_H
00028 #include <inti/memoryhandler.h>
00029 #endif
00030 
00031 #ifndef INTI_G_TYPE_H
00032 #include <inti/glib/type.h>
00033 #endif
00034 
00035 #ifndef INTI_G_QUARK_H
00036 #include <inti/glib/quark.h>
00037 #endif
00038 
00039 #ifndef INTI_G_PROPERTY_H
00040 #include <inti/glib/property.h>
00041 #endif
00042 
00043 namespace Inti {
00044 
00045 namespace G {
00046 
00047 class ObjectClass;
00048 class Quark;
00049 class Value;
00050 
00067 
00068 class Object : virtual public TypeInstance, virtual public MemoryHandler
00069 {
00070         friend class ObjectClass;
00071 
00072         Object(const Object&);
00073         Object& operator=(const Object&);
00074 
00075         static const Quark pointer_quark;
00076         
00077         static void destroy_notify(void *data);
00078 
00079 protected:
00082 
00083         explicit Object(GObject *object, bool reference = true);
00098 
00100 //  Override these do_ methods when you want to change the default behaviour of the GObject.
00101 
00102         virtual void do_set_property(unsigned int property_id, const GValue *value, GParamSpec *pspec);
00103 
00104         virtual void do_get_property(unsigned int property_id, GValue *value, GParamSpec *pspec);
00105 
00106         virtual void do_dispose();
00107 
00108         virtual void do_finalize();
00109 
00112 
00113         virtual void on_notify(GParamSpec *pspec);
00116 
00118 //  Signals
00119 
00120         typedef Signal1<void, GParamSpec*> NotifySignalType;
00121         typedef SignalProxy<TypeInstance, NotifySignalType> NotifySignalProxy;
00122         static const NotifySignalType notify_signal;
00123 
00124 public:
00127 
00128         virtual ~Object();
00130 
00134 
00135         GObject* g_object() const { return (GObject*)instance; }
00137 
00138         GObjectClass* g_object_class() const;
00140 
00141         operator GObject* () const;
00143 
00144         void get(const char *first_property_name, ...) const;
00148 
00149         void get_property(const char *property_name, Value& value) const;
00153 
00154         void* get_data(const Quark& quark) const;
00158 
00159         void* get_data(const char *key) const;
00160         void* get_data(const String& key) const;
00164 
00168 
00169         virtual void ref();
00172 
00173         virtual void unref();
00176 
00177         virtual void dispose();
00180 
00181         void set(const char *first_property_name, ...);
00185 
00186         void set_property(const char *property_name, const Value& value);
00190 
00191         void set_data(const Quark& quark, void *data, GDestroyNotify destroy = 0);
00201 
00202         void set_data(const char *key, void *data, GDestroyNotify destroy = 0);
00203         void set_data(const String& key, void *data, GDestroyNotify destroy = 0);
00213 
00214         void* remove_data(const Quark& quark, bool notify = false);
00223 
00224         void* remove_data(const char *key, bool notify = false);
00225         void* remove_data(const String& key, bool notify = false);
00234 
00235         unsigned long connect(const char *signal_name, GCallback handler, void *data, GClosureNotify destroy_data = 0);
00244 
00245         unsigned long connect_after(const char *signal_name, GCallback handler, void *data, GClosureNotify destroy_data = 0);
00256 
00257         unsigned long connect_swapped(const char *signal_name, GCallback handler, void *data, GClosureNotify destroy_data = 0);
00266 
00267         void emit_by_name(const char *signal_name, ...);
00274         
00275         void stop_emission_by_name(const char *detailed_signal);
00282 
00283         bool disconnect_by_name(const char* signal_name);
00293 
00297 
00298         template <typename T>
00299         static T* pointer(void *obj);
00303         
00304         template<typename T, typename gObj>
00305         static T* wrap(gObj *obj, bool reference = false);
00315 
00316         template<typename T, typename gObj>
00317         static T* wrap_new(gObj *obj, bool reference = false);
00326 
00330 
00331         const NotifySignalProxy sig_notify()
00332         {
00333                 return NotifySignalProxy(this, &notify_signal);
00334         }
00336 
00338 };
00339 
00340 } // namespace G
00341 
00342 template<typename T>
00343 inline T*
00344 G::Object::pointer(void *obj)
00345 {
00346         void *data = 0;
00347         if (obj)
00348         {
00349                 data = g_object_get_qdata(G_OBJECT(obj), G::Object::pointer_quark);
00350         }
00351         return data ? static_cast<T*>(data) : 0;
00352 }
00353 
00354 template<typename T, typename gObj>
00355 inline T*
00356 G::Object::wrap(gObj *obj, bool reference)
00357 {
00358         T *t = 0;
00359         if (obj)
00360         {
00361                 void *data = g_object_get_qdata(G_OBJECT(obj), G::Object::pointer_quark);
00362                 t = data ? static_cast<T*>(data) : new T(obj, reference);
00363         }
00364         return t;
00365 }
00366 
00367 template<typename T, typename gObj>
00368 inline T*
00369 G::Object::wrap_new(gObj *obj, bool reference)
00370 {
00371         return obj ? new T(obj, reference) : 0;
00372 }
00373 
00374 } // namespace Inti
00375 
00376 #endif // INTI_G_OBJECT_H
00377 
Main Page - Footer


Generated on Sun Sep 14 20:08:03 2003 for Inti by doxygen 1.3.2 written by Dimitri van Heesch, © 1997-2002