PPL  1.2
c_streambuf.cc
Go to the documentation of this file.
1 /* c_streambuf 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 "c_streambuf_defs.hh"
26 #include "globals_defs.hh"
27 #include "assertions.hh"
28 
29 namespace Parma_Polyhedra_Library {
30 
32 }
33 
36  const int_type c = underflow();
37  next_char_buf = traits_type::eof();
38  return c;
39 }
40 
43  const int_type eof = traits_type::eof();
44  if (traits_type::eq_int_type(next_char_buf, eof)) {
45  char buf;
46  if (cb_read(&buf, 1) == 1) {
47  next_char_buf = buf;
48  }
49  else {
50  next_char_buf = eof;
51  }
52  }
53  return next_char_buf;
54 }
55 
56 std::streamsize
57 c_streambuf::xsgetn(char_type* s, std::streamsize n) {
58  PPL_ASSERT(n >= 0);
59  if (n == 0) {
60  return n;
61  }
62  const int_type eof = traits_type::eof();
63  const size_t sz_n = static_cast<size_t>(n);
64  size_t a;
65  if (traits_type::eq_int_type(next_char_buf, eof)) {
66  a = 0;
67  }
68  else {
69  s[0] = static_cast<char_type>(next_char_buf);
70  a = 1;
71  }
72  const size_t r = cb_read(s + a, sz_n - a) + a;
73  if (r > 0) {
74  unget_char_buf = traits_type::to_int_type(s[r - 1]);
75  }
76  else {
77  unget_char_buf = traits_type::eof();
78  }
79  return static_cast<std::streamsize>(r);
80 }
81 
84  const int_type eof = traits_type::eof();
85  next_char_buf = traits_type::eq_int_type(c, eof) ? unget_char_buf : c;
86  unget_char_buf = eof;
87  return next_char_buf;
88 }
89 
90 std::streamsize
91 c_streambuf::xsputn(const char_type* s, std::streamsize n) {
92  PPL_ASSERT(n >= 0);
93  const size_t r = cb_write(s, static_cast<size_t>(n));
94  return static_cast<std::streamsize>(r);
95 }
96 
99  const int_type eof = traits_type::eof();
100  if (traits_type::eq_int_type(c, eof)) {
101  return (sync() != 0) ? eof : traits_type::not_eof(c);
102  }
103  else {
104  char buf = static_cast<char>(c);
105  if (cb_write(&buf, 1) == 1) {
106  return c;
107  }
108  else {
109  return eof;
110  }
111  }
112 }
113 
114 int
116  return cb_sync();
117 }
118 
119 } // namespace Parma_Polyhedra_Library
virtual int_type uflow()
In case of underflow, gets a character and advances the next pointer.
Definition: c_streambuf.cc:35
int_type next_char_buf
Buffer for next character.
virtual int sync()
Synchronizes the stream buffer.
Definition: c_streambuf.cc:115
traits_type::int_type int_type
Integer type of the streambuf.
virtual size_t cb_read(char *, size_t)
virtual ~c_streambuf()
Destructor.
Definition: c_streambuf.cc:31
virtual int_type pbackfail(int_type c=traits_type::eof())
Puts character back in case of backup underflow.
Definition: c_streambuf.cc:83
int_type unget_char_buf
Buffer for the last character read.
char char_type
Character type of the streambuf.
virtual int_type overflow(int_type c)
Writes a character in case of overflow.
Definition: c_streambuf.cc:98
virtual int_type underflow()
Gets a character in case of underflow.
Definition: c_streambuf.cc:42
virtual std::streamsize xsputn(const char_type *s, std::streamsize n)
Writes a sequence of characters.
Definition: c_streambuf.cc:91
The entire library is confined to this namespace.
Definition: version.hh:61
virtual size_t cb_write(const char *, size_t)
virtual std::streamsize xsgetn(char_type *s, std::streamsize n)
Gets a sequence of characters.
Definition: c_streambuf.cc:57
Coefficient c
Definition: PIP_Tree.cc:64