// // Dis VM // File: utils.h // Author: arr // #ifndef _DISVM_SRC_INCLUDE_UTILS_H_ #define _DISVM_SRC_INCLUDE_UTILS_H_ #include #include #include #include #include namespace disvm { namespace util { template bool has_flag(const Flags flags, const Flags flag) { return (static_cast>(flags) & static_cast>(flag)) != 0; } template bool are_equal(const T1 &l, const T2 &r) { return (l == r); } template bool are_equal(const T1 &l, const T2 &r, const Others &... args) { return (l == r) && are_equal(r, args...); } // split the string using the delimiters contained in the supplied string inline std::vector split(const std::string &str, const char *delims) { auto split_string = std::vector{}; auto curr = str.begin(); auto end = str.cend(); while (curr != end) { auto curr_begin = curr; while (curr != end && (nullptr == std::strchr(delims, *curr))) ++curr; if (curr_begin != curr) split_string.push_back(std::move(std::string{ curr_begin, curr })); if (curr == end) break; ++curr; } return split_string; } inline std::vector split(const std::string &str) { return split(str, " "); } } } // Adopted from 'winnt.h' in the Windows SDK #define DEFINE_ENUM_FLAG_OPERATORS(TYPE) \ inline TYPE operator | (TYPE a, TYPE b) { return static_cast(static_cast>(a) | static_cast>(b)); } \ inline TYPE &operator |= (TYPE &a, TYPE b) { a = a | b; return a; } \ inline TYPE operator & (TYPE a, TYPE b) { return static_cast(static_cast>(a) & static_cast>(b)); } \ inline TYPE &operator &= (TYPE &a, TYPE b) { a = a & b; return a; } \ inline TYPE operator ^ (TYPE a, TYPE b) { return static_cast(static_cast>(a) ^ static_cast>(b)); } \ inline TYPE &operator ^= (TYPE &a, TYPE b) { a = a ^ b; return a; } \ inline TYPE operator ~ (TYPE a) { return static_cast(~static_cast>(a)); } #endif // _DISVM_SRC_INCLUDE_UTILS_H_