OmniSciDB  85c2d10cdc
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Epoch.h
Go to the documentation of this file.
1 /*
2  * Copyright 2020 OmniSci Technologies, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
25 #pragma once
26 
27 #include <stdint.h>
28 #include <limits>
29 
30 struct Epoch {
31  public:
32  Epoch() {
33  epoch_storage[0] = std::numeric_limits<int32_t>::min();
34  epoch_storage[1] = 0;
35  }
36 
37  Epoch(const int32_t epoch_floor, const int32_t epoch_ceiling) {
38  epoch_storage[0] = epoch_floor;
39  epoch_storage[1] = epoch_ceiling;
40  }
41 
42  // Getters
43  inline int32_t floor() const { return epoch_storage[0]; }
44  inline int32_t ceiling() const { return epoch_storage[1]; }
45 
46  // Setters
47  inline void floor(const int32_t epoch_floor) {
48  epoch_storage[0] = epoch_floor;
49  ;
50  }
51 
52  inline void ceiling(const int32_t epoch_ceiling) { epoch_storage[1] = epoch_ceiling; }
53 
54  inline int32_t increment() { return ++epoch_storage[1]; }
55 
61  inline int8_t* storage_ptr() { return reinterpret_cast<int8_t*>(&epoch_storage[0]); }
62 
63  static inline size_t byte_size() { return 2 * sizeof(int64_t); }
64 
65  static inline int64_t min_allowable_epoch() {
66  return std::numeric_limits<int32_t>::min();
67  }
68 
69  static inline int64_t max_allowable_epoch() {
70  return std::numeric_limits<int32_t>::max() - 1;
71  }
72 
73  private:
74  int64_t epoch_storage[2];
75 };
int8_t * storage_ptr()
Definition: Epoch.h:61
void floor(const int32_t epoch_floor)
Definition: Epoch.h:47
Epoch(const int32_t epoch_floor, const int32_t epoch_ceiling)
Definition: Epoch.h:37
static int64_t min_allowable_epoch()
Definition: Epoch.h:65
int32_t floor() const
Definition: Epoch.h:43
int32_t ceiling() const
Definition: Epoch.h:44
static int64_t max_allowable_epoch()
Definition: Epoch.h:69
int64_t epoch_storage[2]
Definition: Epoch.h:74
int32_t increment()
Definition: Epoch.h:54
Epoch()
Definition: Epoch.h:32
void ceiling(const int32_t epoch_ceiling)
Definition: Epoch.h:52
Definition: Epoch.h:30
static size_t byte_size()
Definition: Epoch.h:63