00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef MESH_READER_HPP
00021 #define MESH_READER_HPP
00022
00023 #include <MeshGenerator.hpp>
00024
00025 #include <ReferenceCounting.hpp>
00026 #include <Vector.hpp>
00027
00028 #include <VerticesSet.hpp>
00029
00030 #include <Vertex.hpp>
00031 #include <Hexahedron.hpp>
00032 #include <Tetrahedron.hpp>
00033 #include <Triangle.hpp>
00034
00035 #include <Stringify.hpp>
00036 #include <ErrorHandler.hpp>
00037
00038 #include <string>
00039 #include <cstdio>
00040
00050 class MeshReader
00051 : public MeshGenerator
00052 {
00053 protected:
00054 FILE * __ifh;
00055 std::string __fileName;
00061 ReferenceCounting<VerticesSet> __vertices;
00062
00067 ReferenceCounting<Vector<Hexahedron> > __hexahedra;
00068
00073 ReferenceCounting<Vector<Quadrangle> > __quadrilaterals;
00074
00079 ReferenceCounting<Vector<Tetrahedron> > __tetrahedra;
00080
00085 ReferenceCounting<Vector<Triangle> > __triangles;
00086
00092 MeshReader(const MeshReader& M);
00093
00099 inline real_t __getReal()
00100 {
00101
00102
00103 register double r;
00104 int retval = fscanf(__ifh,"%le",&r);
00105 if (retval <= 0) {
00106 throw ErrorHandler(__FILE__,__LINE__,
00107 "reading mesh '"+__fileName+"': expected real not found",
00108 ErrorHandler::normal);
00109 return 0;
00110 }
00111 return r;
00112 }
00113
00119 inline int __getInteger()
00120 {
00121 int i;
00122 int retval = fscanf(__ifh,"%d",&i);
00123 if (retval <= 0) {
00124 throw ErrorHandler(__FILE__,__LINE__,
00125 "reading mesh '"+__fileName+"': expected integer not found",
00126 ErrorHandler::normal);
00127 return 0;
00128 }
00129 return i;
00130 }
00131
00136 virtual void __createMesh();
00137
00138 public:
00139
00140 class Error
00141 {
00142 private:
00143 const std::string __message;
00144 public:
00145 Error(const std::string & message) : __message(message) { }
00146 const std::string & message() const { return __message; }
00147 };
00148
00155 ReferenceCounting<Mesh> mesh()
00156 {
00157 return __mesh;
00158 }
00159
00165 MeshReader(const std::string & s);
00166
00171 virtual ~MeshReader();
00172 };
00173
00174 #endif // MESH_READER_HPP