Utilities
Utilities header only library
StrongID.h
1 /*
2  Copyright (C) Skeletex Research, s.r.o. - All Rights Reserved
3  Unauthorized copying of this file, via any medium is strictly prohibited
4  Proprietary and confidential
5 */
6 #ifndef UTILS_STRONG_ID_H
7 #define UTILS_STRONG_ID_H
8 #include <vector>
9 #include <string>
10 #include <Utils/StrongType.h>
11 #include <Utils/ExtSTD.h>
12 
13 
14 
15 namespace utils
16 {
27  template <typename PhantomType>
28  struct StrongId : public StrongType<uint32_t, PhantomType>
29  {
30  public:
31  using ValueType = uint32_t;
32 
35 
37  explicit StrongId(size_t value)
38  : StrongType<ValueType, PhantomType>(static_cast<ValueType>(value))
39  {}
40 
42  explicit StrongId(int value)
43  : StrongType<ValueType, PhantomType>(static_cast<ValueType>(value))
44  {}
45 
46 
48  inline StrongId Next() const
49  {
50  return StrongId(this->template As<ValueType>() + 1);
51  }
52 
54  inline std::string ToString() const
55  {
56  return std::to_string(this->template As<ValueType>());
57  }
58 
59 
61  static inline std::vector<StrongId<PhantomType>> CreateIds(const std::vector<unsigned> &ids)
62  {
63  return std_ext::Transformed(ids, [](const auto & id) { return StrongId<PhantomType>(id); });
64  }
65  };
66 }
67 
68 #endif /* !UTILS_STRONG_ID_H */
Template class implementation of a Named Strong Type.
Definition: StrongType.h:28
std::string ToString() const
Convert the id to string.
Definition: StrongID.h:54
StrongId(size_t value)
Construct from size_t.
Definition: StrongID.h:37
StrongId Next() const
An id following this one. Incremented by 1.
Definition: StrongID.h:48
StrongId(int value)
Construct from int.
Definition: StrongID.h:42
Template class implementation of a Named Strong Id (a Strong Type with an underlying unsigned integer...
Definition: StrongID.h:28
auto Transformed(const C &container, F Function)
Simplified wrapper for std::transform.
Definition: ExtSTD.h:831
General namespace for utilities.
Definition: BulletConversions.h:9
static std::vector< StrongId< PhantomType > > CreateIds(const std::vector< unsigned > &ids)
Creates vector of specific strong ids values from the vector of unsigned values.
Definition: StrongID.h:61