Ipopt
3.12.12
|
TaggedObject class. More...
#include <IpTaggedObject.hpp>
Public Types | |
typedef unsigned int | Tag |
Type for the Tag values. More... | |
Public Member Functions | |
TaggedObject () | |
Constructor. More... | |
virtual | ~TaggedObject () |
Destructor. More... | |
Tag | GetTag () const |
Users of TaggedObjects call this to update their own internal tags every time they perform the expensive operation. More... | |
bool | HasChanged (const Tag comparison_tag) const |
Users of TaggedObjects call this to check if the object HasChanged since they last updated their own internal tag. More... | |
![]() | |
ReferencedObject () | |
virtual | ~ReferencedObject () |
Index | ReferenceCount () const |
void | AddRef (const Referencer *referencer) const |
void | ReleaseRef (const Referencer *referencer) const |
![]() | |
Subject () | |
Default Constructor. More... | |
virtual | ~Subject () |
Default destructor. More... | |
void | AttachObserver (Observer::NotifyType notify_type, Observer *observer) const |
Attach the specified observer (i.e., begin recieving notifications). More... | |
void | DetachObserver (Observer::NotifyType notify_type, Observer *observer) const |
Detach the specified observer (i.e., no longer recieve notifications). More... | |
Protected Member Functions | |
void | ObjectChanged () |
Objects derived from TaggedObject MUST call this method every time their internal state changes to update the internal tag for comparison. More... | |
![]() | |
void | Notify (Observer::NotifyType notify_type) const |
Private Member Functions | |
Default Compiler Generated Methods (Hidden to avoid | |
implicit creation/calling). These methods are not implemented and we do not want the compiler to implement them for us, so we declare them private and do not define them. This ensures that they will not be implicitly created/called. | |
TaggedObject (const TaggedObject &) | |
Copy Constructor. More... | |
void | operator= (const TaggedObject &) |
Overloaded Equals Operator. More... | |
Private Attributes | |
Tag | tag_ |
The tag indicating the current state of the object. More... | |
Index | cache_priority_ |
The index indicating the cache priority for this TaggedObject. More... | |
Static Private Attributes | |
static IPOPT_THREAD_LOCAL Tag | unique_tag_ |
static data member that is incremented every time ANY TaggedObject changes. More... | |
TaggedObject class.
Often, certain calculations or operations are expensive, and it can be very inefficient to perform these calculations again if the input to the calculation has not changed since the result was last stored. This base class provides an efficient mechanism to update a tag, indicating that the object has changed. Users of a TaggedObject class, need their own Tag data member to keep track of the state of the TaggedObject, the last time they performed a calculation. A basic use case for users of a class inheriting from TaggedObject follows like this:
Before an expensive calculation, check if the TaggedObject has changed, passing in your own Tag, indicating the last time you used the object for the calculation. If it has changed, perform the calculation again, and store the result. If it has not changed, simply return the stored result.
Here is a simple example:
if (vector.HasChanged(my_vector_tag_)) { my_vector_tag_ = vector.GetTag(); result = PerformExpensiveCalculation(vector); return result; } else { return result; }
Objects derived from TaggedObject must indicate that they have changed to the base class using the protected member function ObjectChanged(). For example, a Vector class, inside its own set method, MUST call ObjectChanged() to update the internally stored tag for comparison.
Definition at line 76 of file IpTaggedObject.hpp.
typedef unsigned int Ipopt::TaggedObject::Tag |
Type for the Tag values.
Definition at line 80 of file IpTaggedObject.hpp.
|
inline |
Constructor.
Definition at line 83 of file IpTaggedObject.hpp.
|
inlinevirtual |
Destructor.
Definition at line 91 of file IpTaggedObject.hpp.
|
private |
Copy Constructor.
|
inline |
Users of TaggedObjects call this to update their own internal tags every time they perform the expensive operation.
Definition at line 98 of file IpTaggedObject.hpp.
|
inline |
Users of TaggedObjects call this to check if the object HasChanged since they last updated their own internal tag.
Definition at line 108 of file IpTaggedObject.hpp.
|
inlineprotected |
Objects derived from TaggedObject MUST call this method every time their internal state changes to update the internal tag for comparison.
Definition at line 117 of file IpTaggedObject.hpp.
|
private |
Overloaded Equals Operator.
|
staticprivate |
static data member that is incremented every time ANY TaggedObject changes.
This allows us to obtain a unique Tag when the object changes
Definition at line 145 of file IpTaggedObject.hpp.
|
private |
The tag indicating the current state of the object.
We use this to compare against the comparison_tag in the HasChanged method. This member is updated from the unique_tag_ every time the object changes.
Definition at line 152 of file IpTaggedObject.hpp.
|
private |
The index indicating the cache priority for this TaggedObject.
If a result that depended on this TaggedObject is cached, it will be cached with this priority
Definition at line 159 of file IpTaggedObject.hpp.