src/property.h

changeset 603
47e7773c7841
parent 600
209e3f1f7b2c
child 604
01bdac75994a
equal deleted inserted replaced
602:ac1744536b33 603:47e7773c7841
17 */ 17 */
18 18
19 #ifndef LDFORGE_PROPERTY_H 19 #ifndef LDFORGE_PROPERTY_H
20 #define LDFORGE_PROPERTY_H 20 #define LDFORGE_PROPERTY_H
21 21
22 #define PROPERTY( ACCESS, TYPE, NAME, OPS, WRITETYPE ) \ 22 #define PROPERTY( ACCESS, TYPE, NAME, OPS, WRITETYPE ) \
23 private: \ 23 private: \
24 TYPE m_##NAME; \ 24 TYPE m_##NAME; \
25 \ 25 \
26 public: \ 26 public: \
27 inline TYPE const& GET_READ_METHOD( NAME, OPS ) const \ 27 inline TYPE const& GET_READ_METHOD( NAME, OPS ) const \
28 { return m_##NAME; \ 28 { \
29 } \ 29 return m_##NAME; \
30 \ 30 } \
31 ACCESS: \ 31 \
32 ACCESS: \
32 DEFINE_WRITE_METHOD_##WRITETYPE( TYPE, NAME ) \ 33 DEFINE_WRITE_METHOD_##WRITETYPE( TYPE, NAME ) \
33 DEFINE_PROPERTY_##OPS( TYPE, NAME ) 34 DEFINE_PROPERTY_##OPS( TYPE, NAME )
34 35
35 #define GET_READ_METHOD( NAME, OPS ) \ 36 #define GET_READ_METHOD( NAME, OPS ) \
36 GET_READ_METHOD_##OPS( NAME ) 37 GET_READ_METHOD_##OPS( NAME )
40 #define GET_READ_METHOD_STR_OPS( NAME ) get##NAME() 41 #define GET_READ_METHOD_STR_OPS( NAME ) get##NAME()
41 #define GET_READ_METHOD_NUM_OPS( NAME ) get##NAME() 42 #define GET_READ_METHOD_NUM_OPS( NAME ) get##NAME()
42 #define GET_READ_METHOD_LIST_OPS( NAME ) get##NAME() 43 #define GET_READ_METHOD_LIST_OPS( NAME ) get##NAME()
43 44
44 #define DEFINE_WRITE_METHOD_STOCK_WRITE( TYPE, NAME ) \ 45 #define DEFINE_WRITE_METHOD_STOCK_WRITE( TYPE, NAME ) \
45 inline void set##NAME( TYPE const& NAME##_ ) \ 46 inline void set##NAME( TYPE const& NAME##_ ) \
46 { m_##NAME = NAME##_; \ 47 { \
48 m_##NAME = NAME##_; \
47 } 49 }
48 50
49 #define DEFINE_WRITE_METHOD_CUSTOM_WRITE( TYPE, NAME ) \ 51 #define DEFINE_WRITE_METHOD_CUSTOM_WRITE( TYPE, NAME ) \
50 void set##NAME( TYPE const& NAME##_ ); \ 52 void set##NAME( TYPE const& NAME##_ ); \
51 53
52 #define DEFINE_WITH_CB( NAME ) void NAME##Changed(); 54 #define DEFINE_WITH_CB( NAME ) void NAME##Changed();
53 #define DEFINE_NO_CB( NAME ) 55 #define DEFINE_NO_CB( NAME )
54 56
55 #define DEFINE_PROPERTY_NO_OPS( TYPE, NAME ) 57 #define DEFINE_PROPERTY_NO_OPS( TYPE, NAME )
56 58
57 #define DEFINE_PROPERTY_STR_OPS( TYPE, NAME ) \ 59 #define DEFINE_PROPERTY_STR_OPS( TYPE, NAME ) \
58 void append##NAME( TYPE a ) \ 60 void append##NAME( TYPE a ) \
59 { TYPE tmp( m_##NAME ); \ 61 { \
60 tmp.append( a ); \ 62 TYPE tmp( m_##NAME ); \
61 set##NAME( tmp ); \ 63 tmp.append( a ); \
62 } \ 64 set##NAME( tmp ); \
63 \ 65 } \
66 \
64 void prepend##NAME( TYPE a ) \ 67 void prepend##NAME( TYPE a ) \
65 { TYPE tmp( m_##NAME ); \ 68 { \
66 tmp.prepend( a ); \ 69 TYPE tmp( m_##NAME ); \
67 set##NAME( tmp ); \ 70 tmp.prepend( a ); \
68 } \ 71 set##NAME( tmp ); \
69 \ 72 } \
70 void replaceIn##NAME( TYPE a, TYPE b ) \ 73 \
71 { TYPE tmp( m_##NAME ); \ 74 void replaceIn##NAME( TYPE a, TYPE b ) \
72 tmp.replace( a, b ); \ 75 { \
73 set##NAME( tmp ); \ 76 TYPE tmp( m_##NAME ); \
77 tmp.replace( a, b ); \
78 set##NAME( tmp ); \
74 } 79 }
75 80
76 #define DEFINE_PROPERTY_NUM_OPS( TYPE, NAME ) \ 81 #define DEFINE_PROPERTY_NUM_OPS( TYPE, NAME ) \
77 inline void increase##NAME( TYPE a = 1 ) \ 82 inline void increase##NAME( TYPE a = 1 ) \
78 { set##NAME( m_##NAME + a ); \ 83 { \
79 } \ 84 set##NAME( m_##NAME + a ); \
80 \ 85 } \
81 inline void decrease##NAME( TYPE a = 1 ) \ 86 \
82 { set##NAME( m_##NAME - a ); \ 87 inline void decrease##NAME( TYPE a = 1 ) \
88 { \
89 set##NAME( m_##NAME - a ); \
83 } 90 }
84 91
85 #define DEFINE_PROPERTY_BOOL_OPS( TYPE, NAME ) \ 92 #define DEFINE_PROPERTY_BOOL_OPS( TYPE, NAME ) \
86 inline void toggle##NAME() \ 93 inline void toggle##NAME() \
87 { set##NAME( !m_##NAME ); \ 94 { \
95 set##NAME( !m_##NAME ); \
88 } 96 }
89 97
90 #define DEFINE_PROPERTY_LIST_OPS( TYPE, NAME ) \ 98 #define DEFINE_PROPERTY_LIST_OPS( TYPE, NAME ) \
91 void pushTo##NAME( const TYPE::value_type& a ) \ 99 void pushTo##NAME( const TYPE::value_type& a ) \
92 { TYPE tmp( m_##NAME ); \ 100 { \
93 tmp.push_back( a ); \ 101 TYPE tmp( m_##NAME ); \
94 set##NAME( tmp ); \ 102 tmp.push_back( a ); \
95 } \ 103 set##NAME( tmp ); \
96 \ 104 } \
105 \
97 void removeFrom##NAME( const TYPE::value_type& a ) \ 106 void removeFrom##NAME( const TYPE::value_type& a ) \
98 { TYPE tmp( m_##NAME ); \ 107 { \
99 tmp.removeOne( a ); \ 108 TYPE tmp( m_##NAME ); \
100 set##NAME( tmp ); \ 109 tmp.removeOne( a ); \
101 } \ 110 set##NAME( tmp ); \
102 \ 111 } \
103 inline void clear##NAME() \ 112 \
104 { set##NAME( TYPE() ); \ 113 inline void clear##NAME() \
114 { \
115 set##NAME( TYPE() ); \
105 } 116 }
106 117
107 #endif // LDFORGE_PROPERTY_H 118 #endif // LDFORGE_PROPERTY_H

mercurial