Ipopt  trunk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
IpTaggedObject.hpp
Go to the documentation of this file.
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$
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 #ifndef IPOPT_THREAD_LOCAL
00020 #ifdef _MSC_VER
00021 #define IPOPT_THREAD_LOCAL __declspec(thread)
00022 #else
00023 #define IPOPT_THREAD_LOCAL __thread
00024 #endif
00025 #endif
00026 
00027 namespace Ipopt
00028 {
00029 
00069   class TaggedObject : public ReferencedObject, public Subject
00070   {
00071   public:
00073     typedef unsigned int Tag;
00074 
00076     TaggedObject()
00077         :
00078         Subject()
00079     {
00080       ObjectChanged();
00081     }
00082 
00084     virtual ~TaggedObject()
00085     {}
00086 
00091     Tag GetTag() const
00092     {
00093       return tag_;
00094     }
00095 
00101     bool HasChanged(const Tag comparison_tag) const
00102     {
00103       return (comparison_tag == tag_) ? false : true;
00104     }
00105   protected:
00110     void ObjectChanged()
00111     {
00112       DBG_START_METH("TaggedObject::ObjectChanged()", 0);
00113       tag_ = unique_tag_;
00114       unique_tag_++;
00115       DBG_ASSERT(unique_tag_ < std::numeric_limits<Tag>::max());
00116       // The Notify method from the Subject base class notifies all
00117       // registered Observers that this subject has changed.
00118       Notify(Observer::NT_Changed);
00119     }
00120   private:
00128     TaggedObject(const TaggedObject&);
00129 
00131     void operator=(const TaggedObject&);
00133 
00138     static IPOPT_THREAD_LOCAL Tag unique_tag_;
00139 
00145     Tag tag_;
00146 
00152     Index cache_priority_;
00153   };
00154 } // namespace Ipopt
00155 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines