CatapultServer  v0.5.0.1 (Elephant)
BaseValue.h
Go to the documentation of this file.
1 
21 #pragma once
22 #include "ImmutableValue.h"
23 #include <iosfwd>
24 #include <utility>
25 
26 namespace catapult { namespace utils {
27 
29  template<typename TValue, typename TTag, typename TBaseValue>
30  class BasicBaseValue : TTag {
31  public:
33  using ValueType = TValue;
34 
35  public:
37  constexpr explicit BasicBaseValue(TValue value) : m_value(value)
38  {}
39 
41  constexpr BasicBaseValue(const BasicBaseValue& rhs) : m_value(static_cast<TValue>(rhs.m_value))
42  {}
43 
44  public:
47  m_value = std::move(rhs.m_value);
48  return *this;
49  }
50 
51  public:
53  constexpr ValueType unwrap() const {
54  return m_value;
55  }
56 
57  public:
59  constexpr bool operator==(TBaseValue rhs) const {
60  return m_value == rhs.m_value;
61  }
62 
64  constexpr bool operator!=(TBaseValue rhs) const {
65  return !(*this == rhs);
66  }
67 
69  constexpr bool operator>=(TBaseValue rhs) const {
70  return m_value >= rhs.m_value;
71  }
72 
74  constexpr bool operator>(TBaseValue rhs) const {
75  return m_value > rhs.m_value;
76  }
77 
79  constexpr bool operator<=(TBaseValue rhs) const {
80  return m_value <= rhs.m_value;
81  }
82 
84  constexpr bool operator<(TBaseValue rhs) const {
85  return m_value < rhs.m_value;
86  }
87 
89  friend std::ostream& operator<<(std::ostream& out, TBaseValue baseValue) {
90  out << baseValue.m_value;
91  return out;
92  }
93 
94  private:
96  };
97 
99  template<typename TValue, typename TTag>
100  class BaseValue : public BasicBaseValue<TValue, TTag, BaseValue<TValue, TTag>> {
101  public:
103  constexpr explicit BaseValue(TValue value = 0)
104  : BasicBaseValue<TValue, TTag, BaseValue<TValue, TTag>>(value)
105  {}
106 
107  public:
109  constexpr BaseValue operator+(BaseValue rhs) const {
110  return BaseValue(this->unwrap() + rhs.unwrap());
111  }
112 
114  constexpr BaseValue operator-(BaseValue rhs) const {
115  return BaseValue(this->unwrap() - rhs.unwrap());
116  }
117  };
118 }}
catapult::utils::BasicBaseValue::operator<<
friend std::ostream & operator<<(std::ostream &out, TBaseValue baseValue)
Insertion operator for outputting baseValue to out.
Definition: BaseValue.h:89
catapult::utils::BasicBaseValue::m_value
ImmutableValue< TValue > m_value
Definition: BaseValue.h:95
catapult::utils::BasicBaseValue::operator<=
constexpr bool operator<=(TBaseValue rhs) const
Returns true if this value is less than or equal to rhs.
Definition: BaseValue.h:79
catapult::utils::BasicBaseValue::operator!=
constexpr bool operator!=(TBaseValue rhs) const
Returns true if this value is not equal to rhs.
Definition: BaseValue.h:64
catapult::utils::BasicBaseValue< uint64_t, UnresolvedMosaicId_tag, BaseValue< uint64_t, UnresolvedMosaicId_tag > >::ValueType
uint64_t ValueType
Raw value type.
Definition: BaseValue.h:33
catapult::utils::BasicBaseValue::BasicBaseValue
constexpr BasicBaseValue(const BasicBaseValue &rhs)
Creates a copy of rhs.
Definition: BaseValue.h:41
catapult::utils::BaseValue::operator+
constexpr BaseValue operator+(BaseValue rhs) const
Adds rhs and this value and returns a new value.
Definition: BaseValue.h:109
catapult::utils::BasicBaseValue::operator>=
constexpr bool operator>=(TBaseValue rhs) const
Returns true if this value is greater than or equal to rhs.
Definition: BaseValue.h:69
catapult::utils::BasicBaseValue::unwrap
constexpr ValueType unwrap() const
Unwraps this value and returns the underlying raw value.
Definition: BaseValue.h:53
catapult::utils::BaseValue
Immutable wrapper for basic types, to provide some type-safety.
Definition: BaseValue.h:100
catapult::utils::BasicBaseValue
Base class for immutable wrappers of basic types, to provide some type-safety.
Definition: BaseValue.h:30
catapult::utils::BaseValue::BaseValue
constexpr BaseValue(TValue value=0)
Creates a base value from a raw value.
Definition: BaseValue.h:103
catapult::utils::BasicBaseValue::operator==
constexpr bool operator==(TBaseValue rhs) const
Returns true if this value is equal to rhs.
Definition: BaseValue.h:59
catapult::utils::BaseValue::operator-
constexpr BaseValue operator-(BaseValue rhs) const
Subtracts rhs from this value and returns a new value.
Definition: BaseValue.h:114
catapult::utils::BasicBaseValue::operator<
constexpr bool operator<(TBaseValue rhs) const
Returns true if this value is less than rhs.
Definition: BaseValue.h:84
ImmutableValue.h
catapult::utils::BasicBaseValue::operator=
BasicBaseValue & operator=(BasicBaseValue rhs)
Assigns rhs to this.
Definition: BaseValue.h:46
catapult::utils::BasicBaseValue::operator>
constexpr bool operator>(TBaseValue rhs) const
Returns true if this value is greater than rhs.
Definition: BaseValue.h:74
catapult::utils::BasicBaseValue::BasicBaseValue
constexpr BasicBaseValue(TValue value)
Creates a basic base value from a raw value.
Definition: BaseValue.h:37
catapult::utils::ImmutableValue
A move-only value wrapper.
Definition: ImmutableValue.h:30
catapult
Definition: AddressExtractionExtension.cpp:28