FACT++  1.0
tools.h
Go to the documentation of this file.
1 #ifndef FACT_Tools
2 #define FACT_Tools
3 
4 #include <map>
5 #include <string>
6 #include <vector>
7 
8 namespace Tools
9 {
10  std::string Format(const char *fmt, va_list &ap);
11  std::string Form(const char *fmt, ...);
12  std::string Trim(const std::string &str);
13  std::string TrimQuotes(const std::string &str);
14  std::string Wrap(std::string &str, size_t width=78);
15  std::string Scientific(uint64_t val);
16 
17  std::map<std::string,std::string> Split(std::string &, bool = false);
18  std::vector<std::string> Split(const std::string &, const std::string &);
19  std::string Uncomment(const std::string &opt);
20 
21  template<typename T>
22  uint16_t Fletcher16(const T *t, size_t cnt)
23  {
24  const uint8_t *data = reinterpret_cast<const uint8_t*>(t);
25 
26  size_t bytes = cnt*sizeof(T);
27 
28  uint16_t sum1 = 0xff;
29  uint16_t sum2 = 0xff;
30 
31  while (bytes)
32  {
33  size_t tlen = bytes > 20 ? 20 : bytes;
34  bytes -= tlen;
35 
36  do {
37  sum2 += sum1 += *data++;
38  } while (--tlen);
39 
40  sum1 = (sum1 & 0xff) + (sum1 >> 8);
41  sum2 = (sum2 & 0xff) + (sum2 >> 8);
42  }
43 
44  // Second reduction step to reduce sums to 8 bits
45  sum1 = (sum1 & 0xff) + (sum1 >> 8);
46  sum2 = (sum2 & 0xff) + (sum2 >> 8);
47 
48  return sum2 << 8 | sum1;
49  }
50 
51 }
52 
53 #endif
char str[80]
Definition: test_client.c:7
uint16_t Fletcher16(const T *t, size_t cnt)
Definition: tools.h:22
std::string Format(const char *fmt, va_list &ap)
Definition: tools.cc:21
std::string TrimQuotes(const std::string &str)
Definition: tools.cc:92
Definition: tools.h:8
std::map< std::string, std::string > Split(std::string &, bool=false)
Definition: tools.cc:230
std::string Form(const char *fmt,...)
Definition: tools.cc:45
std::string Scientific(uint64_t val)
Definition: tools.cc:148
float data[4 *1440]
std::string Wrap(std::string &str, size_t width=78)
Definition: tools.cc:128
TT t
Definition: test_client.c:26
std::string Uncomment(const std::string &opt)
Definition: tools.cc:292
std::string Trim(const std::string &str)
Definition: tools.cc:68