aboutsummaryrefslogtreecommitdiffstats
path: root/common/pywrappers.h
diff options
context:
space:
mode:
authorDavid Shah <davey1576@gmail.com>2018-07-02 14:14:08 +0200
committerDavid Shah <davey1576@gmail.com>2018-07-02 14:14:08 +0200
commitfe1ad5b086c46b82aa72cb0f9625ebdf941e50f9 (patch)
tree2e1708a12a0700aa2b9653140aff215dd8677738 /common/pywrappers.h
parentcd2028434766e10feca55afec8a2508ff6a86e43 (diff)
downloadnextpnr-fe1ad5b086c46b82aa72cb0f9625ebdf941e50f9.tar.gz
nextpnr-fe1ad5b086c46b82aa72cb0f9625ebdf941e50f9.tar.bz2
nextpnr-fe1ad5b086c46b82aa72cb0f9625ebdf941e50f9.zip
python: Tweaking how the new wrappers will work
Signed-off-by: David Shah <davey1576@gmail.com>
Diffstat (limited to 'common/pywrappers.h')
-rw-r--r--common/pywrappers.h45
1 files changed, 32 insertions, 13 deletions
diff --git a/common/pywrappers.h b/common/pywrappers.h
index e4391b21..2c91f26f 100644
--- a/common/pywrappers.h
+++ b/common/pywrappers.h
@@ -47,38 +47,57 @@ template <typename T> struct ContextualWrapper
typedef T base_type;
};
+template <typename T> ContextualWrapper<T> wrap_ctx(Context *ctx, T x) { return ContextualWrapper<T>(ctx, x); }
+
+// Dummy class, to be implemented by users
+template <typename T> class string_converter;
+
// Action options
-class do_nothing
+template <typename T> class do_nothing
{
- template <typename T> T operator()(Context *ctx, T x) { return x; }
+ T operator()(Context *ctx, T x) { return x; }
- template <typename T> using ret_type = T;
- template <typename T> using arg_type = T;
+ using ret_type = T;
+ using arg_type = T;
};
-class wrap_context
+template <typename T> class wrap_context
{
- template <typename T> ContextualWrapper<T> operator()(Context *ctx, T x) { return ContextualWrapper<T>(ctx, x); }
+ ContextualWrapper<T> operator()(Context *ctx, T x) { return ContextualWrapper<T>(ctx, x); }
+ using arg_type = T;
+ using ret_type = ContextualWrapper<T>;
+};
- template <typename T> using ret_type = ContextualWrapper<T>;
+template <typename T> class unwrap_context
+{
+ T operator()(Context *ctx, ContextualWrapper<T> x) { return x.base; }
+ using ret_type = T;
+ using arg_type = ContextualWrapper<T>;
};
-class unwrap_context
+template <typename T> class conv_from_string
{
- template <typename T> T operator()(Context *ctx, ContextualWrapper<T> x) { return x.base; }
+ T operator()(Context *ctx, std::string x) { return string_converter<T>().from_str(ctx, x); }
+ using ret_type = T;
+ using arg_type = std::string;
+};
- template <typename T> using arg_type = ContextualWrapper<T>;
+template <typename T> class conv_to_string
+{
+ std::string operator()(Context *ctx, T x) { return string_converter<T>().to_str(ctx, x); }
+ using ret_type = std::string;
+ using arg_type = T;
};
// Function wrapper
// Example: one parameter, one return
template <typename Class, typename FuncT, FuncT fn, typename rv_conv, typename arg1_conv> struct function_wrapper
{
- using result_type = typename boost::function_types::result_type<FuncT>::type;
- using arg1_type = typename boost::mpl::at_c<boost::function_types::parameter_types<FuncT>, 1>::type;
using class_type = ContextualWrapper<Class>;
+ using conv_result_type = typename rv_conv::ret_type;
+ using conv_arg1_type = typename arg1_conv::arg_type;
- static typename rv_conv::ret_type wrapped_fn(class_type &cls, typename arg1_conv::arg_type arg1)
+ static conv_result_type wrapped_fn(class_type &cls, conv_arg1_type arg1)
{
return rv_conv()(cls.ctx, cls.base.*fn(arg1_conv()(cls.ctx, arg1)));
}