Merge lp:~fpstovall/nrtb/D_prototype into lp:nrtb
- D_prototype
- Merge into alpha
Proposed by
Rick Stovall
Status: | Merged |
---|---|
Approved by: | Rick Stovall |
Approved revision: | 34 |
Merged at revision: | 12 |
Proposed branch: | lp:~fpstovall/nrtb/D_prototype |
Merge into: | lp:nrtb |
Diff against target: |
940 lines (+862/-0) 12 files modified
D_lang/Makefile (+27/-0) D_lang/common/Makefile (+35/-0) D_lang/common/common.d (+25/-0) D_lang/common/docs/common.html (+10/-0) D_lang/common/docs/vect3d.html (+80/-0) D_lang/common/nrtb/common/GPB_transceiver.d (+24/-0) D_lang/common/nrtb/common/conf_manager.d (+123/-0) D_lang/common/nrtb/common/vect3d.d (+150/-0) D_lang/common/nrtb/common/zmq.d (+236/-0) D_lang/common/nrtb/common/zmq_utils.d (+58/-0) D_lang/testing/threads/Makefile (+30/-0) D_lang/testing/threads/msg_passing.d (+64/-0) |
To merge this branch: | bzr merge lp:~fpstovall/nrtb/D_prototype |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Rick Stovall | merge | Approve | |
NRTB Core | refactoring | Pending | |
Review via email:
|
Commit message
Description of the change
This merge begins our formal project move to use D instead of C++.
1. Refactored directories to obsolete the C++ code and move the D stuff to the top.
2. Added the start of the D NRTB libs, and some test code.
This needs to be pushed to the alpha branch as soon as possible to facilitate the rest of team's work.
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === added directory 'D_lang' | |||
2 | === added file 'D_lang/Makefile' | |||
3 | --- D_lang/Makefile 1970-01-01 00:00:00 +0000 | |||
4 | +++ D_lang/Makefile 2012-10-17 11:54:28 +0000 | |||
5 | @@ -0,0 +1,27 @@ | |||
6 | 1 | #*********************************************** | ||
7 | 2 | #This file is part of the NRTB project (https://launchpad.net/nrtb). | ||
8 | 3 | # | ||
9 | 4 | # NRTB is free software: you can redistribute it and/or modify | ||
10 | 5 | # it under the terms of the GNU General Public License as published by | ||
11 | 6 | # the Free Software Foundation, either version 3 of the License, or | ||
12 | 7 | # (at your option) any later version. | ||
13 | 8 | # | ||
14 | 9 | # NRTB is distributed in the hope that it will be useful, | ||
15 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
17 | 12 | # GNU General Public License for more details. | ||
18 | 13 | # | ||
19 | 14 | # You should have received a copy of the GNU General Public License | ||
20 | 15 | # along with NRTB. If not, see <http://www.gnu.org/licenses/>. | ||
21 | 16 | # | ||
22 | 17 | #*********************************************** | ||
23 | 18 | |||
24 | 19 | build_all: Makefile | ||
25 | 20 | @make action=lib doit | ||
26 | 21 | |||
27 | 22 | clean: | ||
28 | 23 | @make action=clean doit | ||
29 | 24 | @rm -fv lib/* bin/* | ||
30 | 25 | |||
31 | 26 | doit: | ||
32 | 27 | @cd common; make ${action} | ||
33 | 0 | 28 | ||
34 | === added directory 'D_lang/bin' | |||
35 | === added directory 'D_lang/common' | |||
36 | === added file 'D_lang/common/Makefile' | |||
37 | --- D_lang/common/Makefile 1970-01-01 00:00:00 +0000 | |||
38 | +++ D_lang/common/Makefile 2012-10-17 11:54:28 +0000 | |||
39 | @@ -0,0 +1,35 @@ | |||
40 | 1 | #*********************************************** | ||
41 | 2 | # This file is part of the NRTB project (https://launchpad.net/nrtb). | ||
42 | 3 | # | ||
43 | 4 | # NRTB is free software: you can redistribute it and/or modify | ||
44 | 5 | # it under the terms of the GNU General Public License as published by | ||
45 | 6 | # the Free Software Foundation, either version 3 of the License, or | ||
46 | 7 | # (at your option) any later version. | ||
47 | 8 | # | ||
48 | 9 | # NRTB is distributed in the hope that it will be useful, | ||
49 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
50 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
51 | 12 | # GNU General Public License for more details. | ||
52 | 13 | # | ||
53 | 14 | # You should have received a copy of the GNU General Public License | ||
54 | 15 | # along with NRTB. If not, see <http://www.gnu.org/licenses/>. | ||
55 | 16 | # | ||
56 | 17 | #*********************************************** | ||
57 | 18 | |||
58 | 19 | lib: ../lib/common.a | ||
59 | 20 | |||
60 | 21 | ../lib/common.a: test | ||
61 | 22 | @echo building ${modules} | ||
62 | 23 | @cd nrtb/common; dmd -lib -release -of../../../lib/common.a *.d -I../../ | ||
63 | 24 | @echo " ********* common build complete ***********" | ||
64 | 25 | |||
65 | 26 | test: Makefile common.d ${modules} | ||
66 | 27 | @echo testing ${modules} | ||
67 | 28 | @cd nrtb/common; dmd -unittest -lib -of../../common.a *.d -I../../ | ||
68 | 29 | @dmd -unittest common.a -run common.d | ||
69 | 30 | |||
70 | 31 | clean: | ||
71 | 32 | @rm -vf ../lib/common.a common *.o *.a | ||
72 | 33 | @echo all objects and executables have been erased. | ||
73 | 34 | |||
74 | 35 | modules=`find nrtb/common -type f -name \*.d` | ||
75 | 0 | \ No newline at end of file | 36 | \ No newline at end of file |
76 | 1 | 37 | ||
77 | === added file 'D_lang/common/common.d' | |||
78 | --- D_lang/common/common.d 1970-01-01 00:00:00 +0000 | |||
79 | +++ D_lang/common/common.d 2012-10-17 11:54:28 +0000 | |||
80 | @@ -0,0 +1,25 @@ | |||
81 | 1 | /*********************************************** | ||
82 | 2 | This file is part of the NRTB project (https://*launchpad.net/nrtb). | ||
83 | 3 | |||
84 | 4 | NRTB is free software: you can redistribute it and/or modify | ||
85 | 5 | it under the terms of the GNU General Public License as published by | ||
86 | 6 | the Free Software Foundation, either version 3 of the License, or | ||
87 | 7 | (at your option) any later version. | ||
88 | 8 | |||
89 | 9 | NRTB is distributed in the hope that it will be useful, | ||
90 | 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
91 | 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
92 | 12 | GNU General Public License for more details. | ||
93 | 13 | |||
94 | 14 | You should have received a copy of the GNU General Public License | ||
95 | 15 | along with NRTB. If not, see <http://www.gnu.org/licenses/>. | ||
96 | 16 | |||
97 | 17 | **********************************************/ | ||
98 | 18 | |||
99 | 19 | import std.stdio; | ||
100 | 20 | import nrtb.common.vect3d; | ||
101 | 21 | |||
102 | 22 | void main() | ||
103 | 23 | { | ||
104 | 24 | writeln(" ******** NRTB Common Libs Unit Test Complete ********"); | ||
105 | 25 | } | ||
106 | 0 | \ No newline at end of file | 26 | \ No newline at end of file |
107 | 1 | 27 | ||
108 | === added directory 'D_lang/common/docs' | |||
109 | === added file 'D_lang/common/docs/common.html' | |||
110 | --- D_lang/common/docs/common.html 1970-01-01 00:00:00 +0000 | |||
111 | +++ D_lang/common/docs/common.html 2012-10-17 11:54:28 +0000 | |||
112 | @@ -0,0 +1,10 @@ | |||
113 | 1 | <html><head> | ||
114 | 2 | <META http-equiv="content-type" content="text/html; charset=utf-8"> | ||
115 | 3 | <title>common</title> | ||
116 | 4 | </head><body> | ||
117 | 5 | <h1>common</h1> | ||
118 | 6 | <!-- Generated by Ddoc from common.d --> | ||
119 | 7 | <br><br> | ||
120 | 8 | |||
121 | 9 | <hr><small>Page generated by <a href="http://www.digitalmars.com/d/2.0/ddoc.html">Ddoc</a>. </small> | ||
122 | 10 | </body></html> | ||
123 | 0 | 11 | ||
124 | === added file 'D_lang/common/docs/vect3d.html' | |||
125 | --- D_lang/common/docs/vect3d.html 1970-01-01 00:00:00 +0000 | |||
126 | +++ D_lang/common/docs/vect3d.html 2012-10-17 11:54:28 +0000 | |||
127 | @@ -0,0 +1,80 @@ | |||
128 | 1 | <html><head> | ||
129 | 2 | <META http-equiv="content-type" content="text/html; charset=utf-8"> | ||
130 | 3 | <title>vect3d</title> | ||
131 | 4 | </head><body> | ||
132 | 5 | <h1>vect3d</h1> | ||
133 | 6 | <!-- Generated by Ddoc from vect3d/vect3d.d --> | ||
134 | 7 | <br><br> | ||
135 | 8 | <dl><dt><big>struct <u>vect3d</u>; | ||
136 | 9 | </big></dt> | ||
137 | 10 | <dd>Defines a point or vector in cartesian 3d space. Most binary math | ||
138 | 11 | operators shoould work | ||
139 | 12 | with both <u>vect3d</u> and real arguments, but only +, -, *, / and simple | ||
140 | 13 | assignment and equality are unit tested here. Note that operators | ||
141 | 14 | return the simple calculated results; dot product and vector product | ||
142 | 15 | are provided as discrete method calls. | ||
143 | 16 | <br><br> | ||
144 | 17 | Also provided are the common vector operations | ||
145 | 18 | vector_product, | ||
146 | 19 | dot_product, | ||
147 | 20 | magnitude, | ||
148 | 21 | range (distance between points), | ||
149 | 22 | and normalize (scales to magnitude 1.0).<br><br> | ||
150 | 23 | |||
151 | 24 | <dl><dt><big>this(ref vect3d); | ||
152 | 25 | </big></dt> | ||
153 | 26 | <dd>blt copy override to avoid binding accidently.<br><br> | ||
154 | 27 | |||
155 | 28 | </dd> | ||
156 | 29 | <dt><big>this(const(real[]) <i>a</i>); | ||
157 | 30 | </big></dt> | ||
158 | 31 | <dd>Construct from <i>a</i> real array. Only arrays of length 3 are acceptable.<br><br> | ||
159 | 32 | |||
160 | 33 | </dd> | ||
161 | 34 | <dt><big>this(const(real) <i>a</i>); | ||
162 | 35 | </big></dt> | ||
163 | 36 | <dd>Construct from <i>a</i> single real. All three elements will be assigned the | ||
164 | 37 | same value.<br><br> | ||
165 | 38 | |||
166 | 39 | </dd> | ||
167 | 40 | <dt><big>this(const(real) <i>x</i>, real <i>y</i>, real <i>z</i>); | ||
168 | 41 | </big></dt> | ||
169 | 42 | <dd>Construct from 3 reals. They are assigned in the order presented.<br><br> | ||
170 | 43 | |||
171 | 44 | </dd> | ||
172 | 45 | <dt><big>vec <u>values</u>(); | ||
173 | 46 | </big></dt> | ||
174 | 47 | <dd>returns an array containing copies of the coordinates.<br><br> | ||
175 | 48 | |||
176 | 49 | </dd> | ||
177 | 50 | <dt><big>real <u>magnitude</u>(); | ||
178 | 51 | </big></dt> | ||
179 | 52 | <dd>returns the length (the <u>magnitude</u>) of the vector<br><br> | ||
180 | 53 | |||
181 | 54 | </dd> | ||
182 | 55 | <dt><big>real <u>dot_product</u>(in vect3d <i>a</i>); | ||
183 | 56 | </big></dt> | ||
184 | 57 | <dd>returns the dot product<br><br> | ||
185 | 58 | |||
186 | 59 | </dd> | ||
187 | 60 | <dt><big>vect3d <u>vector_product</u>(in vect3d <i>a</i>); | ||
188 | 61 | </big></dt> | ||
189 | 62 | <dd>returns the vector product<br><br> | ||
190 | 63 | |||
191 | 64 | </dd> | ||
192 | 65 | <dt><big>real <u>range</u>(in vect3d <i>a</i>); | ||
193 | 66 | </big></dt> | ||
194 | 67 | <dd><u>range</u> returns the distance between two vect3d<br><br> | ||
195 | 68 | |||
196 | 69 | </dd> | ||
197 | 70 | <dt><big>vect3d <u>normalize</u>(); | ||
198 | 71 | </big></dt> | ||
199 | 72 | <dd>returns the normalized vector (scaled to length 1.0)<br><br> | ||
200 | 73 | |||
201 | 74 | </dd> | ||
202 | 75 | </dl> | ||
203 | 76 | </dd> | ||
204 | 77 | </dl> | ||
205 | 78 | |||
206 | 79 | <hr><small>Page generated by <a href="http://www.digitalmars.com/d/2.0/ddoc.html">Ddoc</a>. </small> | ||
207 | 80 | </body></html> | ||
208 | 0 | 81 | ||
209 | === added directory 'D_lang/common/nrtb' | |||
210 | === added directory 'D_lang/common/nrtb/common' | |||
211 | === added file 'D_lang/common/nrtb/common/GPB_transceiver.d' | |||
212 | --- D_lang/common/nrtb/common/GPB_transceiver.d 1970-01-01 00:00:00 +0000 | |||
213 | +++ D_lang/common/nrtb/common/GPB_transceiver.d 2012-10-17 11:54:28 +0000 | |||
214 | @@ -0,0 +1,24 @@ | |||
215 | 1 | /*********************************************** | ||
216 | 2 | This file is part of the NRTB project (https://*launchpad.net/nrtb). | ||
217 | 3 | |||
218 | 4 | NRTB is free software: you can redistribute it and/or modify | ||
219 | 5 | it under the terms of the GNU General Public License as published by | ||
220 | 6 | the Free Software Foundation, either version 3 of the License, or | ||
221 | 7 | (at your option) any later version. | ||
222 | 8 | |||
223 | 9 | NRTB is distributed in the hope that it will be useful, | ||
224 | 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
225 | 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
226 | 12 | GNU General Public License for more details. | ||
227 | 13 | |||
228 | 14 | You should have received a copy of the GNU General Public License | ||
229 | 15 | along with NRTB. If not, see <http://www.gnu.org/licenses/>. | ||
230 | 16 | |||
231 | 17 | **********************************************/ | ||
232 | 18 | |||
233 | 19 | import std.socket; | ||
234 | 20 | |||
235 | 21 | class gpb_transceiver | ||
236 | 22 | { | ||
237 | 23 | |||
238 | 24 | } | ||
239 | 0 | \ No newline at end of file | 25 | \ No newline at end of file |
240 | 1 | 26 | ||
241 | === added file 'D_lang/common/nrtb/common/conf_manager.d' | |||
242 | --- D_lang/common/nrtb/common/conf_manager.d 1970-01-01 00:00:00 +0000 | |||
243 | +++ D_lang/common/nrtb/common/conf_manager.d 2012-10-17 11:54:28 +0000 | |||
244 | @@ -0,0 +1,123 @@ | |||
245 | 1 | /*********************************************** | ||
246 | 2 | This file is part of the NRTB project (https://*launchpad.net/nrtb). | ||
247 | 3 | |||
248 | 4 | NRTB is free software: you can redistribute it and/or modify | ||
249 | 5 | it under the terms of the GNU General Public License as published by | ||
250 | 6 | the Free Software Foundation, either version 3 of the License, or | ||
251 | 7 | (at your option) any later version. | ||
252 | 8 | |||
253 | 9 | NRTB is distributed in the hope that it will be useful, | ||
254 | 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
255 | 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
256 | 12 | GNU General Public License for more details. | ||
257 | 13 | |||
258 | 14 | You should have received a copy of the GNU General Public License | ||
259 | 15 | along with NRTB. If not, see <http://www.gnu.org/licenses/>. | ||
260 | 16 | |||
261 | 17 | **********************************************/ | ||
262 | 18 | |||
263 | 19 | import std.stdio; | ||
264 | 20 | import std.conv; | ||
265 | 21 | import std.array; | ||
266 | 22 | import std.getopt; | ||
267 | 23 | import std.string; | ||
268 | 24 | |||
269 | 25 | /** Reads command line and configuration file information. | ||
270 | 26 | * | ||
271 | 27 | * For this NRTB implementation, this class is implemented as | ||
272 | 28 | * a singleton. | ||
273 | 29 | * | ||
274 | 30 | * Values read are stored in a multimap of name/value pairs and | ||
275 | 31 | * may be accessed via provided iterators, or directly via the | ||
276 | 32 | * [] operator, all(), get<T>() and getall<T>() methods. Automatic | ||
277 | 33 | * handling of include files and comments is provided as well. The | ||
278 | 34 | * get<>() and getall<>() template methods provide easy and complete | ||
279 | 35 | * access to all types that have the ">>" stream operator | ||
280 | 36 | * defined, including all the C++ standard types. | ||
281 | 37 | **/ | ||
282 | 38 | |||
283 | 39 | class conf_reader | ||
284 | 40 | { | ||
285 | 41 | alias string[string] mylist; | ||
286 | 42 | |||
287 | 43 | this(string[] args) | ||
288 | 44 | { | ||
289 | 45 | string c_file = "nrtb.config"; | ||
290 | 46 | string c_path = "."; | ||
291 | 47 | // get the traditional args. | ||
292 | 48 | getopt(args, | ||
293 | 49 | std.getopt.config.passThrough, | ||
294 | 50 | "config_file", &c_file, | ||
295 | 51 | "config_path", &c_path | ||
296 | 52 | ); | ||
297 | 53 | // store off the program name | ||
298 | 54 | values["__app_name"] = args[0]; | ||
299 | 55 | args = args[1 .. $]; | ||
300 | 56 | // process the includes first | ||
301 | 57 | string[] pending; | ||
302 | 58 | foreach(arg; args) | ||
303 | 59 | { | ||
304 | 60 | string[] tokens = split(arg,"="); | ||
305 | 61 | if (tokens[0] == "include") | ||
306 | 62 | load_file(tokens[1]); | ||
307 | 63 | else | ||
308 | 64 | pending ~= arg; | ||
309 | 65 | } | ||
310 | 66 | // process the remaining elements | ||
311 | 67 | foreach(arg; pending) | ||
312 | 68 | { | ||
313 | 69 | string[] tokens = split(arg,"="); | ||
314 | 70 | if (tokens.length == 1) | ||
315 | 71 | { | ||
316 | 72 | values[tokens[0]] = "1"; | ||
317 | 73 | } | ||
318 | 74 | else if (tokens.length == 2) | ||
319 | 75 | { | ||
320 | 76 | values[tokens[0]] = tokens[1]; | ||
321 | 77 | } | ||
322 | 78 | }; | ||
323 | 79 | } | ||
324 | 80 | |||
325 | 81 | private void load_file(in string file_name) | ||
326 | 82 | { | ||
327 | 83 | // need to add the logic to read files here. | ||
328 | 84 | auto f = File(file_name, "r"); | ||
329 | 85 | scope(exit) {f.close();}; | ||
330 | 86 | foreach(string line; lines(f)) | ||
331 | 87 | { | ||
332 | 88 | // trim for comments | ||
333 | 89 | auto hash_index = indexOf(line,"#"); | ||
334 | 90 | if (hash_index != -1) | ||
335 | 91 | line = line[0 .. hash_index]; | ||
336 | 92 | // if we have anything left, parse it. | ||
337 | 93 | if (line != "") | ||
338 | 94 | { | ||
339 | 95 | // trim the string | ||
340 | 96 | line = line.strip(); | ||
341 | 97 | // split on first whitespace | ||
342 | 98 | for (auto i=0; i<line.length; i++) | ||
343 | 99 | { | ||
344 | 100 | // if ((line[i] == " ") || (line[i] == "\t")) | ||
345 | 101 | } | ||
346 | 102 | // trim both sides | ||
347 | 103 | // how do we store dups? | ||
348 | 104 | } | ||
349 | 105 | } | ||
350 | 106 | |||
351 | 107 | } | ||
352 | 108 | |||
353 | 109 | mylist get_list() { return values.dup; }; | ||
354 | 110 | |||
355 | 111 | T get(T,E)(in string key,in E _default) | ||
356 | 112 | if (typeof(T = E) == typeof(T)) | ||
357 | 113 | { | ||
358 | 114 | if ((key in values) != null) | ||
359 | 115 | return to!T(values[key]); | ||
360 | 116 | else | ||
361 | 117 | return _default; | ||
362 | 118 | } | ||
363 | 119 | |||
364 | 120 | private mylist values; | ||
365 | 121 | |||
366 | 122 | } | ||
367 | 123 | |||
368 | 0 | 124 | ||
369 | === added file 'D_lang/common/nrtb/common/vect3d.d' | |||
370 | --- D_lang/common/nrtb/common/vect3d.d 1970-01-01 00:00:00 +0000 | |||
371 | +++ D_lang/common/nrtb/common/vect3d.d 2012-10-17 11:54:28 +0000 | |||
372 | @@ -0,0 +1,150 @@ | |||
373 | 1 | /*********************************************** | ||
374 | 2 | This file is part of the NRTB project (https://launchpad.net/nrtb). | ||
375 | 3 | |||
376 | 4 | NRTB is free software: you can redistribute it and/or modify | ||
377 | 5 | it under the terms of the GNU General Public License as published by | ||
378 | 6 | the Free Software Foundation, either version 3 of the License, or | ||
379 | 7 | (at your option) any later version. | ||
380 | 8 | |||
381 | 9 | NRTB is distributed in the hope that it will be useful, | ||
382 | 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
383 | 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
384 | 12 | GNU General Public License for more details. | ||
385 | 13 | |||
386 | 14 | You should have received a copy of the GNU General Public License | ||
387 | 15 | along with NRTB. If not, see <http://www.gnu.org/licenses/>. | ||
388 | 16 | |||
389 | 17 | **********************************************/ | ||
390 | 18 | |||
391 | 19 | import std.stdio, std.math; | ||
392 | 20 | |||
393 | 21 | /** Defines a point or vector in cartesian 3d space. Most binary math | ||
394 | 22 | * operators shoould work | ||
395 | 23 | * with both vect3d and real arguments, but only +, -, *, / and simple | ||
396 | 24 | * assignment and equality are unit tested here. Note that operators | ||
397 | 25 | * return the simple calculated results; dot product and vector product | ||
398 | 26 | * are provided as discrete method calls. | ||
399 | 27 | * | ||
400 | 28 | * Also provided are the common vector operations | ||
401 | 29 | * vector_product, | ||
402 | 30 | * dot_product, | ||
403 | 31 | * magnitude, | ||
404 | 32 | * range (distance between points), | ||
405 | 33 | * and normalize (scales to magnitude 1.0). | ||
406 | 34 | **/ | ||
407 | 35 | |||
408 | 36 | struct vect3d | ||
409 | 37 | { | ||
410 | 38 | alias real[3] vec; | ||
411 | 39 | // vector | ||
412 | 40 | private vec coords; | ||
413 | 41 | /// blt copy override to avoid binding accidently. | ||
414 | 42 | this(ref this) { coords = coords.dup; } | ||
415 | 43 | /// Construct from a real array. Only arrays of length 3 are acceptable. | ||
416 | 44 | this(in real[] a) | ||
417 | 45 | { | ||
418 | 46 | assert(a.length==3,"!! Invalid input length in vect3d.(T[] a)."); | ||
419 | 47 | coords[] = a[0 .. 3]; | ||
420 | 48 | } | ||
421 | 49 | /// Construct from a single real. All three elements will be assigned the | ||
422 | 50 | /// same value. | ||
423 | 51 | this(in real a) { coords[] = a;} | ||
424 | 52 | /// Construct from 3 reals. They are assigned in the order presented. | ||
425 | 53 | this(in real x, real y, real z) { coords[0]=x; coords[1]=y; coords[2]=z;} | ||
426 | 54 | /// returns an array containing copies of the coordinates. | ||
427 | 55 | vec values() { vec v; v = coords.dup; return v; } | ||
428 | 56 | /// returns the length (the magnitude) of the vector | ||
429 | 57 | real magnitude() | ||
430 | 58 | { | ||
431 | 59 | real returnme = 0.0; | ||
432 | 60 | foreach(val; coords) { returnme += (val*val); } | ||
433 | 61 | return sqrt(returnme); | ||
434 | 62 | } | ||
435 | 63 | /// returns the dot product | ||
436 | 64 | real dot_product(in vect3d a) | ||
437 | 65 | { | ||
438 | 66 | real returnme = 0.0; | ||
439 | 67 | returnme += coords[0] * a.coords[0]; | ||
440 | 68 | returnme += coords[1] * a.coords[1]; | ||
441 | 69 | returnme += coords[2] * a.coords[2]; | ||
442 | 70 | return returnme; | ||
443 | 71 | } | ||
444 | 72 | /// returns the vector product | ||
445 | 73 | vect3d vector_product(in vect3d a) | ||
446 | 74 | { | ||
447 | 75 | vect3d returnme; | ||
448 | 76 | with (returnme) | ||
449 | 77 | { | ||
450 | 78 | coords[0] = | ||
451 | 79 | (this.coords[1] * a.coords[2]) - (this.coords[2] * a.coords[1]); | ||
452 | 80 | coords[1] = | ||
453 | 81 | (this.coords[2] * a.coords[0]) - (this.coords[0] * a.coords[2]); | ||
454 | 82 | coords[2] = | ||
455 | 83 | (this.coords[0] * a.coords[1]) - (this.coords[1] * a.coords[0]); | ||
456 | 84 | } | ||
457 | 85 | return returnme; | ||
458 | 86 | } | ||
459 | 87 | /// range returns the distance between two vect3d | ||
460 | 88 | real range(in vect3d a) | ||
461 | 89 | { | ||
462 | 90 | return (this - a).magnitude(); | ||
463 | 91 | } | ||
464 | 92 | /// returns the normalized vector (scaled to length 1.0) | ||
465 | 93 | vect3d normalize() | ||
466 | 94 | { | ||
467 | 95 | return this / magnitude(); | ||
468 | 96 | } | ||
469 | 97 | // vect3d by vect3d operators | ||
470 | 98 | vect3d opBinary(string op)(vect3d rhs) | ||
471 | 99 | { | ||
472 | 100 | vect3d v; | ||
473 | 101 | mixin("v.coords[] = coords[] "~op~" rhs.coords[];"); | ||
474 | 102 | return v; | ||
475 | 103 | } | ||
476 | 104 | // vect3d by real operators | ||
477 | 105 | vect3d opBinary(string op)(real rhs) | ||
478 | 106 | { | ||
479 | 107 | vect3d v; | ||
480 | 108 | mixin("v.coords[] = coords[] "~op~" rhs;"); | ||
481 | 109 | return v; | ||
482 | 110 | } | ||
483 | 111 | } | ||
484 | 112 | |||
485 | 113 | unittest | ||
486 | 114 | { | ||
487 | 115 | // test both literal constuctors | ||
488 | 116 | auto a = vect3d(2); | ||
489 | 117 | assert(a==vect3d(2,2,2)); | ||
490 | 118 | // test init from an array. | ||
491 | 119 | real[] array = [2,3,4]; | ||
492 | 120 | auto at = vect3d(array); | ||
493 | 121 | assert(at == vect3d(2,3,4)); | ||
494 | 122 | assert(at.values() == array); | ||
495 | 123 | // test copying | ||
496 | 124 | auto t=a; | ||
497 | 125 | assert(t==vect3d(2,2,2)); | ||
498 | 126 | // test major vect3d by vect3d math | ||
499 | 127 | auto b = vect3d(1,2,3); | ||
500 | 128 | assert((b+a)==vect3d(3,4,5)); | ||
501 | 129 | assert((b-a)==vect3d(-1,0,1)); | ||
502 | 130 | assert((b*a)==vect3d(2,4,6)); | ||
503 | 131 | assert((b/a)==vect3d(1.0/2.0,2.0/2.0,3.0/2.0)); | ||
504 | 132 | // test major vect3d by real math shifts and scales | ||
505 | 133 | assert((b+1)==vect3d(2,3,4)); | ||
506 | 134 | assert((b-1)==vect3d(0,1,2)); | ||
507 | 135 | assert((b*2)==vect3d(2,4,6)); | ||
508 | 136 | assert((b/2.0)==vect3d(1.0/2.0,2.0/2.0,3.0/2.0)); | ||
509 | 137 | // magnitude test | ||
510 | 138 | assert(a.magnitude()==sqrt(2.0*2.0*3.0)); | ||
511 | 139 | // dot_product test | ||
512 | 140 | assert(a.dot_product(a)==12.0); | ||
513 | 141 | // vector_product test. | ||
514 | 142 | assert(b.vector_product(a)==vect3d(-2,4,-2)); | ||
515 | 143 | assert(a.vector_product(a)==vect3d(0.0)); | ||
516 | 144 | // Range tests | ||
517 | 145 | assert(a.range(a)==0.0); | ||
518 | 146 | assert(approxEqual(a.range(b),1.41421)); | ||
519 | 147 | // normalize tests. | ||
520 | 148 | assert(approxEqual(a.normalize().magnitude(),1.0)); | ||
521 | 149 | assert(approxEqual(b.normalize().magnitude(),1.0)); | ||
522 | 150 | } | ||
523 | 0 | 151 | ||
524 | === added file 'D_lang/common/nrtb/common/zmq.d' | |||
525 | --- D_lang/common/nrtb/common/zmq.d 1970-01-01 00:00:00 +0000 | |||
526 | +++ D_lang/common/nrtb/common/zmq.d 2012-10-17 11:54:28 +0000 | |||
527 | @@ -0,0 +1,236 @@ | |||
528 | 1 | /* | ||
529 | 2 | Copyright (c) 2007-2010 iMatix Corporation | ||
530 | 3 | |||
531 | 4 | This file is part of 0MQ. | ||
532 | 5 | |||
533 | 6 | 0MQ is free software; you can redistribute it and/or modify it under | ||
534 | 7 | the terms of the GNU Lesser General Public License as published by | ||
535 | 8 | the Free Software Foundation; either version 3 of the License, or | ||
536 | 9 | (at your option) any later version. | ||
537 | 10 | |||
538 | 11 | 0MQ is distributed in the hope that it will be useful, | ||
539 | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
540 | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
541 | 14 | GNU Lesser General Public License for more details. | ||
542 | 15 | |||
543 | 16 | You should have received a copy of the GNU Lesser General Public License | ||
544 | 17 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
545 | 18 | */ | ||
546 | 19 | module zmq; | ||
547 | 20 | |||
548 | 21 | |||
549 | 22 | extern (C) | ||
550 | 23 | { | ||
551 | 24 | |||
552 | 25 | /******************************************************************************/ | ||
553 | 26 | /* 0MQ versioning support. */ | ||
554 | 27 | /******************************************************************************/ | ||
555 | 28 | |||
556 | 29 | /* Version macros for compile-time API version detection */ | ||
557 | 30 | |||
558 | 31 | enum | ||
559 | 32 | { | ||
560 | 33 | ZMQ_VERSION_MAJOR =2, | ||
561 | 34 | ZMQ_VERSION_MINOR =1, | ||
562 | 35 | ZMQ_VERSION_PATCH =10 | ||
563 | 36 | } | ||
564 | 37 | |||
565 | 38 | /* Run-time API version detection */ | ||
566 | 39 | void zmq_version(int* major, int* minor, int* patch); | ||
567 | 40 | |||
568 | 41 | /******************************************************************************/ | ||
569 | 42 | /* 0MQ errors. */ | ||
570 | 43 | /******************************************************************************/ | ||
571 | 44 | |||
572 | 45 | /* A number random anough not to collide with different errno ranges on */ | ||
573 | 46 | /* different OSes. The assumption is that error_t is at least 32-bit type. */ | ||
574 | 47 | immutable enum | ||
575 | 48 | { | ||
576 | 49 | ZMQ_HAUSNUMERO = 156384712, | ||
577 | 50 | |||
578 | 51 | /* On Windows platform some of the standard POSIX errnos are not defined. */ | ||
579 | 52 | ENOTSUP = (ZMQ_HAUSNUMERO + 1), | ||
580 | 53 | EPROTONOSUPPORT = (ZMQ_HAUSNUMERO + 2), | ||
581 | 54 | ENOBUFS = (ZMQ_HAUSNUMERO + 3), | ||
582 | 55 | ENETDOWN = (ZMQ_HAUSNUMERO + 4), | ||
583 | 56 | EADDRINUSE = (ZMQ_HAUSNUMERO + 5), | ||
584 | 57 | EADDRNOTAVAIL = (ZMQ_HAUSNUMERO + 6), | ||
585 | 58 | ECONNREFUSED = (ZMQ_HAUSNUMERO + 7), | ||
586 | 59 | EINPROGRESS = (ZMQ_HAUSNUMERO + 8), | ||
587 | 60 | ENOTSOCK = (ZMQ_HAUSNUMERO + 9), | ||
588 | 61 | |||
589 | 62 | /* Native 0MQ error codes. */ | ||
590 | 63 | EFSM = (ZMQ_HAUSNUMERO + 51), | ||
591 | 64 | ENOCOMPATPROTO = (ZMQ_HAUSNUMERO + 52), | ||
592 | 65 | ETERM = (ZMQ_HAUSNUMERO + 53), | ||
593 | 66 | EMTHREAD = (ZMQ_HAUSNUMERO + 54) | ||
594 | 67 | }//enum error_code | ||
595 | 68 | |||
596 | 69 | /* This function retrieves the errno as it is known to 0MQ library. The goal */ | ||
597 | 70 | /* of this function is to make the code 100% portable, including where 0MQ */ | ||
598 | 71 | /* compiled with certain CRT library (on Windows) is linked to an */ | ||
599 | 72 | /* application that uses different CRT library. */ | ||
600 | 73 | int zmq_errno(); | ||
601 | 74 | |||
602 | 75 | /* Resolves system errors and 0MQ errors to human-readable string. */ | ||
603 | 76 | char* zmq_strerror(int errnum); | ||
604 | 77 | |||
605 | 78 | /******************************************************************************/ | ||
606 | 79 | /* 0MQ message definition. */ | ||
607 | 80 | /******************************************************************************/ | ||
608 | 81 | immutable enum | ||
609 | 82 | { | ||
610 | 83 | /* Maximal size of "Very Small Message". VSMs are passed by value */ | ||
611 | 84 | /* to avoid excessive memory allocation/deallocation. */ | ||
612 | 85 | /* If VMSs larger than 255 bytes are required, type of 'vsm_size' */ | ||
613 | 86 | /* field in zmq_msg_t structure should be modified accordingly. */ | ||
614 | 87 | ZMQ_MAX_VSM_SIZE = 30, | ||
615 | 88 | |||
616 | 89 | /* Message types. These integers may be stored in 'content' member of the */ | ||
617 | 90 | /* message instead of regular pointer to the data. */ | ||
618 | 91 | ZMQ_DELIMITER = 31, | ||
619 | 92 | ZMQ_VSM = 32, | ||
620 | 93 | |||
621 | 94 | /* Message flags. ZMQ_MSG_SHARED is strictly speaking not a message flag */ | ||
622 | 95 | /* (it has no equivalent in the wire format), however, making it a flag */ | ||
623 | 96 | /* allows us to pack the stucture tigher and thus improve performance. */ | ||
624 | 97 | ZMQ_MSG_MORE = 1, | ||
625 | 98 | ZMQ_MSG_SHARED = 128, | ||
626 | 99 | ZMQ_MSG_MASK = 129 | ||
627 | 100 | } | ||
628 | 101 | |||
629 | 102 | /* A message. Note that 'content' is not a pointer to the raw data. */ | ||
630 | 103 | /* Rather it is pointer to zmq::msg_content_t structure */ | ||
631 | 104 | /* (see src/msg_content.hpp for its definition). */ | ||
632 | 105 | struct zmq_msg_t | ||
633 | 106 | { | ||
634 | 107 | void* content; | ||
635 | 108 | ubyte flags; | ||
636 | 109 | ubyte vsm_size; | ||
637 | 110 | ubyte vsm_data[ZMQ_MAX_VSM_SIZE]; | ||
638 | 111 | } | ||
639 | 112 | |||
640 | 113 | int zmq_msg_init(zmq_msg_t* msg); | ||
641 | 114 | int zmq_msg_init_size(zmq_msg_t* msg, size_t size); | ||
642 | 115 | int zmq_msg_init_data(zmq_msg_t* msg, void* data, | ||
643 | 116 | size_t size, void function(void* data, void* hint), void* hint); | ||
644 | 117 | int zmq_msg_close(zmq_msg_t* msg); | ||
645 | 118 | int zmq_msg_move(zmq_msg_t* dest, zmq_msg_t* src); | ||
646 | 119 | int zmq_msg_copy(zmq_msg_t* dest, zmq_msg_t* src); | ||
647 | 120 | void* zmq_msg_data(zmq_msg_t* msg); | ||
648 | 121 | size_t zmq_msg_size(zmq_msg_t* msg); | ||
649 | 122 | |||
650 | 123 | /******************************************************************************/ | ||
651 | 124 | /* 0MQ infrastructure (a.k.a. context) initialisation & termination. */ | ||
652 | 125 | /******************************************************************************/ | ||
653 | 126 | |||
654 | 127 | void* zmq_init(int io_threads); | ||
655 | 128 | int zmq_term(void* context); | ||
656 | 129 | |||
657 | 130 | /******************************************************************************/ | ||
658 | 131 | /* 0MQ socket definition. */ | ||
659 | 132 | /******************************************************************************/ | ||
660 | 133 | |||
661 | 134 | /* Socket types. */ | ||
662 | 135 | immutable enum | ||
663 | 136 | { | ||
664 | 137 | ZMQ_PAIR = 0, | ||
665 | 138 | ZMQ_PUB = 1, | ||
666 | 139 | ZMQ_SUB = 2, | ||
667 | 140 | ZMQ_REQ = 3, | ||
668 | 141 | ZMQ_REP = 4, | ||
669 | 142 | ZMQ_DEALER = 5, | ||
670 | 143 | ZMQ_ROUTER = 6, | ||
671 | 144 | ZMQ_PULL = 7, | ||
672 | 145 | ZMQ_PUSH = 8, | ||
673 | 146 | ZMQ_XPUB = 9, | ||
674 | 147 | ZMQ_XSUB = 10, | ||
675 | 148 | ZMQ_XREQ = ZMQ_DEALER, /* Old alias, remove in 3.x */ | ||
676 | 149 | ZMQ_XREP = ZMQ_ROUTER, /* Old alias, remove in 3.x */ | ||
677 | 150 | ZMQ_UPSTREAM = ZMQ_PULL, /* Old alias, remove in 3.x */ | ||
678 | 151 | ZMQ_DOWNSTREAM = ZMQ_PUSH /* Old alias, remove in 3.x */ | ||
679 | 152 | } | ||
680 | 153 | |||
681 | 154 | /* Socket options. */ | ||
682 | 155 | immutable enum | ||
683 | 156 | { | ||
684 | 157 | ZMQ_HWM = 1, | ||
685 | 158 | ZMQ_SWAP = 3, | ||
686 | 159 | ZMQ_AFFINITY = 4, | ||
687 | 160 | ZMQ_IDENTITY = 5, | ||
688 | 161 | ZMQ_SUBSCRIBE = 6, | ||
689 | 162 | ZMQ_UNSUBSCRIBE = 7, | ||
690 | 163 | ZMQ_RATE = 8, | ||
691 | 164 | ZMQ_RECOVERY_IVL = 9, | ||
692 | 165 | ZMQ_MCAST_LOOP = 10, | ||
693 | 166 | ZMQ_SNDBUF = 11, | ||
694 | 167 | ZMQ_RCVBUF = 12, | ||
695 | 168 | ZMQ_RCVMORE = 13, | ||
696 | 169 | ZMQ_FD = 14, | ||
697 | 170 | ZMQ_EVENTS = 15, | ||
698 | 171 | ZMQ_TYPE = 16, | ||
699 | 172 | ZMQ_LINGER = 17, | ||
700 | 173 | ZMQ_RECONNECT_IVL = 18, | ||
701 | 174 | ZMQ_BACKLOG = 19, | ||
702 | 175 | ZMQ_RECOVERY_IVL_MSEC = 20, /*opt. recovery time, reconcile in 3.x */ | ||
703 | 176 | ZMQ_RECONNECT_IVL_MAX = 21 | ||
704 | 177 | } | ||
705 | 178 | |||
706 | 179 | /* Send/recv options. */ | ||
707 | 180 | immutable enum | ||
708 | 181 | { | ||
709 | 182 | ZMQ_NOBLOCK = 1, | ||
710 | 183 | ZMQ_SNDMORE = 2 | ||
711 | 184 | } | ||
712 | 185 | |||
713 | 186 | void* zmq_socket(void* context, int type); | ||
714 | 187 | int zmq_close(void* s); | ||
715 | 188 | int zmq_setsockopt(void* s, int option, void* optval, size_t optvallen); | ||
716 | 189 | int zmq_getsockopt(void* s, int option, void* optval, size_t *optvallen); | ||
717 | 190 | int zmq_bind(void* s, const char* addr); | ||
718 | 191 | int zmq_connect(void* s, immutable char* addr); | ||
719 | 192 | int zmq_send(void* s, zmq_msg_t* msg, int flags); | ||
720 | 193 | int zmq_recv(void* s, zmq_msg_t* msg, int flags); | ||
721 | 194 | |||
722 | 195 | /******************************************************************************/ | ||
723 | 196 | /* I/O multiplexing. */ | ||
724 | 197 | /******************************************************************************/ | ||
725 | 198 | |||
726 | 199 | immutable enum | ||
727 | 200 | { | ||
728 | 201 | ZMQ_POLLIN = 1, | ||
729 | 202 | ZMQ_POLLOUT = 2, | ||
730 | 203 | ZMQ_POLLERR = 4 | ||
731 | 204 | } | ||
732 | 205 | |||
733 | 206 | __gshared struct zmq_pollitem_t | ||
734 | 207 | { | ||
735 | 208 | void* socket; | ||
736 | 209 | version (win32) | ||
737 | 210 | { | ||
738 | 211 | SOCKET fd; | ||
739 | 212 | } | ||
740 | 213 | else | ||
741 | 214 | { | ||
742 | 215 | int fd; | ||
743 | 216 | } | ||
744 | 217 | short events; | ||
745 | 218 | short revents; | ||
746 | 219 | } | ||
747 | 220 | |||
748 | 221 | int zmq_poll(zmq_pollitem_t* items, int nitems, long timeout); | ||
749 | 222 | |||
750 | 223 | /******************************************************************************/ | ||
751 | 224 | /* Built-in devices */ | ||
752 | 225 | /******************************************************************************/ | ||
753 | 226 | |||
754 | 227 | immutable enum | ||
755 | 228 | { | ||
756 | 229 | ZMQ_STREAMER = 1, | ||
757 | 230 | ZMQ_FORWARDER = 2, | ||
758 | 231 | ZMQ_QUEUE = 3 | ||
759 | 232 | } | ||
760 | 233 | |||
761 | 234 | int zmq_device(int device, void* insocket, void* outsocket); | ||
762 | 235 | |||
763 | 236 | }// extern (C) | ||
764 | 0 | 237 | ||
765 | === added file 'D_lang/common/nrtb/common/zmq_utils.d' | |||
766 | --- D_lang/common/nrtb/common/zmq_utils.d 1970-01-01 00:00:00 +0000 | |||
767 | +++ D_lang/common/nrtb/common/zmq_utils.d 2012-10-17 11:54:28 +0000 | |||
768 | @@ -0,0 +1,58 @@ | |||
769 | 1 | /* | ||
770 | 2 | Copyright (c) 2007-2011 iMatix Corporation | ||
771 | 3 | Copyright (c) 2007-2011 Other contributors as noted in the AUTHORS file | ||
772 | 4 | |||
773 | 5 | This file is part of 0MQ. | ||
774 | 6 | |||
775 | 7 | 0MQ is free software; you can redistribute it and/or modify it under | ||
776 | 8 | the terms of the GNU Lesser General Public License as published by | ||
777 | 9 | the Free Software Foundation; either version 3 of the License, or | ||
778 | 10 | (at your option) any later version. | ||
779 | 11 | |||
780 | 12 | 0MQ is distributed in the hope that it will be useful, | ||
781 | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
782 | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
783 | 15 | GNU Lesser General Public License for more details. | ||
784 | 16 | |||
785 | 17 | You should have received a copy of the GNU Lesser General Public License | ||
786 | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
787 | 19 | */ | ||
788 | 20 | |||
789 | 21 | module zmq_utils; | ||
790 | 22 | |||
791 | 23 | extern (C) | ||
792 | 24 | { | ||
793 | 25 | |||
794 | 26 | /*Handle DSO symbol visibility */ | ||
795 | 27 | /++ | ||
796 | 28 | #if defined _WIN32 | ||
797 | 29 | # if defined DLL_EXPORT | ||
798 | 30 | # define ZMQ_EXPORT __declspec(dllexport) | ||
799 | 31 | # else | ||
800 | 32 | # define ZMQ_EXPORT __declspec(dllimport) | ||
801 | 33 | # endif | ||
802 | 34 | #else | ||
803 | 35 | # if defined __SUNPRO_C || defined __SUNPRO_CC | ||
804 | 36 | # define ZMQ_EXPORT __global | ||
805 | 37 | # elif (defined __GNUC__ && __GNUC__ >= 4) || defined __INTEL_COMPILER | ||
806 | 38 | # define ZMQ_EXPORT __attribute__ ((visibility("default"))) | ||
807 | 39 | # else | ||
808 | 40 | # define ZMQ_EXPORT | ||
809 | 41 | # endif | ||
810 | 42 | #endif | ||
811 | 43 | ++/ | ||
812 | 44 | |||
813 | 45 | /* Helper functions are used by perf tests so that they don't have to care */ | ||
814 | 46 | /* about minutiae of time-related functions on different OS platforms. */ | ||
815 | 47 | |||
816 | 48 | /* Starts the stopwatch. Returns the handle to the watch. */ | ||
817 | 49 | void* zmq_stopwatch_start(); | ||
818 | 50 | |||
819 | 51 | /* Stops the stopwatch. Returns the number of microseconds elapsed since */ | ||
820 | 52 | /* the stopwatch was started. */ | ||
821 | 53 | ulong zmq_stopwatch_stop(void* watch_); | ||
822 | 54 | |||
823 | 55 | /* Sleeps for specified number of seconds. */ | ||
824 | 56 | void zmq_sleep(int seconds_); | ||
825 | 57 | |||
826 | 58 | } | ||
827 | 0 | 59 | ||
828 | === added directory 'D_lang/lib' | |||
829 | === added directory 'D_lang/testing' | |||
830 | === added directory 'D_lang/testing/threads' | |||
831 | === added file 'D_lang/testing/threads/Makefile' | |||
832 | --- D_lang/testing/threads/Makefile 1970-01-01 00:00:00 +0000 | |||
833 | +++ D_lang/testing/threads/Makefile 2012-10-17 11:54:28 +0000 | |||
834 | @@ -0,0 +1,30 @@ | |||
835 | 1 | #*********************************************** | ||
836 | 2 | # This file is part of the NRTB project (https://launchpad.net/nrtb). | ||
837 | 3 | # | ||
838 | 4 | # NRTB is free software: you can redistribute it and/or modify | ||
839 | 5 | # it under the terms of the GNU General Public License as published by | ||
840 | 6 | # the Free Software Foundation, either version 3 of the License, or | ||
841 | 7 | # (at your option) any later version. | ||
842 | 8 | # | ||
843 | 9 | # NRTB is distributed in the hope that it will be useful, | ||
844 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
845 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
846 | 12 | # GNU General Public License for more details. | ||
847 | 13 | # | ||
848 | 14 | # You should have received a copy of the GNU General Public License | ||
849 | 15 | # along with NRTB. If not, see <http://www.gnu.org/licenses/>. | ||
850 | 16 | # | ||
851 | 17 | #*********************************************** | ||
852 | 18 | |||
853 | 19 | lib: msg_passing | ||
854 | 20 | @./msg_passing | ||
855 | 21 | @echo build complete | ||
856 | 22 | |||
857 | 23 | msg_passing: msg_passing.d Makefile | ||
858 | 24 | @rm -f msg_passing | ||
859 | 25 | @dmd msg_passing.d | ||
860 | 26 | |||
861 | 27 | clean: | ||
862 | 28 | @rm -vf *.o msg_passing | ||
863 | 29 | @echo all objects and executables have been erased. | ||
864 | 30 | |||
865 | 0 | 31 | ||
866 | === added file 'D_lang/testing/threads/msg_passing.d' | |||
867 | --- D_lang/testing/threads/msg_passing.d 1970-01-01 00:00:00 +0000 | |||
868 | +++ D_lang/testing/threads/msg_passing.d 2012-10-17 11:54:28 +0000 | |||
869 | @@ -0,0 +1,64 @@ | |||
870 | 1 | /********************* | ||
871 | 2 | Multithreaded message passing example in D | ||
872 | 3 | *********************/ | ||
873 | 4 | |||
874 | 5 | // import the concurrency and standard IO modules | ||
875 | 6 | import std.concurrency, std.stdio; | ||
876 | 7 | |||
877 | 8 | // main is just like main in C++ | ||
878 | 9 | void main() | ||
879 | 10 | { | ||
880 | 11 | writeln("D Multithreaded Message Passing Example."); | ||
881 | 12 | |||
882 | 13 | // intialize some variable; the compiler can figure out the type from usage. | ||
883 | 14 | auto low=0, high = 100; | ||
884 | 15 | |||
885 | 16 | // launch a second thread using function receiver defined below. | ||
886 | 17 | auto rtid = spawn(&receiver); | ||
887 | 18 | |||
888 | 19 | // foreach iterates a range; in this case all values between | ||
889 | 20 | // low and high are assigned are assigned to i sequencially. | ||
890 | 21 | foreach (i; low .. high) | ||
891 | 22 | { | ||
892 | 23 | // sends a message to receiver using it's thread id; queue management is automatic. | ||
893 | 24 | rtid.send(i); | ||
894 | 25 | // report our action | ||
895 | 26 | writeln("Sent ", i); | ||
896 | 27 | |||
897 | 28 | } | ||
898 | 29 | writeln("** main() is complete **"); | ||
899 | 30 | } | ||
900 | 31 | |||
901 | 32 | // receiver is a function which is run as a seperate thread by main. | ||
902 | 33 | void receiver() | ||
903 | 34 | { | ||
904 | 35 | writeln("** receiver() started. **"); | ||
905 | 36 | |||
906 | 37 | // a variable for error checking. | ||
907 | 38 | auto lastid = -1; | ||
908 | 39 | |||
909 | 40 | // function to handle messages | ||
910 | 41 | void int_handler(int i) | ||
911 | 42 | { | ||
912 | 43 | // just print a line and record the last id received | ||
913 | 44 | writeln(" Received ",i); | ||
914 | 45 | lastid = i; | ||
915 | 46 | } | ||
916 | 47 | |||
917 | 48 | // Loop until we the parent shuts down. | ||
918 | 49 | bool running = true; | ||
919 | 50 | while (running) | ||
920 | 51 | { | ||
921 | 52 | receive | ||
922 | 53 | ( | ||
923 | 54 | // handler for int messages | ||
924 | 55 | (int msg) { int_handler(msg); }, | ||
925 | 56 | // handler for "owner terminated" exception | ||
926 | 57 | (OwnerTerminated e) { running = false; } | ||
927 | 58 | ); | ||
928 | 59 | } | ||
929 | 60 | |||
930 | 61 | // quick check to be sure we got them all. | ||
931 | 62 | assert(lastid == 99); | ||
932 | 63 | writeln("** receiver() is complete. **"); | ||
933 | 64 | } | ||
934 | 0 | \ No newline at end of file | 65 | \ No newline at end of file |
935 | 1 | 66 | ||
936 | === added directory 'obsolete' | |||
937 | === added directory 'obsolete/Cpp' | |||
938 | === renamed directory 'common' => 'obsolete/Cpp/common' | |||
939 | === renamed directory 'plugins' => 'obsolete/Cpp/plugins' | |||
940 | === renamed directory 'sim_engine' => 'obsolete/Cpp/sim_engine' |
8:05 AM
me: I've proposed a (long overdue) merge to alpha. It's the directory restructure and D language code starts that was the D_Prototype branch.
Are you good with that?
8:06 AM
George: yes
12 minutes
8:18 AM
me: Okay.. if you are not where you can approve today, I'll copy this IM exchange and move it on.