Go to the documentation of this file.00001 #ifndef VIENNAGRID_IO_HELPER_GUARD
00002 #define VIENNAGRID_IO_HELPER_GUARD
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <fstream>
00023 #include <sstream>
00024 #include <iostream>
00025 #include <cctype>
00026 #include <string>
00027 #include "viennagrid/forwards.h"
00028
00034 namespace viennagrid
00035 {
00037 namespace io
00038 {
00040 template <int dim>
00041 struct PointWriter
00042 {};
00043
00044 template <>
00045 struct PointWriter<1>
00046 {
00047 template <typename PointType>
00048 static void write(std::ofstream & writer, PointType const& point)
00049 {
00050 writer << point[0];
00051 }
00052
00053 template <typename PointType>
00054 static void write(std::ofstream & writer, PointType & point)
00055 {
00056 writer << point[0];
00057 }
00058 };
00059
00060 template <>
00061 struct PointWriter<2>
00062 {
00063 template <typename PointType>
00064 static void write(std::ofstream & writer, PointType const& point)
00065 {
00066 writer << point[0] << " " << point[1];
00067 }
00068
00069 template <typename PointType>
00070 static void write(std::ofstream & writer, PointType & point)
00071 {
00072 writer << point[0] << " " << point[1];
00073 }
00074 };
00075
00076 template <>
00077 struct PointWriter<3>
00078 {
00079 template <typename PointType>
00080 static void write(std::ofstream & writer, PointType const& point)
00081 {
00082 writer << point[0] << " " << point[1] << " " << point[2];
00083 }
00084
00085 template <typename PointType>
00086 static void write(std::ofstream & writer, PointType & point)
00087 {
00088 writer << point[0] << " " << point[1] << " " << point[2];
00089 }
00090 };
00091
00093 struct strChecker
00094 {
00095
00096
00097
00098 static bool myIsNumber(std::string& str) {
00099 bool numberFlag = true;
00100 long strLen = str.size();
00101 long idx = 0;
00102
00103 while(numberFlag == true && idx < strLen)
00104 {
00105 if(!isdigit(str[idx]))
00106 {
00107 numberFlag = false;
00108 }
00109
00110 idx++;
00111 }
00112
00113 return numberFlag;
00114 }
00115 };
00116
00117
00118
00119
00120
00122 class cannot_open_file_exception : public std::exception
00123 {
00124 public:
00125 virtual const char* what() const throw()
00126 {
00127 std::stringstream ss;
00128 ss << "* ViennaGrid: Cannot open file " << filename_ << "!";
00129 return ss.str().c_str();
00130 }
00131
00132 cannot_open_file_exception(std::string file) : filename_(file) {};
00133
00134 virtual ~cannot_open_file_exception() throw() {};
00135
00136 private:
00137 std::string filename_;
00138 };
00139
00141 class bad_file_format_exception : public std::exception
00142 {
00143 public:
00144 virtual const char* what() const throw()
00145 {
00146 std::stringstream ss;
00147 if (filename_.size() > 0)
00148 ss << "* ViennaGrid: Bad file format in file " << filename_ << ": " << message_;
00149 else
00150 ss << "* ViennaGrid: Bad file format: " << message_;
00151 return ss.str().c_str();
00152 }
00153
00155 bad_file_format_exception(std::string file, std::string message) : filename_(file), message_(message) {};
00157 bad_file_format_exception(std::string message) : filename_(), message_(message) {};
00158
00159 virtual ~bad_file_format_exception() throw() {};
00160
00161 private:
00162 std::string filename_;
00163 std::string message_;
00164 };
00165
00166
00167 }
00168 }
00169
00170 #endif