IterQuantityAccess<T> object and cache the iq_id for fast access later.
More...
#include <IterationPack_CastIQMember.hpp>
Inheritance diagram for IterationPack::CastIQMember< T >:
Public Member Functions | |
| CastIQMember (const std::string iq_name) | |
| Construct with the name of an iteration quantity. | |
| IterQuantityAccess< T > & | operator() (AlgorithmState &s) const |
| Get the iteration quantity from an AlgorithmState object. | |
| const IterQuantityAccess< T > & | operator() (const AlgorithmState &s) const |
| | |
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:
// ///////////////////////////////////////////////////////////////// // x_step_iter_quantity.h #include "IterationPack_CastIQMember.hpp" class x_step_iq_member : public CastIQMember<double> { public: x_step_iq_member() : CastIQMember<double>("x_step") {} }
// ///////////////////////////////////////////////////////////////// // MyStep1.h #include "x_step_iter_quantity.h" class MyStep1 : public AlgorithmStep { public: bool do_step( algo, ... ) { AlgorithmState &s = algo.state(); x_step_(s).set_k(0) = 5.0; } private: x_step_iq_member x_step_; }
// ///////////////////////////////////////////////////////////////// // MyStep2.h #include "x_step_iter_quantity.h" class MyStep2 : public AlgorithmStep { public: bool do_step( algo, ... ) { AlgorithmState &s = algo.state(); double x_step = x_step_(s).get_k(0); cout << "\nx_step = " << x_step << std::endl; } private: x_step_iq_member x_step_; }
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 141 of file IterationPack_CastIQMember.hpp.
|
||||||||||
|
Construct with the name of an iteration quantity.
Definition at line 165 of file IterationPack_CastIQMember.hpp. |
|
||||||||||
|
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 171 of file IterationPack_CastIQMember.hpp. |
|
||||||||||
|
Definition at line 185 of file IterationPack_CastIQMember.hpp. |
1.3.9.1