summaryrefslogtreecommitdiff
path: root/core/pla_set.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/pla_set.hpp')
-rw-r--r--core/pla_set.hpp79
1 files changed, 79 insertions, 0 deletions
diff --git a/core/pla_set.hpp b/core/pla_set.hpp
new file mode 100644
index 0000000..1c99cc9
--- /dev/null
+++ b/core/pla_set.hpp
@@ -0,0 +1,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
contact: Jan Huwald // Impressum