summaryrefslogtreecommitdiff
path: root/core/pla_get.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/pla_get.hpp')
-rw-r--r--core/pla_get.hpp92
1 files changed, 92 insertions, 0 deletions
diff --git a/core/pla_get.hpp b/core/pla_get.hpp
new file mode 100644
index 0000000..ba7d2a0
--- /dev/null
+++ b/core/pla_get.hpp
@@ -0,0 +1,92 @@
+#ifndef j9bZiR9W7dKz17gTUOtW1xODHdA
+#define j9bZiR9W7dKz17gTUOtW1xODHdA
+
+#include <boost/mpl/if.hpp>
+#include <boost/type_traits/is_same.hpp>
+
+#include "context.hpp"
+#include "continuous_property.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>
+struct PLA_Get_Impl;
+
+// PLA template
+template<typename Prop, typename Context = SingleContext<typename Prop::quant>>
+struct PLA_Get {
+ // action consts
+ typedef typename Prop::type result_t;
+ template<typename ContextProp, bool _doWriteResult> struct local_state_t {
+ typedef ContextProp prop;
+ };
+
+ // 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,
+ Void>::type time_t;
+ Context ctx;
+ time_t time;
+ result_t result;
+
+ PLA_Get(time_t time, Context ctx) : ctx(ctx), time(time) {}
+ PLA_Get(Context ctx) : ctx(ctx) {
+ BOOST_STATIC_ASSERT((boost::is_same<time_t, Void>::value));
+ }
+
+ // action methods
+ template<typename _PropComp, typename _ContextData, typename _LocalState>
+ inline void pre(_PropComp &pc, _ContextData &data, _LocalState &state) { }
+
+
+ template<typename PC, typename ContextData, typename LocalState>
+ inline void post(PC &pc, ContextData &data, LocalState &state) {
+ BOOST_MPL_ASSERT(( PL_Contains<PL<typename PC::properties_t>, Prop> ));
+ PLA_Get_Impl<Prop, typename LocalState::prop, ContextData, typename LocalState::prop::quant::class_t>
+ ::eval(pc, data, ctx, time, result);
+ }
+};
+
+// worker template implementation
+// * do nothing at the wrong type
+template<typename Prop, typename WrongProp, typename Data, typename QuantClass>
+struct PLA_Get_Impl {
+ template<typename PC, typename Context = SingleContext<typename Prop::quant>>
+ static inline void eval(PC &, Data &, Context,
+ typename PLA_Get<Prop>::time_t, typename Prop::type &) { }
+};
+
+// * store pointer to the data structure at the correct type
+template<typename Prop, typename Data>
+struct PLA_Get_Impl<Prop, Prop, Data, ContinuousPropertyClass> {
+ template<typename PC, typename Context = SingleContext<typename Prop::quant>>
+ static inline void eval(PC &pc, Data &data, Context ctx,
+ typename PLA_Get<Prop>::time_t time,
+ typename Prop::type &fold_state) {
+ Time oldTime = data.data.getTime(time, ctx.template getptr<typename Prop::quant>()());
+ assert(oldTime <= time); // we can not jump backward
+ if (oldTime < time) {
+ Time dt = time - oldTime;
+ fold_state = ContinuousProperty_Evolve<PC, Prop, typename Prop::quant, Context>
+ ::eval(pc, ctx, oldTime, dt);
+ }else{
+ fold_state = data.data.getValue(time, ctx.template getptr<typename Prop::quant>()());
+ }
+ }
+};
+
+template<typename Prop, typename Data>
+struct PLA_Get_Impl<Prop, Prop, Data, DiscretePropertyClass> {
+ template<typename PC, typename Context = SingleContext<typename Prop::quant>>
+ static inline void eval(PC &, Data &data, Context ctx,
+ typename PLA_Get<Prop>::time_t,
+ typename Prop::type &fold_state) {
+ fold_state = data.data(ctx.template getptr<typename Prop::quant>()());
+ }
+};
+
+#endif // j9bZiR9W7dKz17gTUOtW1xODHdA
contact: Jan Huwald // Impressum