libwreport  3.40
internals/varinfo.h
1 #ifndef WREPORT_INTERNALS_VARINFO_H
2 #define WREPORT_INTERNALS_VARINFO_H
3 
4 #include <wreport/error.h>
5 #include <wreport/fwd.h>
6 #include <wreport/varinfo.h>
7 
8 namespace wreport::varinfo {
9 
10 constexpr int intexp10(unsigned x)
11 {
12  switch (x)
13  {
14  case 0: return 1;
15  case 1: return 10;
16  case 2: return 100;
17  case 3: return 1000;
18  case 4: return 10000;
19  case 5: return 100000;
20  case 6: return 1000000;
21  case 7: return 10000000;
22  case 8: return 100000000;
23  case 9: return 1000000000;
24  default: error_domain::throwf("%u^10 would not fit in 32 bits", x);
25  }
26 }
27 
29 constexpr unsigned count_digits(uint32_t val)
30 {
31  return (val >= 1000000000) ? 10
32  : (val >= 100000000) ? 9
33  : (val >= 10000000) ? 8
34  : (val >= 1000000) ? 7
35  : (val >= 100000) ? 6
36  : (val >= 10000) ? 5
37  : (val >= 1000) ? 4
38  : (val >= 100) ? 3
39  : (val >= 10) ? 2
40  : 1;
41 }
42 
44 void set_bufr(_Varinfo& info, Varcode code, const char* desc, const char* unit,
45  unsigned bit_len, int32_t bit_ref = 0, int scale = 0);
46 
48 void set_crex(_Varinfo& info, Varcode code, const char* desc, const char* unit,
49  unsigned len, int scale = 0);
50 
58 void set_string(_Varinfo& info, Varcode code, const char* desc, unsigned len);
59 
67 void set_binary(_Varinfo& info, Varcode code, const char* desc,
68  unsigned bit_len);
69 
71 void compute_type(_Varinfo& info);
72 
73 } // namespace wreport::varinfo
74 
75 #endif
static void throwf(const char *fmt,...) WREPORT_THROWF_ATTRS(1
Throw the exception, building the message printf-style.
wreport exceptions.
uint16_t Varcode
Holds the WMO variable code of a variable.
Definition: fwd.h:12
Implement fast access to information about WMO variables.