Mercurial > hg > octave-nkf
comparison mk-opts.pl @ 11497:7bddd70bc838
mk-opts.pl: generate initialization lists and in-line code for copy method
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 13 Jan 2011 02:23:38 -0500 |
parents | eb63fbe60fab |
children | fd0a3ac60b0e |
comparison
equal
deleted
inserted
replaced
11496:aee00336a440 | 11497:7bddd70bc838 |
---|---|
358 | 358 |
359 $set_code[$opt_num] .= $_; | 359 $set_code[$opt_num] .= $_; |
360 } | 360 } |
361 } | 361 } |
362 | 362 |
363 sub emit_copy_body | |
364 { | |
365 local ($pfx, $var) = @_; | |
366 | |
367 for ($i = 0; $i < $opt_num; $i++) | |
368 { | |
369 print "${pfx}$optvar[$i] = ${var}.$optvar[$i];\n"; | |
370 } | |
371 | |
372 print "${pfx}reset = ${var}.reset;\n"; | |
373 } | |
374 | |
375 ## To silence GCC warnings, we create an initialization list even | |
376 ## though the init function actually does the work of initialization. | |
377 | |
378 sub emit_default_init_list | |
379 { | |
380 local ($prefix) = @_; | |
381 | |
382 for ($i = 0; $i < $opt_num; $i++) | |
383 { | |
384 if ($i == 0) | |
385 { | |
386 $pfx = ""; | |
387 } | |
388 else | |
389 { | |
390 $pfx = $prefix; | |
391 } | |
392 | |
393 print "${pfx}$optvar[$i] (),\n"; | |
394 } | |
395 | |
396 print "${prefix}reset ()\n"; | |
397 } | |
398 | |
399 sub emit_copy_ctor_init_list | |
400 { | |
401 local ($prefix, $var) = @_; | |
402 | |
403 for ($i = 0; $i < $opt_num; $i++) | |
404 { | |
405 if ($i == 0) | |
406 { | |
407 $pfx = ""; | |
408 } | |
409 else | |
410 { | |
411 $pfx = $prefix; | |
412 } | |
413 | |
414 print "${pfx}$optvar[$i] ($var.$optvar[$i]),\n"; | |
415 } | |
416 | |
417 print "${prefix}reset ($var.reset)\n"; | |
418 } | |
419 | |
363 sub emit_opt_class_header | 420 sub emit_opt_class_header |
364 { | 421 { |
365 local ($i, $s); | 422 local ($i, $s); |
366 | 423 |
367 print "// DO NOT EDIT! | 424 print "// DO NOT EDIT! |
378 class | 435 class |
379 ${class_name} | 436 ${class_name} |
380 { | 437 { |
381 public: | 438 public: |
382 | 439 |
383 ${class_name} (void) { init (); } | 440 ${class_name} (void) |
384 | 441 : "; |
385 ${class_name} (const ${class_name}& opt) { copy (opt); } | 442 |
443 &emit_default_init_list (" "); | |
444 | |
445 print " { | |
446 init (); | |
447 } | |
448 | |
449 ${class_name} (const ${class_name}& opt) | |
450 : "; | |
451 | |
452 &emit_copy_ctor_init_list (" ", "opt"); | |
453 | |
454 print " { } | |
386 | 455 |
387 ${class_name}& operator = (const ${class_name}& opt) | 456 ${class_name}& operator = (const ${class_name}& opt) |
388 { | 457 { |
389 if (this != &opt) | 458 if (this != &opt) |
390 copy (opt); | 459 {\n"; |
460 | |
461 &emit_copy_body (" ", "opt"); | |
462 | |
463 print " } | |
391 | 464 |
392 return *this; | 465 return *this; |
393 } | 466 } |
394 | 467 |
395 ~${class_name} (void) { }\n"; | 468 ~${class_name} (void) { }\n"; |
413 } | 486 } |
414 | 487 |
415 print " reset = true; | 488 print " reset = true; |
416 }\n"; | 489 }\n"; |
417 | 490 |
418 print "\n void copy (const ${class_name}& opt)\n {\n"; | |
419 | |
420 for ($i = 0; $i < $opt_num; $i++) | |
421 { | |
422 print " $optvar[$i] = opt.$optvar[$i];\n"; | |
423 } | |
424 | |
425 print " reset = opt.reset; | |
426 }\n"; | |
427 | |
428 ## For backward compatibility and because set_options is probably | 491 ## For backward compatibility and because set_options is probably |
429 ## a better name in some contexts: | 492 ## a better name in some contexts: |
430 | 493 |
431 print "\n void set_options (const ${class_name}& opt) { copy (opt); }\n"; | 494 print "\n void set_options (const ${class_name}& opt) |
432 | 495 {\n"; |
433 print "\n void set_default_options (void) { init (); }\n"; | 496 |
497 &emit_copy_body (" ", "opt"); | |
498 | |
499 print " }\n\n void set_default_options (void) { init (); }\n"; | |
434 | 500 |
435 for ($i = 0; $i < $opt_num; $i++) | 501 for ($i = 0; $i < $opt_num; $i++) |
436 { | 502 { |
437 if ($set_expr[$i]) | 503 if ($set_expr[$i]) |
438 { | 504 { |