diff --git a/BaseLib/FileTools.h b/BaseLib/FileTools.h index 1eee53aa32d8ad87344d2f5870c76976691e4657..4167a14d21bb1b5b2946d8afcad56db538ac8fe4 100644 --- a/BaseLib/FileTools.h +++ b/BaseLib/FileTools.h @@ -40,7 +40,7 @@ bool IsFileExisting(const std::string &strFilename); */ template <typename T> void writeValueBinary(std::ostream &out, T const& val) { - out.write((const char*)&val, sizeof(T)); + out.write(static_cast<const char*>(&val), sizeof(T)); } template <typename T> diff --git a/BaseLib/MemWatch.cpp b/BaseLib/MemWatch.cpp index 5672751c1c66a0c9131902db733e03fc5211d5e9..48873f90f469eee43e0102a58885f1f5e0dd8a09 100644 --- a/BaseLib/MemWatch.cpp +++ b/BaseLib/MemWatch.cpp @@ -35,7 +35,7 @@ unsigned MemWatch::updateMemUsage () #if !defined(WIN32) && !defined(__APPLE__) std::string fname ("/proc/"); std::stringstream str_pid; - str_pid << (unsigned) getpid(); + str_pid << static_cast<unsigned> (getpid()); fname += str_pid.str(); fname += "/statm"; unsigned pages; @@ -48,13 +48,17 @@ unsigned MemWatch::updateMemUsage () } in >> pages; - _vmem_size = ((unsigned long) pages) * ((unsigned long) getpagesize()); + _vmem_size = static_cast<unsigned long>(pages) * + static_cast<unsigned long>(getpagesize()); in >> pages; - _rmem_size = ((unsigned long) pages) * ((unsigned long) getpagesize()); + _rmem_size =static_cast<unsigned long>(pages) * + static_cast<unsigned long>(getpagesize()); in >> pages; - _smem_size = ((unsigned long) pages) * ((unsigned long) getpagesize()); + _smem_size = static_cast<unsigned long>(pages) * + static_cast<unsigned long>(getpagesize()); in >> pages; - _cmem_size = ((unsigned long) pages) * ((unsigned long) getpagesize()); + _cmem_size = static_cast<unsigned long>(pages) * + static_cast<unsigned long>(getpagesize()); in.close (); #endif diff --git a/GeoLib/Grid.h b/GeoLib/Grid.h index 6ad03f522947dbb8b103b690f4e063e14d524d43..11a5a706f7397af399a0a46dd2ec1b7e78084795 100644 --- a/GeoLib/Grid.h +++ b/GeoLib/Grid.h @@ -262,23 +262,33 @@ private: } else { // 1d case: dx == 0, dy == 0, dz != 0 _n_steps[0] = 1; _n_steps[1] = 1; - _n_steps[2] = static_cast<std::size_t> (ceil(n_pnts / (double) max_num_per_grid_cell)); + _n_steps[2] = static_cast<std::size_t> ( + ceil(n_pnts/static_cast<double>(max_num_per_grid_cell)) + ); } } else { // dy != 0 if(fabs(delta[2]) < eps) { // 1d case: dx == 0, dy != 0, dz == 0 _n_steps[0] = 1; - _n_steps[1] = static_cast<std::size_t> (ceil(n_pnts / (double) max_num_per_grid_cell)); + _n_steps[1] = static_cast<std::size_t> ( + ceil(n_pnts/static_cast<double>(max_num_per_grid_cell)) + ); _n_steps[2] = 1; } else { // 2d case: dx == 0, dy != 0, dz != 0 _n_steps[0] = 1; - _n_steps[1] = static_cast<std::size_t> (ceil(sqrt(n_pnts * delta[1] / (max_num_per_grid_cell * delta[2])))); - _n_steps[2] = static_cast<std::size_t> (ceil(n_pnts / (double) max_num_per_grid_cell)); + _n_steps[1] = static_cast<std::size_t> ( + ceil(sqrt(n_pnts*delta[1]/(max_num_per_grid_cell*delta[2]))) + ); + _n_steps[2] = static_cast<std::size_t> ( + ceil(n_pnts/static_cast<double>(max_num_per_grid_cell)) + ); } } } else { // dx != 0 if(fabs(delta[1]) < eps) { // dy == 0 if(fabs(delta[2]) < eps) { // 1d case: dx != 0, dy == 0, dz == 0 - _n_steps[0] = static_cast<std::size_t> (ceil(n_pnts / (double) max_num_per_grid_cell)); + _n_steps[0] = static_cast<std::size_t> ( + ceil(n_pnts/static_cast<double>(max_num_per_grid_cell)) + ); _n_steps[1] = 1; _n_steps[2] = 1; } else { // 2d case: dx != 0, dy == 0, dz != 0 diff --git a/GeoLib/Station.h b/GeoLib/Station.h index e6acb378347e8be5b2f14b2706a6c057c72df633..deaa1730d17258813db2f523bf691e31817575c2 100644 --- a/GeoLib/Station.h +++ b/GeoLib/Station.h @@ -168,23 +168,41 @@ protected: * \param stnObject A pointer to the station object for which the x-coordinate should be returned, usually (void*)this will work fine. * \return The x-coordinate for this station. */ - static double getX(void* stnObject) { Station* stn = (Station*)stnObject; - return (*stn)[0]; } + static double getX(void* stnObject) + { + Station const*const stn = static_cast<Station*>(stnObject); + return (*stn)[0]; + } /// Returns the y-coordinate of this station. See the detailed documentation for getX concerning the syntax. - static double getY(void* stnObject) { Station* stn = (Station*)stnObject; - return (*stn)[1]; } + static double getY(void* stnObject) + { + Station const*const stn = static_cast<Station*>(stnObject); + return (*stn)[1]; + } /// Returns the z-coordinate of this station. See the detailed documentation for getX concerning the syntax. - static double getZ(void* stnObject) { Station* stn = (Station*)stnObject; - return (*stn)[2]; } + static double getZ(void* stnObject) + { + Station* stn = static_cast<Station*>(stnObject); + return (*stn)[2]; + } /// Sets the x-coordinate for this station. See the detailed documentation for getX concerning the syntax. - static void setX(void* stnObject, double val) { Station* stn = (Station*)stnObject; - (*stn)[0] = val; } + static void setX(void* stnObject, double val) + { + Station* stn = static_cast<Station*>(stnObject); + (*stn)[0] = val; + } /// Sets the y-coordinate for this station. See the detailed documentation for getX concerning the syntax. - static void setY(void* stnObject, double val) { Station* stn = (Station*)stnObject; - (*stn)[1] = val; } + static void setY(void* stnObject, double val) + { + Station* stn = static_cast<Station*>(stnObject); + (*stn)[1] = val; + } /// Sets the z-coordinate for this station. See the detailed documentation for getX concerning the syntax. - static void setZ(void* stnObject, double val) { Station* stn = (Station*)stnObject; - (*stn)[2] = val; } + static void setZ(void* stnObject, double val) + { + Station* stn = static_cast<Station*>(stnObject); + (*stn)[2] = val; + } std::string _name; StationType _type; // GeoSys Station Type diff --git a/MathLib/LinAlg/Dense/DenseMatrix-impl.h b/MathLib/LinAlg/Dense/DenseMatrix-impl.h index 5e9e70975f50ea4b070609eab176c7f7a6dc8835..a05dd54857a09c7d2ad6676d55f83002d97e2077 100644 --- a/MathLib/LinAlg/Dense/DenseMatrix-impl.h +++ b/MathLib/LinAlg/Dense/DenseMatrix-impl.h @@ -289,7 +289,7 @@ template <typename FP_TYPE, typename IDX_TYPE> FP_TYPE sqrFrobNrm (const DenseMatrix<FP_TYPE, IDX_TYPE> &mat) { - FP_TYPE nrm((FP_TYPE) (0)); + FP_TYPE nrm(static_cast<FP_TYPE>(0)); IDX_TYPE i, j; for (j = 0; j < mat.getNCols(); j++) for (i = 0; i < mat.getNRows(); i++) diff --git a/MathLib/LinAlg/Solvers/blas.h b/MathLib/LinAlg/Solvers/blas.h index d4ab83652140d2225bc973709f3827a1183a8294..1e1503e10aefb56e2e9cb9fa122f762868edfc9f 100644 --- a/MathLib/LinAlg/Solvers/blas.h +++ b/MathLib/LinAlg/Solvers/blas.h @@ -293,13 +293,13 @@ namespace blas // Conv.Copy double2float inline void copy(const unsigned n, double* orig, float* dest) { - for (unsigned i=0; i<n; i++) dest[i] = (float) orig[i]; + for (unsigned i=0; i<n; i++) dest[i] = static_cast<float>(orig[i]); } // Conv.Copy float2double inline void copy(const unsigned n, float* orig, double* dest) { - for (unsigned i=0; i<n; i++) dest[i] = (double) orig[i]; + for (unsigned i=0; i<n; i++) dest[i] = static_cast<double>(orig[i]); } // Scalar product conj(x)*y @@ -1014,14 +1014,14 @@ namespace blas inline void fill0_ltr(unsigned n, double* A) { for (unsigned j=0; j<n; ++j) { - *A++ = (double) j; + *A++ = static_cast<double>(j); for (unsigned i=j+1; i<n; ++i) *A++ = D_ZERO; } } inline void fill0_ltr(unsigned n, float* A) { for (unsigned j=0; j<n; ++j) { - *A++ = (float) j; + *A++ = static_cast<float>(j); for (unsigned i=j+1; i<n; ++i) *A++ = S_ZERO; } } @@ -1070,7 +1070,7 @@ namespace blas for (unsigned i=0; i<n; ++i) { for (unsigned j=0; j<i; ++j) *A++ = D_ZERO; // for pivoting, a ltr is assumed to have ones on the diagonal - *A++ = (double) i; + *A++ = static_cast<double>(i); } } inline void fillId_ltr(unsigned n, float *A) @@ -1078,7 +1078,7 @@ namespace blas for (unsigned i=0; i<n; ++i) { for (unsigned j=0; j<i; ++j) *A++ = S_ZERO; // for pivoting, a ltr is assumed to have ones on the diagonal - *A++ = (float) i; + *A++ = static_cast<float>(i); } } diff --git a/MathLib/LinAlg/Sparse/amuxCRS.cpp b/MathLib/LinAlg/Sparse/amuxCRS.cpp index 37212e789bd860741e32dae830778868c9cc940e..935b40b3b0bc50e9f52be77057dfd4b40a716b71 100644 --- a/MathLib/LinAlg/Sparse/amuxCRS.cpp +++ b/MathLib/LinAlg/Sparse/amuxCRS.cpp @@ -45,7 +45,7 @@ struct MatMultThreadParam { extern "C" { void* amuxCRSpthread (void* ptr) { - MatMultThreadParam *thread_param((MatMultThreadParam*) (ptr)); + MatMultThreadParam *thread_param(static_cast<MatMultThreadParam*>(ptr)); const double a(thread_param->_a); const unsigned beg_row(thread_param->_beg_row); const unsigned end_row(thread_param->_end_row); @@ -75,7 +75,7 @@ void amuxCRSParallelPThreads (double a, #ifdef HAVE_PTHREADS // fill thread data objects MatMultThreadParam** thread_param_array (new MatMultThreadParam*[num_of_pthreads]); - double step_size ((double)(n)/(double)(num_of_pthreads)); + double step_size (static_cast<double>(n)/(num_of_pthreads)); for (unsigned k(0); k<num_of_pthreads; k++) { const unsigned beg (static_cast<unsigned>(k*step_size)); const unsigned end (static_cast<unsigned>((k+1)*step_size)); diff --git a/MathLib/sparse.h b/MathLib/sparse.h index aaf56f48c17600f39d50b27c607ee54169d2a4c2..2b9a37cafa8e600375fa10f9e9943c75b3d6303d 100644 --- a/MathLib/sparse.h +++ b/MathLib/sparse.h @@ -23,15 +23,15 @@ template<class T> void CS_write(std::ostream &os, unsigned n, unsigned const* iA, unsigned const* jA, T const* A) { - os.write((char*) &n, sizeof(unsigned)); - os.write((char*) iA, (n + 1) * sizeof(unsigned)); - os.write((char*) jA, iA[n] * sizeof(unsigned)); - os.write((char*) A, iA[n] * sizeof(T)); + os.write(reinterpret_cast<char*>(&n), sizeof(unsigned)); + os.write(reinterpret_cast<char*>(const_cast<unsigned*>(iA)), (n + 1) * sizeof(unsigned)); + os.write(reinterpret_cast<char*>(const_cast<unsigned*>(jA)), iA[n] * sizeof(unsigned)); + os.write(reinterpret_cast<char*>(A), iA[n] * sizeof(T)); } template<class T> void CS_read(std::istream &is, unsigned &n, unsigned* &iA, unsigned* &jA, T* &A) { - is.read((char*) &n, sizeof(unsigned)); + is.read(reinterpret_cast<char*>(&n), sizeof(unsigned)); if (iA != NULL) { delete[] iA; delete[] jA; @@ -39,15 +39,15 @@ template<class T> void CS_read(std::istream &is, unsigned &n, unsigned* &iA, uns } iA = new unsigned[n + 1]; assert(iA != NULL); - is.read((char*) iA, (n + 1) * sizeof(unsigned)); + is.read(reinterpret_cast<char*>(iA), (n + 1) * sizeof(unsigned)); jA = new unsigned[iA[n]]; assert(jA != NULL); - is.read((char*) jA, iA[n] * sizeof(unsigned)); + is.read(reinterpret_cast<char*>(jA), iA[n] * sizeof(unsigned)); A = new T[iA[n]]; assert(A != NULL); - is.read((char*) A, iA[n] * sizeof(T)); + is.read(reinterpret_cast<char*>(A), iA[n] * sizeof(T)); #ifndef NDEBUG // do simple checks