Belofte  version 2.1.5
A promising chess program using the UCI or Winboard interface
util.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------+
2  * File: util.h
3  * Project: part of belofte - A Promising Chess Program
4  * Author: yves
5  * SPDX-License-Identifier: GPL-2.0-only
6 +----------------------------------------------------------------------*/
7 
8 #if !defined(UTIL_H)
9 #define UTIL_H
10 
11 /**
12  * Helper class for measuring execution time for functions
13  * Call ClockStart and ClockEnd at end of execution
14  * If getDuration is being called without ClockEnd, it will return
15  * elapsed time but continue counting
16  */
18 public:
20  virtual ~TimedExecution() = default;
21 
22  std::string getDuration() const;
23  long long getDurationMicroSec() const;
24 
25 protected:
26  void ClockStart();
27  void ClockEnd();
28  int64_t getDurationSec() const;
29  int64_t getDurationMilliSec() const;
30 
31 private:
32  bool m_isEnded = false;
33 #if defined(CHRONO_MISSING)
34  struct timeval execution_start;
35  struct timeval execution_end;
36 #else
37  std::chrono::high_resolution_clock::time_point execution_start;
38  std::chrono::high_resolution_clock::time_point execution_end;
39 #endif
40 };
41 
42 //-----------------------------------------------------------------------
43 
44 namespace belofte {
45 
46  typedef std::vector<std::string> stringList;
47 
48  stringList stringSplit(std::string src, std::string delim);
49  std::pair<std::string, std::string> decompose(std::string const& src,
50  std::string const& delim);
51  std::string to_string(long value);
52  std::string alltrim(std::string s, std::string const& delim = " ");
53  bool is_number(std::string const& s);
54  int getRandomInt(int const nMax);
55  int getRandomRange(int const Range);
56  int positionParamIndex(stringList const& param,
57  std::string const& findstr);
58  int positionParamValue(stringList const& param,
59  std::string const& findstr, unsigned long const nOffSet = 0);
60  std::string currentDate();
61  std::string scoreAsStr(bScore const sc);
62  std::string prettyTime(int64_t const timems);
63 }
64 
65 #endif // defined UTIL_H
66 
67 // eof
int_fast16_t bScore
used to return id of move in movelist
Definition: belofte.h:104
Helper class for measuring execution time for functions Call ClockStart and ClockEnd at end of execut...
Definition: util.h:17
void ClockEnd()
Definition: util.cpp:37
std::string getDuration() const
Definition: util.cpp:47
TimedExecution()
implementation of timing functions
Definition: util.cpp:17
int64_t getDurationSec() const
Definition: util.cpp:105
virtual ~TimedExecution()=default
int64_t getDurationMilliSec() const
Definition: util.cpp:83
void ClockStart()
Definition: util.cpp:27
long long getDurationMicroSec() const
Definition: util.cpp:61
Allow index mapper for char values of piece into int in 1-12 range to reduce space and easy initialis...
Definition: eval.h:43
std::string scoreAsStr(bScore const sc)
Definition: util.cpp:250
std::string alltrim(std::string s, std::string const &delim=" ")
trim left and right spaces or delim from string
Definition: util.cpp:177
std::pair< std::string, std::string > decompose(std::string const &src, std::string const &delim)
Split delimited long string into a pair based on delimiter e.g.
Definition: util.cpp:150
int positionParamIndex(stringList const &param, std::string const &findstr)
find position in which param has been found
Definition: util.cpp:220
std::vector< std::string > stringList
Definition: util.h:46
std::string currentDate()
Definition: util.cpp:240
std::string prettyTime(int64_t const timems)
Definition: util.cpp:278
int positionParamValue(stringList const &param, std::string const &findstr, unsigned long const nOffSet=0)
Definition: util.cpp:229
int getRandomRange(int const Range)
Definition: util.cpp:204
bool is_number(std::string const &s)
Definition: util.cpp:188
std::string to_string(long value)
std::to_string not compatible on Mac OS (Apple LLVM version 5.0) provide generic utility function
Definition: util.cpp:168
int getRandomInt(int const nMax)
Definition: util.cpp:194
stringList stringSplit(std::string src, std::string delim)
Split delimited long string into a vector.
Definition: util.cpp:132