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 1861 2010-12-21 21:34:47Z andreasw $
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 namespace Ipopt
19 {
20 
63  class TaggedObject : public ReferencedObject, public Subject
64  {
65  public:
67  typedef unsigned int Tag;
68 
71  :
72  Subject()
73  {
74  ObjectChanged();
75  }
76 
78  virtual ~TaggedObject()
79  {}
80 
85  Tag GetTag() const
86  {
87  return tag_;
88  }
89 
95  bool HasChanged(const Tag comparison_tag) const
96  {
97  return (comparison_tag == tag_) ? false : true;
98  }
99  protected:
105  {
106  DBG_START_METH("TaggedObject::ObjectChanged()", 0);
107  tag_ = unique_tag_;
108  unique_tag_++;
109  DBG_ASSERT(unique_tag_ < std::numeric_limits<Tag>::max());
110  // The Notify method from the Subject base class notifies all
111  // registed Observers that this subject has changed.
113  }
114  private:
122  TaggedObject(const TaggedObject&);
123 
125  void operator=(const TaggedObject&);
127 
132  static Tag unique_tag_;
133 
140 
147  };
148 } // namespace Ipopt
149 #endif