From 2dca98ef0b23f6a45cf92bd48aca919714e7309d Mon Sep 17 00:00:00 2001 From: Paul McCarthy <pauldmccarthy@gmail.com> Date: Thu, 23 Sep 2021 10:54:34 +0100 Subject: [PATCH] MNT: more namespacing --- Simplex.h | 6 +++--- SpMat.h | 24 ++++++++++++------------ bfmatrix.cpp | 2 ++ bfmatrix.h | 2 +- f2z.cc | 1 + kernel.cc | 1 + kernel.h | 4 ++-- minimize.h | 2 +- miscmaths.h | 8 ++++---- nonlin.h | 10 +++++----- sparse_matrix.h | 2 +- splinterpolator.h | 2 +- t2z.cc | 1 + 13 files changed, 35 insertions(+), 30 deletions(-) diff --git a/Simplex.h b/Simplex.h index 1c1a5ff..3afbf75 100644 --- a/Simplex.h +++ b/Simplex.h @@ -75,14 +75,14 @@ public: /// Update the indicies for best, worst and 2nd to worst points. void UpdateRankIndicies(); // Global function. Prints out the points of the simplex and the associated function values - friend ostream& operator<<(ostream& op, const Simplex& smplx) + friend std::ostream& operator<<(std::ostream& op, const Simplex& smplx) { - op << "Simplex = " << endl; + op << "Simplex = " << std::endl; for (unsigned int i=0; i<smplx._smx.size(); i++) { for (unsigned int j=1; j<smplx._smx.size(); j++) { op << std::setw(10) << std::setprecision(4) << smplx._smx[i](j); } - op << " | " << std::setw(10) << std::setprecision(4) << smplx._fv[i] << endl; + op << " | " << std::setw(10) << std::setprecision(4) << smplx._fv[i] << std::endl; } return(op); } diff --git a/SpMat.h b/SpMat.h index e4f5ce4..0b35796 100644 --- a/SpMat.h +++ b/SpMat.h @@ -40,7 +40,7 @@ public: SpMatException(const std::string& msg) throw(): m_msg(msg) {} virtual const char * what() const throw() { - return string("SpMat::" + m_msg).c_str(); + return std::string("SpMat::" + m_msg).c_str(); } ~SpMatException() throw() {} @@ -318,11 +318,11 @@ public: T& operator()(unsigned int i); unsigned int NO() const {return(_no);} unsigned int ri(unsigned int i) { // Index of i'th non-zero value. - if (!_sorted) {sort(_occi,&(_occi[_no])); _sorted=true;} + if (!_sorted) {std::sort(_occi,&(_occi[_no])); _sorted=true;} return(_occi[i]); } const T& val(unsigned int i) { // i'th non-zero value. Call ri(i) to find what index that corresponds to - if (!_sorted) {sort(_occi,&(_occi[_no])); _sorted=true;} + if (!_sorted) {std::sort(_occi,&(_occi[_no])); _sorted=true;} return(_val[_occi[i]]); } const T& val_at(unsigned int i) const {return(_val[i]);} // Value for index i (or i+1) @@ -515,28 +515,28 @@ template<class T> void SpMat<T>::Print(const std::string& fname, unsigned int precision) const { - ostream *sptr=0; + std::ostream *sptr=0; if (!fname.length()) { - sptr = &cout; + sptr = &std::cout; } else { try { - sptr = new ofstream(fname.c_str()); + sptr = new std::ofstream(fname.c_str()); } catch(...) { std::string errmsg("BFMatrix::print: Failed to write to file " + fname); throw SpMatException(errmsg); } } - (*sptr) << setprecision(precision); + (*sptr) << std::setprecision(precision); for (unsigned int c=0; c<_n; c++) { for (unsigned int i=0; i<_ri[c].size(); i++) { - if (_val[c][i]) (*sptr) << _ri[c][i]+1 << " " << c+1 << " " << _val[c][i] << endl; + if (_val[c][i]) (*sptr) << _ri[c][i]+1 << " " << c+1 << " " << _val[c][i] << std::endl; } } - (*sptr) << _m << " " << _n << " " << 0 << endl; + (*sptr) << _m << " " << _n << " " << 0 << std::endl; if (fname.length()) delete sptr; } @@ -616,9 +616,9 @@ NEWMAT::ReturnMatrix SpMat<T>::SolveForx(const NEWMAT::ColumnVector& } if (status && _pw) { - cout << "SpMat::SolveForx: Warning requested tolerence not obtained." << endl; - cout << "Requested tolerance was " << ltol << ", and achieved tolerance was " << tol << endl; - cout << "This may or may not be a problem in your application, but you should look into it" << endl; + std::cout << "SpMat::SolveForx: Warning requested tolerence not obtained." << std::endl; + std::cout << "Requested tolerance was " << ltol << ", and achieved tolerance was " << tol << std::endl; + std::cout << "This may or may not be a problem in your application, but you should look into it" << std::endl; } x.Release(); diff --git a/bfmatrix.cpp b/bfmatrix.cpp index 541990b..81bd968 100644 --- a/bfmatrix.cpp +++ b/bfmatrix.cpp @@ -15,6 +15,8 @@ #include "miscmaths.h" #include "bfmatrix.h" +using namespace std; + namespace MISCMATHS { // diff --git a/bfmatrix.h b/bfmatrix.h index 4b63c30..673bfc8 100644 --- a/bfmatrix.h +++ b/bfmatrix.h @@ -45,7 +45,7 @@ public: BFMatrixException(const std::string& msg) throw(): m_msg(msg) {} virtual const char * what() const throw() { - return string("BFMatrix::" + m_msg).c_str(); + return std::string("BFMatrix::" + m_msg).c_str(); } ~BFMatrixException() throw() {} diff --git a/f2z.cc b/f2z.cc index e700de6..568fc5d 100644 --- a/f2z.cc +++ b/f2z.cc @@ -13,6 +13,7 @@ #include "cprob/libprob.h" #include <stdexcept> +using namespace std; using namespace NEWMAT; using namespace Utilities; diff --git a/kernel.cc b/kernel.cc index 60381b1..5cf16aa 100644 --- a/kernel.cc +++ b/kernel.cc @@ -9,6 +9,7 @@ #include "kernel.h" #include "miscmaths.h" +using namespace std; using namespace NEWMAT; namespace MISCMATHS { diff --git a/kernel.h b/kernel.h index 131084e..a3aaa5e 100644 --- a/kernel.h +++ b/kernel.h @@ -102,7 +102,7 @@ namespace MISCMATHS { class kernel { private: - static set<kernelstorage*, kernelstorage::comparer> existingkernels; + static std::set<kernelstorage*, kernelstorage::comparer> existingkernels; kernelstorage* storedkernel; public: @@ -135,7 +135,7 @@ namespace MISCMATHS { { // see if already in list: storedkernel = new kernelstorage(kx,ky,kz,wx,wy,wz); - set<kernelstorage*, kernelstorage::comparer>::iterator + std::set<kernelstorage*, kernelstorage::comparer>::iterator it = existingkernels.find(storedkernel); if (it==existingkernels.end()) { existingkernels.insert(storedkernel); diff --git a/minimize.h b/minimize.h index 5039346..c673cdc 100644 --- a/minimize.h +++ b/minimize.h @@ -29,7 +29,7 @@ namespace MISCMATHS { class pair_comparer { public: - bool operator()(const pair<float,NEWMAT::ColumnVector>& p1,const pair<float,NEWMAT::ColumnVector>& p2) const + bool operator()(const std::pair<float,NEWMAT::ColumnVector>& p1,const std::pair<float,NEWMAT::ColumnVector>& p2) const { return p1.first < p2.first; } diff --git a/miscmaths.h b/miscmaths.h index 97d1839..cd7180e 100644 --- a/miscmaths.h +++ b/miscmaths.h @@ -300,7 +300,7 @@ namespace MISCMATHS { float digamma(const float x); void glm_vb(const NEWMAT::Matrix& X, const NEWMAT::ColumnVector& Y, NEWMAT::ColumnVector& B, NEWMAT::SymmetricMatrix& ilambda_B, int niters=20); - vector<float> ColumnVector2vector(const NEWMAT::ColumnVector& col); + std::vector<float> ColumnVector2vector(const NEWMAT::ColumnVector& col); /////////////////////////////////////////////////////////////////////////// // Uninteresting byte swapping functions @@ -329,8 +329,8 @@ namespace MISCMATHS { template<class t> void write_vector(const std::string& fname, const std::vector<t>& vec) { std::ofstream out; - out.open(fname.c_str(), ios::out); - copy(vec.begin(), vec.end(), ostream_iterator<t>(out, " ")); + out.open(fname.c_str(), std::ios::out); + copy(vec.begin(), vec.end(), std::ostream_iterator<t>(out, " ")); } template<class t> void write_vector(const std::vector<t>& vec, const std::string& fname) @@ -345,7 +345,7 @@ namespace MISCMATHS { if (width>0) { os.fill('0'); os.width(width); - os.setf(ios::internal, ios::adjustfield); + os.setf(std::ios::internal, std::ios::adjustfield); } os << n; return os.str(); diff --git a/nonlin.h b/nonlin.h index 14d254f..cd23bbe 100644 --- a/nonlin.h +++ b/nonlin.h @@ -68,7 +68,7 @@ public: NonlinException(const std::string& msg) throw(): m_msg(msg) {} virtual const char * what() const throw() { - return string("Nonlin: msg=" + m_msg).c_str(); + return std::string("Nonlin: msg=" + m_msg).c_str(); } ~NonlinException() throw() {} @@ -397,11 +397,11 @@ NonlinOut nonlin(const NonlinParam& p, const NonlinCF& cfo); // Declaration of global utility functions -pair<NEWMAT::ColumnVector,NEWMAT::ColumnVector> check_grad(const NEWMAT::ColumnVector& par, - const NonlinCF& cfo); +std::pair<NEWMAT::ColumnVector,NEWMAT::ColumnVector> check_grad(const NEWMAT::ColumnVector& par, + const NonlinCF& cfo); -pair<boost::shared_ptr<BFMatrix>,boost::shared_ptr<BFMatrix> > check_hess(const NEWMAT::ColumnVector& par, - const NonlinCF& cfo); +std::pair<boost::shared_ptr<BFMatrix>,boost::shared_ptr<BFMatrix> > check_hess(const NEWMAT::ColumnVector& par, + const NonlinCF& cfo); } // End namespace MISCMATHS diff --git a/sparse_matrix.h b/sparse_matrix.h index e2c4f65..992a403 100644 --- a/sparse_matrix.h +++ b/sparse_matrix.h @@ -125,7 +125,7 @@ namespace MISCMATHS { int nrows; int ncols; - std::vector<map<int,double> > data; + std::vector<std::map<int,double> > data; }; diff --git a/splinterpolator.h b/splinterpolator.h index 02091bd..6366b83 100644 --- a/splinterpolator.h +++ b/splinterpolator.h @@ -30,7 +30,7 @@ public: SplinterpolatorException(const std::string& msg) throw(): m_msg(msg) {} virtual const char *what() const throw() { - return string("Splinterpolator::" + m_msg).c_str(); + return std::string("Splinterpolator::" + m_msg).c_str(); } ~SplinterpolatorException() throw() {} diff --git a/t2z.cc b/t2z.cc index 4d05d27..9026e60 100644 --- a/t2z.cc +++ b/t2z.cc @@ -12,6 +12,7 @@ #include "utils/tracer_plus.h" #include "cprob/libprob.h" +using namespace std; using namespace NEWMAT; using namespace Utilities; -- GitLab