Utilities
Utilities header only library
Property.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 /*
7  Copyright (C) Skeletex Research, s.r.o. - All Rights Reserved
8  Unauthorized copying of this file, via any medium is strictly prohibited
9  Proprietary and confidential
10 */
11 #ifndef UTILS_PROPERTY_H
12 #define UTILS_PROPERTY_H
13 
14 #include <iostream>
15 
16 namespace utils
17 {
18 
19  template<typename C, typename T, T (C::*getter)() const, void (C::*setter)(const T &)>
20  struct Property
21  {
22  C *instance;
23 
24  Property(C *instance)
25  : instance(instance)
26  {
27  }
28 
29  operator T() const
30  {
31  return (instance->*getter)();
32  }
33 
34  Property &operator=(const T &value)
35  {
36  (instance->*setter)(value);
37  return *this;
38  }
39 
40  template<typename C2, typename T2,
41  T2 (C2::*getter2)(), void (C2::*setter2)(const T2 &)>
42  Property &operator=(const Property<C2, T2, getter2, setter2> &other)
43  {
44  return *this = (other.instance->*getter2)();
45  }
46 
47  Property &operator=(const Property &other)
48  {
49  return *this = (other.instance->*getter)();
50  }
51  };
52 
53  template<typename C, typename T, T (C::*getter)() const, void (C::*setter)(T)>
54  struct PropertyByValue
55  {
56  C *instance;
57 
58  PropertyByValue(C *instance)
59  : instance(instance)
60  {
61  }
62 
63  operator T() const
64  {
65  return (instance->*getter)();
66  }
67 
68  PropertyByValue &operator=(const T &value)
69  {
70  (instance->*setter)(value);
71  return *this;
72  }
73 
74  template<typename C2, typename T2,
75  T2 (C2::*getter2)(), void (C2::*setter2)(T2)>
76  PropertyByValue &operator=(const PropertyByValue<C2, T2, getter2, setter2> &other)
77  {
78  return *this = (other.instance->*getter2)();
79  }
80 
81  PropertyByValue &operator=(const PropertyByValue &other)
82  {
83  return *this = (other.instance->*getter)();
84  }
85  };
86 
87 }
88 #endif /* !UTILS_PROPERTY_H */
General namespace for utilities.
Definition: BulletConversions.h:9