ViennaGrid - The Vienna Grid Library
2.1.0
|
00001 #ifndef VIENNAGRID_IO_HELPER_HPP 00002 #define VIENNAGRID_IO_HELPER_HPP 00003 00004 /* ======================================================================= 00005 Copyright (c) 2011-2014, Institute for Microelectronics, 00006 Institute for Analysis and Scientific Computing, 00007 TU Wien. 00008 00009 ----------------- 00010 ViennaGrid - The Vienna Grid Library 00011 ----------------- 00012 00013 License: MIT (X11), see file LICENSE in the base directory 00014 ======================================================================= */ 00015 00016 00017 #include <fstream> 00018 #include <sstream> 00019 #include <iostream> 00020 #include <cctype> 00021 #include <string> 00022 #include <limits> 00023 #include <stdexcept> 00024 00025 #include "viennagrid/forwards.hpp" 00026 00032 namespace viennagrid 00033 { 00034 namespace io 00035 { 00037 template <int dim> 00038 struct PointWriter 00039 {}; 00040 00041 template <> 00042 struct PointWriter<1> 00043 { 00044 template <typename PointType> 00045 static void write(std::ofstream & writer, PointType const& point) 00046 { 00047 writer.precision( std::numeric_limits<typename PointType::value_type>::digits10 ); 00048 writer << point[0]; 00049 } 00050 00051 template <typename PointType> 00052 static void write(std::ofstream & writer, PointType & point) 00053 { 00054 writer.precision( std::numeric_limits<typename PointType::value_type>::digits10 ); 00055 writer << point[0]; 00056 } 00057 }; 00058 00059 template <> 00060 struct PointWriter<2> 00061 { 00062 template <typename PointType> 00063 static void write(std::ofstream & writer, PointType const& point) 00064 { 00065 writer.precision( std::numeric_limits<typename PointType::value_type>::digits10 ); 00066 writer << point[0] << " " << point[1]; 00067 } 00068 00069 template <typename PointType> 00070 static void write(std::ofstream & writer, PointType & point) 00071 { 00072 writer.precision( std::numeric_limits<typename PointType::value_type>::digits10 ); 00073 writer << point[0] << " " << point[1]; 00074 } 00075 }; 00076 00077 template <> 00078 struct PointWriter<3> 00079 { 00080 template <typename PointType> 00081 static void write(std::ofstream & writer, PointType const& point) 00082 { 00083 writer.precision( std::numeric_limits<typename PointType::value_type>::digits10 ); 00084 writer << point[0] << " " << point[1] << " " << point[2]; 00085 } 00086 00087 template <typename PointType> 00088 static void write(std::ofstream & writer, PointType & point) 00089 { 00090 writer.precision( std::numeric_limits<typename PointType::value_type>::digits10 ); 00091 writer << point[0] << " " << point[1] << " " << point[2]; 00092 } 00093 }; 00094 00096 struct strChecker 00097 { 00098 //****************************************** 00099 // Checks, if a string is a number or not 00100 //****************************************** 00101 static bool myIsNumber(std::string& str) { 00102 bool numberFlag = true; 00103 std::size_t strLen = str.size(); 00104 std::size_t idx = 0; 00105 00106 while(numberFlag == true && idx < strLen) 00107 { 00108 if(!isdigit(str[idx])) 00109 { 00110 numberFlag = false; 00111 } 00112 00113 idx++; 00114 } 00115 00116 return numberFlag; 00117 } 00118 }; 00119 00120 00121 00123 class cannot_open_file_exception : public std::runtime_error 00124 { 00125 public: 00126 explicit cannot_open_file_exception(std::string message) : std::runtime_error(message) {} 00127 00128 virtual ~cannot_open_file_exception() throw() {} 00129 }; 00130 00132 class bad_file_format_exception : public std::runtime_error 00133 { 00134 public: 00135 explicit bad_file_format_exception(std::string message) : std::runtime_error(message) {} 00136 00137 virtual ~bad_file_format_exception() throw() {} 00138 }; 00139 00140 } //namespace io 00141 } //namespace viennagrid 00142 00143 #endif