Ipopt  3.11.7
 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 2276 2013-05-05 12:33:44Z 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 #include <utility> // for std::pair
18 
19 namespace Ipopt
20 {
21 
61  class TaggedObject : public ReferencedObject, public Subject
62  {
63  public:
70  typedef std::pair<const TaggedObject*, unsigned int> Tag;
71 
74  :
75  Subject(),
76  /* We can initialize the tag counter to 0, because this objects Tag
77  * will differ from a Tag() object in its first member. */
78  tagcount_(0)
79  {
80  ObjectChanged();
81  }
82 
84  virtual ~TaggedObject()
85  {}
86 
91  Tag GetTag() const
92  {
93  return Tag(this, tagcount_);
94  }
95 
101  bool HasChanged(const Tag comparison_tag) const
102  {
103  return (comparison_tag.first != this) || (comparison_tag.second != tagcount_);
104  }
105  protected:
111  {
112  DBG_START_METH("TaggedObject::ObjectChanged()", 0);
113  tagcount_++;
114  DBG_ASSERT(tagcount_ < std::numeric_limits<Tag::second_type>::max());
115  // The Notify method from the Subject base class notifies all
116  // registered Observers that this subject has changed.
118  }
119  private:
127  TaggedObject(const TaggedObject&);
128 
130  void operator=(const TaggedObject&);
132 
138  Tag::second_type tagcount_;
139 
146  };
147 
152  inline
154  {
155  return TaggedObject::Tag(tag1.first, tag1.second + tag2.second);
156  }
157 
158 } // namespace Ipopt
159 #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
Tag::second_type tagcount_
The tag indicating the current state of the object.
std::pair< const TaggedObject *, unsigned int > Tag
Type for the Tag values.
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...
virtual ~TaggedObject()
Destructor.
TaggedObject::Tag operator+(const TaggedObject::Tag &tag1, const TaggedObject::Tag &tag2)
The addition of two tags - do not use.