|
@@ -26,11 +26,55 @@
|
|
|
#include <artis/context/Value.hpp>
|
|
|
|
|
|
#include <string>
|
|
|
+#include <tuple>
|
|
|
+#include <utility>
|
|
|
#include <vector>
|
|
|
|
|
|
+#include <iostream>
|
|
|
+
|
|
|
namespace artis { namespace kernel {
|
|
|
|
|
|
-enum ValueType { DOUBLE, INT, BOOL };
|
|
|
+enum ValueTypeID { DOUBLE, INT, BOOL, DOUBLE_VECTOR, INT_VECTOR, BOOL_VECTOR,
|
|
|
+ STRING, USER };
|
|
|
+
|
|
|
+// template < typename H, typename T >
|
|
|
+// struct typelist
|
|
|
+// {
|
|
|
+// typedef H head;
|
|
|
+// typedef T tail;
|
|
|
+// };
|
|
|
+
|
|
|
+// struct null_typelist
|
|
|
+// { };
|
|
|
+
|
|
|
+// template < typename Fun >
|
|
|
+// struct cons;
|
|
|
+
|
|
|
+// template < typename T1 >
|
|
|
+// struct cons < void (*)(T1)>
|
|
|
+// {
|
|
|
+// typedef typelist < T1, null_typelist > type;
|
|
|
+
|
|
|
+// };
|
|
|
+
|
|
|
+// template < typename T1, typename T2 >
|
|
|
+// struct cons < void (*)(T1, T2)>
|
|
|
+// {
|
|
|
+// typedef typelist < T1, typelist < T2, null_typelist > > type;
|
|
|
+
|
|
|
+// };
|
|
|
+
|
|
|
+// template < typename T1, typename T2, typename T3 >
|
|
|
+// struct cons < void (*)(T1, T2, T3)>
|
|
|
+// {
|
|
|
+// typedef typelist < T1, typelist < T2, typelist < T3,
|
|
|
+// null_typelist > > > type;
|
|
|
+
|
|
|
+// };
|
|
|
+
|
|
|
+// #define TYPELIST(a) cons < void (*)a >::type
|
|
|
+
|
|
|
+// typedef TYPELIST((double, int, bool)) value_types;
|
|
|
|
|
|
class Any
|
|
|
{
|
|
@@ -54,6 +98,9 @@ private:
|
|
|
|
|
|
base* ptr_;
|
|
|
|
|
|
+ template < typename V >
|
|
|
+ friend struct ValueType;
|
|
|
+
|
|
|
public:
|
|
|
Any() : ptr_(nullptr)
|
|
|
{ }
|
|
@@ -92,32 +139,32 @@ public:
|
|
|
template < typename T >
|
|
|
void restore(T* o, const context::Value& value)
|
|
|
{
|
|
|
- if (value.is_double()) {
|
|
|
+ if (value.is_type < double >()) {
|
|
|
double v;
|
|
|
|
|
|
value.get_content(v);
|
|
|
put(o, v);
|
|
|
- } else if (value.is_int()) {
|
|
|
+ } else if (value.is_type < int >()) {
|
|
|
int v;
|
|
|
|
|
|
value.get_content(v);
|
|
|
put(o, v);
|
|
|
- } else if (value.is_bool()) {
|
|
|
+ } else if (value.is_type < bool >()) {
|
|
|
bool v;
|
|
|
|
|
|
value.get_content(v);
|
|
|
put(o, v);
|
|
|
- } else if (value.is_double_vector()) {
|
|
|
+ } else if (value.is_type < std::vector < double > >()) {
|
|
|
std::vector < double > v;
|
|
|
|
|
|
value.get_content(v);
|
|
|
put(o, v);
|
|
|
- } else if (value.is_int_vector()) {
|
|
|
+ } else if (value.is_type < std::vector < int > >()) {
|
|
|
std::vector < int > v;
|
|
|
|
|
|
value.get_content(v);
|
|
|
put(o, v);
|
|
|
- } else if (value.is_bool_vector()) {
|
|
|
+ } else if (value.is_type < std::vector < bool > >()) {
|
|
|
std::vector < bool > v;
|
|
|
|
|
|
value.get_content(v);
|
|
@@ -236,6 +283,89 @@ public:
|
|
|
}
|
|
|
};
|
|
|
|
|
|
+// template < typename C,
|
|
|
+// typename T,
|
|
|
+// typename Seq = std::make_integer_sequence
|
|
|
+// < int, std::tuple_size < T >::value > >
|
|
|
+// struct TupleIterator;
|
|
|
+
|
|
|
+// template < typename C,
|
|
|
+// typename T,
|
|
|
+// int... S >
|
|
|
+// struct TupleIterator < C, T, std::integer_sequence < int, S... > >
|
|
|
+// {
|
|
|
+// TupleIterator(C caller, const T& val)
|
|
|
+// { result = std::make_tuple(caller(std::get < S >(val))...); }
|
|
|
+
|
|
|
+// std::tuple < context::Value, context::Value, context::Value > result;
|
|
|
+// };
|
|
|
+
|
|
|
+// template < typename C, typename T >
|
|
|
+// TupleIterator < C, T > tuple_iterator(C caller, const T& val)
|
|
|
+// {
|
|
|
+// return TupleIterator < C, T >(caller, val);
|
|
|
+// }
|
|
|
+
|
|
|
+// template < typename T >
|
|
|
+// struct ToValueCaller
|
|
|
+// {
|
|
|
+// ToValueCaller(const Any& any, const T* o) : _any(any), _object(o)
|
|
|
+// { }
|
|
|
+
|
|
|
+// template < typename Z >
|
|
|
+// context::Value operator()(const Z& data) const
|
|
|
+// { return data.to_value(_any, _object); }
|
|
|
+
|
|
|
+// const Any& _any;
|
|
|
+// const T* _object;
|
|
|
+// };
|
|
|
+
|
|
|
+// template < typename V >
|
|
|
+// struct ValueType
|
|
|
+// {
|
|
|
+// template < typename T >
|
|
|
+// context::Value to_value(const Any& any, const T* o) const
|
|
|
+// {
|
|
|
+// Any::data < T, V >* q = dynamic_cast < Any::data < T, V >* >(any.ptr_);
|
|
|
+
|
|
|
+// if (q) {
|
|
|
+// return context::Value(o->*(q->value_));
|
|
|
+// } else {
|
|
|
+// return context::Value();
|
|
|
+// }
|
|
|
+// }
|
|
|
+// };
|
|
|
+
|
|
|
+// template < typename Tuple, typename F, size_t... Is >
|
|
|
+// constexpr auto apply_impl(Tuple t, F f, std::index_sequence < Is... >)
|
|
|
+// { return f(std::get < Is >(t)...); }
|
|
|
+
|
|
|
+// template < typename Tuple, typename F >
|
|
|
+// constexpr auto apply(Tuple t, F f)
|
|
|
+// { return apply_impl(t, f, std::make_index_sequence <
|
|
|
+// std::tuple_size < Tuple >{}>{}); }
|
|
|
+
|
|
|
+// struct find_not_null_value
|
|
|
+// {
|
|
|
+// context::Value operator()(const context::Value& left,
|
|
|
+// const context::Value& right) const;
|
|
|
+// };
|
|
|
+
|
|
|
+// template < typename T >
|
|
|
+// static context::Value to_value(const Any& any, const T* o)
|
|
|
+// {
|
|
|
+// auto value_types =
|
|
|
+// std::make_tuple(ValueType < double >(),
|
|
|
+// ValueType < int >(),
|
|
|
+// ValueType < bool >());
|
|
|
+// auto list = tuple_iterator(ToValueCaller < T >(any, o), value_types);
|
|
|
+// auto result = apply(list.result, find_not_null_value{});
|
|
|
+
|
|
|
+// std::cout << result.to_string() << std::endl;
|
|
|
+
|
|
|
+// assert(false);
|
|
|
+// }
|
|
|
+
|
|
|
} }
|
|
|
|
|
|
#endif
|