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: IpTaggedObject.hpp 2613 2015-11-04 14:42:02Z stefan $ 00006 // 00007 // Authors: Carl Laird, Andreas Waechter IBM 2004-08-13 00008 00009 #ifndef __IPTAGGEDOBJECT_HPP__ 00010 #define __IPTAGGEDOBJECT_HPP__ 00011 00012 #include "IpUtils.hpp" 00013 #include "IpDebug.hpp" 00014 #include "IpReferenced.hpp" 00015 #include "IpObserver.hpp" 00016 #include <limits> 00017 00018 /* keyword to declare a thread-local variable according to http://en.wikipedia.org/wiki/Thread-local_storage 00019 * GCC < 4.5 on MacOS X does not support TLS 00020 * With Intel compiler on MacOS X, problems with TLS were reported. 00021 */ 00022 #ifndef IPOPT_THREAD_LOCAL 00023 00024 #if defined(_MSC_VER) 00025 #define IPOPT_THREAD_LOCAL __declspec(thread) 00026 #elif defined(__APPLE__) && ((defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ < 405)) || defined(__INTEL_COMPILER)) 00027 #define IPOPT_THREAD_LOCAL 00028 #else 00029 #define IPOPT_THREAD_LOCAL __thread 00030 #endif 00031 00032 #endif 00033 00034 namespace Ipopt 00035 { 00036 00076 class TaggedObject : public ReferencedObject, public Subject 00077 { 00078 public: 00080 typedef unsigned int Tag; 00081 00083 TaggedObject() 00084 : 00085 Subject() 00086 { 00087 ObjectChanged(); 00088 } 00089 00091 virtual ~TaggedObject() 00092 {} 00093 00098 Tag GetTag() const 00099 { 00100 return tag_; 00101 } 00102 00108 bool HasChanged(const Tag comparison_tag) const 00109 { 00110 return (comparison_tag == tag_) ? false : true; 00111 } 00112 protected: 00117 void ObjectChanged() 00118 { 00119 DBG_START_METH("TaggedObject::ObjectChanged()", 0); 00120 tag_ = unique_tag_; 00121 unique_tag_++; 00122 DBG_ASSERT(unique_tag_ < std::numeric_limits<Tag>::max()); 00123 // The Notify method from the Subject base class notifies all 00124 // registered Observers that this subject has changed. 00125 Notify(Observer::NT_Changed); 00126 } 00127 private: 00135 TaggedObject(const TaggedObject&); 00136 00138 void operator=(const TaggedObject&); 00140 00145 static IPOPT_THREAD_LOCAL Tag unique_tag_; 00146 00152 Tag tag_; 00153 00159 Index cache_priority_; 00160 }; 00161 } // namespace Ipopt 00162 #endif