3 * Copyright 1999 Karl Nelson <kenelson@ece.ucdavis.edu>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the Free
17 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 #ifndef SIGCXX_OBJECT_H
20 #define SIGCXX_OBJECT_H
21 #include <sigc++/sigc++config.h>
22 #include <sigc++/scope.h>
25 #ifdef SIGC_CXX_NAMESPACES
30 extern int sigc_micro_version;
31 extern int sigc_minor_version;
32 extern int sigc_major_version;
35 class LIBSIGC_API ObjectReferenced
37 friend class Reference;
39 friend class Invalid_;
41 #ifdef SIGC_CXX_FRIEND_TEMPLATES
47 // count of current references
48 unsigned int obj_count_ :24;
50 // indicates object generated through an interface that marks dynamic
51 unsigned int obj_dynamic_ :1;
53 // indicates the pointed to scope is the owner
54 unsigned int obj_owned_ :1;
56 // indicates object not will delete when count reachs zero
57 unsigned int obj_floating_ :1;
59 // indicates the owned scope is surrendering ownership
60 unsigned int obj_transfer_ :1;
62 // indicates the object is doing a list clean up
63 unsigned int obj_invalid_ :1;
65 // indicates the object been destroyed
66 unsigned int obj_destroyed_ :1;
68 // indicates there is a weak reference
69 unsigned int obj_weak_ :1;
72 /*************************************************************/
73 #ifdef SIGC_CXX_FRIEND_TEMPLATES
78 // For the controller and scope
79 virtual void set_dynamic();
80 inline void set_sink() {obj_floating_=0;}
84 inline void register_ref(Reference *)
94 virtual void reference();
95 virtual void unreference();
97 inline bool is_dynamic() {return obj_dynamic_;}
98 inline bool is_floating() {return obj_floating_;}
101 virtual ~ObjectReferenced();
105 class LIBSIGC_API ObjectScoped :public ObjectReferenced
108 typedef ScopeList List_;
113 // interface for scopes
114 void register_scope(Scope *scope,const Scope *parent=0);
115 void unregister_scope(Scope *scope);
118 // This sets a very weak reference which is removed at next invalid
122 void register_data(ScopeNode* data);
124 // inform connections that object wishs to delete
125 void invalid(bool destroy=0);
128 virtual ~ObjectScoped();
132 // There can only be one Scope_Object per any object
133 class LIBSIGC_API Object: public virtual ObjectScoped
140 // mark this a managable object
142 inline T* manage(T* t)
144 if (t) t->set_dynamic();
149 #ifdef SIGC_CXX_NAMESPACES