Ipopt  3.12.12
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
IpTaggedObject.hpp
Go to the documentation of this file.
1 // Copyright (C) 2004, 2006 International Business Machines and others.
2 // All Rights Reserved.
3 // This code is published under the Eclipse Public License.
4 //
5 // $Id: IpTaggedObject.hpp 2613 2015-11-04 14:42:02Z stefan $
6 //
7 // Authors: Carl Laird, Andreas Waechter IBM 2004-08-13
8 
9 #ifndef __IPTAGGEDOBJECT_HPP__
10 #define __IPTAGGEDOBJECT_HPP__
11 
12 #include "IpUtils.hpp"
13 #include "IpDebug.hpp"
14 #include "IpReferenced.hpp"
15 #include "IpObserver.hpp"
16 #include <limits>
17 
18 /* keyword to declare a thread-local variable according to http://en.wikipedia.org/wiki/Thread-local_storage
19  * GCC < 4.5 on MacOS X does not support TLS
20  * With Intel compiler on MacOS X, problems with TLS were reported.
21  */
22 #ifndef IPOPT_THREAD_LOCAL
23 
24 #if defined(_MSC_VER)
25 #define IPOPT_THREAD_LOCAL __declspec(thread)
26 #elif defined(__APPLE__) && ((defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ < 405)) || defined(__INTEL_COMPILER))
27 #define IPOPT_THREAD_LOCAL
28 #else
29 #define IPOPT_THREAD_LOCAL __thread
30 #endif
31 
32 #endif
33 
34 namespace Ipopt
35 {
36 
76  class TaggedObject : public ReferencedObject, public Subject
77  {
78  public:
80  typedef unsigned int Tag;
81 
84  :
85  Subject()
86  {
87  ObjectChanged();
88  }
89 
91  virtual ~TaggedObject()
92  {}
93 
98  Tag GetTag() const
99  {
100  return tag_;
101  }
102 
108  bool HasChanged(const Tag comparison_tag) const
109  {
110  return (comparison_tag == tag_) ? false : true;
111  }
112  protected:
118  {
119  DBG_START_METH("TaggedObject::ObjectChanged()", 0);
120  tag_ = unique_tag_;
121  unique_tag_++;
122  DBG_ASSERT(unique_tag_ < std::numeric_limits<Tag>::max());
123  // The Notify method from the Subject base class notifies all
124  // registered Observers that this subject has changed.
126  }
127  private:
135  TaggedObject(const TaggedObject&);
136 
138  void operator=(const TaggedObject&);
140 
146 
153 
160  };
161 } // namespace Ipopt
162 #endif
void Notify(Observer::NotifyType notify_type) const
Definition: IpObserver.hpp:351
#define DBG_START_METH(__func_name, __verbose_level)
Definition: IpDebug.hpp:49
void operator=(const TaggedObject &)
Overloaded Equals Operator.
void ObjectChanged()
Objects derived from TaggedObject MUST call this method every time their internal state changes to up...
TaggedObject()
Constructor.
Index cache_priority_
The index indicating the cache priority for this TaggedObject.
Slight Variation of the Observer Design Pattern (Subject part).
Definition: IpObserver.hpp:129
TaggedObject class.
ReferencedObject class.
int Index
Type of all indices of vectors, matrices etc.
Definition: IpTypes.hpp:19
#define DBG_ASSERT(test)
Definition: IpDebug.hpp:38
static IPOPT_THREAD_LOCAL Tag unique_tag_
static data member that is incremented every time ANY TaggedObject changes.
unsigned int Tag
Type for the Tag values.
Tag tag_
The tag indicating the current state of the object.
bool HasChanged(const Tag comparison_tag) const
Users of TaggedObjects call this to check if the object HasChanged since they last updated their own ...
Tag GetTag() const
Users of TaggedObjects call this to update their own internal tags every time they perform the expens...
#define IPOPT_THREAD_LOCAL
virtual ~TaggedObject()
Destructor.