# 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 2276 2013-05-05 12:33:44Z 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 #include <utility> // for std::pair
    00018
    00019 namespace Ipopt
    00020 {
    00021
    00061   class TaggedObject : public ReferencedObject, public Subject
    00062   {
    00063   public:
    00070     typedef std::pair<const TaggedObject*, unsigned int> Tag;
    00071
    00073     TaggedObject()
    00074         :
    00075         Subject(),
    00076         /* We can initialize the tag counter to 0, because this objects Tag
    00077          * will differ from a Tag() object in its first member. */
    00078         tagcount_(0)
    00079     {
    00080       ObjectChanged();
    00081     }
    00082
    00084     virtual ~TaggedObject()
    00085     {}
    00086
    00091     Tag GetTag() const
    00092     {
    00093       return Tag(this, tagcount_);
    00094     }
    00095
    00101     bool HasChanged(const Tag comparison_tag) const
    00102     {
    00103       return (comparison_tag.first != this) || (comparison_tag.second != tagcount_);
    00104     }
    00105   protected:
    00110     void ObjectChanged()
    00111     {
    00112       DBG_START_METH("TaggedObject::ObjectChanged()", 0);
    00113       tagcount_++;
    00114       DBG_ASSERT(tagcount_ < std::numeric_limits<Tag::second_type>::max());
    00115       // The Notify method from the Subject base class notifies all
    00116       // registered Observers that this subject has changed.
    00117       Notify(Observer::NT_Changed);
    00118     }
    00119   private:
    00127     TaggedObject(const TaggedObject&);
    00128
    00130     void operator=(const TaggedObject&);
    00132
    00138     Tag::second_type tagcount_;
    00139
    00145     Index cache_priority_;
    00146   };
    00147
    00152   inline
    00153   TaggedObject::Tag operator+(const TaggedObject::Tag& tag1, const TaggedObject::Tag& tag2)
    00154   {
    00155     return TaggedObject::Tag(tag1.first, tag1.second + tag2.second);
    00156   }
    00157
    00158 } // namespace Ipopt
    00159 #endif

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines