Ipopt 3.12.10

- Main Page
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
IpReferenced.hpp
Go to the documentation of this file.
1 // Copyright (C) 2004, 2006 International Business Machines and others.
2 // All Rights Reserved.
3 // This code is published under the Eclipse Public License.
4 //
5 // $Id: IpReferenced.hpp 2182 2013-03-30 20:02:18Z stefan $
6 //
7 // Authors: Carl Laird, Andreas Waechter IBM 2004-08-13
8
9 #ifndef __IPREFERENCED_HPP__
10 #define __IPREFERENCED_HPP__
11
12 #include "IpTypes.hpp"
13 #include "IpDebug.hpp"
14
15 #include <list>
16
17 #if COIN_IPOPT_CHECKLEVEL > 3
18 #define IP_DEBUG_REFERENCED
19 #endif
20
21 namespace Ipopt
22 {
23
27 class Referencer
28 {}
29 ;
30
174 class ReferencedObject
175 {
176 public:
177 ReferencedObject()
178 :
179 reference_count_(0)
180 {}
181
182 virtual ~ReferencedObject()
183 {
184 DBG_ASSERT(reference_count_ == 0);
185 }
186
187 inline
188 Index ReferenceCount() const;
189
190 inline
191 void AddRef(const Referencer* referencer) const;
192
193 inline
194 void ReleaseRef(const Referencer* referencer) const;
195
196 private:
197 mutable Index reference_count_;
198
199 # ifdef IP_DEBUG_REFERENCED
200 mutable std::list<const Referencer*> referencers_;
201 # endif
202
203 };
204
205 /* inline methods */
206 inline
207 Index ReferencedObject::ReferenceCount() const
208 {
209 // DBG_START_METH("ReferencedObject::ReferenceCount()", 0);
210 // DBG_PRINT((1,"Returning reference_count_ = %d\n", reference_count_));
211 return reference_count_;
212 }
213
214 inline
215 void ReferencedObject::AddRef(const Referencer* referencer) const
216 {
217 // DBG_START_METH("ReferencedObject::AddRef(const Referencer* referencer)", 0);
218 reference_count_++;
219 // DBG_PRINT((1, "New reference_count_ = %d\n", reference_count_));
220 # ifdef IP_DEBUG_REFERENCED
221 referencers_.push_back(referencer);
222 # endif
223
224 }
225
226 inline
227 void ReferencedObject::ReleaseRef(const Referencer* referencer) const
228 {
229 // DBG_START_METH("ReferencedObject::ReleaseRef(const Referencer* referencer)",
230 // 0);
231 reference_count_--;
232 // DBG_PRINT((1, "New reference_count_ = %d\n", reference_count_));
233
234 # ifdef IP_DEBUG_REFERENCED
235
236 bool found = false;
237 std::list<const Referencer*>::iterator iter;
238 for (iter = referencers_.begin(); iter != referencers_.end(); iter++) {
239 if ((*iter) == referencer) {
240 found = true;
241 break;
242 }
243 }
244
245 // cannot call release on a reference that was never added...
246 DBG_ASSERT(found);
247
248 if (found) {
249 referencers_.erase(iter);
250 }
251 # endif
252
253 }
254
255
256 } // namespace Ipopt
257
258 #endif
Ipopt::ReferencedObject::ReferenceCount
Index ReferenceCount() const
Definition: IpReferenced.hpp:207
Ipopt::ReferencedObject::reference_count_
Index reference_count_
Definition: IpReferenced.hpp:197
Ipopt::ReferencedObject::AddRef
void AddRef(const Referencer *referencer) const
Definition: IpReferenced.hpp:215
Ipopt::ReferencedObject::~ReferencedObject
virtual ~ReferencedObject()
Definition: IpReferenced.hpp:182
Ipopt::ReferencedObject::ReleaseRef
void ReleaseRef(const Referencer *referencer) const
Definition: IpReferenced.hpp:227
Ipopt::ReferencedObject
ReferencedObject class.
Definition: IpReferenced.hpp:174
Ipopt::Referencer
Psydo-class, from which everything has to inherit that wants to use be registered as a Referencer for...
Definition: IpReferenced.hpp:27
IpDebug.hpp
Ipopt::Index
int Index
Type of all indices of vectors, matrices etc.
Definition: IpTypes.hpp:19
DBG_ASSERT
#define DBG_ASSERT(test)
Definition: IpDebug.hpp:38
Ipopt::ReferencedObject::ReferencedObject
ReferencedObject()
Definition: IpReferenced.hpp:177
IpTypes.hpp