ztsdb
globals.hpp
1 // (C) 2016 Leonardo Silvestri
2 //
3 // This file is part of ztsdb.
4 //
5 // ztsdb is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // ztsdb is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with ztsdb. If not, see <http://www.gnu.org/licenses/>.
17 
18 
19 #ifndef GLOBALS_HPP
20 #define GLOBALS_HPP
21 
22 #include <cstdint>
23 #include <chrono>
24 #include <exception>
25 #include <limits>
26 #include <memory>
27 
28 
29 namespace Global {
30 
31  // static const uint64_t zna = 0x7ff00000000007a2; // 0x7a2 == 1954, the R convention
32  // const double ZNA = *reinterpret_cast<const double*>(&zna);
33  const double ZNAN = std::numeric_limits<double>::quiet_NaN();
34  const double ZINF = std::numeric_limits<double>::infinity();
35 
36  struct NANF {
37  static double f() { return Global::ZNAN; }
38  };
39 
40  // inline bool isna(double d) { return *reinterpret_cast<const uint64_t*>(&d) == zna; }
41 
42  const size_t CHUNKSZ = 131072; // 2^17
43  // static const size_t CHUNKSZ = 1024;
44  const size_t MAGICNB = 0x9316481736403219L;
45 
46  const size_t EPOLL_MAX_EVENTS = 64; // max number of peers...
47 
48  using dtime = std::chrono::system_clock::time_point;
49  using duration = dtime::duration;
50 
51  struct QuitException : std::exception {
52  QuitException(int status_p) : status(status_p) { }
53  int status;
54  };
55 
56  // alignment boundary for strings:
57  const size_t STRALIGN = 8;
58 
61  enum class MsgType : uint64_t {
62  REQ,
63  RSP,
64  APPEND,
65  APPEND_VECTOR
66  };
67 
72  using conn_id_t = uint64_t;
73 
75  using reqid_t = uint64_t;
76 
78  const char* const ZTSDBDIR_ENV = "ZTSDBDIR";
79  const char* const CONFIG_FILENAME = "ztsdb.conf";
80  const char* const LOGFILE_EXTENSION = ".log";
81 
82  using buflen_pair = std::pair<std::unique_ptr<char[]>, size_t>;
83 }
84 
85 
86 #endif
Global::NANF
Definition: globals.hpp:36
Global::QuitException
Definition: globals.hpp:51