Functions | |
std::string | trim (const std::string &s) |
Clears whitespace from front and back of string s. | |
template<typename K, typename V> | |
bool | contains (const std::map< K, V > &m, K thing) |
Does map m contain thing? | |
template<typename E> | |
bool | contains (const std::set< E > &s, E thing) |
Does set s contain thing? | |
template<typename E> | |
bool | includes (const std::set< E > &s1, const std::set< E > &s2) |
Does set s1 include set s2? | |
linalg::matrix | read_matrix (std::string filename) |
Reads matrices from filenames. | |
linalg::vector | read_vector (std::string filename) |
Reads vectors from filenames. | |
std::map< linalg::point, double > | read_pd_map (std::string filename) |
Reads map<point,double> from a matrix. | |
void | show_exception (error_handling::error exc) |
Outputs some information about generic exceptions. | |
template bool | contains (const std::set< linalg::point > &, linalg::point E) |
template bool | contains (const std::map< linalg::point, linalg::vector > &m, linalg::point thing) |
template bool | includes (const std::set< linalg::point > &s1, const std::set< linalg::point > &s2) |
template bool | contains (const std::map< linalg::point, shared_ptr< const bvp::overlapping_domain > > &, linalg::point) |
template bool | contains (const std::set< shared_ptr< const bvp::overlapping_domain > > &, shared_ptr< const bvp::overlapping_domain > E) |
template bool utils::contains | ( | const std::set< shared_ptr< const bvp::overlapping_domain > > & | , | |
shared_ptr< const bvp::overlapping_domain > | E | |||
) |
template bool utils::contains | ( | const std::map< linalg::point, shared_ptr< const bvp::overlapping_domain > > & | , | |
linalg::point | ||||
) |
template bool utils::contains | ( | const std::map< linalg::point, linalg::vector > & | m, | |
linalg::point | thing | |||
) |
template bool utils::contains | ( | const std::set< linalg::point > & | , | |
linalg::point | E | |||
) |
bool utils::contains | ( | const std::set< E > & | s, | |
E | thing | |||
) | [inline] |
bool utils::contains | ( | const std::map< K, V > & | m, | |
K | thing | |||
) | [inline] |
template bool utils::includes | ( | const std::set< linalg::point > & | s1, | |
const std::set< linalg::point > & | s2 | |||
) |
bool utils::includes | ( | const std::set< E > & | s1, | |
const std::set< E > & | s2 | |||
) | [inline] |
Does set s1 include set s2?
00032 { 00033 return std::includes(s2.begin(), s2.end(), s1.begin(), s1.end()); 00034 }
matrix utils::read_matrix | ( | std::string | filename | ) |
Reads matrices from filenames.
00039 { 00040 std::ifstream ifs(filename.c_str()); 00041 if(!ifs){ 00042 error_handling::badArgument exc; 00043 exc.reason = "Cannot open file "; 00044 exc.reason += filename; 00045 exc.line = __LINE__; 00046 exc.file = __FILE__; 00047 throw exc; 00048 } 00049 matrix v; 00050 ifs >> v; 00051 return v; 00052 }
std::map< linalg::point, double > utils::read_pd_map | ( | std::string | filename | ) |
Reads map<point,double> from a matrix.
Last column is the value at each point which is represented in turn by the rest of the row.
00069 { 00070 std::ifstream ifs(filename.c_str()); 00071 if(!ifs){ 00072 error_handling::badArgument exc; 00073 exc.reason = "Cannot open file "; 00074 exc.reason += filename; 00075 exc.line = __LINE__; 00076 exc.file = __FILE__; 00077 throw exc; 00078 } 00079 matrix M; 00080 ifs >> M; 00081 00082 if(M.cols() < 2){ 00083 error_handling::badArgument exc; 00084 exc.reason = 00085 "Input matrix to read_pd_map is too narrow. \n" 00086 "Need at least two columns in the input matrix"; 00087 exc.line = __LINE__; 00088 exc.file = __FILE__; 00089 throw exc; 00090 } 00091 00092 std::map <linalg::point, double> result; 00093 size_t m = M.cols(); 00094 linalg::slice s(1,m-1); 00095 for(size_t i = 1; i <= M.rows(); i++) 00096 result[M(i,s)] = M(i,m); 00097 return result; 00098 }
vector utils::read_vector | ( | std::string | filename | ) |
Reads vectors from filenames.
00054 { 00055 std::ifstream ifs(filename.c_str()); 00056 if(!ifs){ 00057 error_handling::badArgument exc; 00058 exc.reason = "Cannot open file "; 00059 exc.reason += filename; 00060 exc.line = __LINE__; 00061 exc.file = __FILE__; 00062 throw exc; 00063 } 00064 vector v; 00065 ifs >> v; 00066 return v; 00067 }
void utils::show_exception | ( | error_handling::error | exc | ) |
std::string utils::trim | ( | const std::string & | s | ) |
Clears whitespace from front and back of string s.
00011 { 00012 if(s.length() == 0) 00013 return s; 00014 std::size_t beg = s.find_first_not_of(" \a\b\f\n\r\t\v"); 00015 std::size_t end = s.find_last_not_of(" \a\b\f\n\r\t\v"); 00016 if(beg == std::string::npos) // No non-spaces 00017 return ""; 00018 return std::string(s, beg, end - beg + 1); 00019 }