XJ music engine  1.9.6
In-game runtime engine for XJ music.
EntityUtils.h
Go to the documentation of this file.
1 // Copyright (c) XJ Music Inc. (https://xjmusic.com) All Rights Reserved.
2 
3 #ifndef XJMUSIC_ENTITY_UTILS_H
4 #define XJMUSIC_ENTITY_UTILS_H
5 
6 #include <map>
7 #include <string>
8 #include <chrono>
9 
10 #include <nlohmann/json.hpp>
11 
12 #include "xjmusic/music/Note.h"
13 
15 
16 namespace XJ {
17 
28  using UUID = std::string;
29  static unsigned long long UNIQUE_ID_COUNTER = 0;
30 
34  class EntityUtils {
35  public:
36 
40  virtual ~EntityUtils() = default;
41 
49  template<typename A, typename B>
50  static std::map<B, A> reverseMap(const std::map<A, B> &originalMap) {
51  std::map<B, A> reverseMap;
52  for (const auto &pair: originalMap) {
53  reverseMap[pair.second] = pair.first;
54  }
55  return reverseMap;
56  }
57 
62  static long long currentTimeMillis() {
63  return std::chrono::duration_cast<std::chrono::milliseconds>(
64  std::chrono::system_clock::now().time_since_epoch()
65  ).count();
66  }
67 
78  static std::string computeUniqueId();
79 
86  static void setRequired(const json &json, const std::string &key, UUID &value);
87 
94  static void setIfNotNull(const json &json, const std::string &key, std::string &value);
95 
102  static void setIfNotNull(const json &json, const std::string &key, float &value);
103 
110  static void setIfNotNull(const json &json, const std::string &key, bool &value);
111 
118  static void setIfNotNull(const json &json, const std::string &key, int &value);
119 
126  static void setIfNotNull(const json &json, const std::string &key, long long &value);
127  };
128 
129 }// namespace XJ
130 
131 #endif//XJMUSIC_ENTITY_UTILS_H
nlohmann::json json
Definition: EntityUtils.h:14
Definition: EntityUtils.h:34
static std::string computeUniqueId()
Definition: EntityUtils.cpp:10
static long long currentTimeMillis()
Definition: EntityUtils.h:62
static void setIfNotNull(const json &json, const std::string &key, std::string &value)
Definition: EntityUtils.cpp:27
static void setRequired(const json &json, const std::string &key, UUID &value)
Definition: EntityUtils.cpp:16
static void setIfNotNull(const json &json, const std::string &key, long long &value)
static std::map< B, A > reverseMap(const std::map< A, B > &originalMap)
Definition: EntityUtils.h:50
virtual ~EntityUtils()=default
Definition: ActiveAudio.h:11
std::string UUID
Definition: EntityUtils.h:28