IterationPack: General framework for building iterative algorithms
Version of the Day
|
Template class to be used to lookup an interation quantity, cast it to an IterQuantityAccess<T>
object and cache the iq_id
for fast access later.
More...
#include <IterationPack_CastIQMember.hpp>
Public Member Functions | |
CastIQMember (const std::string iq_name) | |
Construct with the name of an iteration quantity. More... | |
IterQuantityAccess< T > & | operator() (AlgorithmState &s) const |
Get the iteration quantity from an AlgorithmState object. More... | |
const IterQuantityAccess< T > & | operator() (const AlgorithmState &s) const |
Public Member Functions inherited from IterationPack::CastIQMemberBase | |
const std::string & | iq_name () const |
Name returns the name of the iteration quantity. More... | |
bool | exists_in (const AlgorithmState &s) const |
Returns if the iteration quantity exists in the state object. More... | |
Additional Inherited Members | |
Protected Member Functions inherited from IterationPack::CastIQMemberBase | |
CastIQMemberBase (const std::string iq_name) | |
void | cache_iq_id (const AlgorithmState &s) const |
void | throw_cast_error (const AlgorithmState::iq_id_type iq_id, const std::string &iqa_name) const |
Protected Attributes inherited from IterationPack::CastIQMemberBase | |
const std::string | iq_name_ |
AlgorithmState::iq_id_type | iq_id_ |
Template class to be used to lookup an interation quantity, cast it to an IterQuantityAccess<T>
object and cache the iq_id
for fast access later.
The idea is that a Step class can create a data member of this type and then access and interation quantity and have the iq_id
looked up the first time.
The best way to use this class to access an iteration quantity is for a header file to be created for the iteration quantity (or several iteration quantities) that contains a new class. For example, suppose we have an double
object that we want to add as an iteration quantity with the name "x_step". For this we might create an header file like:
Now lets suppose we have two step classes that need to access this iteration quantity. These step classes would each include a data member of this new class. For example, these step classes might be implemented as:
In the above example, an O(s.num_iter_quantities())
search for the iq_id
would only be performed the first time x_step_(s)
was called by each step object. In later iterations, the cached iq_id
would be used to access the iteration quantity and the only price one would pay above a few O(1) function calls in is an O(1) dynamic cast.
The default constructor is not allowed by the default copy constructors and assignment operators are allowed since they have the correct semantics.
Definition at line 154 of file IterationPack_CastIQMember.hpp.
IterationPack::CastIQMember< T >::CastIQMember | ( | const std::string | iq_name | ) |
Construct with the name of an iteration quantity.
Definition at line 178 of file IterationPack_CastIQMember.hpp.
IterQuantityAccess< T > & IterationPack::CastIQMember< T >::operator() | ( | AlgorithmState & | s | ) | const |
Get the iteration quantity from an AlgorithmState object.
If the iteration quantity of the name iq_namt does not exist then a AlgorithmState::DoesNotExist exception will be thrown. If the type of the iteration quantity is not of the type IterQuantityAcess<T> (as determined by dynamic_cast<T>) then the exception InvalidTypeCastException: will be thrown with a helpful error message.
Definition at line 184 of file IterationPack_CastIQMember.hpp.
const IterQuantityAccess< T > & IterationPack::CastIQMember< T >::operator() | ( | const AlgorithmState & | s | ) | const |
Definition at line 198 of file IterationPack_CastIQMember.hpp.