Skip to content

Commit

Permalink
Remove using namespace std from header files (#990)
Browse files Browse the repository at this point in the history
* Remove "using namespace std"

* Remove using namespace std

* [FIX] Fix namespace std

* [FIX] Fix some code smells

Co-authored-by: Vincent Payet <[email protected]>
  • Loading branch information
flomnes and payetvin authored Dec 6, 2022
1 parent 9d16f51 commit 88e2138
Show file tree
Hide file tree
Showing 17 changed files with 61 additions and 76 deletions.
4 changes: 2 additions & 2 deletions src/libs/antares/benchmarking/info_collectors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

using namespace Antares::Data;

namespace Benchmarking
namespace Benchmarking
{
// Collecting data study
// ---------------------------
Expand Down Expand Up @@ -149,7 +149,7 @@ namespace Benchmarking
// -------------------------------------
void DurationCollector::toFileContent(FileContent& file_content)
{
for (pair<string, vector<int64_t>> element : duration_items_)
for (const auto& element : duration_items_)
{
const std::string& name = element.first;
const auto& durations = element.second;
Expand Down
4 changes: 2 additions & 2 deletions src/libs/antares/study/parameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -920,9 +920,9 @@ static bool SGDIntLoadFamily_VariablesSelection(Parameters& d,
return true;
}
if (key == "select_var +")
return d.variablesPrintInfo.setPrintStatus(value.to<string>(), true);
return d.variablesPrintInfo.setPrintStatus(value.to<std::string>(), true);
if (key == "select_var -")
return d.variablesPrintInfo.setPrintStatus(value.to<string>(), false);
return d.variablesPrintInfo.setPrintStatus(value.to<std::string>(), false);
return false;
}
static bool SGDIntLoadFamily_SeedsMersenneTwister(Parameters& d,
Expand Down
2 changes: 0 additions & 2 deletions src/libs/antares/study/parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@
#include <antares/study/UnfeasibleProblemBehavior.hpp>
#include <antares/study/OrtoolsSolver.hpp>

using namespace std;

namespace Antares
{
namespace Data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void hydroLevelsData::saveToINIFile(const Study& study, Yuni::IO::File::Stream&
value_into_string << value;
file << prefix << study.areas.byIndex[index]->id << ',' << y << " = "
<< value_into_string.str() << '\n';
value_into_string.str(string()); // Clearing converter
value_into_string.str(std::string()); // Clearing converter
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/libs/antares/study/scenario-builder/rules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ bool Rules::readThermalCluster(const AreaName::Vector& splitKey, String value, b
bool isTheActiveRule = (pName.toLower() == study_.parameters.activeRulesScenario.toLower());
if (!updaterMode and isTheActiveRule)
{
string clusterId = (area->id).to<string>() + "." + clustername.to<string>();
std::string clusterId = (area->id).to<std::string>() + "." + clustername.to<std::string>();
disabledClustersOnRuleActive[clusterId].push_back(year + 1);
return false;
}
Expand Down Expand Up @@ -188,7 +188,7 @@ bool Rules::readRenewableCluster(const AreaName::Vector& splitKey, String value,
bool isTheActiveRule = (pName.toLower() == study_.parameters.activeRulesScenario.toLower());
if (!updaterMode and isTheActiveRule)
{
string clusterId = (area->id).to<string>() + "." + clustername.to<string>();
std::string clusterId = (area->id).to<std::string>() + "." + clustername.to<std::string>();
disabledClustersOnRuleActive[clusterId].push_back(year + 1);
return false;
}
Expand Down Expand Up @@ -356,25 +356,25 @@ bool Rules::apply()

void Rules::sendWarningsForDisabledClusters()
{
for (map<string, vector<uint>>::iterator it = disabledClustersOnRuleActive.begin();
for (auto it = disabledClustersOnRuleActive.begin();
it != disabledClustersOnRuleActive.end();
it++)
{
vector<uint>& scenariiForCurrentCluster = it->second;
std::vector<uint>& scenariiForCurrentCluster = it->second;
int nbScenariiForCluster = (int)scenariiForCurrentCluster.size();
vector<uint>::iterator itv = scenariiForCurrentCluster.begin();
std::vector<uint>::iterator itv = scenariiForCurrentCluster.begin();

// Listing the 10 first years for which the current cluster was given a specific TS number
// in the scenario builder.
// Note that this list of years size could be less then 10, but are at least 1.
string listYears = to_string(*itv);
std::string listYears = std::to_string(*itv);
itv++;
for (int year_count = 1; itv != scenariiForCurrentCluster.end() && year_count < 10; itv++, year_count++)
listYears += ", " + to_string(*itv);
listYears += ", " + std::to_string(*itv);

// Adding last scenario to the list
if (nbScenariiForCluster > 10)
listYears += ", ..., " + to_string(scenariiForCurrentCluster.back());
listYears += ", ..., " + std::to_string(scenariiForCurrentCluster.back());

logs.warning()
<< "Cluster " << it->first
Expand Down
2 changes: 1 addition & 1 deletion src/libs/antares/study/scenario-builder/rules.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class Rules final : private Yuni::NonCopyable<Rules>
//! Name of the rules
RulesScenarioName pName;
// Disabled clusters when current rule is active (useful for sending warnings)
map<string, vector<uint>> disabledClustersOnRuleActive;
std::map<std::string, std::vector<uint>> disabledClustersOnRuleActive;

}; // class Rules

Expand Down
2 changes: 1 addition & 1 deletion src/libs/antares/study/scenario-builder/scBuilderUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace Data
{
namespace ScenarioBuilder
{
string fromHydroLevelToString(double d)
std::string fromHydroLevelToString(double d)
{
std::ostringstream stream;
stream << std::setprecision(4);
Expand Down
6 changes: 2 additions & 4 deletions src/libs/antares/study/scenario-builder/scBuilderUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,13 @@
#include <yuni/core/fwd.h>
#include <string>

using namespace std;

namespace Antares
{
namespace Data
{
namespace ScenarioBuilder
{
string fromHydroLevelToString(double d);
std::string fromHydroLevelToString(double d);
double fromStringToHydroLevel(const Yuni::String& value, const double maxLevel);

uint fromStringToTSnumber(const Yuni::String& value);
Expand All @@ -48,4 +46,4 @@ uint fromStringToTSnumber(const Yuni::String& value);
} // namespace Data
} // namespace Antares

#endif // __LIBS_STUDY_SCENARIO_BUILDER_DATA_UTILS_H__
#endif // __LIBS_STUDY_SCENARIO_BUILDER_DATA_UTILS_H__
20 changes: 9 additions & 11 deletions src/libs/antares/study/variable-print-info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ VariablePrintInfo::VariablePrintInfo(AnyString vname, uint maxNbCols, uint dataL
varname = vname;
}

string VariablePrintInfo::name()
std::string VariablePrintInfo::name()
{
return varname.to<string>();
return varname.to<std::string>();
}
void VariablePrintInfo::enablePrint(bool b)
{
Expand Down Expand Up @@ -108,8 +108,7 @@ void AllVariablesPrintInfo::clear()
// Destroying objects in lists
// ---------------------------
// Deleting variable' print info objects pointed in the list
vector<VariablePrintInfo*>::iterator it = allVarsPrintInfo.begin();
for (it = allVarsPrintInfo.begin(); it != allVarsPrintInfo.end(); ++it)
for (auto it = allVarsPrintInfo.begin(); it != allVarsPrintInfo.end(); ++it)
delete *it;

// After destroying objects in list, clearing lists
Expand Down Expand Up @@ -139,7 +138,7 @@ void AllVariablesPrintInfo::resetInfoIterator() const
it_info = allVarsPrintInfo.begin();
}

bool AllVariablesPrintInfo::setPrintStatus(string varname, bool printStatus)
bool AllVariablesPrintInfo::setPrintStatus(std::string varname, bool printStatus)
{
/*
From the position of the iterator on the print info collection, shifting right until
Expand All @@ -151,7 +150,7 @@ bool AllVariablesPrintInfo::setPrintStatus(string varname, bool printStatus)

for (it_info = allVarsPrintInfo.begin(); it_info != allVarsPrintInfo.end(); it_info++)
{
string current_var_name = (*it_info)->name();
std::string current_var_name = (*it_info)->name();
std::transform(
current_var_name.begin(), current_var_name.end(), current_var_name.begin(), ::toupper);
if (varname == current_var_name)
Expand Down Expand Up @@ -187,7 +186,7 @@ void AllVariablesPrintInfo::prepareForSimulation(bool userSelection,
countSelectedLinkVars();
}

bool AllVariablesPrintInfo::searchIncrementally_getPrintStatus(string var_name) const
bool AllVariablesPrintInfo::searchIncrementally_getPrintStatus(std::string var_name) const
{
// Finds out if an output variable is selected for print or not.
// The search for the variable in the print info list is incremental :
Expand All @@ -211,7 +210,7 @@ bool AllVariablesPrintInfo::searchIncrementally_getPrintStatus(string var_name)
return true;
}

bool AllVariablesPrintInfo::isPrinted(string var_name) const
bool AllVariablesPrintInfo::isPrinted(std::string var_name) const
{
// Finds out if an output variable selected for print or not.
// The search for a variable starts from the beginning of the variable print info list.
Expand Down Expand Up @@ -257,8 +256,7 @@ void AllVariablesPrintInfo::computeMaxColumnsCountInReports()
{
uint currentColumnsCount = 0;

vector<VariablePrintInfo*>::iterator it = allVarsPrintInfo.begin();
for (; it != allVarsPrintInfo.end(); it++)
for (auto it = allVarsPrintInfo.begin(); it != allVarsPrintInfo.end(); it++)
{
if ((*it)->isPrinted() && (*it)->getFileLevel() & CFileLevel
&& (*it)->getDataLevel() & CDataLevel)
Expand Down Expand Up @@ -294,4 +292,4 @@ void AllVariablesPrintInfo::countSelectedLinkVars()
}

} // namespace Data
} // namespace Antares
} // namespace Antares
17 changes: 7 additions & 10 deletions src/libs/antares/study/variable-print-info.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@
#include <yuni/core/fwd.h>
#include <yuni/core/string.h>

using namespace std;
// using namespace Yuni;

namespace Antares
{
namespace Data
Expand All @@ -51,7 +48,7 @@ class VariablePrintInfo
~VariablePrintInfo(){};

// Getting name of the (represented) output variable
string name();
std::string name();

// Do we enable or disable variable's print in output reports ?
void enablePrint(bool b);
Expand Down Expand Up @@ -111,15 +108,15 @@ class AllVariablesPrintInfo

void resetInfoIterator() const;

bool setPrintStatus(string varname, bool printStatus);
bool setPrintStatus(std::string varname, bool printStatus);

void prepareForSimulation(bool userSelection,
const std::vector<std::string>& excluded_vars = {});

// Incremental search for the variable, then get the print status.
bool searchIncrementally_getPrintStatus(string var_name) const;
bool searchIncrementally_getPrintStatus(std::string var_name) const;
// Classic search, then get the print status
bool isPrinted(string var_name) const;
bool isPrinted(std::string var_name) const;

uint getMaxColumnsCount() const
{
Expand All @@ -143,10 +140,10 @@ class AllVariablesPrintInfo

private:
// Contains print info for all variables
vector<VariablePrintInfo*> allVarsPrintInfo;
std::vector<VariablePrintInfo*> allVarsPrintInfo;

// Const iterator on variable print info list, that cannot change current object.
mutable vector<VariablePrintInfo*>::const_iterator it_info;
mutable std::vector<VariablePrintInfo*>::const_iterator it_info;

// Max columns count a report of any kind can contain, depending on the number of selected
// variables. The less variables are selected, the smallest this count is.
Expand All @@ -161,4 +158,4 @@ class AllVariablesPrintInfo
} // namespace Data
} // namespace Antares

#endif // __SOLVER_VARIABLE_PRINT_POLICY_H__
#endif // __SOLVER_VARIABLE_PRINT_POLICY_H__
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ void OPT_InitialiserLesBornesDesVariablesDuProblemeLineaire(PROBLEME_HEBDO* Prob
&& ProblemeHebdo->adequacyPatchRuntimeData.areaMode[Pays]
== Data::AdequacyPatch::physicalAreaInsideAdqPatch)
Xmax[Var]
= min(Xmax[Var],
= std::min(Xmax[Var],
ProblemeHebdo->ResultatsHoraires[Pays]->ValeursHorairesDENS[PdtHebdo]);

ProblemeHebdo->ResultatsHoraires[Pays]
Expand Down
11 changes: 4 additions & 7 deletions src/tests/src/libs/antares/logs/logs.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
#ifndef __TESTS_ANTARES_LIBS_LOGS_FAKE_H__
# define __TESTS_ANTARES_LIBS_LOGS_FAKE_H__

#include<string>
#include<yuni/core/string/string.h>


using namespace std;
#include <string>
#include <yuni/core/string/string.h>

namespace Antares
{
Expand All @@ -29,8 +26,8 @@ namespace Antares
}

void clear() { buffer_.clear(); }
string content() { return buffer_.to<string>(); }
bool contains(string sub_string) { return buffer_.contains(sub_string); }
std::string content() const { return buffer_.to<std::string>(); }
bool contains(const std::string sub_string) const { return buffer_.contains(sub_string); }
bool empty() { return buffer_.empty(); }
private:
Yuni::CString<1024> buffer_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
using namespace Antares::Data;
namespace fs = std::filesystem;

const string generatedIniFileName = "optimization.ini";
const string referenceIniFileName = "optimization-reference.ini";
const std::string generatedIniFileName = "optimization.ini";
const std::string referenceIniFileName = "optimization-reference.ini";

struct Fixture
{
Expand All @@ -31,11 +31,11 @@ struct Fixture

~Fixture()
{
vector<string> filesToRemove = { generatedIniFileName, referenceIniFileName };
std::vector<std::string> filesToRemove = { generatedIniFileName, referenceIniFileName };
remove_files(filesToRemove);
}

Study::Ptr study = std::make_shared<Study>();
Study::Ptr study = std::make_shared<Study>();
Area* area;
Yuni::Clob path_to_generated_file;
};
Expand All @@ -45,19 +45,19 @@ class referenceIniFile
public:
referenceIniFile();
~referenceIniFile() = default;
string name() const { return name_; }
std::string name() const { return name_; }
void save();

void set_property(const string& key, const string& value) { properties_[key] = value; }
void set_property(const std::string& key, const std::string& value) { properties_[key] = value; }
private:
void save_section(string_view sectionTitle, vector<string>& section_properties, ofstream& file);
void save_section(std::string_view sectionTitle, std::vector<std::string>& section_properties, std::ofstream& file);

string name_ = referenceIniFileName;
vector<string> nodal_property_names_ = {
"non-dispatchable-power", "dispatchable-hydro-power", "other-dispatchable-power",
std::string name_ = referenceIniFileName;
std::vector<std::string> nodal_property_names_ = {
"non-dispatchable-power", "dispatchable-hydro-power", "other-dispatchable-power",
"spread-unsupplied-energy-cost", "spread-spilled-energy-cost" };
vector<string> filtering_property_names_ = { "filter-synthesis", "filter-year-by-year" };
map<string, string, less<>> properties_;
std::vector<std::string> filtering_property_names_ = { "filter-synthesis", "filter-year-by-year" };
std::map<std::string, std::string, std::less<>> properties_;
};

referenceIniFile::referenceIniFile()
Expand All @@ -73,19 +73,19 @@ referenceIniFile::referenceIniFile()

void referenceIniFile::save()
{
ofstream file;
std::ofstream file;
file.open(name_);
save_section("[nodal optimization]", nodal_property_names_, file);
save_section("[filtering]", filtering_property_names_, file);
file.close();
}

void referenceIniFile::save_section(string_view sectionTitle, vector<string>& sectionProperties, ofstream & file)
void referenceIniFile::save_section(std::string_view sectionTitle, std::vector<std::string>& sectionProperties, std::ofstream & file)
{
file << sectionTitle << endl;
file << sectionTitle << std::endl;
for (std::size_t i = 0; i < sectionProperties.size(); ++i)
file << sectionProperties[i] << " = " << properties_[sectionProperties[i]] << endl;
file << endl;
file << sectionProperties[i] << " = " << properties_[sectionProperties[i]] << std::endl;
file << std::endl;
}

BOOST_FIXTURE_TEST_SUITE(s, Fixture)
Expand Down
Loading

0 comments on commit 88e2138

Please sign in to comment.