CMS 3D CMS Logo

memstream.h
Go to the documentation of this file.
1 #ifndef PhysicsTools_MVAComputer_memstream_h
2 #define PhysicsTools_MVAComputer_memstream_h
3 // -*- C++ -*-
4 //
5 // Package: MVAComputer
6 //
7 
8 //
9 // Author: Christophe Saout <christophe.saout@cern.ch>
10 // Created: Sat Apr 24 15:18 CEST 2007
11 //
12 
13 #include <iostream>
14 
15 namespace ext {
16 
17  // provide STL stream to read/write into memory buffers
18  //
19  // constructors both take pointer to a buffer and buffer size
20 
21  template <typename Item_t, typename Traits_t = std::char_traits<Item_t>, typename Allocator_t = std::allocator<Item_t> >
22  class basic_omemstream : private std::basic_streambuf<Item_t, Traits_t>, public std::basic_ostream<Item_t, Traits_t> {
23  public:
24  typedef typename Traits_t::char_type char_type;
25  typedef typename Traits_t::int_type int_type;
26  typedef Traits_t traits_type;
27 
29  : std::basic_ostream<Item_t, Traits_t>(this), buffer(buf), cur(buf), last(buf + size) {
30  this->exceptions(std::ios_base::badbit);
31  }
32 
33  char_type *begin() const { return buffer; }
34  char_type *end() const { return cur; }
35  size_t size() const { return cur - buffer; }
36  bool empty() const { return cur == buffer; }
37 
38  private:
39  std::streamsize xsputn(char_type const *data, std::streamsize size) override {
40  size_t n = std::min<size_t>(last - cur, size);
42  cur += n;
43  return n;
44  }
45 
47  if (!traits_type::eq_int_type(c, traits_type::eof())) {
48  char_type t = traits_type::to_char_type(c);
49  if (xsputn(&t, 1) < 1)
50  return traits_type::eof();
51  }
52 
53  return c;
54  }
55 
56  int sync() override { return 0; }
57 
59  };
60 
61  template <typename Item_t, typename Traits_t = std::char_traits<Item_t>, typename Allocator_t = std::allocator<Item_t> >
62  class basic_imemstream : private std::basic_streambuf<Item_t, Traits_t>, public std::basic_istream<Item_t, Traits_t> {
63  public:
64  typedef typename Traits_t::char_type char_type;
65  typedef typename Traits_t::int_type int_type;
66  typedef Traits_t traits_type;
67 
68  basic_imemstream(const char_type *buf, size_t size) : std::basic_istream<Item_t, Traits_t>(this) {
69  this->exceptions(std::ios_base::badbit);
70  this->setg(const_cast<char_type *>(buf), const_cast<char_type *>(buf), const_cast<char_type *>(buf + size));
71  }
72 
73  private:
74  int_type underflow() override {
75  if (this->gptr() && this->gptr() < this->egptr())
76  return traits_type::to_int_type(*this->gptr());
77 
78  return traits_type::eof();
79  }
80  };
81 
86 
87 } // namespace ext
88 
89 #endif // PhysicsTools_MVAComputer_memstream_h
ext::basic_imemstream::underflow
int_type underflow() override
Definition: memstream.h:74
ext
Definition: memstream.h:15
ext::basic_omemstream::overflow
int_type overflow(int_type c) override
Definition: memstream.h:46
ext::basic_imemstream
Definition: memstream.h:62
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
filterCSVwithJSON.copy
copy
Definition: filterCSVwithJSON.py:36
ext::basic_omemstream
Definition: memstream.h:22
ext::basic_omemstream::empty
bool empty() const
Definition: memstream.h:36
ext::basic_omemstream::buffer
char_type * buffer
Definition: memstream.h:58
ext::basic_imemstream::basic_imemstream
basic_imemstream(const char_type *buf, size_t size)
Definition: memstream.h:68
ext::imemstream
basic_imemstream< char > imemstream
Definition: memstream.h:84
ext::basic_omemstream::basic_omemstream
basic_omemstream(char_type *buf, size_t size)
Definition: memstream.h:28
ext::basic_omemstream::char_type
Traits_t::char_type char_type
Definition: memstream.h:24
ext::basic_omemstream::traits_type
Traits_t traits_type
Definition: memstream.h:26
ext::basic_omemstream::xsputn
std::streamsize xsputn(char_type const *data, std::streamsize size) override
Definition: memstream.h:39
ext::basic_omemstream::end
char_type * end() const
Definition: memstream.h:34
ext::basic_omemstream::int_type
Traits_t::int_type int_type
Definition: memstream.h:25
ext::basic_omemstream::cur
char_type * cur
Definition: memstream.h:58
ext::basic_imemstream::traits_type
Traits_t traits_type
Definition: memstream.h:66
ext::basic_omemstream::sync
int sync() override
Definition: memstream.h:56
visDQMUpload.buf
buf
Definition: visDQMUpload.py:160
ext::basic_omemstream::last
char_type * last
Definition: memstream.h:58
std
Definition: JetResolutionObject.h:76
ext::basic_imemstream::int_type
Traits_t::int_type int_type
Definition: memstream.h:65
ext::womemstream
basic_omemstream< wchar_t > womemstream
Definition: memstream.h:83
ext::basic_omemstream::begin
char_type * begin() const
Definition: memstream.h:33
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
ext::omemstream
basic_omemstream< char > omemstream
Definition: memstream.h:82
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:56
ext::wimemstream
basic_imemstream< wchar_t > wimemstream
Definition: memstream.h:85
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
ext::basic_imemstream::char_type
Traits_t::char_type char_type
Definition: memstream.h:64
ext::basic_omemstream::size
size_t size() const
Definition: memstream.h:35
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443