CatapultServer  v0.5.0.1 (Elephant)
RootNamespace.h
Go to the documentation of this file.
1 
21 #pragma once
22 #include "Namespace.h"
23 #include "NamespaceAlias.h"
24 #include "catapult/utils/Hashers.h"
25 #include <set>
26 #include <unordered_map>
27 
28 namespace catapult { namespace state {
29 
31  class RootNamespace {
32  private:
33  struct PathsComparator {
34  public:
35  bool operator()(const Namespace::Path& lhs, const Namespace::Path& rhs) const {
36  return std::lexicographical_compare(lhs.cbegin(), lhs.cend(), rhs.cbegin(), rhs.cend());
37  }
38  };
39 
40  public:
43  public:
46  {}
47 
48  public:
51 
54  };
55 
56  using Children = std::unordered_map<NamespaceId, ChildNamespaceData, utils::BaseValueHasher<NamespaceId>>;
57  using OrderedChildPaths = std::set<Namespace::Path, PathsComparator>;
58 
59  public:
62 
64  RootNamespace(NamespaceId id, const Key& owner, const NamespaceLifetime& lifetime, const std::shared_ptr<Children>& pChildren);
65 
66  public:
68  NamespaceId id() const;
69 
71  const Children& children() const;
72 
74  const Key& owner() const;
75 
77  const NamespaceLifetime& lifetime() const;
78 
80  bool empty() const;
81 
83  size_t size() const;
84 
85  public:
88  Namespace child(NamespaceId id) const;
89 
91  const NamespaceAlias& alias(NamespaceId id) const;
92 
93  public:
95  void add(const Namespace& ns);
96 
99  void remove(NamespaceId id);
100 
102  void setAlias(NamespaceId id, const NamespaceAlias& alias);
103 
104  public:
106  bool operator==(const RootNamespace& rhs) const;
107 
109  bool operator!=(const RootNamespace& rhs) const;
110 
111  public:
114  RootNamespace renew(const NamespaceLifetime& newLifetime) const;
115 
119 
120  private:
122  NamespaceAlias m_alias; // root namespace alias
125  std::shared_ptr<Children> m_pChildren;
126  };
127 }}
catapult::state::RootNamespace::ChildNamespaceData::Alias
NamespaceAlias Alias
Child namespace alias.
Definition: RootNamespace.h:53
catapult::state::RootNamespace::children
const Children & children() const
Gets a const reference to the children.
Definition: RootNamespace.cpp:45
catapult::state::RootNamespace::operator==
bool operator==(const RootNamespace &rhs) const
Returns true if this root namespace is equal to rhs.
Definition: RootNamespace.cpp:141
catapult::state::RootNamespace::PathsComparator::operator()
bool operator()(const Namespace::Path &lhs, const Namespace::Path &rhs) const
Definition: RootNamespace.h:35
catapult::state::RootNamespace::setAlias
void setAlias(NamespaceId id, const NamespaceAlias &alias)
Sets an alias for root or child namespace id.
Definition: RootNamespace.cpp:126
catapult::utils::CheckedArray::cend
const T * cend() const
Returns a const iterator that represents one past last element.
Definition: CheckedArray.h:75
catapult::state::Namespace
A catapult namespace.
Definition: Namespace.h:30
m_id
size_t m_id
Definition: AuditConsumer.cpp:65
Namespace.h
catapult::state::Namespace::rootId
NamespaceId rootId() const
Gets the corresponding root namespace id.
Definition: Namespace.h:53
catapult::state::Namespace::id
NamespaceId id() const
Gets the namespace id.
Definition: Namespace.h:43
catapult::state::RootNamespace::add
void add(const Namespace &ns)
Adds the child namespace ns.
Definition: RootNamespace.cpp:85
catapult::state::RootNamespace::child
Namespace child(NamespaceId id) const
Definition: RootNamespace.cpp:65
catapult::state::RootNamespace::size
size_t size() const
Gets the number of child namespaces.
Definition: RootNamespace.cpp:61
CATAPULT_THROW_INVALID_ARGUMENT_2
#define CATAPULT_THROW_INVALID_ARGUMENT_2(MESSAGE, PARAM1, PARAM2)
Macro used to throw a catapult invalid argument with two parameters.
Definition: exceptions.h:187
catapult::state::RootNamespace::m_owner
Key m_owner
Definition: RootNamespace.h:123
catapult::utils::CheckedArray< NamespaceId, Namespace_Max_Depth >
catapult::state::RootNamespace::remove
void remove(NamespaceId id)
Definition: RootNamespace.cpp:107
catapult::state::RootNamespace::ChildNamespaceData::ChildNamespaceData
ChildNamespaceData(const Namespace::Path &path)
Creates data around path.
Definition: RootNamespace.h:45
catapult::state::Namespace::path
const Path & path() const
Gets the path.
Definition: Namespace.h:63
catapult::state::RootNamespace::renew
RootNamespace renew(const NamespaceLifetime &newLifetime) const
Definition: RootNamespace.cpp:149
catapult::state::RootNamespace::ChildNamespaceData::Path
Namespace::Path Path
Child namespace path.
Definition: RootNamespace.h:50
catapult::utils::CheckedArray::size
size_t size() const
Gets the size of the array.
Definition: CheckedArray.h:40
catapult::state::RootNamespace::m_id
NamespaceId m_id
Definition: RootNamespace.h:121
catapult::state::RootNamespace::Children
std::unordered_map< NamespaceId, ChildNamespaceData, utils::BaseValueHasher< NamespaceId > > Children
Definition: RootNamespace.h:56
catapult::utils::BaseValue< uint64_t, NamespaceId_tag >
catapult::state::RootNamespace::OrderedChildPaths
std::set< Namespace::Path, PathsComparator > OrderedChildPaths
Definition: RootNamespace.h:57
catapult::state::RootNamespace::alias
const NamespaceAlias & alias(NamespaceId id) const
Gets a namespace alias for root or child namespace id.
Definition: RootNamespace.cpp:73
catapult::state::RootNamespace::m_pChildren
std::shared_ptr< Children > m_pChildren
Definition: RootNamespace.h:125
NamespaceAlias.h
RootNamespace.h
catapult::state::RootNamespace::RootNamespace
RootNamespace(NamespaceId id, const Key &owner, const NamespaceLifetime &lifetime)
Creates a root namespace around id, owner and liftime.
Definition: RootNamespace.cpp:26
catapult::state::RootNamespace::id
NamespaceId id() const
Gets the namespace id.
Definition: RootNamespace.cpp:41
catapult::state::Namespace::Path
utils::CheckedArray< NamespaceId, Namespace_Max_Depth > Path
Definition: Namespace.h:32
catapult::state::RootNamespace::empty
bool empty() const
Returns true if this root namespace has no children.
Definition: RootNamespace.cpp:57
catapult::state::RootNamespace::PathsComparator
Definition: RootNamespace.h:33
catapult::state::NamespaceLifetime
Lifetime of a namespace.
Definition: NamespaceLifetime.h:27
CATAPULT_THROW_INVALID_ARGUMENT_1
#define CATAPULT_THROW_INVALID_ARGUMENT_1(MESSAGE, PARAM1)
Macro used to throw a catapult invalid argument with a single parameter.
Definition: exceptions.h:183
catapult::state::NamespaceAlias
A namespace alias.
Definition: NamespaceAlias.h:39
AccountState.h
catapult::state::Namespace::parentId
NamespaceId parentId() const
Gets the parent namespace id.
Definition: Namespace.h:48
catapult::state::RootNamespace::m_lifetime
NamespaceLifetime m_lifetime
Definition: RootNamespace.h:124
catapult
Definition: AddressExtractionExtension.cpp:28
Hashers.h
catapult::state::RootNamespace::operator!=
bool operator!=(const RootNamespace &rhs) const
Returns true if this root namespace is not equal to rhs.
Definition: RootNamespace.cpp:145
catapult::state::RootNamespace::lifetime
const NamespaceLifetime & lifetime() const
Gets a const reference to the lifetime of this namespace.
Definition: RootNamespace.cpp:53
catapult::utils::ByteArray< Key_Size, Key_tag >
catapult::state::RootNamespace
A root namespace.
Definition: RootNamespace.h:31
catapult::state::RootNamespace::sortedChildPaths
OrderedChildPaths sortedChildPaths() const
Definition: RootNamespace.cpp:153
catapult::state::RootNamespace::m_alias
NamespaceAlias m_alias
Definition: RootNamespace.h:122
catapult::utils::CheckedArray::cbegin
const T * cbegin() const
Returns a const iterator that represents first element.
Definition: CheckedArray.h:70
catapult::state::RootNamespace::ChildNamespaceData
Child namespace information.
Definition: RootNamespace.h:42
catapult::state::RootNamespace::owner
const Key & owner() const
Gets a const reference to the owner of this namespace.
Definition: RootNamespace.cpp:49