blob: 9234b70e8b59a6a6154e5988f2e7424de735a94a (
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
#pragma once
#include <util/system/unaligned_mem.h>
namespace NKikimr {
namespace NMiniKQL {
template <typename T, bool IsConst = std::is_const_v<T>>
class TStateWrapper;
template <typename T>
class TStateWrapper<T, true> {
public:
TStateWrapper(const void* ptr)
: State_(ReadUnaligned<typename std::remove_const<T>::type>(ptr))
{ }
T* Get() {
return &State_;
}
T* operator->() {
return Get();
}
private:
T State_;
};
template <typename T>
class TStateWrapper<T, false> {
public:
TStateWrapper(void* ptr)
: State_(ReadUnaligned<T>(ptr))
, Ptr_(ptr)
{ }
~TStateWrapper() {
WriteUnaligned<T>(Ptr_, State_);
}
T* Get() {
return &State_;
}
T* operator->() {
return Get();
}
private:
T State_;
void* Ptr_;
};
template <typename T>
inline TStateWrapper<T> MakeStateWrapper(void* ptr) {
return TStateWrapper<T>(ptr);
}
template <typename T>
inline TStateWrapper<const T> MakeStateWrapper(const void* ptr) {
return TStateWrapper<const T>(ptr);
}
template<typename T>
inline T Cast(T t) {
return t;
}
inline NYql::NDecimal::TDecimal Cast(const std::shared_ptr<arrow::Buffer>& buffer) {
return *reinterpret_cast<const NYql::NDecimal::TDecimal*>(buffer->data());
}
}
}
|