IOManipulate.tlh 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. #pragma once
  2. //-----------------------------------------------------------------------------
  3. // fcn_obj
  4. //-----------------------------------------------------------------------------
  5. template <class stype, class vtype>
  6. class fcn_obj
  7. {
  8. public:
  9. fcn_obj (stype & (*f) (stype &, vtype), vtype v):
  10. func (f), val (v)
  11. {
  12. }
  13. stype & operator () (stype & s) const
  14. {
  15. return (*func) (s, val);
  16. }
  17. private:
  18. stype & (*func) (stype &, vtype);
  19. vtype val;
  20. };
  21. template <class stype, class vtype>
  22. stype & operator << (stype & ofile, const fcn_obj <stype, vtype> (im))
  23. {
  24. return im (ofile);
  25. }
  26. template <class stype, class vtype>
  27. stype & operator >> (stype & ifile, const fcn_obj <stype, vtype> (im))
  28. {
  29. return im (ifile);
  30. }
  31. //-----------------------------------------------------------------------------
  32. // fcn_2obj
  33. //-----------------------------------------------------------------------------
  34. template <class stype, class vtype1, class vtype2>
  35. class fcn_2obj
  36. {
  37. public:
  38. fcn_2obj (stype & (*f) (stype &, vtype1, vtype2), vtype1 v1, vtype2 v2):
  39. func (f), val1 (v1), val2 (v2)
  40. {
  41. }
  42. stype & operator () (stype & s) const
  43. {
  44. return (*func) (s, val1, val2);
  45. }
  46. private:
  47. stype & (*func) (stype &, vtype1, vtype2);
  48. vtype1 val1;
  49. vtype2 val2;
  50. };
  51. template <class stype, class vtype1, class vtype2>
  52. stype & operator << (stype & ofile, const fcn_2obj <stype, vtype1, vtype2> (im))
  53. {
  54. return im (ofile);
  55. }
  56. template <class stype, class vtype1, class vtype2>
  57. stype & operator >> (stype & ifile, const fcn_2obj <stype, vtype1, vtype2> (im))
  58. {
  59. return im (ifile);
  60. }
  61. //-----------------------------------------------------------------------------
  62. // fcn_3obj
  63. //-----------------------------------------------------------------------------
  64. template <class stype, class vtype1, class vtype2, class vtype3>
  65. class fcn_3obj
  66. {
  67. public:
  68. fcn_3obj (stype & (*f) (stype &, vtype1, vtype2, vtype3), vtype1 v1, vtype2 v2, vtype3 v3):
  69. func (f), val1 (v1), val2 (v2), val3 (v3)
  70. {
  71. }
  72. stype & operator () (stype & s) const
  73. {
  74. return (*func) (s, val1, val2, val3);
  75. }
  76. private:
  77. stype & (*func) (stype &, vtype1, vtype2, vtype3);
  78. vtype1 val1;
  79. vtype2 val2;
  80. vtype3 val3;
  81. };
  82. template <class stype, class vtype1, class vtype2, class vtype3>
  83. stype & operator << (stype & ofile, const fcn_3obj <stype, vtype1, vtype2, vtype3> (im))
  84. {
  85. return im (ofile);
  86. }
  87. template <class stype, class vtype1, class vtype2, class vtype3>
  88. stype & operator >> (stype & ifile, const fcn_3obj <stype, vtype1, vtype2, vtype3> (im))
  89. {
  90. return im (ifile);
  91. }
  92. //-----------------------------------------------------------------------------
  93. // fcn_4obj
  94. //-----------------------------------------------------------------------------
  95. template <class stype, class vtype1, class vtype2, class vtype3, class vtype4>
  96. class fcn_4obj
  97. {
  98. public:
  99. fcn_4obj (stype & (*f) (stype &, vtype1, vtype2, vtype3, vtype4), vtype1 v1, vtype2 v2, vtype3 v3, vtype4 v4) :
  100. func (f), val1 (v1), val2 (v2), val3 (v3), val4 (v4)
  101. {
  102. }
  103. stype & operator () (stype & s) const
  104. {
  105. return (*func) (s, val1, val2, val3, val4);
  106. }
  107. private:
  108. stype & (*func) (stype &, vtype1, vtype2, vtype3, vtype4);
  109. vtype1 val1;
  110. vtype2 val2;
  111. vtype3 val3;
  112. vtype4 val4;
  113. };
  114. template <class stype, class vtype1, class vtype2, class vtype3, class vtype4>
  115. stype & operator << (stype & ofile, const fcn_4obj <stype, vtype1, vtype2, vtype3, vtype4> (im))
  116. {
  117. return im (ofile);
  118. }
  119. template <class stype, class vtype1, class vtype2, class vtype3, class vtype4>
  120. stype & operator >> (stype & ifile, const fcn_4obj <stype, vtype1, vtype2, vtype3, vtype4> (im))
  121. {
  122. return im (ifile);
  123. }