Utilities
Utilities header only library
Couple.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_COUPLE_H
7 #define UTILS_COUPLE_H
8 #include <array>
9 
10 namespace utils
11 {
12 
14  template <typename Type>
15  class Couple
16  {
17  public:
18 
19  Couple() = default;
20 
21  Couple(Type val_1, Type val_2)
22  {
23  Set(val_1, val_2);
24  };
25 
27  void Set(Type val_1, Type val_2)
28  {
29  data_ = { val_1, val_2 };
30  };
31 
33  bool Contains(const Type value) const
34  {
35  return data_[0] == value || data_[1] == value;
36  };
37 
39  Type &operator[] (size_t idx)
40  {
41  return data_[idx];
42  };
43 
44 #ifdef _WIN32
45  __declspec(property(get = GetFirst, put = SetFirst)) Type a;
46  __declspec(property(get = GetSecond, put = SetSecond)) Type b;
47 #endif // _WIN32
48 
50  const Type &GetFirst() const
51  {
52  return data_[0];
53  };
54 
56  void SetFirst(Type value)
57  {
58  data_[0] = value;
59  };
60 
62  const Type &GetSecond() const
63  {
64  return data_[1];
65  };
66 
68  void SetSecond(Type value)
69  {
70  data_[1] = value;
71  };
72 
74  bool operator== (const Couple<Type> &other)
75  {
76  for (auto val : data_)
77  {
78  if (!other.Contains(val))
79  {
80  return false;
81  }
82  }
83  return true;
84  };
85 
87  bool operator!= (const Couple<Type> &other)
88  {
89  return !operator==(other);
90  };
91 
93  Couple &operator+=(const Type val)
94  {
95  for (auto &data : this->data_)
96  {
97  data = data + val;
98  }
99  return *this;
100  }
101 
103  Couple &operator*=(const Type val)
104  {
105  for (auto &data : this->data_)
106  {
107  data = data * val;
108  }
109  return *this;
110  }
111 
112  private:
113  std::array<Type, 2> data_;
114  };
115 
116 }
117 #endif /* !UTILS_COUPLE_H */
const Type & GetFirst() const
Returns the first value.
Definition: Couple.h:50
bool operator==(const Couple< Type > &other)
Compares two couples. The order of values is not important.
Definition: Couple.h:74
Structure holding two variables of the same type.
Definition: Couple.h:15
Type & operator[](size_t idx)
Returns reference to the value by a specified index.
Definition: Couple.h:39
void SetSecond(Type value)
Sets the second value.
Definition: Couple.h:68
const Type & GetSecond() const
Returns the second value.
Definition: Couple.h:62
bool operator!=(const Couple< Type > &other)
Compares two couples. The order of values is not important.
Definition: Couple.h:87
Couple & operator+=(const Type val)
Increases both values by a specific amount.
Definition: Couple.h:93
void SetFirst(Type value)
Sets the first value.
Definition: Couple.h:56
General namespace for utilities.
Definition: BulletConversions.h:9
bool Contains(const Type value) const
Checks if at least one of the two is equal to the value.
Definition: Couple.h:33
void Set(Type val_1, Type val_2)
Sets values.
Definition: Couple.h:27
Couple & operator*=(const Type val)
Multiples both values with a specific value.
Definition: Couple.h:103