Skip to content

Commit

Permalink
Merge pull request Unidata#135 from ZedThree/fix-casts
Browse files Browse the repository at this point in the history
Fix a bunch of warnings from casts
  • Loading branch information
WardF authored Oct 12, 2023
2 parents f2dcc94 + 2eaaba0 commit 1b1e0e6
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 33 deletions.
7 changes: 3 additions & 4 deletions cxx4/ncCompoundType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ NcCompoundType::NcCompoundType(const NcType& rhs):
// Inserts a named field.
void NcCompoundType::addMember(const string& memberName, const NcType& newMemberType,size_t offset)
{
ncCheck(nc_insert_compound(groupId,myId,const_cast<char*>(memberName.c_str()),offset,newMemberType.getId()),__FILE__,__LINE__);
ncCheck(nc_insert_compound(groupId,myId, memberName.c_str(),offset,newMemberType.getId()),__FILE__,__LINE__);
}


Expand All @@ -88,7 +88,7 @@ void NcCompoundType::addMember(const string& memberName, const NcType& newMember
void NcCompoundType::addMember(const string& memberName, const NcType& newMemberType, size_t offset, const vector<int>& shape)
{
if (!shape.empty())
ncCheck(nc_insert_array_compound(groupId, myId,const_cast<char*>(memberName.c_str()), offset, newMemberType.getId(), shape.size(), const_cast<int*>(&shape[0])),__FILE__,__LINE__);
ncCheck(nc_insert_array_compound(groupId, myId, memberName.c_str(), offset, newMemberType.getId(), static_cast<int>(shape.size()), &shape[0]),__FILE__,__LINE__);
else
addMember(memberName, newMemberType, offset);
}
Expand Down Expand Up @@ -155,8 +155,7 @@ int NcCompoundType::getMemberDimCount(int memberIndex) const
// Returns the shape of the given member.
vector<int> NcCompoundType::getMemberShape(int memberIndex) const
{
vector<int> dim_size;
dim_size.resize(getMemberDimCount(memberIndex));
vector<int> dim_size(static_cast<std::size_t>(getMemberDimCount(memberIndex)));
if(!dim_size.empty())
ncCheck(nc_inq_compound_fielddim_sizes(groupId,myId,memberIndex,&dim_size[0]),__FILE__,__LINE__);
return dim_size;
Expand Down
2 changes: 1 addition & 1 deletion cxx4/ncDim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> unlimdimid(numlimdims);
vector<int> unlimdimid(static_cast<std::size_t>(numlimdims));
ncCheck(nc_inq_unlimdims(groupId,&numlimdims,&unlimdimid[0]),__FILE__,__LINE__);
vector<int>::iterator it;
// now look to see if this dimension is unlimited
Expand Down
4 changes: 2 additions & 2 deletions cxx4/ncFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(ncid), static_cast<int>(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<int>(ncid), static_cast<int>(varid), idp, nparamsp, params),__FILE__,__LINE__);
}
45 changes: 23 additions & 22 deletions cxx4/ncGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "ncFloat.h"
#include "ncDouble.h"
#include "ncString.h"
#include <cstddef>
#include <ncException.h>
#include "ncCheck.h"
using namespace std;
Expand Down Expand Up @@ -165,14 +166,14 @@ int NcGroup::getGroupCount(NcGroup::GroupLocation location) const {
// search in parent groups
if(location == ParentsGrps || location == ParentsAndCurrentGrps || location == AllGrps ) {
multimap<string,NcGroup> groups(getGroups(ParentsGrps));
ngroups += groups.size();
ngroups += static_cast<int>(groups.size());
}


// get the number of all children that are childreof children
if(location == ChildrenOfChildrenGrps || location == AllChildrenGrps || location == AllGrps ) {
multimap<string,NcGroup> groups(getGroups(ChildrenOfChildrenGrps));
ngroups += groups.size();
ngroups += static_cast<int>(groups.size());
}

return ngroups;
Expand All @@ -193,13 +194,13 @@ multimap<std::string,NcGroup> 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<std::size_t>(getGroupCount());
if (groupCount){
vector<int> 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<groupCount;i++){
for(std::size_t i=0; i<groupCount;i++){
NcGroup tmpGroup(ncids[i]);
ncGroups.insert(pair<const string,NcGroup>(tmpGroup.getName(),tmpGroup));
}
Expand Down Expand Up @@ -265,7 +266,7 @@ set<NcGroup> NcGroup::getGroups(const std::string& name,NcGroup::GroupLocation l
NcGroup NcGroup::addGroup(const string& name) const {
if(isNull()) throw NcNullGrp("Attempt to invoke NcGroup::addGroup on a Null group",__FILE__,__LINE__);
int new_ncid;
ncCheck(nc_def_grp(myId,const_cast<char*> (name.c_str()),&new_ncid),__FILE__,__LINE__);
ncCheck(nc_def_grp(myId, name.c_str(), &new_ncid),__FILE__,__LINE__);
return NcGroup(new_ncid);
}

Expand Down Expand Up @@ -319,13 +320,13 @@ multimap<std::string,NcVar> 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<std::size_t>(getVarCount());
if (varCount){
// now get the name of each NcVar object and populate the ncVars container.
int* nvars=NULL;
vector<int> varids(varCount);
ncCheck(nc_inq_varids(myId, nvars,&varids[0]),__FILE__,__LINE__);
for(int i=0; i<varCount;i++){
for(std::size_t i=0; i<varCount;i++){
NcVar tmpVar(*this,varids[i]);
ncVars.insert(pair<const string,NcVar>(tmpVar.getName(),tmpVar));
}
Expand All @@ -338,13 +339,13 @@ multimap<std::string,NcVar> 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<std::size_t>(tmpGroup.getVarCount());
if (varCount){
// now get the name of each NcVar object and populate the ncVars container.
int* nvars=NULL;
vector<int> varids(varCount);
ncCheck(nc_inq_varids(tmpGroup.getId(), nvars,&varids[0]),__FILE__,__LINE__);
for(int i=0; i<varCount;i++){
for(std::size_t i=0; i<varCount;i++){
NcVar tmpVar(tmpGroup,varids[i]);
ncVars.insert(pair<const string,NcVar>(tmpVar.getName(),tmpVar));
}
Expand Down Expand Up @@ -465,7 +466,7 @@ NcVar NcGroup::addVar(const string& name, const string& typeName, const vector<s
// finally define a new netCDF variable
int varId;
int *dimIdsPtr = dimIds.empty() ? 0 : &dimIds[0];
ncCheck(nc_def_var(myId,name.c_str(),tmpType.getId(),dimIds.size(), dimIdsPtr,&varId),__FILE__,__LINE__);
ncCheck(nc_def_var(myId,name.c_str(),tmpType.getId(), static_cast<int>(dimIds.size()), dimIdsPtr,&varId),__FILE__,__LINE__);
// return an NcVar object for this new variable
return NcVar(*this,varId);
}
Expand Down Expand Up @@ -493,7 +494,7 @@ NcVar NcGroup::addVar(const string& name, const NcType& ncType, const vector<NcD
// finally define a new netCDF variable
int varId;
int *dimIdsPtr = dimIds.empty() ? 0 : &dimIds[0];
ncCheck(nc_def_var(myId,name.c_str(),tmpType.getId(),dimIds.size(), dimIdsPtr,&varId),__FILE__,__LINE__);
ncCheck(nc_def_var(myId,name.c_str(),tmpType.getId(), static_cast<int>(dimIds.size()), dimIdsPtr,&varId),__FILE__,__LINE__);
// return an NcVar object for this new variable
return NcVar(*this,varId);
}
Expand Down Expand Up @@ -943,12 +944,12 @@ multimap<string,NcDim> 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<std::size_t>(getDimCount());
if (dimCount){
vector<int> 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<dimCount;i++){
for(std::size_t i=0; i<dimCount;i++){
NcDim tmpDim(*this,dimids[i]);
ncDims.insert(pair<const string,NcDim>(tmpDim.getName(),tmpDim));
}
Expand Down Expand Up @@ -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<int> typeids(ntypesp);
vector<int> typeids(static_cast<std::size_t>(ntypesp));
ncCheck(nc_inq_typeids(getId(), &ntypesp,&typeids[0]),__FILE__,__LINE__);
for (int i=0; i<ntypesp;i++){
for (std::size_t i=0; i<static_cast<std::size_t>(ntypesp); i++){
NcType tmpType(*this,typeids[i]);
if(tmpType.getTypeClass() == enumType) ntypes++;
}
Expand Down Expand Up @@ -1126,12 +1127,12 @@ multimap<string,NcType> 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<std::size_t>(getTypeCount());
if (typeCount){
vector<int> 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<typeCount;i++){
for(std::size_t i=0; i<typeCount;i++){
NcType tmpType(*this,typeids[i]);
ncTypes.insert(pair<const string,NcType>(tmpType.getName(),tmpType));
}
Expand Down Expand Up @@ -1271,7 +1272,7 @@ NcEnumType NcGroup::addEnumType(const string& name,NcEnumType::ncEnumType baseTy
NcVlenType NcGroup::addVlenType(const string& name,NcType& baseType) const {
ncCheckDefineMode(myId);
nc_type typeId;
ncCheck(nc_def_vlen(myId, const_cast<char*>(name.c_str()),baseType.getId(),&typeId),__FILE__,__LINE__);
ncCheck(nc_def_vlen(myId, name.c_str(), baseType.getId(),&typeId),__FILE__,__LINE__);
NcVlenType ncTypeTmp(*this,name);
return ncTypeTmp;
}
Expand All @@ -1281,7 +1282,7 @@ NcVlenType NcGroup::addVlenType(const string& name,NcType& baseType) const {
NcOpaqueType NcGroup::addOpaqueType(const string& name, size_t size) const {
ncCheckDefineMode(myId);
nc_type typeId;
ncCheck(nc_def_opaque(myId, size,const_cast<char*>(name.c_str()), &typeId),__FILE__,__LINE__);
ncCheck(nc_def_opaque(myId, size, name.c_str(), &typeId),__FILE__,__LINE__);
NcOpaqueType ncTypeTmp(*this,name);
return ncTypeTmp;
}
Expand All @@ -1290,7 +1291,7 @@ NcOpaqueType NcGroup::addOpaqueType(const string& name, size_t size) const {
NcCompoundType NcGroup::addCompoundType(const string& name, size_t size) const {
ncCheckDefineMode(myId);
nc_type typeId;
ncCheck(nc_def_compound(myId, size,const_cast<char*>(name.c_str()),&typeId),__FILE__,__LINE__);
ncCheck(nc_def_compound(myId, size, name.c_str(), &typeId),__FILE__,__LINE__);
NcCompoundType ncTypeTmp(*this,name);
return ncTypeTmp;
}
Expand Down
9 changes: 5 additions & 4 deletions cxx4/ncVar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "ncGroup.h"
#include "ncCheck.h"
#include "ncException.h"
#include <cstddef>
#include<netcdf.h>
using namespace std;
using namespace netCDF::exceptions;
Expand Down Expand Up @@ -151,14 +152,14 @@ int NcVar::getDimCount() const
vector<NcDim> NcVar::getDims() const
{
// get the number of dimensions
int dimCount = getDimCount();
const auto dimCount = static_cast<std::size_t>(getDimCount());
// create a vector of dimensions.
vector<NcDim> ncDims;
if (dimCount){
vector<int> dimids(dimCount);
ncCheck(nc_inq_vardimid(groupId,myId, &dimids[0]),__FILE__,__LINE__);
ncDims.reserve(dimCount);
for (int i=0; i<dimCount; i++){
for (std::size_t i = 0; i < dimCount; i++) {
NcDim tmpDim(getParentGroup(),dimids[i]);
ncDims.push_back(tmpDim);
}
Expand All @@ -172,7 +173,7 @@ NcDim NcVar::getDim(int i) const
{
vector<NcDim> 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<std::size_t>(i)];
}


Expand Down Expand Up @@ -549,7 +550,7 @@ void NcVar::setChunking(ChunkMode chunkMode, vector<size_t>& chunkSizes) const {
// Gets the chunking parameters
void NcVar::getChunkingParameters(ChunkMode& chunkMode, vector<size_t>& chunkSizes) const {
int chunkModeInt;
chunkSizes.resize(getDimCount());
chunkSizes.resize(static_cast<std::size_t>(getDimCount()));
size_t *chunkSizesPtr = chunkSizes.empty() ? 0 : &chunkSizes[0];
ncCheck(nc_inq_var_chunking(groupId,myId, &chunkModeInt, chunkSizesPtr),__FILE__,__LINE__);
chunkMode = static_cast<ChunkMode> (chunkModeInt);
Expand Down

0 comments on commit 1b1e0e6

Please sign in to comment.