Advertisement
GeneralGDA

IO Builder

Mar 8th, 2020
3,581
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 1.07 KB | None | 0 0
  1. module io.builder;
  2.  
  3. import std.stdio;
  4.  
  5. const format = "%f\n";
  6.  
  7. struct Vector
  8. {
  9.     float x = 0;
  10.     float y = 0;
  11.     float z = 0;
  12.     float w = 1;
  13. }
  14.  
  15. void WriteVector(ref Vector victim)
  16. {
  17.     writeln(victim.x);
  18.     writeln(victim.y);
  19.     writeln(victim.z);
  20.     writeln(victim.w);
  21. }
  22.  
  23. void ReadVector(ref Vector victim)
  24. {
  25.     readf!format(victim.x);
  26.     readf!format(victim.y);
  27.     readf!format(victim.z);
  28.     readf!format(victim.w);
  29. }
  30.  
  31. interface IO
  32. {
  33.     void Exec(ref float victim);
  34. }
  35.  
  36. final class Input : IO
  37. {
  38.     void Exec(ref float victim)
  39.     {
  40.         readf!format(victim);
  41.     }
  42. }
  43.  
  44. final class Output : IO
  45. {
  46.     void Exec(ref float victim)
  47.     {
  48.         writeln(victim);
  49.     }
  50. }
  51.  
  52. void Io(ref Vector victim, IO io)
  53. {
  54.     io.Exec(victim.x);
  55.     io.Exec(victim.y);
  56.     io.Exec(victim.z);
  57.     io.Exec(victim.w);
  58. }
  59.  
  60. int main()
  61. {
  62.     Vector fourDimentional;
  63.    
  64.     //ReadVector(fourDimentional);
  65.     //WriteVector(fourDimentional);
  66.  
  67.     Io(fourDimentional, new Input());
  68.     Io(fourDimentional, new Output());
  69.    
  70.  
  71.     return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement