Ipopt Documentation  
 
Loading...
Searching...
No Matches
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// Authors: Carl Laird, Andreas Waechter IBM 2004-08-13
6
7#ifndef __IPREFERENCED_HPP__
8#define __IPREFERENCED_HPP__
9
10#include "IpTypes.hpp"
11#include "IpDebug.hpp"
12
13#include <list>
14
15#if IPOPT_CHECKLEVEL > 3
16#define IP_DEBUG_REFERENCED
17#endif
18
19namespace Ipopt
20{
21
25class Referencer { };
26
170{
171public:
173 : reference_count_(0)
174 { }
175
177 {
178 DBG_ASSERT(reference_count_ == 0);
179 }
180
181 inline Index ReferenceCount() const;
182
183 inline
184 void AddRef(
186 ) const;
187
188 inline
189 void ReleaseRef(
191 ) const;
192
193private:
195
196# ifdef IP_DEBUG_REFERENCED
197 mutable std::list<const Referencer*> referencers_;
198# endif
199
200};
201
202/* inline methods */
204{
205 // DBG_START_METH("ReferencedObject::ReferenceCount()", 0);
206 // DBG_PRINT((1,"Returning reference_count_ = %" IPOPT_INDEX_FORMAT "\n", reference_count_));
207 return reference_count_;
208}
209
210inline
213) const
214{
215 // DBG_START_METH("ReferencedObject::AddRef(const Referencer* referencer)", 0);
217 // DBG_PRINT((1, "New reference_count_ = %" IPOPT_INDEX_FORMAT "\n", reference_count_));
218# ifdef IP_DEBUG_REFERENCED
219 referencers_.push_back(referencer);
220# else
222# endif
223}
224
225inline
228) const
229{
230 // DBG_START_METH("ReferencedObject::ReleaseRef(const Referencer* referencer)",
231 // 0);
233 // DBG_PRINT((1, "New reference_count_ = %" IPOPT_INDEX_FORMAT "\n", reference_count_));
234
235# ifdef IP_DEBUG_REFERENCED
236
237 bool found = false;
238 std::list<const Referencer*>::iterator iter;
239 for( iter = referencers_.begin(); iter != referencers_.end(); ++iter )
240 {
241 if ((*iter) == referencer)
242 {
243 found = true;
244 break;
245 }
246 }
247
248 // cannot call release on a reference that was never added...
250
251 if (found)
252 {
253 referencers_.erase(iter);
254 }
255# else
257# endif
258}
259
260} // namespace Ipopt
261
262#endif
#define DBG_ASSERT(test)
Definition IpDebug.hpp:27
Templated class which stores one entry for the CachedResult class.
Storing the reference count of all the smart pointers that currently reference it.
void AddRef(const Referencer *referencer) const
void ReleaseRef(const Referencer *referencer) const
Pseudo-class, from which everything has to inherit that wants to use be registered as a Referencer fo...
#define IPOPTLIB_EXPORT
This file contains a base class for all exceptions and a set of macros to help with exceptions.
ipindex Index
Type of all indices of vectors, matrices etc.
Definition IpTypes.hpp:20