PPL  1.2
stdiobuf.cc
Go to the documentation of this file.
1 /* stdiobuf class implementation (non-inline functions).
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 #include "ppl-config.h"
25 #include "stdiobuf_defs.hh"
26 #include "globals_defs.hh"
27 #include "assertions.hh"
28 #include <cstddef>
29 
30 namespace Parma_Polyhedra_Library {
31 
34  unget_char_buf = getc(fp);
35  return unget_char_buf;
36 }
37 
40  const int_type c = getc(fp);
41  return ungetc(c, fp);
42 }
43 
44 std::streamsize
45 stdiobuf::xsgetn(char_type* s, std::streamsize n) {
46  PPL_ASSERT(n >= 0);
47  const size_t r = fread(s, 1, static_cast<size_t>(n), fp);
48  if (r > 0) {
49  unget_char_buf = traits_type::to_int_type(s[r - 1]);
50  }
51  else {
52  unget_char_buf = traits_type::eof();
53  }
54  return static_cast<std::streamsize>(r);
55 }
56 
59  const int_type eof = traits_type::eof();
60  const int_type u = traits_type::eq_int_type(c, eof) ? unget_char_buf : c;
61  unget_char_buf = eof;
62  return traits_type::eq_int_type(u, eof) ? eof : ungetc(u, fp);
63 }
64 
65 std::streamsize
66 stdiobuf::xsputn(const char_type* s, std::streamsize n) {
67  PPL_ASSERT(n >= 0);
68  const size_t r = fwrite(s, 1, static_cast<size_t>(n), fp);
69  return static_cast<std::streamsize>(r);
70 }
71 
74  const int_type eof = traits_type::eof();
75  if (traits_type::eq_int_type(c, eof)) {
76  return (fflush(fp) != 0) ? eof : traits_type::not_eof(c);
77  }
78  else {
79  return putc(c, fp);
80  }
81 }
82 
83 int
85  return fflush(fp);
86 }
87 
88 } // namespace Parma_Polyhedra_Library
virtual int_type uflow()
In case of underflow, gets a character and advances the next pointer.
Definition: stdiobuf.cc:33
virtual int_type pbackfail(int_type c=traits_type::eof())
Puts character back in case of backup underflow.
Definition: stdiobuf.cc:58
virtual std::streamsize xsgetn(char_type *s, std::streamsize n)
Gets a sequence of characters.
Definition: stdiobuf.cc:45
FILE * fp
The encapsulated stdio file.
virtual int_type underflow()
Gets a character in case of underflow.
Definition: stdiobuf.cc:39
char char_type
Character type of the streambuf.
virtual std::streamsize xsputn(const char_type *s, std::streamsize n)
Writes a sequence of characters.
Definition: stdiobuf.cc:66
virtual int_type overflow(int_type c)
Writes a character in case of overflow.
Definition: stdiobuf.cc:73
The entire library is confined to this namespace.
Definition: version.hh:61
int_type unget_char_buf
Buffer for the last character read.
Coefficient c
Definition: PIP_Tree.cc:64
virtual int sync()
Synchronizes the stream buffer.
Definition: stdiobuf.cc:84
traits_type::int_type int_type
Integer type of the streambuf.