};
BOOST_MPL_HAS_XXX_TRAIT_DEF(element_type)
+
+ template<class T1, class T2>
+ struct reduced_is_same:
+ public boost::is_same<
+ typename boost::remove_cv<
+ typename boost::remove_reference<T1>::type
+ >::type,
+ T2
+ >
+ {};
}
/**
args(args)
{}
+ bool isNumeric(size_t index) const
+ {
+ return (index < argc && naIsNum(args[index]));
+ }
+
+ bool isString(size_t index) const
+ {
+ return (index < argc && naIsString(args[index]));
+ }
+
+ bool isHash(size_t index) const
+ {
+ return (index < argc && naIsHash(args[index]));
+ }
+
+ bool isVector(size_t index) const
+ {
+ return (index < argc && naIsVector(args[index]));
+ }
+
+ bool isGhost(size_t index) const
+ {
+ return (index < argc && naIsGhost(args[index]));
+ }
+
+ void popFront(size_t num = 1)
+ {
+ if( argc < num )
+ return;
+
+ args += num;
+ argc -= num;
+ }
+
+ void popBack(size_t num = 1)
+ {
+ if( argc < num )
+ return;
+
+ argc -= num;
+ }
+
/**
* Get the argument with given index if it exists. Otherwise returns the
* passed default value.
if( index >= argc )
return def;
- return (*from_nasal_ptr<T>::get())(c, args[index]);
+ return from_nasal<T>(args[index]);
}
/**
if( index >= argc )
naRuntimeError(c, "Missing required arg #%d", index);
- return (*from_nasal_ptr<T>::get())(c, args[index]);
+ return from_nasal<T>(args[index]);
}
template<class T>
return nasal::to_nasal(c, arg);
}
+ template<class T>
+ typename from_nasal_ptr<T>::return_type
+ from_nasal(naRef ref) const
+ {
+ return (*from_nasal_ptr<T>::get())(c, ref);
+ }
+
naContext c;
size_t argc;
naRef *args;
template<class Arg>
static
typename boost::disable_if<
- boost::is_same<Arg, const CallContext&>,
+ internal::reduced_is_same<Arg, CallContext>,
typename from_nasal_ptr<Arg>::return_type
>::type
arg_from_nasal(const CallContext& ctx, size_t index)
template<class Arg>
static
typename boost::enable_if<
- boost::is_same<Arg, const CallContext&>,
+ internal::reduced_is_same<Arg, CallContext>,
typename from_nasal_ptr<Arg>::return_type
>::type
arg_from_nasal(const CallContext& ctx, size_t)
{
+ // Either const CallContext& or CallContext, non-const reference
+ // does not make sense.
+ BOOST_STATIC_ASSERT( (!boost::is_same<Arg, CallContext&>::value) );
return ctx;
};
// Test nasal::CallContext
//----------------------------------------------------------------------------
+
+ int int_vec[] = {1,2,3};
+ std::map<std::string, std::string> map;
naRef args[] = {
- to_nasal(c, std::string("test-arg"))
+ to_nasal(c, std::string("test-arg")),
+ to_nasal(c, 4),
+ to_nasal(c, int_vec),
+ to_nasal(c, map)
};
CallContext cc(c, sizeof(args)/sizeof(args[0]), args);
VERIFY( cc.requireArg<std::string>(0) == "test-arg" );
VERIFY( cc.getArg<std::string>(0) == "test-arg" );
- VERIFY( cc.getArg<std::string>(1) == "" );
+ VERIFY( cc.getArg<std::string>(10) == "" );
+ VERIFY( cc.isString(0) );
+ VERIFY( !cc.isNumeric(0) );
+ VERIFY( !cc.isVector(0) );
+ VERIFY( !cc.isHash(0) );
+ VERIFY( !cc.isGhost(0) );
+ VERIFY( cc.isNumeric(1) );
+ VERIFY( cc.isVector(2) );
+ VERIFY( cc.isHash(3) );
naRef args_vec = nasal::to_nasal(c, args);
VERIFY( naIsVector(args_vec) );