utils Namespace Reference

A few helpful functions that didn't seem to be readily classified anywhere else. More...


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)


Detailed Description

A few helpful functions that didn't seem to be readily classified anywhere else.

Function Documentation

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 
)

template<typename E>
bool utils::contains ( const std::set< E > &  s,
thing 
) [inline]

Does set s contain thing?

00027                                             {
00028     return s.find(thing) != s.end();
00029   }

template<typename K, typename V>
bool utils::contains ( const std::map< K, V > &  m,
thing 
) [inline]

Does map m contain thing?

00022                                               {
00023     return m.find(thing) != m.end();
00024   }

template bool utils::includes ( const std::set< linalg::point > &  s1,
const std::set< linalg::point > &  s2 
)

template<typename E>
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   }

Here is the call graph for this function:

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  ) 

Outputs some information about generic exceptions.

00100                                               {
00101     using namespace std;
00102 
00103     cout << "Caught an exception!" << endl;
00104     cout << exc.reason << endl;
00105     cout << "On line " << exc.line << endl;
00106     cout << "From file " << exc.file << endl;
00107   }

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   }


Generated on Fri Jun 6 17:28:30 2008 by  doxygen 1.5.6