Antal.Ai - Virtual Makeup
Utils.h
1 #pragma once
2 
3 
4 #include <string>
5 #include <vector>
6 
7 
8 namespace core {
9  namespace file {
10 
18  bool listFiles( const std::string &path,
19  const std::string &extension,
20  std::vector<std::string> &files);
21 
28  bool loadFileToMemory(std::string path,
29  std::vector<unsigned char> &buffer);
30 
31  } // namespace file
32 
33  namespace string {
34  /*
35  @brief Gets filename without extension
36  @param[in] filepath - full file name
37  @return filename without extension
38  */
39  std::string fileNameNoExt(const std::string &filepath);
40 
41  /*
42  @brief Replaces string in other string
43  @param[in, out] str - full file name
44  @param[in] from - replace the given string from
45  @param[in] to - replace the given string to
46  @return True if there was any replace, false otherwise
47  */
48  bool replace( std::string &str,
49  const std::string &from,
50  const std::string &to);
51 
52  /*
53  @brief Splits string around the given delimiter character
54  @param[in] str - Input string
55  @param[in] delimiter - Delimiter character
56  @return Return the chunks of the original string separated by the delimiter character.
57  */
58  std::vector<std::string> split(const std::string &str,
59  char delimiter);
60  }//namespace string
61 
62  namespace math {
63 
64  template <class T>
65  T map(T x, T in_min, T in_max, T out_min, T out_max)
66  {
67  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
68  }
69 
70  /*
71  @brief Converts radian value to degree
72  @param[in] value - Input value in radian
73  @return Return value in degree
74  */
75  double radToDeg(double value);
76 
77  /*
78  @brief Converts degree value to radian
79  @param[in] value - Input value in degree
80  @return Return value in radian
81  */
82  double degToRad(double value);
83 
84  }//namespace math
85 } // namespace core