dune-grid
2.1.1
|
00001 // -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- 00002 // vi: set et ts=8 sw=2 sts=2: 00003 00004 #ifndef DUNE_GRID_IO_FILE_VTK_STREAMS_HH 00005 #define DUNE_GRID_IO_FILE_VTK_STREAMS_HH 00006 00007 #include <ostream> 00008 00009 #include <dune/grid/io/file/vtk/b64enc.hh> 00010 00011 namespace Dune { 00012 00014 class Base64Stream { 00015 std::ostream& s; 00016 b64chunk chunk; 00017 char obuf[4]; 00018 00019 public: 00021 00025 Base64Stream(std::ostream& s_) 00026 : s(s_) 00027 { 00028 // reset chunk 00029 chunk.txt.read(0,0); 00030 } 00031 00033 00039 template <class X> 00040 void write(X & data) 00041 { 00042 char* p = reinterpret_cast<char*>(&data); 00043 for (size_t len = sizeof(X); len > 0; len--,p++) 00044 { 00045 chunk.txt.put(*p); 00046 if (chunk.txt.size == 3) 00047 { 00048 chunk.data.write(obuf); 00049 s.write(obuf,4); 00050 } 00051 } 00052 } 00053 00055 00062 void flush() 00063 { 00064 if (chunk.txt.size > 0) 00065 { 00066 chunk.data.write(obuf); 00067 s.write(obuf,4); 00068 } 00069 } 00070 00072 00075 ~Base64Stream() { 00076 flush(); 00077 } 00078 }; 00079 00081 class RawStream 00082 { 00083 public: 00085 inline RawStream (std::ostream& theStream) 00086 : s(theStream) 00087 {} 00088 00090 template<class T> 00091 void write (T data) 00092 { 00093 char* p = reinterpret_cast<char*>(&data); 00094 s.write(p,sizeof(T)); 00095 } 00096 private: 00097 std::ostream& s; 00098 }; 00099 00100 } // namespace Dune 00101 00102 #endif // DUNE_GRID_IO_FILE_VTK_STREAMS_HH