2
0

c_streambuf.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /* $XConsortium: streambuf.h /main/4 1996/06/11 17:39:15 cde-hal $ */
  24. #ifndef _x_streambuf_h
  25. #define _x_streambuf_h
  26. #ifdef EOF
  27. #if EOF!=-1
  28. #define EOF (-1)
  29. #endif
  30. #else
  31. #define EOF (-1)
  32. #endif
  33. typedef long streampos;
  34. #ifdef STREAM_DEBUG
  35. #define form x_form
  36. #define streambuf x_streambuf
  37. #define filebuf x_filebuf
  38. #define ios x_ios
  39. #define iostream x_iostream
  40. #define istream x_istream
  41. #define ostream x_ostream
  42. #define fstream x_fstream
  43. #define istrstream x_istrstream
  44. #define ostrstream x_ostrstream
  45. #endif
  46. class streambuf
  47. {
  48. protected:
  49. char* base;
  50. char* end;
  51. char* put_ptr;
  52. char* get_ptr;
  53. int _size;
  54. int _capacity;
  55. int _alloc;
  56. int _pcount;
  57. int _gcount;
  58. protected:
  59. enum notify_action_t { GET, PUT };
  60. virtual void notify(int) {};
  61. virtual int overflow() { return EOF;};
  62. virtual int underflow() { return EOF; };
  63. int full() { return ( _size == _capacity ) ? 1 : 0 ; };
  64. int empty() { return ( _size == 0 ) ? 1 : 0 ; };
  65. void empty_buffer() {
  66. _size = 0;
  67. put_ptr = get_ptr = base;
  68. };
  69. int move_get_ptr(int);
  70. int move_put_ptr(int);
  71. public:
  72. streambuf();
  73. streambuf(char* p, int l, int pHasContent = 0);
  74. virtual ~streambuf();
  75. virtual int examine() ; // EOF: no char available. Otherwise,
  76. // return 0.The get_ptr pointer does
  77. // not move.
  78. virtual int get() ; // EOF: can't get a char. Otherwise,
  79. // return 0. The get_ptr pointer does move.
  80. virtual int putback(char c) ; // EOF: can't put back. Otherwise,
  81. // putback operation is ok.
  82. virtual int put(char c) ; // EOF: can't put. Otherwise,
  83. // put operation is ok.
  84. int gcount() { return _gcount; };
  85. void clear_gcount() { _gcount = 0; };
  86. int pcount() { return _pcount; };
  87. void clear_pcount() { _pcount = 0; };
  88. virtual int flush() { return EOF; };
  89. virtual int seekg(streampos) { return EOF; };
  90. char* get_buf() { return base; };
  91. };
  92. #endif