4 #ifndef DUNE_GRID_IO_FILE_VTK_DATAARRAYWRITER_HH 5 #define DUNE_GRID_IO_FILE_VTK_DATAARRAYWRITER_HH 11 #include <dune/common/exceptions.hh> 12 #include <dune/common/indent.hh> 57 virtual void write (T data) = 0;
79 int ncomps,
const Indent& indent_)
80 : s(theStream), counter(0), numPerLine(12), indent(indent_)
83 s << indent <<
"<DataArray type=\"" << tn() <<
"\" " 84 <<
"Name=\"" << name <<
"\" ";
85 s <<
"NumberOfComponents=\"" << ncomps <<
"\" ";
86 s <<
"format=\"ascii\">\n";
94 if(counter%numPerLine==0) s << indent;
98 if (counter%numPerLine==0) s <<
"\n";
104 if (counter%numPerLine!=0) s <<
"\n";
106 s << indent <<
"</DataArray>\n";
133 int ncomps,
int nitems,
const Indent& indent_)
134 : s(theStream), b64(theStream), indent(indent_)
137 s << indent <<
"<DataArray type=\"" << tn() <<
"\" " 138 <<
"Name=\"" << name <<
"\" ";
139 s <<
"NumberOfComponents=\"" << ncomps <<
"\" ";
140 s <<
"format=\"binary\">\n";
145 std::uint32_t size = ncomps*nitems*
sizeof(T);
162 s << indent <<
"</DataArray>\n";
169 const Indent& indent;
191 int ncomps,
unsigned nitems,
unsigned& offset,
192 const Indent& indent)
195 s << indent <<
"<DataArray type=\"" << tn() <<
"\" " 196 <<
"Name=\"" << name <<
"\" ";
197 s <<
"NumberOfComponents=\"" << ncomps <<
"\" ";
198 s <<
"format=\"appended\" offset=\""<< offset <<
"\" />\n";
200 offset += ncomps*nitems*
sizeof(T);
229 int ncomps,
unsigned nitems,
230 unsigned& offset,
const Indent& indent)
233 s << indent <<
"<DataArray type=\"" << tn() <<
"\" " 234 <<
"Name=\"" << name <<
"\" ";
235 s <<
"NumberOfComponents=\"" << ncomps <<
"\" ";
236 s <<
"format=\"appended\" offset=\""<< offset <<
"\" />\n";
238 unsigned bytes = ncomps*nitems*
sizeof(T);
273 std::uint32_t size = ncomps*nitems*
sizeof(T);
306 s.
write((
unsigned int)(ncomps*nitems*
sizeof(T)));
328 enum Phase {
main, appended };
331 std::ostream& stream;
348 : type(type_), stream(stream_), offset(0), phase(
main)
365 case ascii :
return false;
366 case base64 :
return false;
370 DUNE_THROW(IOError,
"Dune::VTK::DataArrayWriter: unsupported " 371 "OutputType " << type);
376 static const std::string rawString =
"raw";
377 static const std::string base64String =
"base64";
382 DUNE_THROW(IOError,
"DataArrayWriterFactory::appendedEncoding(): No " 383 "appended encoding for OutputType " << type);
387 DUNE_THROW(IOError,
"DataArrayWriterFactory::appendedEncoding(): " 388 "unsupported OutputType " << type);
407 unsigned nitems,
const Indent& indent) {
418 nitems, offset, indent);
437 DUNE_THROW(IOError,
"Dune::VTK::DataArrayWriter: unsupported " 438 "OutputType " << type <<
" in phase " << phase);
448 #endif // DUNE_GRID_IO_FILE_VTK_DATAARRAYWRITER_HH void write(T data)
write data to stream
Definition: streams.hh:91
a streaming writer for appended data array tags, uses base64 format
Definition: dataarraywriter.hh:258
AsciiDataArrayWriter(std::ostream &theStream, std::string name, int ncomps, const Indent &indent_)
make a new data array writer
Definition: dataarraywriter.hh:78
void write(T data)
write one data element to output stream
Definition: dataarraywriter.hh:279
Output is to the file is appended raw binary.
Definition: common.hh:46
~AsciiDataArrayWriter()
finish output; writes end tag
Definition: dataarraywriter.hh:102
DataArrayWriterFactory(OutputType type_, std::ostream &stream_)
create a DataArrayWriterFactory
Definition: dataarraywriter.hh:347
void write(T)
write one data element to output stream (noop)
Definition: dataarraywriter.hh:204
bool writeIsNoop() const
whether calls to write may be skipped
Definition: dataarraywriter.hh:207
OutputType
How the bulk data should be stored in the file.
Definition: common.hh:40
void write(T data)
write one data element to output stream
Definition: dataarraywriter.hh:151
Common stuff for the VTKWriter.
BinaryDataArrayWriter(std::ostream &theStream, std::string name, int ncomps, int nitems, const Indent &indent_)
make a new data array writer
Definition: dataarraywriter.hh:132
void write(T data)
write one data element to output stream
Definition: dataarraywriter.hh:310
NakedRawDataArrayWriter(std::ostream &theStream, int ncomps, int nitems)
make a new data array writer
Definition: dataarraywriter.hh:302
DataArrayWriter< T > * make(const std::string &name, unsigned ncomps, unsigned nitems, const Indent &indent)
create a DataArrayWriter
Definition: dataarraywriter.hh:406
bool beginAppended()
signal start of the appended section
Definition: dataarraywriter.hh:362
void write(T data)
write one data element to output stream
Definition: dataarraywriter.hh:91
a streaming writer for data array tags, uses binary inline format
Definition: dataarraywriter.hh:118
~BinaryDataArrayWriter()
finish output; writes end tag
Definition: dataarraywriter.hh:157
Output is to the file is appended base64 binary.
Definition: common.hh:48
NakedBase64DataArrayWriter(std::ostream &theStream, int ncomps, int nitems)
make a new data array writer
Definition: dataarraywriter.hh:268
void write(T)
write one data element to output stream (noop)
Definition: dataarraywriter.hh:245
a factory for DataArrayWriters
Definition: dataarraywriter.hh:327
Include standard header files.
Definition: agrid.hh:59
Output to the file is in ascii.
Definition: common.hh:42
AppendedRawDataArrayWriter(std::ostream &s, std::string name, int ncomps, unsigned nitems, unsigned &offset, const Indent &indent)
make a new data array writer
Definition: dataarraywriter.hh:190
write out data in binary
Definition: streams.hh:81
map type to its VTK name in data array
Definition: common.hh:124
a streaming writer for data array tags, uses appended base64 format
Definition: dataarraywriter.hh:212
a streaming writer for data array tags, uses ASCII inline format
Definition: dataarraywriter.hh:66
virtual bool writeIsNoop() const
whether calls to write may be skipped
Definition: dataarraywriter.hh:59
virtual ~DataArrayWriter()
virtual destructor
Definition: dataarraywriter.hh:61
class to base64 encode a stream of data
Definition: streams.hh:14
Output to the file is inline base64 binary.
Definition: common.hh:44
T Type
type to convert T to before putting it into a stream with <<
Definition: common.hh:94
virtual void write(T data)=0
write one data element
const std::string & appendedEncoding() const
query encoding string for appended data
Definition: dataarraywriter.hh:375
a streaming writer for appended data arrays, uses raw format
Definition: dataarraywriter.hh:290
a streaming writer for data array tags, uses appended raw format
Definition: dataarraywriter.hh:174
int main(int argc, char *argv[])
Definition: dgf2dgf.cc:37
bool writeIsNoop() const
whether calls to write may be skipped
Definition: dataarraywriter.hh:248
base class for data array writers
Definition: dataarraywriter.hh:53
AppendedBase64DataArrayWriter(std::ostream &s, std::string name, int ncomps, unsigned nitems, unsigned &offset, const Indent &indent)
make a new data array writer
Definition: dataarraywriter.hh:228