Ipopt  3.12.12
 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 
175  {
176  public:
178  :
180  {}
181 
183  {
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:
198 
199 # ifdef IP_DEBUG_REFERENCED
200  mutable std::list<const Referencer*> referencers_;
201 # endif
202 
203  };
204 
205  /* inline methods */
206  inline
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);
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);
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
Index ReferenceCount() const
void AddRef(const Referencer *referencer) const
void ReleaseRef(const Referencer *referencer) const
ReferencedObject class.
Psydo-class, from which everything has to inherit that wants to use be registered as a Referencer for...
int Index
Type of all indices of vectors, matrices etc.
Definition: IpTypes.hpp:19
#define DBG_ASSERT(test)
Definition: IpDebug.hpp:38