12 #ifndef sprockit_common_util_h 13 #define sprockit_common_util_h 25 template <
class Out,
class In>
31 const char* error_msg =
"error")
33 Out* out =
dynamic_cast<Out*
>(in);
36 "%s: failed to cast object at %s:%d",
37 error_msg, file, line);
46 #define safe_cast(type,...) \ 47 ::sprockit::__safe_cast__<type>(#type, __FILE__, __LINE__, __VA_ARGS__) 49 #define test_cast(type, obj) \ 50 dynamic_cast<type*>(obj) 52 #define known_cast(type,...) \ 53 safe_cast(type, __VA_ARGS__) 55 #define interface_cast(type,obj) \ 56 dynamic_cast<type*>(obj) 58 template <
class maptype,
class keytype>
59 const typename maptype::mapped_type&
60 mapget(
const maptype& mapobj,
const keytype& keyobj,
const char* errormsg)
62 typename maptype::const_iterator it = mapobj.find(keyobj);
63 if (it == mapobj.end()) {
77 struct integer_meta_sequence
80 template<
int N,
int... S>
81 struct meta_sequence_generator
82 : meta_sequence_generator<N-1, N-1, S...>
86 struct meta_sequence_generator<0, S...>{
87 typedef integer_meta_sequence<S...> type;
90 template <
typename Function,
typename Tuple,
int... S>
91 typename Function::result_type
95 const integer_meta_sequence<S...>&
98 return func(std::get<S>(tup)...);
103 template <
typename Tuple,
typename Return,
typename... Args>
104 Return splat_tuple(std::function<Return(Args...)>&& func, Tuple&& tup)
106 return detail::splat_tuple_impl(
108 typename detail::meta_sequence_generator<std::tuple_size<Tuple>::value>::type()
145 namespace modal_mixin {
156 virtual std::string get_mode_name()
const =0;
157 virtual std::string get_baseof_name()
const =0;
162 const std::string& method_name
165 "method %s() of %s is not valid in %s mode",
166 get_baseof_name().c_str(),
167 get_mode_name().c_str()
174 const std::string& method_name
177 throw_method_called_in_wrong_mode(method_name);
185 #define ASSERT_CORRECT_MODE check_mode(__PRETTY_FUNCTION__); 195 #define SPKT_DELEGATE_ALL_OVERLOADS(method_name, member) \ 196 template <typename... __MethArgs> \ 197 auto method_name(__MethArgs&&... __in_args) \ 199 member->method_name( \ 200 std::forward<__MethArgs>(__in_args)... \ 204 assert(member != NULL); \ 205 return member->method_name( \ 206 std::forward<__MethArgs>(__in_args)... \ 209 #define SPKT_DELEGATE_ALL_CONST_OVERLOADS(method_name, member) \ 210 template <typename... __MethArgs> \ 211 auto method_name(__MethArgs&&... __in_args) const \ 213 member->method_name( \ 214 std::forward<__MethArgs>(__in_args)... \ 218 assert(member != NULL); \ 219 return member->method_name( \ 220 std::forward<__MethArgs>(__in_args)... \ 224 #define SPKT_DELEGATE_ALL_OVERLOADS(method_name, member) \ 225 spkt_static_assert(false, "SPKT_DELEGATE_ALL_OVERLOADS requires c++11") 231 #define spkt_find_if(iterable, param, ...) \ 232 std::find_if(iterable.begin(), iterable.end(), \ 233 [&](const typename std::iterator_traits<decltype(iterable.begin())>::value_type& param) -> bool \ 238 #define spkt_find_if(...) \ 239 spkt_static_assert(false, "spkt_find_if() requires c++11")
void check_mode(const std::string &method_name) const
virtual ~ModalMixinBase()
ModalMixinBase(bool disabled)
Out * __safe_cast__(const char *objname, const char *file, int line, In *in, const char *error_msg="error")
const maptype::mapped_type & mapget(const maptype &mapobj, const keytype &keyobj, const char *errormsg)
void throw_method_called_in_wrong_mode(const std::string &method_name) const
#define spkt_throw_printf(exc, template_str,...)
Error indicating some internal value was unexpected.