Horizon
log_util.hpp
1 #pragma once
2 #include "common/object_descr.hpp"
3 #include "logger.hpp"
4 #include "util/uuid.hpp"
5 #include <map>
6 #include <string>
7 #include <tuple>
8 
9 namespace horizon {
10 template <typename T, typename... Args1>
11 void load_and_log(std::map<UUID, T> &map, ObjectType type, std::tuple<Args1...> args,
12  Logger::Domain dom = Logger::Domain::UNSPECIFIED)
13 {
14  auto uu = std::get<0>(args);
15  try {
16  map.emplace(std::piecewise_construct, std::forward_as_tuple(uu), std::forward<std::tuple<Args1...>>(args));
17  }
18  catch (const std::exception &e) {
19  Logger::log_warning("couldn't load " + object_descriptions.at(type).name + " " + (std::string)uu, dom,
20  e.what());
21  }
22  catch (...) {
23  Logger::log_warning("couldn't load " + object_descriptions.at(type).name + " " + (std::string)uu, dom);
24  }
25 }
26 } // namespace horizon