10#include "Arp/System/Core/Enum.hxx"
15namespace Arp {
namespace System {
namespace Nm {
namespace Internal
27template<
typename T,
typename TypeTag>
30 static_assert(std::is_unsigned<T>::value,
"T must be an unsigned integer type");
31 static_assert(std::is_same<T, bool>::value == 0,
"Cannot be used with bool");
39 constexpr IdType() noexcept = default;
44 constexpr explicit
IdType(T value) noexcept : Value(value)
48 constexpr IdType(
const self_type&)
noexcept =
default;
52 other.Value = self_type().Value;
55 ~IdType() noexcept = default;
58 self_type& operator=(const self_type&) noexcept = default;
60 self_type& operator=(
IdType&& other) noexcept
62 this->Value = other.Value;
63 other.Value = self_type().Value;
68 constexpr bool operator<(
const self_type& rhs)
const noexcept
70 return this->Value < rhs.Value;
74 constexpr bool operator==(
const self_type& rhs)
const noexcept
76 return this->Value == rhs.Value;
80 constexpr bool operator!=(
const self_type& rhs)
const noexcept
82 return this->Value != rhs.Value;
101 constexpr static const self_type GetIncrementedId(
const self_type&
id)
noexcept
103 return self_type(
static_cast<T
>(
id.Value + 1));
107 constexpr static const self_type CreateInitalId() noexcept
109 return GetIncrementedId(self_type());
113 constexpr const self_type CreateNextIdUnique() const noexcept
115 return GetIncrementedId(*
this);
119 constexpr const self_type CreateNextId() const noexcept
121 return this->
IsValid() ? this->CreateNextIdUnique() : self_type();
126 T Value = std::numeric_limits<T>::min();
128 friend Internal::IdGenerator<self_type>;
132template<
typename T,
typename TypeTag>
142template<
typename IdType>
145 std::vector<typename IdType::type> result;
146 result.reserve(ids.size());
147 for (
const IdType& each : ids)
149 result.emplace_back(each.GetValue());
157template<
typename IdType>
160 std::vector<IdType> result;
161 result.reserve(ids.size());
162 for (
const typename IdType::type& each : ids)
164 result.emplace_back(
IdType(each));
176template<
typename T,
typename TypeTag>
177struct hash<
Arp::System::Nm::IdType<T, TypeTag>>
180 using result_type = std::size_t;
183 return std::hash<T>()(
id.GetValue());
Representation of an unique id
Definition: IdType.hpp:29
constexpr T GetValue() const noexcept
Returns the underlying value
Definition: IdType.hpp:94
constexpr bool IsValid() const noexcept
Returns true if this object represents a valid id (!= 0)
Definition: IdType.hpp:87
constexpr IdType() noexcept=default
Creates an invalid id
@ System
System components used by the System, Device, Plc or Io domains.
std::vector< typename IdType::type > ConvertIdTypesToRawIds(const std::vector< IdType > &ids)
Converts a vector of IdType to a vector of the underlying type
Definition: IdType.hpp:143
std::vector< IdType > ConvertRawIdsToIdTypes(const std::vector< typename IdType::type > &ids)
Converts a vector of underlying ids to a vector of IdType
Definition: IdType.hpp:158
Root namespace for the PLCnext API
Namespace of the C++ standard library