Dune Core Modules (2.6.0)

streams.hh
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 
4 #ifndef DUNE_GRID_IO_FILE_VTK_STREAMS_HH
5 #define DUNE_GRID_IO_FILE_VTK_STREAMS_HH
6 
7 #include <ostream>
8 
10 
11 namespace Dune {
12 
14  class Base64Stream {
15  std::ostream& s;
16  b64chunk chunk;
17  char obuf[4];
18 
19  public:
21 
25  Base64Stream(std::ostream& s_)
26  : s(s_)
27  {
28  // reset chunk
29  chunk.txt.read(0,0);
30  }
31 
33 
39  template <class X>
40  void write(X & data)
41  {
42  char* p = reinterpret_cast<char*>(&data);
43  for (size_t len = sizeof(X); len > 0; len--,p++)
44  {
45  chunk.txt.put(*p);
46  if (chunk.txt.size == 3)
47  {
48  chunk.data.write(obuf);
49  s.write(obuf,4);
50  }
51  }
52  }
53 
55 
62  void flush()
63  {
64  if (chunk.txt.size > 0)
65  {
66  chunk.data.write(obuf);
67  s.write(obuf,4);
68  }
69  }
70 
72 
76  flush();
77  }
78  };
79 
81  class RawStream
82  {
83  public:
85  inline RawStream (std::ostream& theStream)
86  : s(theStream)
87  {}
88 
90  template<class T>
91  void write (T data)
92  {
93  char* p = reinterpret_cast<char*>(&data);
94  s.write(p,sizeof(T));
95  }
96  private:
97  std::ostream& s;
98  };
99 
100 } // namespace Dune
101 
102 #endif // DUNE_GRID_IO_FILE_VTK_STREAMS_HH
Simple base64 encode.
class to base64 encode a stream of data
Definition: streams.hh:14
void write(X &data)
encode a data item
Definition: streams.hh:40
void flush()
flush the current unwritten data to the stream.
Definition: streams.hh:62
Base64Stream(std::ostream &s_)
Construct a Base64Stream.
Definition: streams.hh:25
~Base64Stream()
destroy the object
Definition: streams.hh:75
write out data in binary
Definition: streams.hh:82
void write(T data)
write data to stream
Definition: streams.hh:91
RawStream(std::ostream &theStream)
make a new stream
Definition: streams.hh:85
Dune namespace.
Definition: alignedallocator.hh:10
union representing the three byte text as well as the four 6 bit chunks
Definition: b64enc.hh:72
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (May 2, 22:35, 2024)