CatapultServer  v0.5.0.1 (Elephant)
WeakEntityInfo.h
Go to the documentation of this file.
1 
21 #pragma once
22 #include "VerifiableEntity.h"
24 #include <iosfwd>
25 #include <vector>
26 
27 namespace catapult { namespace model { struct BlockHeader; } }
28 
29 namespace catapult { namespace model {
30 
32  template<typename TEntity>
34  public:
36  constexpr WeakEntityInfoT()
37  : m_pEntity(nullptr)
38  , m_pHash(nullptr)
39  , m_pAssociatedBlockHeader(nullptr)
40  {}
41 
44  constexpr WeakEntityInfoT(const TEntity& entity)
45  : m_pEntity(&entity)
46  , m_pHash(nullptr)
47  , m_pAssociatedBlockHeader(nullptr)
48  {}
49 
51  constexpr explicit WeakEntityInfoT(const TEntity& entity, const Hash256& hash)
52  : m_pEntity(&entity)
53  , m_pHash(&hash)
54  , m_pAssociatedBlockHeader(nullptr)
55  {}
56 
58  constexpr explicit WeakEntityInfoT(const TEntity& entity, const Hash256& hash, const BlockHeader& associatedBlockHeader)
59  : m_pEntity(&entity)
60  , m_pHash(&hash)
62  {}
63 
64  public:
66  constexpr bool isSet() const {
67  return !!m_pEntity;
68  }
69 
71  constexpr bool isHashSet() const {
72  return !!m_pHash;
73  }
74 
76  constexpr bool isAssociatedBlockHeaderSet() const {
77  return !!m_pAssociatedBlockHeader;
78  }
79 
80  public:
82  constexpr const TEntity& entity() const {
83  return *m_pEntity;
84  }
85 
87  constexpr EntityType type() const {
88  return m_pEntity->Type;
89  }
90 
92  constexpr const Hash256& hash() const {
93  return *m_pHash;
94  }
95 
97  constexpr const BlockHeader& associatedBlockHeader() const {
99  }
100 
101  public:
103  template<typename TEntityResult>
105  const auto& typedEntity = static_cast<const TEntityResult&>(entity());
108  : WeakEntityInfoT<TEntityResult>(typedEntity, hash());
109  }
110 
111  public:
113  constexpr bool operator==(const WeakEntityInfoT& rhs) const {
114  return m_pEntity == rhs.m_pEntity && m_pHash == rhs.m_pHash;
115  }
116 
118  constexpr bool operator!=(const WeakEntityInfoT& rhs) const {
119  return !(*this == rhs);
120  }
121 
122  private:
123  const TEntity* m_pEntity;
124  const Hash256* m_pHash;
126  };
127 
129 
131  template<typename TEntity>
132  std::ostream& operator<<(std::ostream& out, const WeakEntityInfoT<TEntity>& entityInfo) {
133  if (!entityInfo.isSet()) {
134  out << "WeakEntityInfo (unset)";
135  } else {
136  const auto& hash = entityInfo.hash();
137  out << entityInfo.entity() << " [" << utils::HexFormat(hash.cbegin(), hash.cend()) << "]";
138  }
139 
140  return out;
141  }
142 
144  using WeakEntityInfos = std::vector<WeakEntityInfo>;
145 }}
catapult::model::WeakEntityInfoT::operator==
constexpr bool operator==(const WeakEntityInfoT &rhs) const
Returns true if this info is equal to rhs.
Definition: WeakEntityInfo.h:113
catapult::model::WeakEntityInfoT::m_pHash
const Hash256 * m_pHash
Definition: WeakEntityInfo.h:124
catapult::model::WeakEntityInfoT::WeakEntityInfoT
constexpr WeakEntityInfoT(const TEntity &entity, const Hash256 &hash)
Creates an entity info around entity and hash.
Definition: WeakEntityInfo.h:51
catapult::utils::HexFormat
constexpr void HexFormat(const ByteArray< N, TTag > &)
catapult::model::WeakEntityInfoT::WeakEntityInfoT
constexpr WeakEntityInfoT(const TEntity &entity)
Definition: WeakEntityInfo.h:44
catapult::model::EntityType
EntityType
Enumeration of entity types.
Definition: EntityType.h:43
catapult::model::BlockHeader
Binary layout for a block header.
Definition: Block.h:34
catapult::model::WeakEntityInfoT::WeakEntityInfoT
constexpr WeakEntityInfoT(const TEntity &entity, const Hash256 &hash, const BlockHeader &associatedBlockHeader)
Creates an entity info around entity, hash and associatedBlockHeader.
Definition: WeakEntityInfo.h:58
catapult::model::WeakEntityInfoT::WeakEntityInfoT
constexpr WeakEntityInfoT()
Creates an entity info.
Definition: WeakEntityInfo.h:36
catapult::model::WeakEntityInfoT
Wrapper around a strongly typed entity and its associated metadata.
Definition: WeakEntityInfo.h:33
HexFormatter.h
VerifiableEntity.h
catapult::model::WeakEntityInfoT::entity
constexpr const TEntity & entity() const
Gets the entity.
Definition: WeakEntityInfo.h:82
catapult::model::WeakEntityInfoT::type
constexpr EntityType type() const
Gets the entity type.
Definition: WeakEntityInfo.h:87
catapult::model::WeakEntityInfoT::m_pEntity
const TEntity * m_pEntity
Definition: WeakEntityInfo.h:123
catapult::model::WeakEntityInfoT::hash
constexpr const Hash256 & hash() const
Gets the entity hash.
Definition: WeakEntityInfo.h:92
catapult::model::WeakEntityInfoT::operator!=
constexpr bool operator!=(const WeakEntityInfoT &rhs) const
Returns true if this info is not equal to rhs.
Definition: WeakEntityInfo.h:118
catapult::model::WeakEntityInfoT::associatedBlockHeader
constexpr const BlockHeader & associatedBlockHeader() const
Gets the associated block header.
Definition: WeakEntityInfo.h:97
catapult::model::operator<<
std::ostream & operator<<(std::ostream &out, const EmbeddedTransaction &transaction)
Insertion operator for outputting transaction to out.
Definition: EmbeddedTransaction.cpp:28
catapult::model::WeakEntityInfoT::isSet
constexpr bool isSet() const
Returns true if this info has an associated entity.
Definition: WeakEntityInfo.h:66
catapult::model::WeakEntityInfoT::isHashSet
constexpr bool isHashSet() const
Returns true if this info has an associated hash.
Definition: WeakEntityInfo.h:71
catapult
Definition: AddressExtractionExtension.cpp:28
catapult::model::WeakEntityInfoT::m_pAssociatedBlockHeader
const BlockHeader * m_pAssociatedBlockHeader
Definition: WeakEntityInfo.h:125
catapult::model::WeakEntityInfoT::cast
WeakEntityInfoT< TEntityResult > cast() const
Coerces this info into a differently typed info.
Definition: WeakEntityInfo.h:104
catapult::utils::ByteArray< Hash256_Size, Hash256_tag >
catapult::model::WeakEntityInfoT::isAssociatedBlockHeaderSet
constexpr bool isAssociatedBlockHeaderSet() const
Returns true if this info has an associated block header.
Definition: WeakEntityInfo.h:76
catapult::model::WeakEntityInfos
std::vector< WeakEntityInfo > WeakEntityInfos
A container of weak entity infos.
Definition: WeakEntityInfo.h:144