Ipopt 3.11.9
Loading...
Searching...
No Matches
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 2493 2014-05-31 19:08:59Z 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 */
21#ifndef IPOPT_THREAD_LOCAL
22
23#if defined(_MSC_VER)
24#define IPOPT_THREAD_LOCAL __declspec(thread)
25#elif defined(__APPLE__) && defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ < 405)
26#define IPOPT_THREAD_LOCAL
27#else
28#define IPOPT_THREAD_LOCAL __thread
29#endif
30
31#endif
32
33namespace Ipopt
34{
35
75 class TaggedObject : public ReferencedObject, public Subject
76 {
77 public:
79 typedef unsigned int Tag;
80
83 :
84 Subject()
85 {
87 }
88
90 virtual ~TaggedObject()
91 {}
92
97 Tag GetTag() const
98 {
99 return tag_;
100 }
101
107 bool HasChanged(const Tag comparison_tag) const
108 {
109 return (comparison_tag == tag_) ? false : true;
110 }
111 protected:
117 {
118 DBG_START_METH("TaggedObject::ObjectChanged()", 0);
120 unique_tag_++;
121 DBG_ASSERT(unique_tag_ < std::numeric_limits<Tag>::max());
122 // The Notify method from the Subject base class notifies all
123 // registered Observers that this subject has changed.
125 }
126 private:
135
139
145
152
159 };
160} // namespace Ipopt
161#endif
#define DBG_ASSERT(test)
Definition IpDebug.hpp:38
#define DBG_START_METH(__func_name, __verbose_level)
Definition IpDebug.hpp:49
#define IPOPT_THREAD_LOCAL
ReferencedObject class.
Slight Variation of the Observer Design Pattern (Subject part).
void Notify(Observer::NotifyType notify_type) const
TaggedObject class.
Tag GetTag() const
Users of TaggedObjects call this to update their own internal tags every time they perform the expens...
TaggedObject(const TaggedObject &)
Copy Constructor.
void ObjectChanged()
Objects derived from TaggedObject MUST call this method every time their internal state changes to up...
bool HasChanged(const Tag comparison_tag) const
Users of TaggedObjects call this to check if the object HasChanged since they last updated their own ...
unsigned int Tag
Type for the Tag values.
Tag tag_
The tag indicating the current state of the object.
TaggedObject()
Constructor.
void operator=(const TaggedObject &)
Overloaded Equals Operator.
Index cache_priority_
The index indicating the cache priority for this TaggedObject.
static IPOPT_THREAD_LOCAL Tag unique_tag_
static data member that is incremented every time ANY TaggedObject changes.
virtual ~TaggedObject()
Destructor.
int Index
Type of all indices of vectors, matrices etc.
Definition IpTypes.hpp:19