Utilities
Utilities header only library
Triplet.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_TRIPLET_H
7 #define UTILS_TRIPLET_H
8 #include <array>
9 #include <Utils/ExtSTD.h>
10 
11 namespace utils
12 {
13 
15  template <typename Type>
16  class Triplet
17  {
18  public:
19 
20  Triplet() = default;
21 
22  Triplet(Type val_1, Type val_2, Type val_3)
23  {
24  Set(val_1, val_2, val_3);
25  };
26 
28  virtual void Set(Type val_1, Type val_2, Type val_3)
29  {
30  data_ = { val_1, val_2, val_3 };
31  };
32 
34  virtual bool Contains(const Type value) const
35  {
36  return std_ext::Contains(value, data_);
37  };
38 
40  virtual Type &operator[] (size_t idx)
41  {
42  return data_[idx];
43  };
44 
45 #ifdef _WIN32
46  __declspec(property(get = GetFirst, put = SetFirst)) Type a;
47  __declspec(property(get = GetSecond, put = SetSecond)) Type b;
48  __declspec(property(get = GetThird, put = SetThird)) Type c;
49 #endif // _WIN32
50 
52  Type GetFirst() const
53  {
54  return data_[0];
55  };
56 
58  void SetFirst(Type value)
59  {
60  data_[0] = value;
61  };
62 
64  Type GetSecond() const
65  {
66  return data_[1];
67  };
68 
70  void SetSecond(Type value)
71  {
72  data_[1] = value;
73  };
74 
76  Type GetThird() const
77  {
78  return data_[2];
79  };
80 
82  void SetThird(Type value)
83  {
84  data_[2] = value;
85  };
86 
88  virtual bool operator== (const Triplet<Type> &obj) const
89  {
90  for (const auto &val : this->data_)
91  {
92  if (!obj.Contains(val))
93  {
94  return false;
95  }
96  }
97  return true;
98  };
99 
101  virtual bool operator!= (const Triplet<Type> &obj) const
102  {
103  return !operator==(obj);
104  };
105 
107  Triplet &operator+=(const Type val)
108  {
109  for (auto &data : this->data_)
110  {
111  data = data + val;
112  }
113  return *this;
114  }
115 
117  Triplet &operator*=(const Type val)
118  {
119  for (auto &data : this->data_)
120  {
121  data = data * val;
122  }
123  return *this;
124  }
125 
126  private:
127  std::array<Type, 3> data_;
128  };
129 
130 }
131 #endif /* !UTILS_TRIPLET_H */
void SetSecond(Type value)
Sets the second value.
Definition: Triplet.h:70
Type GetFirst() const
Returns the first value.
Definition: Triplet.h:52
bool Contains(const std::string &substring, const std::string &text)
Checks if the text contains substring.
Definition: ExtSTD.h:327
virtual void Set(Type val_1, Type val_2, Type val_3)
Sets values.
Definition: Triplet.h:28
Type GetThird() const
Returns the third value.
Definition: Triplet.h:76
Type GetSecond() const
Returns the second value.
Definition: Triplet.h:64
Structure which holds three variables of same type.
Definition: Triplet.h:16
void SetThird(Type value)
Sets the third value.
Definition: Triplet.h:82
Triplet & operator*=(const Type val)
Multiples all values with a specific value.
Definition: Triplet.h:117
void SetFirst(Type value)
Sets the first value.
Definition: Triplet.h:58
virtual bool operator!=(const Triplet< Type > &obj) const
Compares two triplets. The order of values is not important.
Definition: Triplet.h:101
virtual Type & operator[](size_t idx)
Returns reference to the value by a specified index.
Definition: Triplet.h:40
virtual bool operator==(const Triplet< Type > &obj) const
Compares two triplets. The order of values is not important.
Definition: Triplet.h:88
Triplet & operator+=(const Type val)
Increases all values by a specific amount.
Definition: Triplet.h:107
General namespace for utilities.
Definition: BulletConversions.h:9
virtual bool Contains(const Type value) const
Checks if at least one of the three is equal to the value.
Definition: Triplet.h:34