StreamBuf.hpp
Go to the documentation of this file.
1 //==============================================================================
2 //
3 // This file is part of GNSSTk, the ARL:UT GNSS Toolkit.
4 //
5 // The GNSSTk is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published
7 // by the Free Software Foundation; either version 3.0 of the License, or
8 // any later version.
9 //
10 // The GNSSTk is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with GNSSTk; if not, write to the Free Software Foundation,
17 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 //
19 // This software was developed by Applied Research Laboratories at the
20 // University of Texas at Austin.
21 // Copyright 2004-2022, The Board of Regents of The University of Texas System
22 //
23 //==============================================================================
24 
25 //==============================================================================
26 //
27 // This software was developed by Applied Research Laboratories at the
28 // University of Texas at Austin, under contract to an agency or agencies
29 // within the U.S. Department of Defense. The U.S. Government retains all
30 // rights to use, duplicate, distribute, disclose, or release this software.
31 //
32 // Pursuant to DoD Directive 523024
33 //
34 // DISTRIBUTION STATEMENT A: This software has been approved for public
35 // release, distribution is unlimited.
36 //
37 //==============================================================================
38 
44 #ifndef GNSSTK_STREAMBUF_HPP
45 #define GNSSTK_STREAMBUF_HPP
46 
47 #include <streambuf>
48 #include <iosfwd>
49 #include <ios>
50 
51 namespace gnsstk
52 {
54  template <typename ch, typename tr>
55  class BasicStreamBuf: public std::basic_streambuf<ch, tr>
56  {
57  protected:
58  typedef std::basic_streambuf<ch, tr> Base;
59  typedef std::basic_ios<ch, tr> IOS;
60  typedef ch char_type;
61  typedef tr char_traits;
62  typedef typename Base::int_type int_type;
63  typedef typename Base::pos_type pos_type;
64  typedef typename Base::off_type off_type;
65  typedef typename IOS::openmode openmode;
66 
67  public:
68  BasicStreamBuf() : _pb(char_traits::eof()), _ispb(false)
69  {
70  this->setg(0, 0, 0);
71  this->setp(0, 0);
72  }
73 
75  {
76  }
77 
79  {
80  if (c != char_traits::eof())
81  return writeToDevice(char_traits::to_char_type(c));
82  else
83  return c;
84  }
85 
86  virtual int_type underflow()
87  {
88  if (_ispb)
89  {
90  return _pb;
91  }
92  else
93  {
95  if (c != char_traits::eof())
96  {
97  _ispb = true;
98  _pb = c;
99  }
100  return c;
101  }
102  }
103 
104  virtual int_type uflow()
105  {
106  if (_ispb)
107  {
108  _ispb = false;
109  return _pb;
110  }
111  else
112  {
113  int_type c = readFromDevice();
114  if (c != char_traits::eof())
115  {
116  _pb = c;
117  }
118  return c;
119  }
120  }
121 
123  {
124  if (_ispb)
125  {
126  return char_traits::eof();
127  }
128  else
129  {
130  _ispb = true;
131  _pb = c;
132  return c;
133  }
134  }
135 
136  virtual std::streamsize xsgetn(char_type* p, std::streamsize count)
137  {
138  std::streamsize copied = 0;
139  while (count > 0)
140  {
141  int_type c = uflow();
142  if (c == char_traits::eof()) break;
143  *p++ = char_traits::to_char_type(c);
144  ++copied;
145  --count;
146  }
147  return copied;
148  }
149 
150  protected:
152  {
153  return char_traits::to_int_type(c);
154  }
155 
156  private:
158  {
159  return char_traits::eof();
160  }
161 
163  {
164  return char_traits::eof();
165  }
166 
168  bool _ispb;
169 
172 
173  }; // End of class 'BasicStreamBuf'
174 
176 
177 } // End of namespace gnsstk
178 
179 
180 
181 #endif //GNSSTK_BASICSTREAMBUF_HPP
gnsstk::BasicStreamBuf::uflow
virtual int_type uflow()
Definition: StreamBuf.hpp:104
gnsstk::BasicStreamBuf::underflow
virtual int_type underflow()
Definition: StreamBuf.hpp:86
gnsstk::BasicStreamBuf::xsgetn
virtual std::streamsize xsgetn(char_type *p, std::streamsize count)
Definition: StreamBuf.hpp:136
gnsstk::BasicStreamBuf::writeToDevice
virtual int_type writeToDevice(char_type)
Definition: StreamBuf.hpp:162
gnsstk::BasicStreamBuf::pbackfail
virtual int_type pbackfail(int_type c)
Definition: StreamBuf.hpp:122
gnsstk::BasicStreamBuf::pos_type
Base::pos_type pos_type
Definition: StreamBuf.hpp:63
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
gnsstk::BasicStreamBuf::~BasicStreamBuf
~BasicStreamBuf()
Definition: StreamBuf.hpp:74
gnsstk::BasicStreamBuf::BasicStreamBuf
BasicStreamBuf()
Definition: StreamBuf.hpp:68
gnsstk::BasicStreamBuf::Base
std::basic_streambuf< ch, tr > Base
Definition: StreamBuf.hpp:58
gnsstk::BasicStreamBuf::charToInt
static int_type charToInt(char_type c)
Definition: StreamBuf.hpp:151
gnsstk::BasicStreamBuf::_ispb
bool _ispb
Definition: StreamBuf.hpp:168
gnsstk::BasicStreamBuf::operator=
BasicStreamBuf & operator=(const BasicStreamBuf &)
gnsstk::BasicStreamBuf::readFromDevice
virtual int_type readFromDevice()
Definition: StreamBuf.hpp:157
gnsstk::BasicStreamBuf::char_traits
tr char_traits
Definition: StreamBuf.hpp:61
gnsstk::BasicStreamBuf::off_type
Base::off_type off_type
Definition: StreamBuf.hpp:64
gnsstk::StreamBuf
BasicStreamBuf< char, std::char_traits< char > > StreamBuf
Definition: StreamBuf.hpp:175
gnsstk::BasicStreamBuf
This class easy implement the custom streambufs.
Definition: StreamBuf.hpp:55
gnsstk::BasicStreamBuf::IOS
std::basic_ios< ch, tr > IOS
Definition: StreamBuf.hpp:59
gnsstk::BasicStreamBuf::openmode
IOS::openmode openmode
Definition: StreamBuf.hpp:65
gnsstk::BasicStreamBuf::_pb
int_type _pb
Definition: StreamBuf.hpp:167
gnsstk::BasicStreamBuf::char_type
ch char_type
Definition: StreamBuf.hpp:60
gnsstk::BasicStreamBuf::overflow
virtual int_type overflow(int_type c)
Definition: StreamBuf.hpp:78
gnsstk::BasicStreamBuf::int_type
Base::int_type int_type
Definition: StreamBuf.hpp:62


gnsstk
Author(s):
autogenerated on Wed Oct 25 2023 02:40:41