libcubescript/src/cs_util.hh

45 lines
929 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>
#include <ostd/string.hh>
#include <ostd/utility.hh>
2017-01-31 19:28:34 +01:00
#include <ostd/unordered_map.hh>
namespace cscript {
2016-11-11 22:19:51 +01:00
template<typename K, typename V>
2017-01-31 19:28:34 +01:00
using CsMap = std::unordered_map<K, V>;
2016-11-11 22:19:51 +01:00
template<typename T>
2017-01-25 01:18:29 +01:00
using CsVector = std::vector<T>;
2016-11-11 22:19:51 +01:00
2016-08-15 19:55:22 +02:00
CsInt cs_parse_int(
ostd::ConstCharRange input, ostd::ConstCharRange *end = nullptr
);
2016-08-15 19:55:22 +02:00
CsFloat cs_parse_float(
ostd::ConstCharRange input, ostd::ConstCharRange *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 */