src/common.h

changeset 540
0334789cb4d7
parent 539
72ad83a67165
equal deleted inserted replaced
539:72ad83a67165 540:0334789cb4d7
86 #else // WIN32 86 #else // WIN32
87 # define DIRSLASH "/" 87 # define DIRSLASH "/"
88 # define DIRSLASH_CHAR '/' 88 # define DIRSLASH_CHAR '/'
89 #endif // WIN32 89 #endif // WIN32
90 90
91 #define PROPERTY( ACCESS, TYPE, NAME, OPS, CALLBACK ) \ 91 #define PROPERTY( ACCESS, TYPE, NAME, OPS, WRITETYPE ) \
92 private: \ 92 private: \
93 TYPE m_##NAME; \ 93 TYPE m_##NAME; \
94 DEFINE_##CALLBACK( NAME ) \
95 \ 94 \
96 public: \ 95 public: \
97 inline TYPE const& GET_READ_METHOD( NAME, OPS ) const \ 96 inline TYPE const& GET_READ_METHOD( NAME, OPS ) const \
98 { return m_##NAME; \ 97 { return m_##NAME; \
99 } \ 98 } \
100 \ 99 \
101 ACCESS: \ 100 ACCESS: \
102 inline void set##NAME( TYPE const& NAME##_ ) \ 101 DEFINE_WRITE_METHOD_##WRITETYPE( TYPE, NAME ) \
103 { m_##NAME = NAME##_; \ 102 DEFINE_PROPERTY_##OPS( TYPE, NAME )
104 TRIGGER_CALLBACK( NAME, CALLBACK ) \
105 } \
106 \
107 DEFINE_PROPERTY_##OPS( TYPE, NAME, CALLBACK )
108 103
109 #define GET_READ_METHOD( NAME, OPS ) \ 104 #define GET_READ_METHOD( NAME, OPS ) \
110 GET_READ_METHOD_##OPS( NAME ) 105 GET_READ_METHOD_##OPS( NAME )
111 106
112 #define GET_READ_METHOD_BOOL_OPS( NAME ) is##NAME() 107 #define GET_READ_METHOD_BOOL_OPS( NAME ) is##NAME()
113 #define GET_READ_METHOD_NO_OPS( NAME ) get##NAME() 108 #define GET_READ_METHOD_NO_OPS( NAME ) get##NAME()
114 #define GET_READ_METHOD_STR_OPS( NAME ) get##NAME() 109 #define GET_READ_METHOD_STR_OPS( NAME ) get##NAME()
115 #define GET_READ_METHOD_NUM_OPS( NAME ) get##NAME() 110 #define GET_READ_METHOD_NUM_OPS( NAME ) get##NAME()
116 111
112 #define DEFINE_WRITE_METHOD_STOCK_WRITE( TYPE, NAME ) \
113 inline void set##NAME( TYPE const& NAME##_ ) \
114 { m_##NAME = NAME##_; \
115 }
116
117 #define DEFINE_WRITE_METHOD_CUSTOM_WRITE( TYPE, NAME ) \
118 void set##NAME( TYPE const& NAME##_ ); \
119
117 #define DEFINE_WITH_CB( NAME ) void NAME##Changed(); 120 #define DEFINE_WITH_CB( NAME ) void NAME##Changed();
118 #define DEFINE_NO_CB( NAME ) 121 #define DEFINE_NO_CB( NAME )
119 122
120 #define DEFINE_PROPERTY_NO_OPS( TYPE, NAME, CALLBACK ) 123 #define DEFINE_PROPERTY_NO_OPS( TYPE, NAME )
121 124
122 #define DEFINE_PROPERTY_STR_OPS( TYPE, NAME, CALLBACK ) \ 125 #define DEFINE_PROPERTY_STR_OPS( TYPE, NAME ) \
123 void append##NAME( TYPE a ) \ 126 void append##NAME( TYPE a ) \
124 { m_##NAME.append( a ); \ 127 { TYPE tmp( m_##NAME ); \
125 TRIGGER_CALLBACK( NAME, CALLBACK ) \ 128 tmp.append( a ); \
126 } \ 129 set##NAME( tmp ); \
127 \ 130 } \
128 void prepend##NAME( TYPE a ) \ 131 \
129 { m_##NAME.prepend( a ); \ 132 void prepend##NAME( TYPE a ) \
130 TRIGGER_CALLBACK( NAME, CALLBACK ) \ 133 { TYPE tmp( m_##NAME ); \
131 } \ 134 tmp.prepend( a ); \
132 \ 135 set##NAME( tmp ); \
133 void replaceIn##NAME( TYPE a, TYPE b ) \ 136 } \
134 { m_##NAME.replace( a, b ); \ 137 \
135 TRIGGER_CALLBACK( NAME, CALLBACK ) \ 138 void replaceIn##NAME( TYPE a, TYPE b ) \
136 } 139 { TYPE tmp( m_##NAME ); \
137 140 tmp.replace( a, b ); \
138 #define DEFINE_PROPERTY_NUM_OPS( TYPE, NAME, CALLBACK ) \ 141 set##NAME( tmp ); \
139 inline void increase##NAME( TYPE a = 1 ) \ 142 }
140 { m_##NAME += a; \ 143
141 TRIGGER_CALLBACK( NAME, CALLBACK ) \ 144 #define DEFINE_PROPERTY_NUM_OPS( TYPE, NAME ) \
142 } \ 145 inline void increase##NAME( TYPE a = 1 ) \
143 \ 146 { set##NAME( m_##NAME + a ); \
144 inline void decrease##NAME( TYPE a = 1 ) \ 147 } \
145 { m_##NAME -= a; \ 148 \
146 TRIGGER_CALLBACK( NAME, CALLBACK ) \ 149 inline void decrease##NAME( TYPE a = 1 ) \
147 } 150 { set##NAME( m_##NAME - a ); \
148 151 }
149 #define DEFINE_PROPERTY_BOOL_OPS( TYPE, NAME, CALLBACK ) \ 152
150 inline void toggle##NAME() \ 153 #define DEFINE_PROPERTY_BOOL_OPS( TYPE, NAME ) \
151 { m_##NAME = !m_##NAME; \ 154 inline void toggle##NAME() \
152 TRIGGER_CALLBACK( NAME, CALLBACK ) \ 155 { set##NAME( !m_##NAME ); \
153 } 156 }
154
155 #define TRIGGER_CALLBACK( NAME, CALLBACK ) \
156 TRIGGER_CALLBACK_##CALLBACK( NAME );
157
158 #define TRIGGER_CALLBACK_NO_CB( NAME )
159 #define TRIGGER_CALLBACK_WITH_CB( NAME ) \
160 NAME##Changed();
161 157
162 #ifdef null 158 #ifdef null
163 #undef null 159 #undef null
164 #endif // null 160 #endif // null
165 161

mercurial