iostream.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /**
  2. * Copyright (c) 2011-2018 Bill Greiman
  3. * This file is part of the SdFat library for SD memory cards.
  4. *
  5. * MIT License
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a
  8. * copy of this software and associated documentation files (the "Software"),
  9. * to deal in the Software without restriction, including without limitation
  10. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  11. * and/or sell copies of the Software, and to permit persons to whom the
  12. * Software is furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included
  15. * in all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  18. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  22. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  23. * DEALINGS IN THE SOFTWARE.
  24. */
  25. #ifndef iostream_h
  26. #define iostream_h
  27. /**
  28. * \file
  29. * \brief \ref iostream class
  30. */
  31. #include "istream.h"
  32. #include "ostream.h"
  33. /** Skip white space
  34. * \param[in] is the Stream
  35. * \return The stream
  36. */
  37. inline istream& ws(istream& is) {
  38. is.skipWhite();
  39. return is;
  40. }
  41. /** insert endline
  42. * \param[in] os The Stream
  43. * \return The stream
  44. */
  45. inline ostream& endl(ostream& os) {
  46. os.put('\n');
  47. #if ENDL_CALLS_FLUSH
  48. os.flush();
  49. #endif // ENDL_CALLS_FLUSH
  50. return os;
  51. }
  52. /** flush manipulator
  53. * \param[in] os The stream
  54. * \return The stream
  55. */
  56. inline ostream& flush(ostream& os) {
  57. os.flush();
  58. return os;
  59. }
  60. /**
  61. * \struct setfill
  62. * \brief type for setfill manipulator
  63. */
  64. struct setfill {
  65. /** fill character */
  66. char c;
  67. /** constructor
  68. *
  69. * \param[in] arg new fill character
  70. */
  71. explicit setfill(char arg) : c(arg) {}
  72. };
  73. /** setfill manipulator
  74. * \param[in] os the stream
  75. * \param[in] arg set setfill object
  76. * \return the stream
  77. */
  78. inline ostream &operator<< (ostream &os, const setfill &arg) {
  79. os.fill(arg.c);
  80. return os;
  81. }
  82. /** setfill manipulator
  83. * \param[in] obj the stream
  84. * \param[in] arg set setfill object
  85. * \return the stream
  86. */
  87. inline istream &operator>>(istream &obj, const setfill &arg) {
  88. obj.fill(arg.c);
  89. return obj;
  90. }
  91. //------------------------------------------------------------------------------
  92. /** \struct setprecision
  93. * \brief type for setprecision manipulator
  94. */
  95. struct setprecision {
  96. /** precision */
  97. unsigned int p;
  98. /** constructor
  99. * \param[in] arg new precision
  100. */
  101. explicit setprecision(unsigned int arg) : p(arg) {}
  102. };
  103. /** setprecision manipulator
  104. * \param[in] os the stream
  105. * \param[in] arg set setprecision object
  106. * \return the stream
  107. */
  108. inline ostream &operator<< (ostream &os, const setprecision &arg) {
  109. os.precision(arg.p);
  110. return os;
  111. }
  112. /** setprecision manipulator
  113. * \param[in] is the stream
  114. * \param[in] arg set setprecision object
  115. * \return the stream
  116. */
  117. inline istream &operator>>(istream &is, const setprecision &arg) {
  118. is.precision(arg.p);
  119. return is;
  120. }
  121. //------------------------------------------------------------------------------
  122. /** \struct setw
  123. * \brief type for setw manipulator
  124. */
  125. struct setw {
  126. /** width */
  127. unsigned w;
  128. /** constructor
  129. * \param[in] arg new width
  130. */
  131. explicit setw(unsigned arg) : w(arg) {}
  132. };
  133. /** setw manipulator
  134. * \param[in] os the stream
  135. * \param[in] arg set setw object
  136. * \return the stream
  137. */
  138. inline ostream &operator<< (ostream &os, const setw &arg) {
  139. os.width(arg.w);
  140. return os;
  141. }
  142. /** setw manipulator
  143. * \param[in] is the stream
  144. * \param[in] arg set setw object
  145. * \return the stream
  146. */
  147. inline istream &operator>>(istream &is, const setw &arg) {
  148. is.width(arg.w);
  149. return is;
  150. }
  151. //==============================================================================
  152. /**
  153. * \class iostream
  154. * \brief Input/Output stream
  155. */
  156. class iostream : public istream, public ostream {
  157. };
  158. #endif // iostream_h