1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
#ifndef LVOy9pHh2bcXzO1tZ5oxb80UXy8
#define LVOy9pHh2bcXzO1tZ5oxb80UXy8
#include <boost/mpl/if.hpp>
#include <boost/type_traits/is_same.hpp>
#include "property_instance.hpp"
#include "property_list.hpp"
#include "quant_types.hpp"
#include "template_helpers.hpp"
// worker template forward decl
template<typename Prop, typename CurrentProp, typename Data, typename QuantClass, bool isWrite>
struct PLA_Set_Impl;
// PLA template
template<typename Prop>
struct PLA_Set {
// action consts
typedef Void result_t;
template<typename ContextProp, bool _doWriteResult> struct local_state_t {
typedef ContextProp prop;
static const bool write = _doWriteResult;
};
// action parameters
typedef typename Prop::instance_ptr_t instance_t;
typedef typename boost::mpl::if_<boost::is_same<ContinuousPropertyClass, typename Prop::quant::class_t>,
Time,
FakeTime>::type time_t;
typedef typename Prop::type value_t;
instance_t instance;
time_t time;
value_t value;
result_t result;
inline PLA_Set(instance_t instance, value_t value)
: instance(instance), value(value) {
// ctor only allowed for discrete properties
BOOST_STATIC_ASSERT((boost::is_same<DiscretePropertyClass,
typename Prop::quant::class_t>::value));
}
inline PLA_Set(time_t time, instance_t instance, value_t value) : instance(instance), time(time), value(value) { }
// action methods
template<typename _PropComp, typename _ContextData, typename _LocalState>
inline void pre(_PropComp &pc, _ContextData &data, _LocalState &state) { }
template<typename PropComp, typename ContextData, typename LocalState>
inline void post(PropComp &pl, ContextData &data, LocalState &state) {
BOOST_MPL_ASSERT(( PL_Contains<PL<typename PropComp::properties_t>, Prop> ));
PLA_Set_Impl<Prop, typename LocalState::prop, ContextData, typename LocalState::prop::quant::class_t, LocalState::write>
::eval(data, instance, time, value);
}
};
// worker template implementation
// * do nothing at the wrong type
template<typename Prop, typename WrongProp, typename Data, typename QuantClass, bool isWrite>
struct PLA_Set_Impl {
static inline void eval(Data &data, typename PLA_Set<Prop>::instance_t instance, typename PLA_Set<Prop>::time_t time, typename Prop::type &value) { }
};
// * store pointer to the data structure at the correct type
template<typename Prop, typename Data, bool _isWrite>
struct PLA_Set_Impl<Prop, Prop, Data, ContinuousPropertyClass, _isWrite> {
static inline void eval(Data &data, typename PLA_Set<Prop>::instance_t instance, typename PLA_Set<Prop>::time_t time, typename Prop::type &value) {
data.data.set(time, instance(), value);
}
};
template<typename Prop, typename Data, bool _isWrite>
struct PLA_Set_Impl<Prop, Prop, Data, DiscretePropertyClass, _isWrite> {
static inline void eval(Data &data, typename PLA_Set<Prop>::instance_t instance, typename PLA_Set<Prop>::time_t time, typename Prop::type &value) {
data.data.set(instance(), value);
}
};
#endif // LVOy9pHh2bcXzO1tZ5oxb80UXy8
|