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 2476 2014-04-08 09:41:07Z 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 #ifdef _MSC_VER 00020 #define IPOPT_THREAD_LOCAL __declspec(thread) 00021 #else 00022 #define IPOPT_THREAD_LOCAL __thread 00023 #endif 00024 00025 namespace Ipopt 00026 { 00027 00067 class TaggedObject : public ReferencedObject, public Subject 00068 { 00069 public: 00071 typedef unsigned int Tag; 00072 00074 TaggedObject() 00075 : 00076 Subject() 00077 { 00078 ObjectChanged(); 00079 } 00080 00082 virtual ~TaggedObject() 00083 {} 00084 00089 Tag GetTag() const 00090 { 00091 return tag_; 00092 } 00093 00099 bool HasChanged(const Tag comparison_tag) const 00100 { 00101 return (comparison_tag == tag_) ? false : true; 00102 } 00103 protected: 00108 void ObjectChanged() 00109 { 00110 DBG_START_METH("TaggedObject::ObjectChanged()", 0); 00111 tag_ = unique_tag_; 00112 unique_tag_++; 00113 DBG_ASSERT(unique_tag_ < std::numeric_limits<Tag>::max()); 00114 // The Notify method from the Subject base class notifies all 00115 // registered Observers that this subject has changed. 00116 Notify(Observer::NT_Changed); 00117 } 00118 private: 00126 TaggedObject(const TaggedObject&); 00127 00129 void operator=(const TaggedObject&); 00131 00136 static IPOPT_THREAD_LOCAL Tag unique_tag_; 00137 00143 Tag tag_; 00144 00150 Index cache_priority_; 00151 }; 00152 } // namespace Ipopt 00153 #endif