CatapultServer  v0.5.0.1 (Elephant)
MosaicProperties.h
Go to the documentation of this file.
1 
21 #pragma once
22 #include "MosaicProperty.h"
23 #include "catapult/utils/Casting.h"
24 #include "catapult/types.h"
25 #include <array>
26 
27 namespace catapult { namespace model {
28 
29 #pragma pack(push, 1)
30 
34  uint8_t Count;
35 
38 
40  uint8_t Divisibility;
41  };
42 
43 #pragma pack(pop)
44 
47  private:
48  using PropertiesContainer = std::array<MosaicProperty, Num_Mosaic_Properties>;
49 
50  public:
52  using PropertyValuesContainer = std::array<uint64_t, Num_Mosaic_Properties>;
53 
54  private:
55  explicit MosaicProperties(const PropertyValuesContainer& values) {
56  uint8_t i = 0;
57  for (auto value : values) {
58  m_properties[i] = { static_cast<MosaicPropertyId>(i), value };
59  ++i;
60  }
61  }
62 
63  public:
66  return MosaicProperties(values);
67  }
68 
69  public:
71  size_t size() const {
72  return Num_Mosaic_Properties;
73  }
74 
76  auto begin() const {
77  return m_properties.cbegin();
78  }
79 
81  auto end() const {
82  return m_properties.cend();
83  }
84 
85  private:
86  template<typename T>
87  T property(MosaicPropertyId id) const {
89  }
90 
91  public:
93  bool is(MosaicFlags testedFlag) const {
94  return HasFlag(testedFlag, property<MosaicFlags>(MosaicPropertyId::Flags));
95  }
96 
98  uint8_t divisibility() const {
99  return property<uint8_t>(MosaicPropertyId::Divisibility);
100  }
101 
104  return property<BlockDuration>(MosaicPropertyId::Duration);
105  }
106 
107  public:
109  bool operator==(const MosaicProperties& rhs) const {
110  for (auto i = 0u; i < Num_Mosaic_Properties; ++i) {
111  if (m_properties[i].Value != rhs.m_properties[i].Value)
112  return false;
113  }
114 
115  return true;
116  }
117 
119  bool operator!=(const MosaicProperties& rhs) const {
120  return !(*this == rhs);
121  }
122 
123  private:
124  std::array<MosaicProperty, Num_Mosaic_Properties> m_properties;
125  };
126 
129 }}
catapult::model::MosaicPropertyId
MosaicPropertyId
Available mosaic property ids.
Definition: MosaicProperty.h:28
catapult::model::MosaicProperties::operator!=
bool operator!=(const MosaicProperties &rhs) const
Returns true if this properties bag is not equal to rhs.
Definition: MosaicProperties.h:119
catapult::model::MosaicProperties::m_properties
std::array< MosaicProperty, Num_Mosaic_Properties > m_properties
Definition: MosaicProperties.h:124
catapult::model::MosaicPropertyId::Duration
Mosaic duration.
catapult::utils::to_underlying_type
constexpr std::underlying_type_t< TEnum > to_underlying_type(TEnum value)
Converts a strongly typed enumeration value to its underlying integral value.
Definition: Casting.h:37
catapult::model::MosaicProperties::end
auto end() const
Returns a const iterator to the element following the last property.
Definition: MosaicProperties.h:81
catapult::model::MosaicProperties::duration
BlockDuration duration() const
Gets mosaic duration.
Definition: MosaicProperties.h:103
catapult::model::MosaicProperties::MosaicProperties
MosaicProperties(const PropertyValuesContainer &values)
Definition: MosaicProperties.h:55
catapult::utils::BasicBaseValue::unwrap
constexpr ValueType unwrap() const
Unwraps this value and returns the underlying raw value.
Definition: BaseValue.h:53
catapult::Eternal_Artifact_Duration
constexpr BlockDuration Eternal_Artifact_Duration(0)
Duration of eternal artifact.
Value
uint32_t Value
Definition: BlockScorer.cpp:32
catapult::model::MosaicProperties::is
bool is(MosaicFlags testedFlag) const
Returns true if mosaic flags contain testedFlag.
Definition: MosaicProperties.h:93
catapult::utils::BaseValue< uint64_t, BlockDuration_tag >
catapult::model::MosaicFlags
MosaicFlags
Mosaic property flags.
Definition: MosaicProperty.h:50
catapult::model::MosaicProperty
Mosaic property composed of an id and a value.
Definition: MosaicProperty.h:69
catapult::model::MosaicPropertiesHeader::Flags
MosaicFlags Flags
Mosaic flags.
Definition: MosaicProperties.h:37
CATAPULT_SET_REQUIRED_PROPERTY
#define CATAPULT_SET_REQUIRED_PROPERTY(KEY, VALUE)
catapult::model::MosaicPropertiesHeader::Divisibility
uint8_t Divisibility
Mosaic divisibility.
Definition: MosaicProperties.h:40
catapult::model::Num_Mosaic_Properties
constexpr size_t Num_Mosaic_Properties
Number of available properties.
Definition: MosaicProperty.h:81
catapult::model::MosaicPropertyId::Divisibility
Mosaic divisibility.
MosaicProperty.h
catapult::model::ExtractAllProperties
MosaicProperties ExtractAllProperties(const MosaicPropertiesHeader &header, const MosaicProperty *pProperties)
Extracts all properties from header and pProperties.
Definition: MosaicProperties.cpp:32
MosaicProperties.h
catapult::model::MosaicProperties::FromValues
static MosaicProperties FromValues(const PropertyValuesContainer &values)
Creates mosaic properties from values.
Definition: MosaicProperties.h:65
constants.h
catapult::model::MosaicProperties::PropertiesContainer
std::array< MosaicProperty, Num_Mosaic_Properties > PropertiesContainer
Definition: MosaicProperties.h:48
catapult::model::MosaicPropertiesHeader
Mosaic properties header.
Definition: MosaicProperties.h:32
catapult::model::MosaicPropertyId::Sentinel_Property_Id
catapult::model::MosaicProperties::size
size_t size() const
Gets the number of properties.
Definition: MosaicProperties.h:71
catapult::model::MosaicPropertiesHeader::Count
uint8_t Count
Number of elements in optional properties array.
Definition: MosaicProperties.h:34
types.h
Casting.h
catapult
Definition: AddressExtractionExtension.cpp:28
catapult::model::MosaicProperties::operator==
bool operator==(const MosaicProperties &rhs) const
Returns true if this properties bag is equal to rhs.
Definition: MosaicProperties.h:109
catapult::model::MosaicPropertyId::Flags
Mosaic flags.
catapult::model::MosaicProperties::divisibility
uint8_t divisibility() const
Gets mosaic divisibility.
Definition: MosaicProperties.h:98
catapult::model::MosaicProperties::property
T property(MosaicPropertyId id) const
Definition: MosaicProperties.h:87
catapult::model::MosaicProperties
Container for mosaic properties.
Definition: MosaicProperties.h:46
catapult::model::MosaicProperties::PropertyValuesContainer
std::array< uint64_t, Num_Mosaic_Properties > PropertyValuesContainer
Type of values container.
Definition: MosaicProperties.h:52
catapult::model::MosaicProperties::begin
auto begin() const
Returns a const iterator to the first property.
Definition: MosaicProperties.h:76