blob: cbab5e6191f2deb290a5be3adffbab9bd0d95ffc (
plain)
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
|
#ifndef LOp9uF4R8c3Nq3YZQrpOlN8rCLE
#define LOp9uF4R8c3Nq3YZQrpOlN8rCLE
#include <inttypes.h>
#include <boost/static_assert.hpp>
#include <string>
#include "mempool.hpp"
using std::string;
template<typename T, long long width = 8 * sizeof(T)>
struct Scalar {
explicit Scalar(const string name);
inline T & operator() () const;
inline T get() const;
inline void set(const T value) const;
void sync() const;
// associated memory container
MemPool mem;
BOOST_STATIC_ASSERT((width > 0));
private:
// Scalar();
};
// Implementation
template<typename T, long long width>
Scalar<T, width>::Scalar(const string name) : mem((width + 7) / 8, name) {
}
template<typename T, long long width>
inline T & Scalar<T, width>::operator() () const {
return *((T*) mem());
}
template<typename T, long long width>
inline T Scalar<T, width>::get() const {
return (*this)();
}
template<typename T, long long width>
inline void Scalar<T, width>::set(const T value) const {
// only a single value is in a scalar so we do not require bit-level
// access
(*this)() = value;
}
template<typename T, long long width>
void Scalar<T, width>::sync() const {
mem.sync();
}
#endif // LOp9uF4R8c3Nq3YZQrpOlN8rCLE
|