|
@@ -24,6 +24,8 @@
|
|
|
#define __ARTIS_KERNEL_STATES_HPP
|
|
|
|
|
|
#include <artis/kernel/State.hpp>
|
|
|
+#include <artis/kernel/Value.hpp>
|
|
|
+
|
|
|
#include <vector>
|
|
|
|
|
|
namespace artis { namespace kernel {
|
|
@@ -38,80 +40,80 @@ public:
|
|
|
virtual ~States()
|
|
|
{ }
|
|
|
|
|
|
- virtual void restore(const State < U >& state)
|
|
|
- {
|
|
|
- unsigned int index = 0;
|
|
|
-
|
|
|
- for (typename std::vector < bool T::* >::iterator it =
|
|
|
- statesB.begin(); it != statesB.end(); ++it) {
|
|
|
- state.get_state(index, *it);
|
|
|
- ++index;
|
|
|
- }
|
|
|
- index = 0;
|
|
|
- for (typename std::vector < int T::* >::iterator it =
|
|
|
- statesI.begin(); it != statesI.end(); ++it) {
|
|
|
- state.get_state(index, *it);
|
|
|
- ++index;
|
|
|
- }
|
|
|
- index = 0;
|
|
|
- for (typename std::vector < double T::* >::iterator it =
|
|
|
- statesD.begin(); it != statesD.end(); ++it) {
|
|
|
- state.get_state(index, *it);
|
|
|
- ++index;
|
|
|
- }
|
|
|
- }
|
|
|
+ const Any& get(unsigned int index) const
|
|
|
+ { return states.at(index); }
|
|
|
|
|
|
- virtual void save(State < U >& state) const
|
|
|
+ template < typename V >
|
|
|
+ void S(std::initializer_list < std::pair < unsigned int,
|
|
|
+ V T::* > > list)
|
|
|
{
|
|
|
- unsigned int index = 0;
|
|
|
-
|
|
|
- for (typename std::vector < bool T::* >::const_iterator it =
|
|
|
- statesB.begin(); it != statesB.end(); ++it) {
|
|
|
- state.add_state(index, *it);
|
|
|
- ++index;
|
|
|
- }
|
|
|
- index = 0;
|
|
|
- for (typename std::vector < int T::* >::const_iterator it =
|
|
|
- statesI.begin(); it != statesI.end(); ++it) {
|
|
|
- state.add_state(index, *it);
|
|
|
- ++index;
|
|
|
- }
|
|
|
- index = 0;
|
|
|
- for (typename std::vector < double T::* >::const_iterator it =
|
|
|
- statesD.begin(); it != statesD.end(); ++it) {
|
|
|
- state.add_state(index, *it);
|
|
|
- ++index;
|
|
|
+ for (typename std::initializer_list < std::pair < unsigned int,
|
|
|
+ V T::* > >::iterator it = list.begin(); it != list.end();
|
|
|
+ ++it) {
|
|
|
+ if (states.size() <= it->first) {
|
|
|
+ states.resize(it->first + 1);
|
|
|
+ }
|
|
|
+ states[it->first] = it->second;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- void stateB(unsigned int index, bool T::* var)
|
|
|
+ virtual void restore(const State < U >& /* state */)
|
|
|
{
|
|
|
- if (statesB.size() <= index) {
|
|
|
- statesB.resize(index + 1);
|
|
|
- }
|
|
|
- statesB[index] = var;
|
|
|
+ // unsigned int index = 0;
|
|
|
+
|
|
|
+ // for (typename std::vector < bool T::* >::iterator it =
|
|
|
+ // statesB.begin(); it != statesB.end(); ++it) {
|
|
|
+ // state.get_state(index, *it);
|
|
|
+ // ++index;
|
|
|
+ // }
|
|
|
+ // index = 0;
|
|
|
+ // for (typename std::vector < int T::* >::iterator it =
|
|
|
+ // statesI.begin(); it != statesI.end(); ++it) {
|
|
|
+ // state.get_state(index, *it);
|
|
|
+ // ++index;
|
|
|
+ // }
|
|
|
+ // index = 0;
|
|
|
+ // for (typename std::vector < double T::* >::iterator it =
|
|
|
+ // statesD.begin(); it != statesD.end(); ++it) {
|
|
|
+ // state.get_state(index, *it);
|
|
|
+ // ++index;
|
|
|
+ // }
|
|
|
}
|
|
|
|
|
|
- void stateI(unsigned int index, int T::* var)
|
|
|
+ virtual void save(State < U >& /* state */) const
|
|
|
{
|
|
|
- if (statesI.size() <= index) {
|
|
|
- statesI.resize(index + 1);
|
|
|
- }
|
|
|
- statesI[index] = var;
|
|
|
+ // unsigned int index = 0;
|
|
|
+
|
|
|
+ // for (typename std::vector < bool T::* >::const_iterator it =
|
|
|
+ // statesB.begin(); it != statesB.end(); ++it) {
|
|
|
+ // state.add_state(index, *it);
|
|
|
+ // ++index;
|
|
|
+ // }
|
|
|
+ // index = 0;
|
|
|
+ // for (typename std::vector < int T::* >::const_iterator it =
|
|
|
+ // statesI.begin(); it != statesI.end(); ++it) {
|
|
|
+ // state.add_state(index, *it);
|
|
|
+ // ++index;
|
|
|
+ // }
|
|
|
+ // index = 0;
|
|
|
+ // for (typename std::vector < double T::* >::const_iterator it =
|
|
|
+ // statesD.begin(); it != statesD.end(); ++it) {
|
|
|
+ // state.add_state(index, *it);
|
|
|
+ // ++index;
|
|
|
+ // }
|
|
|
}
|
|
|
|
|
|
- void state(unsigned int index, double T::* var)
|
|
|
+ template < typename V >
|
|
|
+ void state(unsigned int index, V T::* var)
|
|
|
{
|
|
|
- if (statesD.size() <= index) {
|
|
|
- statesD.resize(index + 1);
|
|
|
+ if (states.size() <= index) {
|
|
|
+ states.resize(index + 1);
|
|
|
}
|
|
|
- statesD[index] = var;
|
|
|
+ states[index] = Any(var);
|
|
|
}
|
|
|
|
|
|
-protected:
|
|
|
- std::vector < bool T::* > statesB;
|
|
|
- std::vector < int T::* > statesI;
|
|
|
- std::vector < double T::* > statesD;
|
|
|
+private:
|
|
|
+ std::vector < Any > states;
|
|
|
};
|
|
|
|
|
|
} }
|