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: IpTaggedObject.hpp 2493 2014-05-31 19:08:59Z 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  */
00021 #ifndef IPOPT_THREAD_LOCAL
00022 
00023 #if defined(_MSC_VER)
00024 #define IPOPT_THREAD_LOCAL __declspec(thread)
00025 #elif defined(__APPLE__) && defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ < 405)
00026 #define IPOPT_THREAD_LOCAL
00027 #else
00028 #define IPOPT_THREAD_LOCAL __thread
00029 #endif
00030 
00031 #endif
00032 
00033 namespace Ipopt
00034 {
00035 
00075   class TaggedObject : public ReferencedObject, public Subject
00076   {
00077   public:
00079     typedef unsigned int Tag;
00080 
00082     TaggedObject()
00083         :
00084         Subject()
00085     {
00086       ObjectChanged();
00087     }
00088 
00090     virtual ~TaggedObject()
00091     {}
00092 
00097     Tag GetTag() const
00098     {
00099       return tag_;
00100     }
00101 
00107     bool HasChanged(const Tag comparison_tag) const
00108     {
00109       return (comparison_tag == tag_) ? false : true;
00110     }
00111   protected:
00116     void ObjectChanged()
00117     {
00118       DBG_START_METH("TaggedObject::ObjectChanged()", 0);
00119       tag_ = unique_tag_;
00120       unique_tag_++;
00121       DBG_ASSERT(unique_tag_ < std::numeric_limits<Tag>::max());
00122       // The Notify method from the Subject base class notifies all
00123       // registered Observers that this subject has changed.
00124       Notify(Observer::NT_Changed);
00125     }
00126   private:
00134     TaggedObject(const TaggedObject&);
00135 
00137     void operator=(const TaggedObject&);
00139 
00144     static IPOPT_THREAD_LOCAL Tag unique_tag_;
00145 
00151     Tag tag_;
00152 
00158     Index cache_priority_;
00159   };
00160 } // namespace Ipopt
00161 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 17 Aug 2014 for Ipopt by  doxygen 1.6.1