WSL/SLF GitLab Repository

Commit 53aec8c9 authored by Mathias Bavay's avatar Mathias Bavay
Browse files

Lots of small fixes after running cppcheck on Windows: unused variables, use...

Lots of small fixes after running cppcheck on Windows: unused variables, use ++i instead of i++ for complex types (ie mostly iterators for us) for more performance, a few variables that could be passed as const&, use vector.empty() instead of vector.size==0 (for clarity and potentially performances).
parent a9c337ba
......@@ -277,7 +277,7 @@ void BufferedIOHandler::readMeteoData(const Date& date_start, const Date& date_e
//Try to buffer after the requested chunk for subsequent calls
//0. initialize if not already initialized
if (vec_buffer_meteo.size() == 0) //init
if (vec_buffer_meteo.empty()) //init
bufferData(new_buffer_start, new_buffer_end, vec_buffer_meteo);
size_t buffer_size = vec_buffer_meteo.size();
......@@ -413,7 +413,7 @@ std::ostream& operator<<(std::ostream& os, const BufferedIOHandler& data)
}
std::map<std::string, Grid2DObject>::const_iterator it1;
for (it1=data.mapBufferedGrids.begin(); it1 != data.mapBufferedGrids.end(); it1++){
for (it1=data.mapBufferedGrids.begin(); it1 != data.mapBufferedGrids.end(); ++it1){
os << setw(10) << "Grid" << " = " << it1->first << ", ";
os << (it1->second).ncols << " x " << (it1->second).nrows << " @ " << (it1->second).cellsize << "m\n";
}
......
......@@ -88,7 +88,7 @@ std::ostream& operator<<(std::ostream &os, const Config& cfg)
{
os << "<Config>\n";
map<string,string>::const_iterator it;
for (it=cfg.properties.begin(); it != cfg.properties.end(); it++){
for (it=cfg.properties.begin(); it != cfg.properties.end(); ++it){
os << (*it).first << " -> " << (*it).second << "\n";
}
os << "</Config>\n";
......@@ -184,7 +184,7 @@ size_t Config::findKeys(std::vector<std::string>& vecResult, const std::string&
const string tmp_keystart = IOUtils::strToUpper(section) + "::" + IOUtils::strToUpper(keystart);
//Loop through keys, look for substring match - push it into vecResult
for (map<string,string>::const_iterator it=properties.begin(); it != properties.end(); it++){
for (map<string,string>::const_iterator it=properties.begin(); it != properties.end(); ++it){
const string tmp = (it->first).substr(0, tmp_keystart.length());
const int matchcount = tmp_keystart.compare(tmp);
......@@ -220,7 +220,7 @@ void Config::write(const std::string& filename)
try {
string current_section;
unsigned int sectioncount = 0;
for (map<string,string>::const_iterator it=properties.begin(); it != properties.end(); it++){
for (map<string,string>::const_iterator it=properties.begin(); it != properties.end(); ++it){
const string key = it->first;
const string section = extract_section(key);
......
......@@ -383,15 +383,10 @@ void Gradient::getColor(const double& val, unsigned char& r, unsigned char& g, u
a=false;
double r_d,g_d,b_d;
double val_norm;
if(nr_unique_cols==0) {
if(autoscale && val<min) val_norm=0.;
else if(autoscale && val>max) val_norm=1.;
else val_norm = (val-min)/delta;
} else {
if(autoscale && val<min) val_norm=0.;
else if(autoscale && val>max) val_norm=1.;
else val_norm = (val-min)/delta;
}
if(autoscale && val<min) val_norm=0.;
else if(autoscale && val>max) val_norm=1.;
else val_norm = (val-min)/delta;
model->getColor(val_norm, r_d, g_d, b_d);
r = static_cast<unsigned char>(r_d*channel_max_color);
g = static_cast<unsigned char>(g_d*channel_max_color);
......
......@@ -85,7 +85,7 @@ bool Grid2DObject::gridify(std::vector<Coords>& vec_points) const {
v_Itr = vec_points.erase(v_Itr);
status=false;
} else {
v_Itr++;
++v_Itr;
}
}
......@@ -274,7 +274,7 @@ bool Grid2DObject::isSameGeolocalization(const Grid2DObject& target) const
bool Grid2DObject::clusterization(const std::vector<double>& thresholds, const std::vector<double>& ids)
{
if (thresholds.size()==0) {
if (thresholds.empty()==0) {
throw IOException("Can't start clusterization, cluster definition list is empty", AT);
}
if ((thresholds.size()+1) != ids.size()) {
......
......@@ -93,7 +93,7 @@ bool Grid3DObject::gridify(std::vector<Coords>& vec_points) const
v_Itr = vec_points.erase(v_Itr);
status=false;
} else {
v_Itr++;
++v_Itr;
}
}
......
......@@ -205,7 +205,7 @@ IOHandler::~IOHandler() throw(){
#endif
// Get rid of the objects
std::map<std::string, IOPlugin>::iterator mapit;
for (mapit = mapPlugins.begin(); mapit!=mapPlugins.end(); mapit++){
for (mapit = mapPlugins.begin(); mapit!=mapPlugins.end(); ++mapit){
IOInterface*& io = (mapit->second).io;
if (io != NULL) {
delete io;
......@@ -436,7 +436,7 @@ std::string IOHandler::toString() const
os << "<mapPlugins>\n";
os << setw(10) << "Keyword" << " = " << IOPlugin::header << "\n";
std::map<std::string, IOPlugin>::const_iterator it1;
for (it1=mapPlugins.begin(); it1 != mapPlugins.end(); it1++){
for (it1=mapPlugins.begin(); it1 != mapPlugins.end(); ++it1){
os << setw(10) << it1->first << " = " << it1->second;
}
os << "</mapPlugins>\n";
......
......@@ -470,7 +470,7 @@ std::string IOManager::toString() const {
size_t min_stations=std::numeric_limits<size_t>::max();
size_t max_stations=0;
std::map<Date, std::vector<MeteoData> >::const_iterator iter = point_cache.begin();
for (; iter != point_cache.end(); iter++) {
for (; iter != point_cache.end(); ++iter) {
const size_t nb_stations = iter->second.size();
if(nb_stations>max_stations) max_stations=nb_stations;
if(nb_stations<min_stations) min_stations=nb_stations;
......
......@@ -149,7 +149,6 @@ std::string getExtension(const std::string& filename)
std::string removeExtension(const std::string& filename)
{
const std::string whitespaces(" \t\f\v\n\r");
const size_t start_basename = filename.find_last_of("/\\"); //we will skip the path
const size_t startpos = filename.find_last_of('.');
if( startpos==std::string::npos ) return filename;
......@@ -648,7 +647,7 @@ size_t seek(const Date& soughtdate, const std::vector<MeteoData>& vecM, const bo
{
//returns index of element, if element does not exist it returns closest index after soughtdate
//the element needs to be an exact hit or embedded between two measurments
if (vecM.size() <= 0) {//no elements in buffer
if (vecM.empty()) {//no elements in buffer
return npos;
}
......
......@@ -105,7 +105,7 @@ InterpolationAlgorithm* AlgorithmFactory::getAlgorithm(const std::string& i_algo
std::stringstream info; ///<to store some extra information about the interoplation process
size_t nrOfMeasurments; ///<the available number of measurements
InterpolationAlgorithm::InterpolationAlgorithm(Meteo2DInterpolator& i_mi,
const Date& i_date,
const DEMObject& i_dem,
......@@ -129,10 +129,10 @@ size_t InterpolationAlgorithm::getData(const MeteoData::Parameters& i_param,
size_t InterpolationAlgorithm::getData(const MeteoData::Parameters& i_param,
std::vector<double>& o_vecData, std::vector<StationData>& o_vecMeta) const
{
if (o_vecData.size() > 0)
if (o_vecData.empty())
o_vecData.clear();
if (o_vecMeta.size() > 0)
if (o_vecMeta.empty())
o_vecMeta.clear();
for (size_t ii=0; ii<vecMeteo.size(); ii++){
......@@ -261,7 +261,7 @@ void ConstLapseRateAlgorithm::calculate(Grid2DObject& grid)
getStationAltitudes(vecMeta, vecAltitudes);
LapseRateProjectPtr funcptr = &Interpol2D::LinProject;
if ((vecAltitudes.size() == 0) || (nrOfMeasurments == 0))
if ((vecAltitudes.empty()) || (nrOfMeasurments == 0))
throw IOException("Interpolation FAILED for parameter " + MeteoData::getParameterName(param), AT);
double avgAltitudes = Interpol1D::arithmeticMean(vecAltitudes);
......@@ -447,7 +447,7 @@ double RHAlgorithm::getQualityRating()
if (param != MeteoData::RH)
return 0.0;
if (vecDataTA.size() == 0)
if (vecDataTA.empty())
return 0.0;
if( ( nrOfMeasurments<(size_t)(0.5*vecDataRH.size()) ) || ( nrOfMeasurments<2 ) )
return 0.6;
......@@ -464,7 +464,7 @@ void RHAlgorithm::calculate(Grid2DObject& grid)
vector<double> vecAltitudes;
getStationAltitudes(vecMeta, vecAltitudes);
if (vecDataTA.size() == 0) //No matching data
if (vecDataTA.empty()) //No matching data
throw IOException("Interpolation FAILED for parameter " + MeteoData::getParameterName(param), AT);
Grid2DObject ta;
......@@ -515,7 +515,7 @@ double ILWRAlgorithm::getQualityRating()
if (param != MeteoData::ILWR)
return 0.0;
if (vecDataEA.size() == 0)
if (vecDataEA.empty())
return 0.0;
return 0.9;
......@@ -526,7 +526,7 @@ void ILWRAlgorithm::calculate(Grid2DObject& grid)
//This algorithm is only valid for RH
if (param != MeteoData::ILWR)
throw IOException("Interpolation FAILED for parameter " + MeteoData::getParameterName(param), AT);
if (vecDataEA.size() == 0) //No matching data
if (vecDataEA.empty()) //No matching data
throw IOException("Interpolation FAILED for parameter " + MeteoData::getParameterName(param), AT);
vector<double> vecAltitudes;
......@@ -606,7 +606,7 @@ double SimpleWindInterpolationAlgorithm::getQualityRating()
return 0.0;
}
if (vecDataVW.size() == 0)
if (vecDataVW.empty())
return 0.0;
if( ( nrOfMeasurments<(size_t)(0.5*vecDataVW.size()) ) || ( nrOfMeasurments<2 ) )
return 0.6;
......@@ -624,7 +624,7 @@ void SimpleWindInterpolationAlgorithm::calculate(Grid2DObject& grid)
getStationAltitudes(vecMeta, vecAltitudes);
if( vecDataDW.size() == 0)
if( vecDataDW.empty())
throw IOException("Interpolation FAILED for parameter " + MeteoData::getParameterName(param), AT);
Grid2DObject dw;
......@@ -654,7 +654,7 @@ std::string USERInterpolation::getGridFileName()
const std::string& grid_path = vecArgs[0];
std::string gridname = grid_path + std::string("/");
if(vecMeteo.size()>0) {
if(vecMeteo.empty()) {
const Date& timestep = vecMeteo.at(0).date;
gridname = gridname + timestep.toString(Date::NUM) + std::string("_") + MeteoData::getParameterName(param) + ext;
} else {
......
......@@ -210,7 +210,7 @@ std::ostream& operator<<(std::ostream &os, const Meteo2DInterpolator &mi) {
os << "User list of algorithms:\n";
std::map<std::string, std::vector<std::string> >::const_iterator iter = mi.mapAlgorithms.begin();
for (; iter != mi.mapAlgorithms.end(); iter++) {
for (; iter != mi.mapAlgorithms.end(); ++iter) {
os << setw(10) << iter->first << " :: ";
for(unsigned int jj=0; jj<iter->second.size(); jj++) {
os << iter->second[jj] << " ";
......
......@@ -300,7 +300,7 @@ std::ostream& operator<<(std::ostream& os, const MeteoData& data) {
void MeteoData::merge(std::vector<MeteoData>& vec1, const std::vector<MeteoData>& vec2, const bool& simple_merge)
{
if(vec1.size()>0 && vec2.size()>0 && vec1[0].date!=vec2[0].date) return; //vectors MUST contain data at the same date
if(vec1.empty() && vec2.empty() && vec1[0].date!=vec2[0].date) return; //vectors MUST contain data at the same date
if(simple_merge) {
for(size_t ii=0; ii<vec2.size(); ii++) vec1.push_back( vec2[ii] );
......@@ -311,7 +311,7 @@ void MeteoData::merge(std::vector<MeteoData>& vec1, const std::vector<MeteoData>
void MeteoData::merge(std::vector<MeteoData>& vec, const MeteoData& meteo2, const bool& simple_merge)
{
if(vec.size()>0 && vec[0].date!=meteo2.date) return; //the data must be time synchronized!
if(vec.empty() && vec[0].date!=meteo2.date) return; //the data must be time synchronized!
if(!simple_merge) {
for(size_t ii=0; ii<vec.size(); ii++) {
......
......@@ -27,7 +27,7 @@ MeteoProcessor::MeteoProcessor(const Config& cfg) : mi1d(cfg), processing_stack(
set<string> set_of_used_parameters;
get_parameters(cfg, set_of_used_parameters);
for (set<string>::const_iterator it = set_of_used_parameters.begin(); it != set_of_used_parameters.end(); it++){
for (set<string>::const_iterator it = set_of_used_parameters.begin(); it != set_of_used_parameters.end(); ++it){
ProcessingStack* tmp = new ProcessingStack(cfg, *it);
processing_stack[*it] = tmp;
}
......@@ -36,7 +36,7 @@ MeteoProcessor::MeteoProcessor(const Config& cfg) : mi1d(cfg), processing_stack(
MeteoProcessor::~MeteoProcessor()
{
//clean up heap memory
for (map<string, ProcessingStack*>::const_iterator it=processing_stack.begin(); it != processing_stack.end(); it++)
for (map<string, ProcessingStack*>::const_iterator it=processing_stack.begin(); it != processing_stack.end(); ++it)
delete it->second;
}
......@@ -60,7 +60,7 @@ void MeteoProcessor::getWindowSize(ProcessingProperties& o_properties)
{
ProcessingProperties tmp;
for (map<string, ProcessingStack*>::const_iterator it=processing_stack.begin(); it != processing_stack.end(); it++){
for (map<string, ProcessingStack*>::const_iterator it=processing_stack.begin(); it != processing_stack.end(); ++it){
(*(it->second)).getWindowSize(tmp);
compareProperties(tmp, o_properties);
......@@ -89,7 +89,7 @@ void MeteoProcessor::process(const std::vector< std::vector<MeteoData> >& ivec,
//call the different processing stacks
std::vector< std::vector<MeteoData> > vec_tmp;
for (map<string, ProcessingStack*>::const_iterator it=processing_stack.begin(); it != processing_stack.end(); it++){
for (map<string, ProcessingStack*>::const_iterator it=processing_stack.begin(); it != processing_stack.end(); ++it){
if (it==processing_stack.begin()){
(*(it->second)).process(ivec, ovec, second_pass);
} else {
......@@ -98,7 +98,7 @@ void MeteoProcessor::process(const std::vector< std::vector<MeteoData> >& ivec,
vec_tmp = ovec;
}
if (processing_stack.size() == 0)
if (processing_stack.empty())
ovec = ivec;
}
......@@ -113,7 +113,7 @@ std::ostream& operator<<(std::ostream& os, const MeteoProcessor& data)
os << data.mi1d;
os << "Processing stacks:\n";
for (map<string, ProcessingStack*>::const_iterator it=data.processing_stack.begin();
it != data.processing_stack.end(); it++){
it != data.processing_stack.end(); ++it){
//os << setw(10) << it->first << "::"; //the processing stack already contains it
os << (*it->second);
}
......
......@@ -342,9 +342,8 @@ bool SMETWriter::check_fields(const std::string& key, const std::string& value)
nr_of_fields = counter;
}
size_t count_wgs84 = 0, count_epsg = 0;
if (key == "fields"){
//set<string> fieldnames; //this will help us locate duplicate fields
if (key == "fields"){
size_t count_wgs84 = 0, count_epsg = 0;
//check if location is in data and if timestamp is present
for (size_t ii = 0; ii<tmp_vec.size(); ii++){
......@@ -378,7 +377,7 @@ bool SMETWriter::check_fields(const std::string& key, const std::string& value)
location_in_data_epsg = true;
} else {
//every value in units_offset and units_multiplier must be a decimal
for (vector<string>::const_iterator it = tmp_vec.begin(); it != tmp_vec.end(); it++)
for (vector<string>::const_iterator it = tmp_vec.begin(); it != tmp_vec.end(); ++it)
if (!SMETCommon::is_decimal(*it)) return false;
}
......@@ -448,7 +447,7 @@ void SMETWriter::write(const std::vector<std::string>& vec_timestamp, const std:
if (smet_type == ASCII){
for (size_t ii=0; ii<nr_of_lines; ii++){
const size_t offset = ii*(nr_of_fields-1);
if (data.size() != 0)
if (!data.empty())
copy(data.begin()+offset, data.begin()+offset+nr_of_data_fields, current_data.begin());
write_data_line_ascii(vec_timestamp[ii], current_data);
}
......@@ -484,13 +483,13 @@ void SMETWriter::write(const std::vector<double>& data)
if (smet_type == ASCII){
for (size_t ii=0; ii<nr_of_lines; ii++){
if (data.size() != 0)
if (!data.empty())
copy(data.begin()+ii*nr_of_fields, data.begin()+ii*nr_of_fields+nr_of_fields, current_data.begin());
write_data_line_ascii("0000-01-01T00:00", current_data); //dummy time
}
} else {
for (size_t ii=0; ii<nr_of_lines; ii++){
if (data.size() != 0)
if (!data.empty())
copy(data.begin()+ii*nr_of_fields, data.begin()+ii*nr_of_fields+nr_of_fields, current_data.begin());
write_data_line_binary(current_data);
}
......@@ -604,7 +603,7 @@ void SMETWriter::write_data_line_ascii(const std::string& timestamp, const std::
fout << right;
fout << fixed;
if ((data.size() == 0) && timestamp_present) fout << timestamp;
if ((data.empty()) && timestamp_present) fout << timestamp;
for (size_t ii = 0; ii < data.size(); ii++){
if (ii > 0) fout << " ";
......@@ -743,14 +742,14 @@ void SMETReader::process_header()
{
vector<string> tmp_vec;
set<string> obligatory_keys;
for (map<string,string>::iterator it = header.begin(); it != header.end(); it++){
for (map<string,string>::iterator it = header.begin(); it != header.end(); ++it){
if (SMETCommon::all_mandatory_header_keys.find(it->first) != SMETCommon::all_mandatory_header_keys.end())
obligatory_keys.insert(it->first);
if (it->first == "fields"){
SMETCommon::readLineToVec(it->second, tmp_vec);
string newfields;
if (tmp_vec.size() > 0){
if (!tmp_vec.empty()){
for (size_t ii=0; ii<tmp_vec.size(); ii++){
if (tmp_vec[ii] == "timestamp"){
timestamp_present = true;
......
......@@ -26,7 +26,7 @@ FilterBlock::FilterBlock(const std::string& filter_name) : ProcessingBlock(filte
FilterBlock::~FilterBlock() {}
bool FilterBlock::is_soft(std::vector<std::string>& vec_args) {
if (vec_args.size() > 0){
if (!vec_args.empty()){
if (vec_args[0] == "soft"){
vec_args.erase(vec_args.begin());
return true;
......
......@@ -113,10 +113,10 @@ double FilterTukey::getU3(const std::vector<MeteoData>& ivec, const unsigned int
if(value!=IOUtils::nodata)
u.push_back( value );
}
if(u.size()>0)
if(!u.empty())
u1.push_back( Interpol1D::getMedian(u) );
}
if(u1.size()>0)
if(!u1.empty())
u2.push_back( Interpol1D::getMedian(u1) );
else
u2.push_back( IOUtils::nodata );
......
......@@ -65,7 +65,7 @@ void FilterUnheatedHNW::parse_args(std::vector<std::string> vec_args) {
vector<double> filter_args;
soft = false;
if (vec_args.size() >= 1){
if (!vec_args.empty()){
soft = is_soft(vec_args);
}
......
......@@ -74,7 +74,7 @@ void ProcUndercatch_Hamon::process(const unsigned int& param, const std::vector<
void ProcUndercatch_Hamon::parse_args(std::vector<std::string> filter_args)
{
if (filter_args.size() < 1)
if (filter_args.empty())
throw InvalidArgumentException("Wrong number of arguments for filter " + getName(), AT);
for(size_t ii=0; ii<filter_args.size(); ii++) {
......
......@@ -124,7 +124,7 @@ void ProcUndercatch_WMO::process(const unsigned int& param, const std::vector<Me
void ProcUndercatch_WMO::parse_args(std::vector<std::string> filter_args)
{
if (filter_args.size() < 1)
if (filter_args.empty())
throw InvalidArgumentException("Wrong number of arguments for filter " + getName(), AT);
for(size_t ii=0; ii<filter_args.size(); ii++) {
......
......@@ -99,7 +99,7 @@ void ProcUnventilatedT::parse_args(std::vector<std::string> vec_args) {
vector<double> filter_args;
is_soft = false;
if (vec_args.size() >= 1){
if (!vec_args.empty()){
is_soft = FilterBlock::is_soft(vec_args);
}
......@@ -108,7 +108,7 @@ void ProcUnventilatedT::parse_args(std::vector<std::string> vec_args) {
if (filter_args.size() > 1)
throw InvalidArgumentException("Wrong number of arguments for filter " + getName(), AT);
if (filter_args.size() == 0){
if (filter_args.empty()){
usr_albedo = dflt_albedo;
} else {
usr_albedo = filter_args[0];
......
......@@ -28,7 +28,7 @@ WindowedFilter::WindowedFilter(const std::string& name)
unsigned int WindowedFilter::get_centering(std::vector<std::string>& vec_args)
{
if (vec_args.size() > 0){
if (!vec_args.empty()){
if (vec_args[0] == "left"){
vec_args.erase(vec_args.begin());
return WindowedFilter::left;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment