00001 // Copyright (C) 2004, 2006 International Business Machines and others. 00002 // All Rights Reserved. 00003 // This code is published under the Eclipse Public License. 00004 // 00005 // $Id: OSIpReferenced.hpp 1861 2010-12-21 21:34:47Z andreasw $ 00006 // 00007 // Authors: Carl Laird, Andreas Waechter IBM 2004-08-13 00008 00009 // copied from IpReferenced.hpp so as to allow OS to be compiled 00010 // stand-alone (without the Fortran implications inherent in Ipopt) 00011 00012 #ifndef OSREFERENCED_HPP 00013 #define OSREFERENCED_HPP 00014 00015 #include <list> 00016 #include <assert.h> 00017 00021 class OSReferencer 00022 {} 00023 ; 00024 00160 class OSReferencedObject 00161 { 00162 public: 00163 OSReferencedObject() 00164 : 00165 reference_count_(0) 00166 {} 00167 00168 virtual ~OSReferencedObject() 00169 { 00170 assert(reference_count_ == 0); 00171 } 00172 00173 int ReferenceCount() const; 00174 00175 void AddRef(const OSReferencer* referencer) const; 00176 00177 void ReleaseRef(const OSReferencer* referencer) const; 00178 00179 private: 00180 mutable int reference_count_; 00181 }; 00182 00183 /* inline methods */ 00184 inline 00185 int OSReferencedObject::ReferenceCount() const 00186 { 00187 return reference_count_; 00188 } 00189 00190 inline 00191 void OSReferencedObject::AddRef(const OSReferencer* referencer) const 00192 { 00193 reference_count_++; 00194 } 00195 00196 inline 00197 void OSReferencedObject::ReleaseRef(const OSReferencer* referencer) const 00198 { 00199 reference_count_--; 00200 } 00201 00202 #endif