dune-grid 2.9.0
streams.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (C) DUNE Project contributors, see file LICENSE.md in module root
2// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
3// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
4// vi: set et ts=4 sw=2 sts=2:
5
6#ifndef DUNE_GRID_IO_FILE_VTK_STREAMS_HH
7#define DUNE_GRID_IO_FILE_VTK_STREAMS_HH
8
9#include <ostream>
10
12
13namespace Dune {
14
17 std::ostream& s;
18 b64chunk chunk;
19 char obuf[4];
20
21 public:
23
27 Base64Stream(std::ostream& s_)
28 : s(s_)
29 {
30 // reset chunk
31 chunk.reset();
32 }
33
35
41 template <class X>
42 void write(X & data)
43 {
44 char* p = reinterpret_cast<char*>(&data);
45 for (size_t len = sizeof(X); len > 0; len--,p++)
46 {
47 chunk.put(*p);
48 if (chunk.size == 3)
49 {
50 chunk.write(obuf);
51 s.write(obuf,4);
52 }
53 }
54 }
55
57
64 void flush()
65 {
66 if (chunk.size > 0)
67 {
68 chunk.write(obuf);
69 s.write(obuf,4);
70 }
71 }
72
74
78 flush();
79 }
80 };
81
84 {
85 public:
87 inline RawStream (std::ostream& theStream)
88 : s(theStream)
89 {}
90
92 template<class T>
93 void write (T data)
94 {
95 char* p = reinterpret_cast<char*>(&data);
96 s.write(p,sizeof(T));
97 }
98 private:
99 std::ostream& s;
100 };
101
102} // namespace Dune
103
104#endif // DUNE_GRID_IO_FILE_VTK_STREAMS_HH
Simple base64 encode.
Include standard header files.
Definition: agrid.hh:60
struct representing the three byte text as well as the four 6 bit chunks
Definition: b64enc.hh:34
void write(char *t)
Definition: b64enc.hh:60
size_type size
Definition: b64enc.hh:36
void put(const char c)
Definition: b64enc.hh:54
void reset()
Definition: b64enc.hh:39
class to base64 encode a stream of data
Definition: streams.hh:16
void write(X &data)
encode a data item
Definition: streams.hh:42
void flush()
flush the current unwritten data to the stream.
Definition: streams.hh:64
Base64Stream(std::ostream &s_)
Construct a Base64Stream.
Definition: streams.hh:27
~Base64Stream()
destroy the object
Definition: streams.hh:77
write out data in binary
Definition: streams.hh:84
void write(T data)
write data to stream
Definition: streams.hh:93
RawStream(std::ostream &theStream)
make a new stream
Definition: streams.hh:87