sapphirec  0.1
The Sapphire compiler.
utils.h
1 #pragma once
2 #include "FormatString/FormatString.hpp"
3 #include "sapphirepch.h"
4 #include <chrono>
5 
6 /*
7  * Replaces all ocurrences of a substring with another one in a string.
8  * @param[in] str The input string.
9  * @param[in] from The substring to remove.
10  * @param[in] to The substring to add.
11  * @param[out] replaced Whether anything was replaced.
12  */
13 bool replace(std::string& str, const std::string& from, const std::string& to);
14 
15 /* Easy way of converting an int to a string without writing 5 lines of code every time you want to do it. */
16 std::string to_string(const int& value);
17 
18 /* Easy way of converting a float to a string without writing 5 lines of code every time you want to do it. */
19 std::string to_string(const float& value);
20 
21 /* Benchmarking utilities. */
22 
24 {
25  public:
26  __benchmark_impl(std::string_view __function_name);
28 
29  static void enable();
30  static void disable();
31 
32  static void init();
33 
34  private:
35  std::chrono::time_point<std::chrono::high_resolution_clock> m_StartTimePoint;
36  std::string_view m_FunctionName;
37  static bool m_BenchmarkingEnabled;
38  bool m_InternalBenchmarkingEnabled;
39 };
40 
41 #define benchmark(message) __benchmark_impl __benchmark_impl_timer(message)
Definition: utils.h:24