87 #endif // RELEASE |
87 #endif // RELEASE |
88 |
88 |
89 #define PROP_NAME(GET) m_##GET |
89 #define PROP_NAME(GET) m_##GET |
90 |
90 |
91 #define READ_ACCESSOR(T, GET) \ |
91 #define READ_ACCESSOR(T, GET) \ |
92 T const& GET () const { return PROP_NAME (GET); } |
92 T const& GET () const |
93 |
93 |
94 #define SET_ACCESSOR(T, GET, SET) \ |
94 #define SET_ACCESSOR(T, SET) \ |
95 T const& SET (T val) { PROP_NAME (GET) = val; return PROP_NAME (GET); } |
95 void SET (T val) |
96 |
96 |
97 // Read-only, private property with a get accessor |
97 // Read-only, private property with a get accessor |
|
98 #define DECLARE_READ_PROPERTY(T, GET, SET) \ |
|
99 private: \ |
|
100 T PROP_NAME (GET); \ |
|
101 SET_ACCESSOR (T, SET); \ |
|
102 public: \ |
|
103 READ_ACCESSOR (T, GET); |
|
104 |
|
105 // Read/write private property with get and set accessors |
|
106 #define DECLARE_PROPERTY(T, GET, SET) \ |
|
107 private: \ |
|
108 T PROP_NAME (GET); \ |
|
109 public: \ |
|
110 READ_ACCESSOR (T, GET); \ |
|
111 SET_ACCESSOR (T, SET); |
|
112 |
|
113 #define DEFINE_PROPERTY(T, CLASS, GET, SET) \ |
|
114 READ_ACCESSOR (T, CLASS::GET) { return PROP_NAME (GET); } \ |
|
115 SET_ACCESSOR (T, CLASS::SET) { PROP_NAME (GET) = val; } |
|
116 |
|
117 // Shortcuts |
|
118 #define PROPERTY(T, GET, SET) \ |
|
119 private: \ |
|
120 T PROP_NAME (GET); \ |
|
121 public: \ |
|
122 READ_ACCESSOR (T, GET) { return PROP_NAME (GET); } \ |
|
123 SET_ACCESSOR (T, SET) { PROP_NAME (GET) = val; } |
|
124 |
98 #define READ_PROPERTY(T, GET, SET) \ |
125 #define READ_PROPERTY(T, GET, SET) \ |
99 private: \ |
126 private: \ |
100 T PROP_NAME (GET); \ |
127 T PROP_NAME (GET); \ |
101 SET_ACCESSOR (T, GET, SET) \ |
128 SET_ACCESSOR (T, SET) { PROP_NAME (GET) = val; } \ |
102 public: \ |
129 public: \ |
103 READ_ACCESSOR (T, GET) |
130 READ_ACCESSOR (T, GET) { return PROP_NAME (GET); } |
104 |
|
105 // Same as above except not const |
|
106 #define MUTABLE_READ_PROPERTY(T, GET) \ |
|
107 private: \ |
|
108 T PROP_NAME(GET); \ |
|
109 public: \ |
|
110 T& GET () { return PROP_NAME(GET); } |
|
111 |
|
112 // Read/write private property with get and set accessors |
|
113 #define PROPERTY(T, GET, SET) \ |
|
114 private: \ |
|
115 T PROP_NAME(GET); \ |
|
116 public: \ |
|
117 READ_ACCESSOR(T, GET) \ |
|
118 SET_ACCESSOR(T, GET, SET) |
|
119 |
|
120 // Property that triggers a callback when it is changed |
|
121 #define CALLBACK_PROPERTY(T, GET, SET, CALLBACK) \ |
|
122 private: \ |
|
123 T PROP_NAME(GET); \ |
|
124 public: \ |
|
125 READ_ACCESSOR(T, GET) \ |
|
126 void CALLBACK (); \ |
|
127 T const& SET (T val) { \ |
|
128 PROP_NAME(GET) = val; \ |
|
129 CALLBACK (); \ |
|
130 return m_##GET; \ |
|
131 } |
|
132 |
|
133 // Property with thread locking, use when multiple threads access the same property |
|
134 // Comes with a callback function for detecting when the value is changed. |
|
135 #define THREAD_PROPERTY(T, GET, SET) \ |
|
136 private: \ |
|
137 T PROP_NAME (GET); \ |
|
138 QMutex m_threadLock_##GET; \ |
|
139 public: \ |
|
140 READ_ACCESSOR(T, GET) \ |
|
141 void callback_##SET (); \ |
|
142 T const& SET (T val) { \ |
|
143 m_threadLock_##GET.lock (); \ |
|
144 PROP_NAME (GET) = val; \ |
|
145 callback_##SET (); \ |
|
146 m_threadLock_##GET.unlock (); \ |
|
147 return m_##GET; \ |
|
148 } |
|
149 |
131 |
150 #ifdef null |
132 #ifdef null |
151 #undef null |
133 #undef null |
152 #endif // null |
134 #endif // null |
153 |
135 |