CatapultServer  v0.5.0.1 (Elephant)
Namespace.h
Go to the documentation of this file.
1 
21 #pragma once
22 #include "NamespaceLifetime.h"
25 #include "catapult/types.h"
26 
27 namespace catapult { namespace state {
28 
30  class Namespace {
31  public:
33 
34  public:
36  explicit Namespace(const Path& path) : m_path(path) {
37  if (m_path.empty())
38  CATAPULT_THROW_OUT_OF_RANGE("path cannot be empty");
39  }
40 
41  public:
43  NamespaceId id() const {
44  return m_path[m_path.size() - 1];
45  }
46 
49  return 1 == m_path.size() ? Namespace_Base_Id : m_path[m_path.size() - 2];
50  }
51 
53  NamespaceId rootId() const {
54  return m_path[0];
55  }
56 
58  bool isRoot() const {
59  return 1 == m_path.size();
60  }
61 
63  const Path& path() const {
64  return m_path;
65  }
66 
67  public:
71  CATAPULT_THROW_OUT_OF_RANGE("maximum depth for namepsace path exceeded");
72 
73  Path childPath = m_path;
74  childPath.push_back(id);
75  return Namespace(childPath);
76  }
77 
78  public:
80  bool operator==(const Namespace& rhs) const {
81  return m_path == rhs.m_path;
82  }
83 
85  bool operator!=(const Namespace& rhs) const {
86  return !(*this == rhs);
87  }
88 
89  private:
91  };
92 }}
NamespaceConstants.h
catapult::utils::CheckedArray::empty
bool empty() const
Returns true if the array is empty, false otherwise.
Definition: CheckedArray.h:35
CheckedArray.h
catapult::state::Namespace
A catapult namespace.
Definition: Namespace.h:30
catapult::Namespace_Base_Id
constexpr NamespaceId Namespace_Base_Id(0)
Base id for namespaces.
catapult::Namespace_Max_Depth
constexpr size_t Namespace_Max_Depth
Maximum number of parts for a namespace.
Definition: plugins/txes/namespace/src/constants.h:27
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::Namespace::operator!=
bool operator!=(const Namespace &rhs) const
Returns true if this namespace is not equal to rhs.
Definition: Namespace.h:85
catapult::utils::CheckedArray< NamespaceId, Namespace_Max_Depth >
catapult::state::Namespace::path
const Path & path() const
Gets the path.
Definition: Namespace.h:63
catapult::utils::CheckedArray::size
size_t size() const
Gets the size of the array.
Definition: CheckedArray.h:40
catapult::utils::BaseValue< uint64_t, NamespaceId_tag >
catapult::state::Namespace::createChild
Namespace createChild(NamespaceId id) const
Creates a child namespace of this namespace with namespace identifier id.
Definition: Namespace.h:69
catapult::state::Namespace::isRoot
bool isRoot() const
Gets a value indicating whether or not this namespace is a root namespace.
Definition: Namespace.h:58
CATAPULT_THROW_OUT_OF_RANGE
#define CATAPULT_THROW_OUT_OF_RANGE(MESSAGE)
Macro used to throw a catapult out of range.
Definition: exceptions.h:191
catapult::state::Namespace::m_path
Path m_path
Definition: Namespace.h:90
catapult::state::Namespace::parentId
NamespaceId parentId() const
Gets the parent namespace id.
Definition: Namespace.h:48
catapult::utils::CheckedArray::push_back
void push_back(T val)
Definition: CheckedArray.h:51
types.h
catapult
Definition: AddressExtractionExtension.cpp:28
catapult::state::Namespace::operator==
bool operator==(const Namespace &rhs) const
Returns true if this namespace is equal to rhs.
Definition: Namespace.h:80
NamespaceLifetime.h
catapult::state::Namespace::Namespace
Namespace(const Path &path)
Creates a namespace around path.
Definition: Namespace.h:36