2016-08-15 03:19:59 +02:00
|
|
|
#ifndef LIBCUBESCRIPT_CS_UTIL_HH
|
|
|
|
#define LIBCUBESCRIPT_CS_UTIL_HH
|
|
|
|
|
|
|
|
#include <ostd/string.hh>
|
2016-09-08 23:42:14 +02:00
|
|
|
#include <ostd/utility.hh>
|
|
|
|
#include <ostd/type_traits.hh>
|
2016-08-15 03:19:59 +02:00
|
|
|
|
|
|
|
namespace cscript {
|
|
|
|
|
2016-08-15 19:55:22 +02:00
|
|
|
CsInt cs_parse_int(
|
2016-08-15 03:19:59 +02:00
|
|
|
ostd::ConstCharRange input, ostd::ConstCharRange *end = nullptr
|
|
|
|
);
|
|
|
|
|
2016-08-15 19:55:22 +02:00
|
|
|
CsFloat cs_parse_float(
|
2016-08-15 03:19:59 +02:00
|
|
|
ostd::ConstCharRange input, ostd::ConstCharRange *end = nullptr
|
|
|
|
);
|
|
|
|
|
2016-09-08 23:42:14 +02:00
|
|
|
template<typename F>
|
|
|
|
struct CsScopeExit {
|
|
|
|
template<typename FF>
|
|
|
|
CsScopeExit(FF &&f): func(ostd::forward<FF>(f)) {}
|
|
|
|
~CsScopeExit() {
|
|
|
|
func();
|
|
|
|
}
|
|
|
|
ostd::Decay<F> func;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename F1, typename F2>
|
|
|
|
inline void cs_do_and_cleanup(F1 &&dof, F2 &&clf) {
|
|
|
|
CsScopeExit<F2> cleanup(ostd::forward<F2>(clf));
|
|
|
|
dof();
|
|
|
|
}
|
|
|
|
|
2016-08-15 03:19:59 +02:00
|
|
|
} /* namespace cscript */
|
|
|
|
|
|
|
|
#endif /* LIBCUBESCRIPT_CS_UTIL_HH */
|