1 /* stdiobuf class declaration.
2    Copyright (C) 2001-2010 Roberto Bagnara <bagnara@cs.unipr.it>
3    Copyright (C) 2010-2016 BUGSENG srl (http://bugseng.com)
4 
5 This file is part of the Parma Polyhedra Library (PPL).
6 
7 The PPL is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 The PPL is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software Foundation,
19 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA.
20 
21 For the most up-to-date information see the Parma Polyhedra Library
22 site: http://bugseng.com/products/ppl/ . */
23 
24 #ifndef PPL_stdiobuf_defs_hh
25 #define PPL_stdiobuf_defs_hh 1
26 
27 #include "stdiobuf_types.hh"
28 #include <cstdio>
29 #include <streambuf>
30 
31 class Parma_Polyhedra_Library::stdiobuf
32   : public std::basic_streambuf<char, std::char_traits<char> > {
33 public:
34   //! Constructor.
35   stdiobuf(FILE* file);
36 
37 protected:
38   /*! \brief
39     Gets a character in case of underflow.
40 
41     \remarks
42     Specified by ISO/IEC 14882:1998: 27.5.2.4.3.
43   */
44   virtual int_type underflow();
45 
46   /*! \brief
47     In case of underflow, gets a character and advances the next pointer.
48 
49     \remarks
50     Specified by ISO/IEC 14882:1998: 27.5.2.4.3.
51   */
52   virtual int_type uflow();
53 
54   /*! \brief
55     Gets a sequence of characters.
56 
57     \remarks
58     Specified by ISO/IEC 14882:1998: 27.5.2.4.3.
59   */
60   virtual std::streamsize xsgetn(char_type* s, std::streamsize n);
61 
62   /*! \brief
63     Puts character back in case of backup underflow.
64 
65     \remarks
66     Specified by ISO/IEC 14882:1998: 27.5.2.4.4.
67   */
68   virtual int_type pbackfail(int_type c = traits_type::eof());
69 
70   /*! \brief
71     Writes a sequence of characters.
72 
73     \remarks
74     Specified by ISO/IEC 14882:1998: 27.5.2.4.5.
75   */
76   virtual std::streamsize xsputn(const char_type* s, std::streamsize n);
77 
78   /*! \brief
79     Writes a character in case of overflow.
80 
81     Specified by ISO/IEC 14882:1998: 27.5.2.4.5.
82   */
83   virtual int_type overflow(int_type c);
84 
85   /*! \brief
86     Synchronizes the stream buffer.
87 
88     Specified by ISO/IEC 14882:1998: 27.5.2.4.2.
89   */
90   virtual int sync();
91 
92 private:
93   //! Character type of the streambuf.
94   typedef char char_type;
95 
96   //! Traits type of the streambuf.
97   typedef std::char_traits<char_type> traits_type;
98 
99   //! Integer type of the streambuf.
100   typedef traits_type::int_type int_type;
101 
102   //! The encapsulated stdio file.
103   FILE* fp;
104 
105   //! Buffer for the last character read.
106   int_type unget_char_buf;
107 };
108 
109 #include "stdiobuf_inlines.hh"
110 
111 #endif // !defined(PPL_stdiobuf_defs_hh)
112