Advertisement
Guest User

sample cascade emulation

a guest
Oct 7th, 2013
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 1.47 KB | None | 0 0
  1. module plus.models.removeme;
  2.  
  3. import vibe.data.json;
  4. import std.datetime;
  5.  
  6. struct Person {
  7.   string birthDate;
  8.   string deathDate;
  9.   string retirementDate;
  10.  
  11.   // custom <struct public Person>
  12.   // end <struct public Person>
  13.  
  14. }
  15. struct Asset {
  16.   string name;
  17.   int quantity = 1;
  18.   double unitValue = 1.0;
  19.  
  20.   // custom <struct public Asset>
  21.   // end <struct public Asset>
  22.  
  23. }
  24. struct Dossier {
  25.   Person[string] family;
  26.   Asset[string] assets;
  27.  
  28.   // custom <struct public Dossier>
  29.   // end <struct public Dossier>
  30.  
  31. }
  32.  
  33. // custom <module public removeme>
  34.  
  35. T make(T)(void delegate(ref T t) dg) {
  36.   T result;
  37.   dg(result);
  38.   return result;
  39. }
  40.  
  41. // end <module public removeme>
  42.  
  43. static if(1) unittest {
  44.   // custom <unittest removeme>
  45.  
  46.   import std.stdio;
  47.  
  48.   auto d = make((ref Dossier _) {
  49.       _.family = [
  50.        "father" : make((ref Person _) {
  51.            _.birthDate = "2001/1/1";
  52.            _.deathDate = "2101/1/1";
  53.            _.retirementDate = "2100/1/1"; }),
  54.        "mother" : make((ref Person _) {
  55.            _.birthDate = "2005/1/1";
  56.            _.deathDate = "2125/1/1";
  57.            _.retirementDate = "2100/1/1"; }),
  58.        ];
  59.       _.assets = [
  60.        "house" : make((ref Asset _) {
  61.            _.name = "Home on the Hill";
  62.            _.unitValue = 120_000; }),
  63.        "car" : make((ref Asset _) {
  64.            _.name = "Dodge Dart";
  65.            _.unitValue = 500; })
  66.       ];
  67.     });
  68.  
  69.   writeln(d);
  70.   // end <unittest removeme>
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement