Toshihiro Shimizu 890ddd
#if !defined(UTILS_PARAM_TRAITS_HPP__)
Toshihiro Shimizu 890ddd
#define UTILS_PARAM_TRAITS_HPP__
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include <toonz_plugin.h></toonz_plugin.h>
Toshihiro Shimizu 890ddd
#include <toonz_hostif.h></toonz_hostif.h>
Toshihiro Shimizu 890ddd
#include <toonz_params.h></toonz_params.h>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/* helper-types to define toonz_param_*_t's table */
Toshihiro Shimizu 890ddd
struct param_desc_t : public toonz_param_desc_t {
Toshihiro Shimizu 890ddd
	param_desc_t(const char *k, const char *l, int ttag, const char *nt = "")
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		base = {{1, 0} /* type version */, TOONZ_PARAM_DESC_TYPE_PARAM, l};
Toshihiro Shimizu 890ddd
		key = k;
Toshihiro Shimizu 890ddd
		note = nt;
Toshihiro Shimizu 890ddd
		reserved_[0] = NULL; // must be zero
Toshihiro Shimizu 890ddd
		reserved_[1] = NULL;
Toshihiro Shimizu 890ddd
		traits_tag = ttag;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <typename t=""></typename>
Toshihiro Shimizu 890ddd
void init_param_traits_union(toonz_param_desc_t &t, const T &p){};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <typename t=""></typename>
Toshihiro Shimizu 890ddd
struct param_desc_holder_t {
Toshihiro Shimizu 890ddd
	typedef T realtype;
Toshihiro Shimizu 890ddd
	param_desc_t t;
Toshihiro Shimizu 890ddd
	param_desc_holder_t(const char *key, const char *label, const T &p, const char *note) : t{key, label, T::E, note} { init_param_traits_union<t>(t, p); }</t>
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <>
Toshihiro Shimizu 890ddd
void init_param_traits_union<toonz_param_traits_double_t>(toonz_param_desc_t &t, const toonz_param_traits_double_t &p) { t.traits.d = p; }</toonz_param_traits_double_t>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <>
Toshihiro Shimizu 890ddd
void init_param_traits_union<toonz_param_traits_int_t>(toonz_param_desc_t &t, const toonz_param_traits_int_t &p) { t.traits.i = p; }</toonz_param_traits_int_t>
Toshihiro Shimizu 890ddd
template <>
Toshihiro Shimizu 890ddd
void init_param_traits_union<toonz_param_traits_enum_t>(toonz_param_desc_t &t, const toonz_param_traits_enum_t &p) { t.traits.e = p; }</toonz_param_traits_enum_t>
Toshihiro Shimizu 890ddd
template <>
Toshihiro Shimizu 890ddd
void init_param_traits_union<toonz_param_traits_range_t>(toonz_param_desc_t &t, const toonz_param_traits_range_t &p) { t.traits.rd = p; }</toonz_param_traits_range_t>
Toshihiro Shimizu 890ddd
template <>
Toshihiro Shimizu 890ddd
void init_param_traits_union<toonz_param_traits_bool_t>(toonz_param_desc_t &t, const toonz_param_traits_bool_t &p) { t.traits.b = p; }</toonz_param_traits_bool_t>
Toshihiro Shimizu 890ddd
template <>
Toshihiro Shimizu 890ddd
void init_param_traits_union<toonz_param_traits_color_t>(toonz_param_desc_t &t, const toonz_param_traits_color_t &p) { t.traits.c = p; }</toonz_param_traits_color_t>
Toshihiro Shimizu 890ddd
template <>
Toshihiro Shimizu 890ddd
void init_param_traits_union<toonz_param_traits_point_t>(toonz_param_desc_t &t, const toonz_param_traits_point_t &p) { t.traits.p = p; }</toonz_param_traits_point_t>
Toshihiro Shimizu 890ddd
template <>
Toshihiro Shimizu 890ddd
void init_param_traits_union<toonz_param_traits_spectrum_t>(toonz_param_desc_t &t, const toonz_param_traits_spectrum_t &p) { t.traits.g = p; }</toonz_param_traits_spectrum_t>
Toshihiro Shimizu 890ddd
template <>
Toshihiro Shimizu 890ddd
void init_param_traits_union<toonz_param_traits_string_t>(toonz_param_desc_t &t, const toonz_param_traits_string_t &p) { t.traits.s = p; }</toonz_param_traits_string_t>
Toshihiro Shimizu 890ddd
template <>
Toshihiro Shimizu 890ddd
void init_param_traits_union<toonz_param_traits_tonecurve_t>(toonz_param_desc_t &t, const toonz_param_traits_tonecurve_t &p) { t.traits.t = p; }</toonz_param_traits_tonecurve_t>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
typedef param_desc_holder_t<toonz_param_traits_double_t> traits_double_t;</toonz_param_traits_double_t>
Toshihiro Shimizu 890ddd
typedef param_desc_holder_t<toonz_param_traits_int_t> traits_int_t;</toonz_param_traits_int_t>
Toshihiro Shimizu 890ddd
typedef param_desc_holder_t<toonz_param_traits_enum_t> traits_enum_t;</toonz_param_traits_enum_t>
Toshihiro Shimizu 890ddd
typedef param_desc_holder_t<toonz_param_traits_range_t> traits_range_t;</toonz_param_traits_range_t>
Toshihiro Shimizu 890ddd
typedef param_desc_holder_t<toonz_param_traits_bool_t> traits_bool_t;</toonz_param_traits_bool_t>
Toshihiro Shimizu 890ddd
typedef param_desc_holder_t<toonz_param_traits_color_t> traits_color_t;</toonz_param_traits_color_t>
Toshihiro Shimizu 890ddd
typedef param_desc_holder_t<toonz_param_traits_point_t> traits_point_t;</toonz_param_traits_point_t>
Toshihiro Shimizu 890ddd
typedef param_desc_holder_t<toonz_param_traits_spectrum_t> traits_spectrum_t;</toonz_param_traits_spectrum_t>
Toshihiro Shimizu 890ddd
typedef param_desc_holder_t<toonz_param_traits_string_t> traits_string_t;</toonz_param_traits_string_t>
Toshihiro Shimizu 890ddd
typedef param_desc_holder_t<toonz_param_traits_tonecurve_t> traits_tonecurve_t;</toonz_param_traits_tonecurve_t>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <typename t=""></typename>
Toshihiro Shimizu 890ddd
static param_desc_t param_desc_ctor(const char *key, const char *label, const typename T::realtype &p, const char *note = "")
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	param_desc_holder_t<typename t::realtype=""> t(key, label, p, note);</typename>
Toshihiro Shimizu 890ddd
	return t.t;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
static toonz_param_group_t param_group_ctor(const char *label, size_t n, toonz_param_desc_t *p)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return {{{1, 0}, TOONZ_PARAM_DESC_TYPE_GROUP, label}, static_cast<int>(n), p};</int>
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
static toonz_param_page_t param_page_ctor(const char *label, size_t n, toonz_param_group_t *g)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return {{{1, 0}, TOONZ_PARAM_DESC_TYPE_PAGE, label}, static_cast<int>(n), g};</int>
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif