libcubescript/src/cs_util.hh

44 lines
890 B
C++
Raw Normal View History

#ifndef LIBCUBESCRIPT_CS_UTIL_HH
#define LIBCUBESCRIPT_CS_UTIL_HH
2017-02-09 20:59:14 +01:00
#include <type_traits>
2017-04-23 15:34:45 +02:00
#include <unordered_map>
2017-02-09 20:59:14 +01:00
#include <ostd/string.hh>
namespace cscript {
2016-11-11 22:19:51 +01:00
template<typename K, typename V>
2018-04-27 23:53:55 +02:00
using cs_map = std::unordered_map<K, V>;
2016-11-11 22:19:51 +01:00
template<typename T>
2018-04-27 23:53:55 +02:00
using cs_vector = std::vector<T>;
2016-11-11 22:19:51 +01:00
2017-02-13 18:10:40 +01:00
cs_int cs_parse_int(
2017-02-16 19:07:22 +01:00
ostd::string_range input, ostd::string_range *end = nullptr
);
2017-02-13 18:10:40 +01:00
cs_float cs_parse_float(
2017-02-16 19:07:22 +01:00
ostd::string_range input, ostd::string_range *end = nullptr
);
template<typename F>
struct CsScopeExit {
template<typename FF>
2017-01-25 01:57:33 +01:00
CsScopeExit(FF &&f): func(std::forward<FF>(f)) {}
~CsScopeExit() {
func();
}
2017-02-09 20:59:14 +01:00
std::decay_t<F> func;
};
template<typename F1, typename F2>
inline void cs_do_and_cleanup(F1 &&dof, F2 &&clf) {
2017-01-25 01:57:33 +01:00
CsScopeExit<F2> cleanup(std::forward<F2>(clf));
dof();
}
} /* namespace cscript */
#endif /* LIBCUBESCRIPT_CS_UTIL_HH */