Antares Simulator
Power System Simulator
utils.h
1 /*
2 ** Copyright 2007-2025, RTE (https://www.rte-france.com)
3 ** See AUTHORS.txt
4 ** SPDX-License-Identifier: MPL-2.0
5 ** This file is part of Antares-Simulator,
6 ** Adequacy and Performance assessment for interconnected energy networks.
7 **
8 ** Antares_Simulator is free software: you can redistribute it and/or modify
9 ** it under the terms of the Mozilla Public Licence 2.0 as published by
10 ** the Mozilla Foundation, either version 2 of the License, or
11 ** (at your option) any later version.
12 **
13 ** Antares_Simulator is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ** Mozilla Public Licence 2.0 for more details.
17 **
18 ** You should have received a copy of the Mozilla Public Licence 2.0
19 ** along with Antares_Simulator. If not, see <https://opensource.org/license/mpl-2-0/>.
20 */
21 #ifndef __ANTARES_LIBS_UTILS_H__
22 #define __ANTARES_LIBS_UTILS_H__
23 
24 #include <chrono>
25 #include <map>
26 #include <string>
27 #include <vector>
28 
29 #include <yuni/yuni.h>
30 #include <yuni/core/string.h>
31 
32 namespace Antares
33 {
39 template<class StringT>
40 void TransformNameIntoID(const AnyString& name, StringT& out);
41 std::string transformNameIntoID(const std::string& name);
42 
43 std::tm getCurrentTime();
44 std::string formatTime(const std::tm& localTime, const std::string& format);
45 
49 void BeautifyName(YString& out, AnyString oldname);
50 void BeautifyName(std::string& out, const std::string& oldname);
51 
52 std::vector<std::pair<std::string, std::string>> splitStringIntoPairs(const std::string& s,
53  char delimiter1,
54  char delimiter2);
55 
56 namespace Utils
57 {
58 
59 bool isZero(double d);
60 double round(double d, unsigned precision);
61 double ceil(double d);
62 double floor(double d);
63 
64 bool isPathValid(const std::string& path);
65 
66 std::map<std::string, unsigned> giveNumbersToStrings(const std::vector<std::string>& strs);
67 bool checkAllElementsIdenticalOrOne(std::vector<unsigned> w);
68 bool checkAllElementsIdenticalOrOne(std::vector<std::pair<unsigned, std::string>>& p);
69 
70 class TimeMeasurement final
71 {
72  using clock = std::chrono::steady_clock;
73 
74 public:
76  void tick();
77  long duration_ms() const;
78  std::string toString() const;
79  std::string toStringInSeconds() const;
80  void reset();
81 
82 private:
83  clock::time_point start_;
84  clock::time_point end_;
85 };
86 
87 } // namespace Utils
88 } // namespace Antares
89 
90 #include "utils.hxx"
91 
92 #endif // __ANTARES_LIBS_UTILS_H__
Definition: utils.h:71