cpp-common/bt2: use raw value proxy for scalar value classes
[babeltrace.git] / src / cpp-common / bt2 / raw-value-proxy.hpp
1 /*
2 * Copyright (c) 2023 Philippe Proulx <pproulx@efficios.com>
3 *
4 * SPDX-License-Identifier: MIT
5 */
6
7 #ifndef BABELTRACE_CPP_COMMON_BT2_RAW_VALUE_PROXY_HPP
8 #define BABELTRACE_CPP_COMMON_BT2_RAW_VALUE_PROXY_HPP
9
10 #include <string>
11
12 namespace bt2 {
13
14 template <typename ObjT>
15 class RawValueProxy
16 {
17 private:
18 using _RawVal = typename ObjT::Value;
19
20 public:
21 explicit RawValueProxy(const ObjT obj) : _mObj {obj}
22 {
23 }
24
25 RawValueProxy& operator=(const _RawVal& rawVal)
26 {
27 _mObj.value(rawVal);
28 return *this;
29 }
30
31 operator _RawVal() const noexcept
32 {
33 return _mObj.value();
34 }
35
36 private:
37 ObjT _mObj;
38 };
39
40 template <typename ObjT>
41 class RawStringValueProxy final : public RawValueProxy<ObjT>
42 {
43 public:
44 explicit RawStringValueProxy(const ObjT obj) : RawValueProxy<ObjT> {obj}
45 {
46 }
47
48 RawStringValueProxy& operator=(const std::string& rawVal)
49 {
50 RawValueProxy<ObjT>::operator=(rawVal.data());
51 return *this;
52 }
53 };
54
55 } /* namespace bt2 */
56
57 #endif /* BABELTRACE_CPP_COMMON_BT2_RAW_VALUE_PROXY_HPP */
This page took 0.03192 seconds and 5 git commands to generate.