Horizon
util.hpp
1 #pragma once
2 #include "common/common.hpp"
3 #include "nlohmann/json_fwd.hpp"
4 #include <string>
5 #include <vector>
6 
7 namespace horizon {
8 using json = nlohmann::json;
9 void save_json_to_file(const std::string &filename, const json &j);
10 int orientation_to_angle(Orientation o);
11 std::string get_exe_dir();
12 std::string coord_to_string(const Coordf &c, bool delta = false);
13 std::string dim_to_string(int64_t x, bool with_sign = true);
14 std::string angle_to_string(int angle, bool pos_only = true);
15 
16 int64_t round_multiple(int64_t x, int64_t mul);
17 
18 template <typename T, typename U> std::vector<T> dynamic_cast_vector(const std::vector<U> &cin)
19 {
20  std::vector<T> out;
21  out.reserve(cin.size());
22  std::transform(cin.begin(), cin.end(), std::back_inserter(out), [](auto x) { return dynamic_cast<T>(x); });
23  return out;
24 }
25 
26 template <typename Map, typename F> static void map_erase_if(Map &m, F pred)
27 {
28  for (typename Map::iterator i = m.begin(); (i = std::find_if(i, m.end(), pred)) != m.end(); m.erase(i++))
29  ;
30 }
31 
32 bool endswith(const std::string &haystack, const std::string &needle);
33 
34 template <typename T> int sgn(T val)
35 {
36  return (T(0) < val) - (val < T(0));
37 }
38 
39 int strcmp_natural(const std::string &a, const std::string &b);
40 void create_config_dir();
41 std::string get_config_dir();
42 
43 void replace_backslash(std::string &path);
44 json json_from_resource(const std::string &rsrc);
45 } // namespace horizon
a class to store JSON values
Definition: json.hpp:161
Definition: block.cpp:7
basic_json<> json
default JSON class
Definition: json_fwd.hpp:61