00001 #ifndef BINARY_FILE_WRITER_H_
00002 #define BINARY_FILE_WRITER_H_
00003
00004 #include "IMeshWriter.h"
00005
00006 #include <fstream>
00007
00008 namespace MeshWrite {
00009
00010 class BinaryFileWriter : public MeshWrite::IMeshWriter
00011 {
00012 public:
00013 BinaryFileWriter();
00014 BinaryFileWriter(const std::string & fileName);
00015 ~BinaryFileWriter();
00016
00017 bool Init();
00018 bool Init(const std::string & fileName);
00019 void Free();
00020
00021 bool doWrite(const hHybridMesh *);
00022
00023 template <typename T>
00024 friend BinaryFileWriter& operator<<(BinaryFileWriter& w, const T & obj);
00025 template <typename T>
00026 friend BinaryFileWriter& operator<<(BinaryFileWriter& w, const T * obj);
00027
00030 void WriteVerticesCount(const int noVerts);
00031
00034 void WriteVertex(const double coords[],const uTind type) ;
00035
00038 virtual void WriteEdgesCount(const int noEdges);
00039
00042 void WriteEdge(const uTind verts[], const uTind type) ;
00043
00046 void WriteFacesCount(const int noFaces) ;
00047
00050 void WriteFace(const uTind edges[],const uTind type,const int8_t bc, const uTind neigh[]) ;
00051
00054 void WriteElementCount(const int noElems) ;
00055
00059 void WriteElement(const uTind faces[], const uTind neighbours[],const uTind type, const uTind father, const int8_t ref, const int8_t material) ;
00060
00061
00062 private:
00063 std::string fileName_;
00064 std::ofstream oFile_;
00065 };
00066
00067 template <typename T>
00068 BinaryFileWriter& operator<<(BinaryFileWriter& w, const T & obj)
00069 {
00070 w.oFile_.write(reinterpret_cast<char *>(&obj),sizeof(obj));
00071 return w;
00072 }
00073
00074 template <typename T>
00075 BinaryFileWriter& operator<<(BinaryFileWriter& w, const T * obj)
00076 {
00077 w.oFile_.write(reinterpret_cast<char *>(obj),sizeof(T));
00078 return w;
00079 }
00080
00081 };
00082
00083 #endif // BINARY_FILE_WRITER_H_