summaryrefslogtreecommitdiff
path: root/core/scalar.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/scalar.hpp')
-rw-r--r--core/scalar.hpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/core/scalar.hpp b/core/scalar.hpp
new file mode 100644
index 0000000..cbab5e6
--- /dev/null
+++ b/core/scalar.hpp
@@ -0,0 +1,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
contact: Jan Huwald // Impressum