src/PropertyMacro.h

changeset 675
450827da2376
parent 629
b75c6cce02e2
child 630
42ec68fcad9e
equal deleted inserted replaced
674:3d8ab0f89102 675:450827da2376
1 /*
2 * LDForge: LDraw parts authoring CAD
3 * Copyright (C) 2013, 2014 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 { \
29 return m_##NAME; \
30 } \
31 \
32 ACCESS: \
33 DEFINE_WRITE_METHOD_##WRITETYPE( TYPE, NAME ) \
34 DEFINE_PROPERTY_##OPS( TYPE, NAME )
35
36 #define GET_READ_METHOD( NAME, OPS ) \
37 GET_READ_METHOD_##OPS( NAME )
38
39 #define GET_READ_METHOD_BOOL_OPS( NAME ) is##NAME()
40 #define GET_READ_METHOD_NO_OPS( NAME ) get##NAME()
41 #define GET_READ_METHOD_STR_OPS( NAME ) get##NAME()
42 #define GET_READ_METHOD_NUM_OPS( NAME ) get##NAME()
43 #define GET_READ_METHOD_LIST_OPS( NAME ) get##NAME()
44
45 #define DEFINE_WRITE_METHOD_STOCK_WRITE( TYPE, NAME ) \
46 inline void set##NAME( TYPE const& NAME##_ ) \
47 { \
48 m_##NAME = NAME##_; \
49 }
50
51 #define DEFINE_WRITE_METHOD_CUSTOM_WRITE( TYPE, NAME ) \
52 void set##NAME( TYPE const& NAME##_ ); \
53
54 #define DEFINE_WITH_CB( NAME ) void NAME##Changed();
55 #define DEFINE_NO_CB( NAME )
56
57 #define DEFINE_PROPERTY_NO_OPS( TYPE, NAME )
58
59 #define DEFINE_PROPERTY_STR_OPS( TYPE, NAME ) \
60 void appendTo##NAME( TYPE a ) \
61 { \
62 TYPE tmp( m_##NAME ); \
63 tmp.append( a ); \
64 set##NAME( tmp ); \
65 } \
66 \
67 void prependTo##NAME( TYPE a ) \
68 { \
69 TYPE tmp( m_##NAME ); \
70 tmp.prepend( a ); \
71 set##NAME( tmp ); \
72 } \
73 \
74 void replaceIn##NAME( TYPE a, TYPE b ) \
75 { \
76 TYPE tmp( m_##NAME ); \
77 tmp.replace( a, b ); \
78 set##NAME( tmp ); \
79 }
80
81 #define DEFINE_PROPERTY_NUM_OPS( TYPE, NAME ) \
82 inline void increase##NAME( TYPE a = 1 ) \
83 { \
84 set##NAME( m_##NAME + a ); \
85 } \
86 \
87 inline void decrease##NAME( TYPE a = 1 ) \
88 { \
89 set##NAME( m_##NAME - a ); \
90 }
91
92 #define DEFINE_PROPERTY_BOOL_OPS( TYPE, NAME ) \
93 inline void toggle##NAME() \
94 { \
95 set##NAME( !m_##NAME ); \
96 }
97
98 #define DEFINE_PROPERTY_LIST_OPS( TYPE, NAME ) \
99 void pushTo##NAME( const TYPE::value_type& a ) \
100 { \
101 TYPE tmp( m_##NAME ); \
102 tmp.push_back( a ); \
103 set##NAME( tmp ); \
104 } \
105 \
106 void removeFrom##NAME( const TYPE::value_type& a ) \
107 { \
108 TYPE tmp( m_##NAME ); \
109 tmp.removeOne( a ); \
110 set##NAME( tmp ); \
111 } \
112 \
113 inline void clear##NAME() \
114 { \
115 set##NAME( TYPE() ); \
116 } \
117 \
118 public: \
119 inline int count##NAME() \
120 { \
121 return get##NAME().size(); \
122 }
123
124 #endif // LDFORGE_PROPERTY_H

mercurial