DUNE-FEM (unstable)

streams.hh
1// SPDX-FileCopyrightText: Copyright © 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.
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
Dune namespace.
Definition: alignedallocator.hh:13
struct representing the three byte text as well as the four 6 bit chunks
Definition: b64enc.hh:34
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 13, 23:29, 2024)