dune-grid
2.11
Toggle main menu visibility
Loading...
Searching...
No Matches
dune
grid
io
file
vtk
streams.hh
Go to the documentation of this file.
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
11
#include <
dune/grid/io/file/vtk/b64enc.hh
>
12
13
namespace
Dune
{
14
16
class
Base64Stream
{
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
77
~Base64Stream
() {
78
flush
();
79
}
80
};
81
83
class
RawStream
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
b64enc.hh
Simple base64 encode.
Dune
Include standard header files.
Definition
agrid.hh:60
Dune::b64chunk
struct representing the three byte text as well as the four 6 bit chunks
Definition
b64enc.hh:34
Dune::Base64Stream::write
void write(X &data)
encode a data item
Definition
streams.hh:42
Dune::Base64Stream::flush
void flush()
flush the current unwritten data to the stream.
Definition
streams.hh:64
Dune::Base64Stream::Base64Stream
Base64Stream(std::ostream &s_)
Construct a Base64Stream.
Definition
streams.hh:27
Dune::Base64Stream::~Base64Stream
~Base64Stream()
destroy the object
Definition
streams.hh:77
Dune::RawStream::write
void write(T data)
write data to stream
Definition
streams.hh:93
Dune::RawStream::RawStream
RawStream(std::ostream &theStream)
make a new stream
Definition
streams.hh:87
Generated by
1.17.0