1 #ifndef CommonTools_Utils_AnyMethodArgument_h
2 #define CommonTools_Utils_AnyMethodArgument_h
4 #include "Reflex/Object.h"
5 #include "Reflex/Member.h"
12 #include <boost/variant.hpp>
13 #include <boost/type_traits/is_same.hpp>
14 #include <boost/type_traits/is_integral.hpp>
15 #include <boost/type_traits/is_floating_point.hpp>
16 #include <boost/utility/enable_if.hpp>
17 #include <boost/mpl/if.hpp>
37 typedef boost::mpl::if_<matches_another_integral_type<unsigned long>,
38 boost::variant<int8_t, uint8_t,
44 boost::variant<int8_t, uint8_t,
56 template<
typename From,
typename To>
57 std::pair<AnyMethodArgument, int>
retOk_(
const From &
f,
int cast)
const {
58 return std::pair<AnyMethodArgument,int>(
AnyMethodArgument(static_cast<To>(f)), cast);
62 std::pair<AnyMethodArgument,int>
doInt(
int t)
const {
63 if (
type_ ==
typeid(int8_t)) {
return retOk_<int,int8_t> (
t,0); }
64 if (
type_ ==
typeid(uint8_t)) {
return retOk_<int,uint8_t> (
t,0); }
65 if (
type_ ==
typeid(int16_t)) {
return retOk_<int,int16_t> (
t,0); }
66 if (
type_ ==
typeid(uint16_t)) {
return retOk_<int,uint16_t>(
t,0); }
67 if (
type_ ==
typeid(int32_t)) {
return retOk_<int,int32_t> (
t,0); }
68 if (
type_ ==
typeid(uint32_t)) {
return retOk_<int,uint32_t>(
t,0); }
69 if (
type_ ==
typeid(int64_t)) {
return retOk_<int,int64_t> (
t,0); }
70 if (
type_ ==
typeid(
uint64_t)) {
return retOk_<int,uint64_t>(
t,0); }
71 if (
type_ ==
typeid(
unsigned long)) {
return retOk_<int,unsigned long> (
t,0); }
72 if (
type_ ==
typeid(
double)) {
return retOk_<int,double> (
t,1); }
73 if (
type_ ==
typeid(
float)) {
return retOk_<int,float> (
t,1); }
74 return std::pair<AnyMethodArgument,int>(
t,-1);
79 type_(type.Name() ==
"string" ? typeid(std::string) : type.TypeInfo())
95 typename boost::enable_if<boost::is_integral<I>, std::pair<AnyMethodArgument,int> >
::type
99 typename boost::enable_if<boost::is_floating_point<F>, std::pair<AnyMethodArgument,int> >
::type
101 if (
type_ ==
typeid(
double)) {
return retOk_<F,double>(
t,0); }
102 if (
type_ ==
typeid(
float)) {
return retOk_<F,float> (
t,0); }
103 return std::pair<AnyMethodArgument,int>(
t,-1);
106 std::pair<AnyMethodArgument,int>
operator()(
const std::string &
t)
const {
107 if (
type_ ==
typeid(std::string)) {
return std::pair<AnyMethodArgument,int>(
t,0); }
110 throw parser::Exception(t.c_str()) <<
"Enumerator '" <<
rflxType_.Name() <<
"' has no keys.\nPerhaps the reflex dictionary is missing?\n";
115 return std::pair<AnyMethodArgument,int>(
t,-1);
118 if (value.TypeOf().TypeInfo() !=
typeid(int))
121 int ival = *
reinterpret_cast<const int *
>(value.Get().Address());
123 return std::pair<AnyMethodArgument,int>(ival,1);
125 return std::pair<AnyMethodArgument,int>(
t,-1);
133 void *
operator()(
const T &
t)
const {
return const_cast<void*
>(
static_cast<const void *
>(&
t)); }
void * operator()(const T &t) const
boost::enable_if< boost::is_integral< I >, std::pair< AnyMethodArgument, int > >::type operator()(const I &t) const
std::pair< AnyMethodArgument, int > operator()(const std::string &t) const
std::pair< AnyMethodArgument, int > retOk_(const From &f, int cast) const
AnyMethodArgumentFixup(Reflex::Type type)
const std::complex< double > I
std::pair< AnyMethodArgument, int > doInt(int t) const
boost::mpl::if_< matches_another_integral_type< unsigned long >, boost::variant< int8_t, uint8_t, int16_t, uint16_t, int32_t, uint32_t, int64_t, uint64_t, double, float, std::string >, boost::variant< int8_t, uint8_t, int16_t, uint16_t, int32_t, uint32_t, int64_t, uint64_t, unsigned long, double, float, std::string > >::type AnyMethodArgument
unsigned long long uint64_t
boost::enable_if< boost::is_floating_point< F >, std::pair< AnyMethodArgument, int > >::type operator()(const F &t) const
const std::type_info & type_