| |
1 /* |
| |
2 * LDForge: LDraw parts authoring CAD |
| |
3 * Copyright (C) 2013 Santeri Piippo |
| |
4 * |
| |
5 * This program is free software: you can redistribute it and/or modify |
| |
6 * it under the terms of the GNU General Public License as published by |
| |
7 * the Free Software Foundation, either version 3 of the License, or |
| |
8 * (at your option) any later version. |
| |
9 * |
| |
10 * This program is distributed in the hope that it will be useful, |
| |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| |
13 * GNU General Public License for more details. |
| |
14 * |
| |
15 * You should have received a copy of the GNU General Public License |
| |
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| |
17 */ |
| |
18 |
| |
19 #ifndef LDFORGE_PROPERTY_H |
| |
20 #define LDFORGE_PROPERTY_H |
| |
21 |
| |
22 #define PROPERTY( ACCESS, TYPE, NAME, OPS, WRITETYPE ) \ |
| |
23 private: \ |
| |
24 TYPE m_##NAME; \ |
| |
25 \ |
| |
26 public: \ |
| |
27 inline TYPE const& GET_READ_METHOD( NAME, OPS ) const \ |
| |
28 { return m_##NAME; \ |
| |
29 } \ |
| |
30 \ |
| |
31 ACCESS: \ |
| |
32 DEFINE_WRITE_METHOD_##WRITETYPE( TYPE, NAME ) \ |
| |
33 DEFINE_PROPERTY_##OPS( TYPE, NAME ) |
| |
34 |
| |
35 #define GET_READ_METHOD( NAME, OPS ) \ |
| |
36 GET_READ_METHOD_##OPS( NAME ) |
| |
37 |
| |
38 #define GET_READ_METHOD_BOOL_OPS( NAME ) is##NAME() |
| |
39 #define GET_READ_METHOD_NO_OPS( NAME ) get##NAME() |
| |
40 #define GET_READ_METHOD_STR_OPS( NAME ) get##NAME() |
| |
41 #define GET_READ_METHOD_NUM_OPS( NAME ) get##NAME() |
| |
42 |
| |
43 #define DEFINE_WRITE_METHOD_STOCK_WRITE( TYPE, NAME ) \ |
| |
44 inline void set##NAME( TYPE const& NAME##_ ) \ |
| |
45 { m_##NAME = NAME##_; \ |
| |
46 } |
| |
47 |
| |
48 #define DEFINE_WRITE_METHOD_CUSTOM_WRITE( TYPE, NAME ) \ |
| |
49 void set##NAME( TYPE const& NAME##_ ); \ |
| |
50 |
| |
51 #define DEFINE_WITH_CB( NAME ) void NAME##Changed(); |
| |
52 #define DEFINE_NO_CB( NAME ) |
| |
53 |
| |
54 #define DEFINE_PROPERTY_NO_OPS( TYPE, NAME ) |
| |
55 |
| |
56 #define DEFINE_PROPERTY_STR_OPS( TYPE, NAME ) \ |
| |
57 void append##NAME( TYPE a ) \ |
| |
58 { TYPE tmp( m_##NAME ); \ |
| |
59 tmp.append( a ); \ |
| |
60 set##NAME( tmp ); \ |
| |
61 } \ |
| |
62 \ |
| |
63 void prepend##NAME( TYPE a ) \ |
| |
64 { TYPE tmp( m_##NAME ); \ |
| |
65 tmp.prepend( a ); \ |
| |
66 set##NAME( tmp ); \ |
| |
67 } \ |
| |
68 \ |
| |
69 void replaceIn##NAME( TYPE a, TYPE b ) \ |
| |
70 { TYPE tmp( m_##NAME ); \ |
| |
71 tmp.replace( a, b ); \ |
| |
72 set##NAME( tmp ); \ |
| |
73 } |
| |
74 |
| |
75 #define DEFINE_PROPERTY_NUM_OPS( TYPE, NAME ) \ |
| |
76 inline void increase##NAME( TYPE a = 1 ) \ |
| |
77 { set##NAME( m_##NAME + a ); \ |
| |
78 } \ |
| |
79 \ |
| |
80 inline void decrease##NAME( TYPE a = 1 ) \ |
| |
81 { set##NAME( m_##NAME - a ); \ |
| |
82 } |
| |
83 |
| |
84 #define DEFINE_PROPERTY_BOOL_OPS( TYPE, NAME ) \ |
| |
85 inline void toggle##NAME() \ |
| |
86 { set##NAME( !m_##NAME ); \ |
| |
87 } |
| |
88 |
| |
89 #endif // LDFORGE_PROPERTY_H |