aboutsummaryrefslogtreecommitdiffstats
path: root/meowpp/utility.h
blob: 156971ac871c79e3c6b7a7d39d02501b0df2cbec (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#ifndef   UTILITY_H_
#define   UTILITY_H_

#include <string>
#include <stack>
#include <cctype>

namespace meow{

  inline std::string stringPrintf(char const * fmt, ...);
  inline std::string stringReplace(std::string str,
                                   std::string const& from,
                                   std::string const& to);
  inline bool cstringEndWith(char const* str, int n, ...);
#define debugPrintf(...) \
  meow::debugPrintf_(\
                     __FILE__,\
                     __PRETTY_FUNCTION__,\
                     __LINE__,\
                     meow::stringPrintf(__VA_ARGS__).c_str())
  inline void debugPrintf_(char const* file,
                           char const* func,
                           size_t      line,
                           char const* msg);
  inline void messagePrintf(int level_change, char const* fmt, ...);

  static const double PI = 3.14159265358979323846264338327950288;

  inline double noEPS(double value, double eps = 1e-9);
  inline double   normalize(double lower, double upper, double value);
  inline double denormalize(double lower, double upper, double ratio);
  inline double ratioMapping(double l1, double u1, double m1,
                             double l2, double u2);
  template<class T>
  inline T inRange(T const& mn, T const& mx, T const& v);
  template<class T>
  inline T squ(T const& x);

  template<class T>
  inline double average(T const& beg, T const& end, double sigs);
  template<class T>
  inline double average(T const& beg, T const& end, T const& p, double sigs);
}

#include "utility.hpp"

#endif // UTILITY_H_