4 #ifndef DUNE_GRID_IO_FILE_VTK_DATAARRAYWRITER_HH
5 #define DUNE_GRID_IO_FILE_VTK_DATAARRAYWRITER_HH
10 #include <dune/common/exceptions.hh>
11 #include <dune/common/indent.hh>
56 virtual void write (T data) = 0;
78 int ncomps,
const Indent& indent_)
79 : s(theStream), counter(0), numPerLine(12), indent(indent_)
82 s << indent <<
"<DataArray type=\"" << tn() <<
"\" "
83 <<
"Name=\"" << name <<
"\" ";
84 s <<
"NumberOfComponents=\"" << ncomps <<
"\" ";
85 s <<
"format=\"ascii\">\n";
93 if(counter%numPerLine==0) s << indent;
97 if (counter%numPerLine==0) s <<
"\n";
103 if (counter%numPerLine!=0) s <<
"\n";
105 s << indent <<
"</DataArray>\n";
132 int ncomps,
int nitems,
const Indent& indent_)
133 : s(theStream), b64(theStream), indent(indent_)
136 s << indent <<
"<DataArray type=\"" << tn() <<
"\" "
137 <<
"Name=\"" << name <<
"\" ";
138 s <<
"NumberOfComponents=\"" << ncomps <<
"\" ";
139 s <<
"format=\"binary\">\n";
144 unsigned long int size = ncomps*nitems*
sizeof(T);
161 s << indent <<
"</DataArray>\n";
168 const Indent& indent;
190 int ncomps,
unsigned nitems,
unsigned& offset,
191 const Indent& indent)
194 s << indent <<
"<DataArray type=\"" << tn() <<
"\" "
195 <<
"Name=\"" << name <<
"\" ";
196 s <<
"NumberOfComponents=\"" << ncomps <<
"\" ";
197 s <<
"format=\"appended\" offset=\""<< offset <<
"\" />\n";
199 offset += ncomps*nitems*
sizeof(T);
228 int ncomps,
unsigned nitems,
229 unsigned& offset,
const Indent& indent)
232 s << indent <<
"<DataArray type=\"" << tn() <<
"\" "
233 <<
"Name=\"" << name <<
"\" ";
234 s <<
"NumberOfComponents=\"" << ncomps <<
"\" ";
235 s <<
"format=\"appended\" offset=\""<< offset <<
"\" />\n";
237 unsigned bytes = ncomps*nitems*
sizeof(T);
272 unsigned long int size = ncomps*nitems*
sizeof(T);
305 s.
write((
unsigned int)(ncomps*nitems*
sizeof(T)));
327 enum Phase { main, appended };
330 std::ostream& stream;
347 : type(type_), stream(stream_), offset(0), phase(main)
364 case ascii :
return false;
365 case base64 :
return false;
369 DUNE_THROW(IOError,
"Dune::VTK::DataArrayWriter: unsupported "
370 "OutputType " << type);
375 static const std::string rawString =
"raw";
376 static const std::string base64String =
"base64";
381 DUNE_THROW(IOError,
"DataArrayWriterFactory::appendedEncoding(): No "
382 "appended encoding for OutputType " << type);
386 DUNE_THROW(IOError,
"DataArrayWriterFactory::appendedEncoding(): "
387 "unsupported OutputType " << type);
406 unsigned nitems,
const Indent& indent) {
417 nitems, offset, indent);
436 DUNE_THROW(IOError,
"Dune::VTK::DataArrayWriter: unsupported "
437 "OutputType " << type <<
" in phase " << phase);
447 #endif // DUNE_GRID_IO_FILE_VTK_DATAARRAYWRITER_HH
write out data in binary
Definition: streams.hh:81
NakedRawDataArrayWriter(std::ostream &theStream, int ncomps, int nitems)
make a new data array writer
Definition: dataarraywriter.hh:301
bool writeIsNoop() const
whether calls to write may be skipped
Definition: dataarraywriter.hh:206
Output to the file is inline base64 binary.
Definition: common.hh:44
bool writeIsNoop() const
whether calls to write may be skipped
Definition: dataarraywriter.hh:247
virtual ~DataArrayWriter()
virtual destructor
Definition: dataarraywriter.hh:60
Common stuff for the VTKWriter.
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:227
NakedBase64DataArrayWriter(std::ostream &theStream, int ncomps, int nitems)
make a new data array writer
Definition: dataarraywriter.hh:267
Output to the file is in ascii.
Definition: common.hh:42
DataArrayWriterFactory(OutputType type_, std::ostream &stream_)
create a DataArrayWriterFactory
Definition: dataarraywriter.hh:346
void write(T data)
write data to stream
Definition: streams.hh:91
void write(X &data)
encode a data item
Definition: streams.hh:40
base class for data array writers
Definition: dataarraywriter.hh:52
void write(T data)
write one data element to output stream
Definition: dataarraywriter.hh:150
T Type
type to convert T to before putting it into a stream with <<
Definition: common.hh:94
class to base64 encode a stream of data
Definition: streams.hh:14
void write(T data)
write one data element to output stream
Definition: dataarraywriter.hh:90
a streaming writer for data array tags, uses ASCII inline format
Definition: dataarraywriter.hh:65
const std::string & appendedEncoding() const
query encoding string for appended data
Definition: dataarraywriter.hh:374
a streaming writer for appended data arrays, uses raw format
Definition: dataarraywriter.hh:289
virtual void write(T data)=0
write one data element
Ouput is to the file is appended raw binary.
Definition: common.hh:46
bool beginAppended()
signal start of the appeneded section
Definition: dataarraywriter.hh:361
OutputType
How the bulk data should be stored in the file.
Definition: common.hh:40
void flush()
flush the current unwritten data to the stream.
Definition: streams.hh:62
a streaming writer for appended data array tags, uses base64 format
Definition: dataarraywriter.hh:257
BinaryDataArrayWriter(std::ostream &theStream, std::string name, int ncomps, int nitems, const Indent &indent_)
make a new data array writer
Definition: dataarraywriter.hh:131
~BinaryDataArrayWriter()
finish output; writes end tag
Definition: dataarraywriter.hh:156
virtual bool writeIsNoop() const
whether calls to write may be skipped
Definition: dataarraywriter.hh:58
AsciiDataArrayWriter(std::ostream &theStream, std::string name, int ncomps, const Indent &indent_)
make a new data array writer
Definition: dataarraywriter.hh:77
a streaming writer for data array tags, uses appended raw format
Definition: dataarraywriter.hh:173
void write(T data)
write one data element to output stream
Definition: dataarraywriter.hh:309
Ouput is to the file is appended base64 binary.
Definition: common.hh:48
void write(T data)
write one data element to output stream (noop)
Definition: dataarraywriter.hh:244
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:189
DataArrayWriter< T > * make(const std::string &name, unsigned ncomps, unsigned nitems, const Indent &indent)
create a DataArrayWriter
Definition: dataarraywriter.hh:405
a streaming writer for data array tags, uses binary inline format
Definition: dataarraywriter.hh:117
void write(T data)
write one data element to output stream (noop)
Definition: dataarraywriter.hh:203
void write(T data)
write one data element to output stream
Definition: dataarraywriter.hh:278
~AsciiDataArrayWriter()
finish output; writes end tag
Definition: dataarraywriter.hh:101
a factory for DataArrayWriters
Definition: dataarraywriter.hh:326
a streaming writer for data array tags, uses appended base64 format
Definition: dataarraywriter.hh:211
map type to its VTK name in data array
Definition: common.hh:124