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