diff options
author | Mike Buland <eichlan@xagasoft.com> | 2011-06-22 15:15:13 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2011-06-22 15:15:13 +0000 |
commit | f16c5dd212ca03ec5f13759997bf95982e3aee94 (patch) | |
tree | 2d48fe6867c965f8f101651d074b4a71e46c83be | |
parent | ec57e315a3d370910925c67e21482c1cf46ecfbd (diff) | |
download | libbu++-f16c5dd212ca03ec5f13759997bf95982e3aee94.tar.gz libbu++-f16c5dd212ca03ec5f13759997bf95982e3aee94.tar.bz2 libbu++-f16c5dd212ca03ec5f13759997bf95982e3aee94.tar.xz libbu++-f16c5dd212ca03ec5f13759997bf95982e3aee94.zip |
gensigs actually works, I'm going to try replacing the old signal code with
generated signal code. After that, I can actually make changes to the signal
code.
Diffstat (limited to '')
-rw-r--r-- | gensigs.bld | 282 |
1 files changed, 155 insertions, 127 deletions
diff --git a/gensigs.bld b/gensigs.bld index accf107..0658b88 100644 --- a/gensigs.bld +++ b/gensigs.bld | |||
@@ -1,136 +1,164 @@ | |||
1 | for i in range( 0, 5 ) do | 1 | function genSigs( maxParams ) |
2 | { | 2 | { |
3 | templparams = ""; | 3 | fOut = open("testsignal.h", "w"); |
4 | funcparams = ""; | 4 | fOut.write( |
5 | templcallparams = ""; | 5 | "/*\n" |
6 | funccallparams = ""; | 6 | " * Copyright (C) 2007-2011 Xagasoft, All rights reserved.\n" |
7 | if i >= 1 then | 7 | " *\n" |
8 | " * This file is part of the libbu++ library and is released under the\n" | ||
9 | " * terms of the license contained in the file LICENSE.\n" | ||
10 | " */\n" | ||
11 | "\n" | ||
12 | "#ifndef BU_OBJECT_SIGNALS_H\n" | ||
13 | "#define BU_OBJECT_SIGNALS_H\n" | ||
14 | "\n" | ||
15 | "#include \"bu/util.h\"\n" | ||
16 | "#include \"bu/exceptionbase.h\"\n" | ||
17 | "\n" | ||
18 | "namespace Bu\n" | ||
19 | "{\n" | ||
20 | " subExceptionDecl( SignalException );\n" | ||
21 | "\n" | ||
22 | ); | ||
23 | |||
24 | for i in range( 0, 5 ) do | ||
8 | { | 25 | { |
9 | for p in range( 1, i ) do | 26 | templParams = "typename ret"; |
27 | funcParams = ""; | ||
28 | funcAnonParams = ""; | ||
29 | templCallParams = "ret"; | ||
30 | funcCallParams = ""; | ||
31 | if i >= 1 then | ||
10 | { | 32 | { |
11 | if p > 1 then | 33 | for p in range( 1, i ) do |
12 | { | 34 | { |
13 | templcallparams << ", "; | 35 | if p > 1 then |
14 | funccallparams << ", "; | 36 | { |
15 | funcparams << ", "; | 37 | funcCallParams << ", "; |
38 | funcParams << ", "; | ||
39 | funcAnonParams << ", "; | ||
40 | } | ||
41 | templParams << ", typename p${p}t"; | ||
42 | funcParams << "p${p}t p${p}"; | ||
43 | funcAnonParams << "p${p}t"; | ||
44 | templCallParams << ", p${p}t"; | ||
45 | funcCallParams << "p${p}"; | ||
16 | } | 46 | } |
17 | templparams << ", typename p${p}t"; | ||
18 | funcparams << "p${p}t p${p}"; | ||
19 | templcallparams << "p${p}t"; | ||
20 | funccallparams << "p${p}"; | ||
21 | } | 47 | } |
48 | fOut.write( | ||
49 | " //\n" | ||
50 | " // ${i} Parameter(s)\n" | ||
51 | " //\n" | ||
52 | " template<${templParams}>\n" | ||
53 | " class _Slot${i}\n" | ||
54 | " {\n" | ||
55 | " public:\n" | ||
56 | " _Slot${i}() { }\n" | ||
57 | " virtual ~_Slot${i}() { }\n" | ||
58 | " virtual ret operator()( ${funcParams} )=0;\n" | ||
59 | " virtual _Slot${i}<${templCallParams}> *clone() const=0;\n" | ||
60 | " };\n" | ||
61 | " \n" | ||
62 | " template<typename cls, ${templParams}>\n" | ||
63 | " class __Slot${i} : public _Slot${i}<${templCallParams}>\n" | ||
64 | " {\n" | ||
65 | " public:\n" | ||
66 | " __Slot${i}( cls *pCls, ret (cls::*pFnc)( ${funcAnonParams} ) ) :\n" | ||
67 | " pCls( pCls ), pFnc( pFnc ) { }\n" | ||
68 | " virtual ~__Slot${i}() { }\n" | ||
69 | " \n" | ||
70 | " virtual ret operator()( ${funcParams} )\n" | ||
71 | " {\n" | ||
72 | " return (pCls->*pFnc)( ${funcCallParams} );\n" | ||
73 | " }\n" | ||
74 | " \n" | ||
75 | " virtual _Slot${i}<${templCallParams}> *clone() const\n" | ||
76 | " {\n" | ||
77 | " return new __Slot${i}<cls, ${templCallParams}>( pCls, pFnc );\n" | ||
78 | " }\n" | ||
79 | " \n" | ||
80 | " private:\n" | ||
81 | " cls *pCls;\n" | ||
82 | " ret (cls::*pFnc)( ${funcAnonParams} );\n" | ||
83 | " };\n" | ||
84 | " \n" | ||
85 | " template<${templParams}>\n" | ||
86 | " class __Slot${i}F : public _Slot${i}<${templCallParams}>\n" | ||
87 | " {\n" | ||
88 | " public:\n" | ||
89 | " __Slot${i}F( ret (*pFnc)( ${funcAnonParams} ) ) :\n" | ||
90 | " pFnc( pFnc ) { }\n" | ||
91 | " virtual ~__Slot${i}F() { }\n" | ||
92 | " \n" | ||
93 | " virtual ret operator()( ${funcParams} )\n" | ||
94 | " {\n" | ||
95 | " return (*pFnc)( ${funcCallParams} );\n" | ||
96 | " }\n" | ||
97 | " \n" | ||
98 | " virtual _Slot${i}<${templCallParams}> *clone() const\n" | ||
99 | " {\n" | ||
100 | " return new __Slot${i}F<${templCallParams}>( pFnc );\n" | ||
101 | " }\n" | ||
102 | " \n" | ||
103 | " private:\n" | ||
104 | " ret (*pFnc)( ${funcAnonParams} );\n" | ||
105 | " };\n" | ||
106 | " \n" | ||
107 | " template<${templParams}>\n" | ||
108 | " class Signal${i}\n" | ||
109 | " {\n" | ||
110 | " public:\n" | ||
111 | " Signal${i}() : pCb( NULL ) { }\n" | ||
112 | " Signal${i}( _Slot${i}<${templCallParams}> *pCb ) : pCb( pCb ) { }\n" | ||
113 | " Signal${i}( const Signal${i}<${templCallParams}> &rSrc ) :\n" | ||
114 | " pCb( (rSrc.pCb)?(rSrc.pCb->clone()):(NULL) ) { }\n" | ||
115 | " virtual ~Signal${i}() { delete pCb; pCb = NULL; }\n" | ||
116 | " \n" | ||
117 | " ret operator()( ${funcParams} )\n" | ||
118 | " {\n" | ||
119 | " if( !pCb ) throw SignalException(\"Uninitialized signal called.\");\n" | ||
120 | " return (*pCb)( ${funcCallParams} );\n" | ||
121 | " }\n" | ||
122 | " \n" | ||
123 | " bool isSet() const { return pCb != NULL; }\n" | ||
124 | " operator bool() const { return isSet(); }\n" | ||
125 | " \n" | ||
126 | " Signal${i}<${templCallParams}> &operator=( const Signal${i}<${templCallParams}> &rhs )\n" | ||
127 | " {\n" | ||
128 | " pCb = rhs.pCb->clone();\n" | ||
129 | " return *this;\n" | ||
130 | " }\n" | ||
131 | " \n" | ||
132 | " private:\n" | ||
133 | " _Slot${i}<${templCallParams}> *pCb;\n" | ||
134 | " };\n" | ||
135 | " \n" | ||
136 | " template<typename cls, ${templParams}>\n" | ||
137 | " Signal${i}<${templCallParams}> slot( cls *pCls, ret (cls::*pFnc)( ${funcAnonParams} ) )\n" | ||
138 | " {\n" | ||
139 | " if( !pCls || !pFnc ) throw SignalException(\"NULL pointer in slot().\");\n" | ||
140 | " return Signal${i}<${templCallParams}>(\n" | ||
141 | " new __Slot${i}<cls, ${templCallParams}>( pCls, pFnc )\n" | ||
142 | " );\n" | ||
143 | " }\n" | ||
144 | " \n" | ||
145 | " template<${templParams}>\n" | ||
146 | " Signal${i}<${templCallParams}> slot( ret (*pFnc)( ${funcAnonParams} ) )\n" | ||
147 | " {\n" | ||
148 | " if( !pFnc ) throw SignalException(\"NULL pointer in slot().\");\n" | ||
149 | " return Signal${i}<${templCallParams}>(\n" | ||
150 | " new __Slot${i}F<${templCallParams}>( pFnc )\n" | ||
151 | " );\n" | ||
152 | " }\n" | ||
153 | "\n" | ||
154 | ); | ||
22 | } | 155 | } |
23 | warning "template<typename ret${templparams}>"; | ||
24 | warning "virtual ret operator()( ${funcparams} )=0;"; | ||
25 | } | ||
26 | /* | ||
27 | |||
28 | // | ||
29 | // 1 Parameter | ||
30 | // | ||
31 | |||
32 | template<typename ret, typename p1t> | ||
33 | class _Slot1 | ||
34 | { | ||
35 | public: | ||
36 | _Slot1() { } | ||
37 | virtual ~_Slot1() { } | ||
38 | |||
39 | virtual ret operator()( p1t p1 )=0; | ||
40 | |||
41 | virtual _Slot1<ret, p1t> *clone() const=0; | ||
42 | }; | ||
43 | |||
44 | template<typename cls, typename ret, typename p1t> | ||
45 | class __Slot1 : public _Slot1<ret, p1t> | ||
46 | { | ||
47 | public: | ||
48 | __Slot1( cls *pCls, ret (cls::*pFnc)( p1t ) ) : | ||
49 | pCls( pCls ), pFnc( pFnc ) { } | ||
50 | virtual ~__Slot1() { } | ||
51 | |||
52 | virtual ret operator()( p1t p1 ) | ||
53 | { | ||
54 | return (pCls->*pFnc)( p1 ); | ||
55 | } | ||
56 | |||
57 | virtual _Slot1<ret, p1t> *clone() const | ||
58 | { | ||
59 | return new __Slot1<cls, ret, p1t>( pCls, pFnc ); | ||
60 | } | ||
61 | |||
62 | private: | ||
63 | cls *pCls; | ||
64 | ret (cls::*pFnc)( p1t ); | ||
65 | }; | ||
66 | |||
67 | template<typename ret, typename p1t> | ||
68 | class __Slot1F : public _Slot1<ret, p1t> | ||
69 | { | ||
70 | public: | ||
71 | __Slot1F( ret (*pFnc)( p1t ) ) : | ||
72 | pFnc( pFnc ) { } | ||
73 | virtual ~__Slot1F() { } | ||
74 | |||
75 | virtual ret operator()( p1t p1 ) | ||
76 | { | ||
77 | return (*pFnc)( p1 ); | ||
78 | } | ||
79 | |||
80 | virtual _Slot1<ret, p1t> *clone() const | ||
81 | { | ||
82 | return new __Slot1F<ret, p1t>( pFnc ); | ||
83 | } | ||
84 | |||
85 | private: | ||
86 | ret (*pFnc)( p1t p1 ); | ||
87 | }; | ||
88 | |||
89 | template<typename ret, typename p1t> | ||
90 | class Signal1 | ||
91 | { | ||
92 | public: | ||
93 | Signal1() : pCb( NULL ) { } | ||
94 | Signal1( _Slot1<ret, p1t> *pCb ) : pCb( pCb ) { } | ||
95 | Signal1( const Signal1<ret, p1t> &rSrc ) : | ||
96 | pCb( (rSrc.pCb)?(rSrc.pCb->clone()):(NULL) ) { } | ||
97 | |||
98 | virtual ~Signal1() { delete pCb; pCb = NULL; } | ||
99 | |||
100 | ret operator()( p1t p1 ) | ||
101 | { | ||
102 | if( !pCb ) throw SignalException("Uninitialized signal used."); | ||
103 | return (*pCb)( p1 ); | ||
104 | } | ||
105 | 156 | ||
106 | bool isSet() const { return pCb != NULL; } | 157 | fOut.write( |
107 | operator bool() const { return isSet(); } | 158 | "};\n" |
108 | 159 | "\n" | |
109 | Signal1<ret, p1t> &operator=( const Signal1<ret, p1t> &rhs ) | 160 | "#endif\n" |
110 | { | 161 | ); |
111 | pCb = rhs.pCb->clone(); | 162 | fOut.close(); |
112 | return *this; | 163 | } |
113 | } | ||
114 | 164 | ||
115 | private: | ||
116 | _Slot1<ret, p1t> *pCb; | ||
117 | }; | ||
118 | |||
119 | template<typename cls, typename ret, typename p1t> | ||
120 | Signal1<ret, p1t> slot( cls *pCls, ret (cls::*pFnc)( p1t ) ) | ||
121 | { | ||
122 | if( !pCls || !pFnc ) throw SignalException("NULL pointer in slot()."); | ||
123 | return Signal1<ret, p1t>( | ||
124 | new __Slot1<cls, ret, p1t>( pCls, pFnc ) | ||
125 | ); | ||
126 | } | ||
127 | |||
128 | template<typename ret, typename p1t> | ||
129 | Signal1<ret, p1t> slot( ret (*pFnc)( p1t ) ) | ||
130 | { | ||
131 | if( !pFnc ) throw SignalException("NULL pointer in slot()."); | ||
132 | return Signal1<ret, p1t>( | ||
133 | new __Slot1F<ret, p1t>( pFnc ) | ||
134 | ); | ||
135 | } | ||
136 | */ | ||