COMMS
Template library intended to help with implementation of communication protocols.
Loading...
Searching...
No Matches
VersionStorage.h
1//
2// Copyright 2017 - 2024 (C). Alex Robenko. All rights reserved.
3//
4// This Source Code Form is subject to the terms of the Mozilla Public
5// License, v. 2.0. If a copy of the MPL was not distributed with this
6// file, You can obtain one at http://mozilla.org/MPL/2.0/.
7
8
9#pragma once
10
11namespace comms
12{
13
14namespace field
15{
16
17namespace adapter
18{
19
20template <typename TBase>
21class VersionStorage : public TBase
22{
23 using BaseImpl = TBase;
24public:
25
26 using ValueType = typename BaseImpl::ValueType;
27 using VersionType = typename BaseImpl::VersionType;
28
29 VersionStorage() = default;
30
31 explicit VersionStorage(const ValueType& val)
32 : BaseImpl(val)
33 {
34 }
35
36 explicit VersionStorage(ValueType&& val)
37 : BaseImpl(std::move(val))
38 {
39 }
40
41 VersionStorage(const VersionStorage&) = default;
42 VersionStorage(VersionStorage&&) = default;
43 VersionStorage& operator=(const VersionStorage&) = default;
44 VersionStorage& operator=(VersionStorage&&) = default;
45
46 static constexpr bool isVersionDependent()
47 {
48 return true;
49 }
50
51 VersionType getVersion() const
52 {
53 return m_version;
54 }
55
56 bool setVersion(VersionType val)
57 {
58 bool updated = BaseImpl::setVersion(val);
59 if (m_version != val) {
60 m_version = val;
61 return true;
62 }
63 return updated;
64 }
65
66private:
67 VersionType m_version = static_cast<VersionType>(0);
68};
69
70} // namespace adapter
71
72} // namespace field
73
74} // namespace comms
75
comms::option::def::VersionType< T > VersionType
Same as comms::option::def::VersionType.
Definition options.h:1797
comms::option::def::VersionStorage VersionStorage
Same as comms::option::def::VersionStorage.
Definition options.h:1818
Main namespace for all classes / functions of COMMS library.
STL namespace.