From 2eaaba09f126759d91f112e96a165ee0032e9a4c Mon Sep 17 00:00:00 2001 From: Peter Hill Date: Tue, 10 Oct 2023 16:00:02 +0100 Subject: [PATCH] Suppress clang-tidy warnings about implicit conversions --- cxx4/ncCompoundType.cpp | 3 +-- cxx4/ncDim.cpp | 2 +- cxx4/ncFilter.cpp | 4 ++-- cxx4/ncGroup.cpp | 29 +++++++++++++++-------------- cxx4/ncVar.cpp | 9 +++++---- 5 files changed, 24 insertions(+), 23 deletions(-) diff --git a/cxx4/ncCompoundType.cpp b/cxx4/ncCompoundType.cpp index 4764c85..7698946 100644 --- a/cxx4/ncCompoundType.cpp +++ b/cxx4/ncCompoundType.cpp @@ -155,8 +155,7 @@ int NcCompoundType::getMemberDimCount(int memberIndex) const // Returns the shape of the given member. vector NcCompoundType::getMemberShape(int memberIndex) const { - vector dim_size; - dim_size.resize(getMemberDimCount(memberIndex)); + vector dim_size(static_cast(getMemberDimCount(memberIndex))); if(!dim_size.empty()) ncCheck(nc_inq_compound_fielddim_sizes(groupId,myId,memberIndex,&dim_size[0]),__FILE__,__LINE__); return dim_size; diff --git a/cxx4/ncDim.cpp b/cxx4/ncDim.cpp index a0f3aa8..c207b37 100644 --- a/cxx4/ncDim.cpp +++ b/cxx4/ncDim.cpp @@ -91,7 +91,7 @@ bool NcDim::isUnlimited() const ncCheck(nc_inq_unlimdims(groupId,&numlimdims,unlimdimidsp),__FILE__,__LINE__); if (numlimdims){ // get all the unlimited dimension ids in this group - vector unlimdimid(numlimdims); + vector unlimdimid(static_cast(numlimdims)); ncCheck(nc_inq_unlimdims(groupId,&numlimdims,&unlimdimid[0]),__FILE__,__LINE__); vector::iterator it; // now look to see if this dimension is unlimited diff --git a/cxx4/ncFilter.cpp b/cxx4/ncFilter.cpp index 4516027..b3ff766 100644 --- a/cxx4/ncFilter.cpp +++ b/cxx4/ncFilter.cpp @@ -18,12 +18,12 @@ NcFilter::~NcFilter() { method allows for setting of the filter which is to be used wen writing a variable. */ void NcFilter::setFilter(unsigned int ncid, unsigned int varid, unsigned int filterId, size_t nparams, const unsigned int* parms) { - ncCheck(nc_def_var_filter(ncid,varid,filterId,nparams,parms),__FILE__,__LINE__); + ncCheck(nc_def_var_filter(static_cast(ncid), static_cast(varid),filterId,nparams,parms),__FILE__,__LINE__); } /* This second API method makes it possible to query a varible to obtain information about any associated filter using this signature */ void NcFilter::getFilter(unsigned int ncid, unsigned int varid, unsigned int* idp, size_t* nparamsp, unsigned int* params) { - ncCheck(nc_inq_var_filter(ncid, varid, idp, nparamsp, params),__FILE__,__LINE__); + ncCheck(nc_inq_var_filter(static_cast(ncid), static_cast(varid), idp, nparamsp, params),__FILE__,__LINE__); } diff --git a/cxx4/ncGroup.cpp b/cxx4/ncGroup.cpp index f3acf0e..aa543f1 100644 --- a/cxx4/ncGroup.cpp +++ b/cxx4/ncGroup.cpp @@ -17,6 +17,7 @@ #include "ncFloat.h" #include "ncDouble.h" #include "ncString.h" +#include #include #include "ncCheck.h" using namespace std; @@ -193,13 +194,13 @@ multimap NcGroup::getGroups(NcGroup::GroupLocation location // the child groups of the current group if(location == ChildrenGrps || location == AllChildrenGrps || location == AllGrps ) { // get the number of groups - int groupCount = getGroupCount(); + const auto groupCount = static_cast(getGroupCount()); if (groupCount){ vector ncids(groupCount); int* numgrps=NULL; // now get the id of each NcGroup and populate the ncGroups container. ncCheck(nc_inq_grps(myId, numgrps,&ncids[0]),__FILE__,__LINE__); - for(int i=0; i(tmpGroup.getName(),tmpGroup)); } @@ -319,13 +320,13 @@ multimap NcGroup::getVars(NcGroup::Location location) const { NcGroup tmpGroup(*this); if((location == ParentsAndCurrent || location == ChildrenAndCurrent || location == Current || location ==All) && !tmpGroup.isNull()) { // get the number of variables. - int varCount = getVarCount(); + const auto varCount = static_cast(getVarCount()); if (varCount){ // now get the name of each NcVar object and populate the ncVars container. int* nvars=NULL; vector varids(varCount); ncCheck(nc_inq_varids(myId, nvars,&varids[0]),__FILE__,__LINE__); - for(int i=0; i(tmpVar.getName(),tmpVar)); } @@ -338,13 +339,13 @@ multimap NcGroup::getVars(NcGroup::Location location) const { tmpGroup=getParentGroup(); while(!tmpGroup.isNull()) { // get the number of variables - int varCount = tmpGroup.getVarCount(); + const auto varCount = static_cast(tmpGroup.getVarCount()); if (varCount){ // now get the name of each NcVar object and populate the ncVars container. int* nvars=NULL; vector varids(varCount); ncCheck(nc_inq_varids(tmpGroup.getId(), nvars,&varids[0]),__FILE__,__LINE__); - for(int i=0; i(tmpVar.getName(),tmpVar)); } @@ -943,12 +944,12 @@ multimap NcGroup::getDims(NcGroup::Location location) const { // search in current group if(location == Current || location == ParentsAndCurrent || location == ChildrenAndCurrent || location == All ) { - int dimCount = getDimCount(); + const auto dimCount = static_cast(getDimCount()); if (dimCount){ vector dimids(dimCount); - ncCheck(nc_inq_dimids(getId(), &dimCount, &dimids[0], 0),__FILE__,__LINE__); + ncCheck(nc_inq_dimids(getId(), nullptr, &dimids[0], 0),__FILE__,__LINE__); // now get the name of each NcDim and populate the nDims container. - for(int i=0; i(tmpDim.getName(),tmpDim)); } @@ -1088,9 +1089,9 @@ int NcGroup::getTypeCount(NcType::ncType enumType, NcGroup::Location location) c int* typeidsp=NULL; ncCheck(nc_inq_typeids(getId(), &ntypesp,typeidsp),__FILE__,__LINE__); if (ntypesp){ - vector typeids(ntypesp); + vector typeids(static_cast(ntypesp)); ncCheck(nc_inq_typeids(getId(), &ntypesp,&typeids[0]),__FILE__,__LINE__); - for (int i=0; i(ntypesp); i++){ NcType tmpType(*this,typeids[i]); if(tmpType.getTypeClass() == enumType) ntypes++; } @@ -1126,12 +1127,12 @@ multimap NcGroup::getTypes(NcGroup::Location location) const { // search in current group if(location == Current || location == ParentsAndCurrent || location == ChildrenAndCurrent || location == All ) { - int typeCount = getTypeCount(); + const auto typeCount = static_cast(getTypeCount()); if (typeCount){ vector typeids(typeCount); - ncCheck(nc_inq_typeids(getId(), &typeCount,&typeids[0]),__FILE__,__LINE__); + ncCheck(nc_inq_typeids(getId(), nullptr, &typeids[0]),__FILE__,__LINE__); // now get the name of each NcType and populate the nTypes container. - for(int i=0; i(tmpType.getName(),tmpType)); } diff --git a/cxx4/ncVar.cpp b/cxx4/ncVar.cpp index 16a99c2..76d4feb 100644 --- a/cxx4/ncVar.cpp +++ b/cxx4/ncVar.cpp @@ -4,6 +4,7 @@ #include "ncGroup.h" #include "ncCheck.h" #include "ncException.h" +#include #include using namespace std; using namespace netCDF::exceptions; @@ -151,14 +152,14 @@ int NcVar::getDimCount() const vector NcVar::getDims() const { // get the number of dimensions - int dimCount = getDimCount(); + const auto dimCount = static_cast(getDimCount()); // create a vector of dimensions. vector ncDims; if (dimCount){ vector dimids(dimCount); ncCheck(nc_inq_vardimid(groupId,myId, &dimids[0]),__FILE__,__LINE__); ncDims.reserve(dimCount); - for (int i=0; i ncDims = getDims(); if((size_t)i >= ncDims.size() || i < 0) throw NcException("Index out of range",__FILE__,__LINE__); - return ncDims[i]; + return ncDims[static_cast(i)]; } @@ -549,7 +550,7 @@ void NcVar::setChunking(ChunkMode chunkMode, vector& chunkSizes) const { // Gets the chunking parameters void NcVar::getChunkingParameters(ChunkMode& chunkMode, vector& chunkSizes) const { int chunkModeInt; - chunkSizes.resize(getDimCount()); + chunkSizes.resize(static_cast(getDimCount())); size_t *chunkSizesPtr = chunkSizes.empty() ? 0 : &chunkSizes[0]; ncCheck(nc_inq_var_chunking(groupId,myId, &chunkModeInt, chunkSizesPtr),__FILE__,__LINE__); chunkMode = static_cast (chunkModeInt);