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 #include <sigc++/object.h>
21 #ifdef SIGC_CXX_NAMESPACES
24 #endif // SIGC_CXX_NAMESPACES
26 int sigc_major_version=SIGC_MAJOR_VERSION;
27 int sigc_minor_version=SIGC_MINOR_VERSION;
28 int sigc_micro_version=SIGC_MICRO_VERSION;
30 ObjectReferenced::ObjectReferenced():
32 obj_dynamic_(0),obj_owned_(1),obj_floating_(1),obj_transfer_(0),
33 obj_invalid_(0),obj_destroyed_(0),obj_weak_(0)
36 ObjectScoped::ObjectScoped():list_()
39 ObjectReferenced::~ObjectReferenced()
42 ObjectScoped::~ObjectScoped()
44 // we can't be destroyed again.
51 void ObjectReferenced::reference()
53 // if we exceed the int limit, we should unset dynamic_
58 void ObjectReferenced::unreference()
72 void ObjectScoped::register_data(ScopeNode *data)
74 list_.insert_direct(list_.end(),data);
77 void ObjectScoped::register_scope(Scope *scope,const Scope *parent)
81 // check for invalid in progress
85 // reregistering a scope
86 if (scope->obj_==this)
88 if (obj_transfer_&&(ScopeNode*)parent==list_.begin().node())
89 {list_.swap_elements(const_cast<Scope*>(parent),scope);
95 if (obj_transfer_&&(ScopeNode*)parent==list_.begin().node())
97 list_.insert_direct(list_.begin(),scope);
101 list_.insert_direct(list_.end(),scope);
103 // complete connection
108 void ObjectScoped::unregister_scope(Scope *scope)
112 // Check for loss of ownership
113 if (obj_owned_&&(ScopeNode*)scope==list_.begin().node())
120 void ObjectScoped::set_weak()
122 if (obj_weak_) return;
129 ObjectReferenced* r_;
130 Invalid_(ObjectReferenced& r): r_(&r)
142 void ObjectScoped::invalid(bool level)
144 if (!level&&(obj_invalid_||!obj_dynamic_))
147 List_::Iterator current=list_.begin();
148 List_::Iterator next=current;
149 if (current==list_.end()&&!obj_weak_)
160 while (current!=(list_.end()))
163 (*current).disconnect(level);
171 void ObjectReferenced::set_dynamic() {obj_dynamic_=1;}
174 #ifdef SIGC_CXX_NAMESPACES
176 #endif // SIGC_CXX_NAMESPACES