Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drown using namespace std #603

Merged
merged 19 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions include/forcing/AorcForcing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@

#include <map>

//using namespace std// causes build error on gcc-12 with boost::geometry

/**
* @brief forcing_params providing configuration information for forcing time period and source.
*/
Expand Down
16 changes: 7 additions & 9 deletions include/forcing/DeferredWrappedProvider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
#include <algorithm>
#include "WrappedDataProvider.hpp"

using namespace std;

namespace data_access {

/**
Expand Down Expand Up @@ -41,14 +39,14 @@ namespace data_access {
*
* @param providedOutputs The collection of the names of outputs this instance will need to provide.
*/
explicit DeferredWrappedProvider(vector<string> providedOutputs) : WrappedDataProvider(nullptr), providedOutputs(std::move(providedOutputs)) { }
explicit DeferredWrappedProvider(std::vector<std::string> providedOutputs) : WrappedDataProvider(nullptr), providedOutputs(std::move(providedOutputs)) { }

/**
* Convenience constructor for when there is only one provided output name.
*
* @param outputName The name of the single output this instance will need to provide.
*/
explicit DeferredWrappedProvider(const string& outputName) : DeferredWrappedProvider(vector<string>(1)) {
explicit DeferredWrappedProvider(const std::string& outputName) : DeferredWrappedProvider(std::vector<std::string>(1)) {
providedOutputs[0] = outputName;
}

Expand Down Expand Up @@ -85,7 +83,7 @@ namespace data_access {
*
* @return The message string for the last call to @ref setWrappedProvider.
*/
inline const string &getSetMessage() {
inline const std::string &getSetMessage() {
return setMessage;
}

Expand Down Expand Up @@ -139,8 +137,8 @@ namespace data_access {
}

// Confirm this will provide everything needed
const vector<string> &available = provider->get_available_variable_names();
for (const string &requiredName : providedOutputs) {
const std::vector<std::string> &available = provider->get_available_variable_names();
for (const std::string &requiredName : providedOutputs) {
if (std::find(available.begin(), available.end(), requiredName) == available.end()) {
setMessage = "Given provider does not provide the required " + requiredName;
return false;
Expand All @@ -155,15 +153,15 @@ namespace data_access {

protected:
/** The collection of names of the outputs this type can/will be able to provide from its wrapped source. */
vector<string> providedOutputs;
std::vector<std::string> providedOutputs;

/**
* A message providing information from the last @ref setWrappedProvider call.
*
* The value will be empty if the function returned ``true``. If it returned ``false``, this will have an
* info message set explaining more detail on the failure.
*/
string setMessage;
std::string setMessage;
};

}
Expand Down
52 changes: 25 additions & 27 deletions include/forcing/OptionalWrappedDataProvider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

#include "DeferredWrappedProvider.hpp"

using namespace std;

namespace data_access {

/**
Expand Down Expand Up @@ -55,7 +53,7 @@ namespace data_access {
* @param providedOuts The collection of the names of outputs this instance will need to provide.
* @param defaultVals Mapping of some or all provided output defaults, keyed by output name.
*/
OptionalWrappedDataProvider(vector<string> providedOuts, map<string, double> defaultVals)
OptionalWrappedDataProvider(std::vector<std::string> providedOuts, std::map<std::string, double> defaultVals)
: DeferredWrappedProvider(std::move(providedOuts)), defaultValues(std::move(defaultVals))
{
// Validate the provided map of default values to ensure there aren't any unrecognized keys, as this
Expand All @@ -64,14 +62,14 @@ namespace data_access {
for (const auto &def_vals_it : defaultValues) {
auto name_it = find(providedOutputs.begin(), providedOutputs.end(), def_vals_it.first);
if (name_it == providedOutputs.end()) {
string msg = "Invalid default values for OptionalWrappedDataProvider: default value given for "
std::string msg = "Invalid default values for OptionalWrappedDataProvider: default value given for "
"unknown output with name '" + def_vals_it.first + "' (expected names are ["
+ providedOutputs[0];
for (int i = 1; i < providedOutputs.size(); ++i) {
msg += ", " + providedOutputs[i];
}
msg += "])";
throw runtime_error(msg);
throw std::runtime_error(msg);
}
}
}
Expand All @@ -87,8 +85,8 @@ namespace data_access {
* @param defaultWaits Map of the number of default usages for each provided output that the instance must wait
* before using values from the backing provider.
*/
OptionalWrappedDataProvider(vector<string> providedOuts, map<string, double> defaultVals,
map<string, int> defaultWaits)
OptionalWrappedDataProvider(std::vector<std::string> providedOuts, std::map<std::string, double> defaultVals,
std::map<std::string, int> defaultWaits)
: OptionalWrappedDataProvider(std::move(providedOuts), std::move(defaultVals))
{
// Validate that all keys/names in the defaultWaits map have corresponding key in defaultValues
Expand All @@ -97,7 +95,7 @@ namespace data_access {
for (const auto &wait_it : defaultWaits) {
auto def_it = defaultValues.find(wait_it.first);
if (def_it == defaultValues.end()) {
string msg = "Invalid default usage waits for OptionalWrappedDataProvider: wait count given for "
std::string msg = "Invalid default usage waits for OptionalWrappedDataProvider: wait count given for "
"non-default output '" + wait_it.first + "' (outputs with defaults set are [";
def_it = defaultValues.begin();
msg += def_it->first;
Expand All @@ -107,7 +105,7 @@ namespace data_access {
def_it++;
}
msg += "])";
throw runtime_error(msg);
throw std::runtime_error(msg);
}
}
// Assuming the mapping is valid, set it for the instance
Expand All @@ -120,15 +118,15 @@ namespace data_access {
*
* @param providedOutputs The collection of the names of outputs this instance will need to provide.
*/
explicit OptionalWrappedDataProvider(vector<string> providedOutputs)
: OptionalWrappedDataProvider(std::move(providedOutputs), map<string, double>()) { }
explicit OptionalWrappedDataProvider(std::vector<std::string> providedOutputs)
: OptionalWrappedDataProvider(std::move(providedOutputs), std::map<std::string, double>()) { }

/**
* Convenience constructor for when there is only one provided output name, which does not have a default.
*
* @param outputName The name of the single output this instance will need to provide.
*/
explicit OptionalWrappedDataProvider(const string& outputName) : OptionalWrappedDataProvider(vector<string>(1)) {
explicit OptionalWrappedDataProvider(const std::string& outputName) : OptionalWrappedDataProvider(std::vector<std::string>(1)) {
providedOutputs[0] = outputName;
}

Expand All @@ -145,7 +143,7 @@ namespace data_access {
* @param defaultUsageWait The number of default usages that the instance must wait before using values from
* the backing provider.
*/
OptionalWrappedDataProvider(const string& outputName, double defaultValue, int defaultUsageWait)
OptionalWrappedDataProvider(const std::string& outputName, double defaultValue, int defaultUsageWait)
: OptionalWrappedDataProvider(outputName)
{
defaultValues[providedOutputs[0]] = defaultValue;
Expand All @@ -160,7 +158,7 @@ namespace data_access {
* @param outputName The name of the single output this instance will need to provide.
* @param defaultValue The default to associate with the given output.
*/
OptionalWrappedDataProvider(const string& outputName, double defaultValue)
OptionalWrappedDataProvider(const std::string& outputName, double defaultValue)
: OptionalWrappedDataProvider(outputName, defaultValue, 0) { }

/**
Expand Down Expand Up @@ -194,18 +192,18 @@ namespace data_access {
*/
double get_value(const CatchmentAggrDataSelector& selector, data_access::ReSampleMethod m) override
{
string output_name = selector.get_variable_name();
std::string output_name = selector.get_variable_name();
time_t init_time = selector.get_init_time();
const long duration_s = selector.get_duration_secs();
const string output_units = selector.get_output_units();
const std::string output_units = selector.get_output_units();

// Balk if not in this instance's collection of outputs
if (find(providedOutputs.begin(), providedOutputs.end(), output_name) == providedOutputs.end()) {
throw runtime_error("Unknown output " + output_name + " requested from wrapped provider");
throw std::runtime_error("Unknown output " + output_name + " requested from wrapped provider");
}
// Balk if this instance is not ready
if (!isReadyToProvideData()) {
throw runtime_error("Cannot get value for " + output_name
throw std::runtime_error("Cannot get value for " + output_name
+ " from optional wrapped provider before it is ready");
}

Expand Down Expand Up @@ -248,7 +246,7 @@ namespace data_access {
* @see get_value
* @see recordUsingDefault
*/
bool isDefaultOverride(const string &output_name) {
bool isDefaultOverride(const std::string &output_name) {
// First, there must be a default, and there must be something to override
if (!isSuppliedWithDefault(output_name) || !isSuppliedByWrappedProvider(output_name)) {
return false;
Expand Down Expand Up @@ -284,7 +282,7 @@ namespace data_access {
* @param outputName The output in question.
* @return Whether a default value is available for this output.
*/
inline bool isSuppliedWithDefault(const string &outputName) {
inline bool isSuppliedWithDefault(const std::string &outputName) {
return defaultValues.find(outputName) != defaultValues.end();
}

Expand Down Expand Up @@ -323,7 +321,7 @@ namespace data_access {

// Check this provides everything needed, accounting for defaults (and also tallying the outputs provided)
unsigned short providedByProviderCount = 0;
for (const string &requiredName : providedOutputs) {
for (const std::string &requiredName : providedOutputs) {
// If supplied by the provider, increment our count and continue to the next required output name
if (isSuppliedByProvider(requiredName, provider)) {
++providedByProviderCount;
Expand Down Expand Up @@ -367,7 +365,7 @@ namespace data_access {
*
* @param output_name The name of the output for which a default was used.
*/
virtual void recordUsingDefault(const string &output_name) {
virtual void recordUsingDefault(const std::string &output_name) {
// Don't bother doing anything if there aren't waits assigned for this output
// Also, in this implementation, don't count usages until there is a backing provider that can provide this
auto waits_it = defaultUsageWaits.find(output_name);
Expand All @@ -389,21 +387,21 @@ namespace data_access {
/**
* A collection of mapped default values for some or all of the provided outputs.
*/
map<string, double> defaultValues;
std::map<std::string, double> defaultValues;
/**
* The number of times a default value should still be used before beginning to proxy a backing provider value.
*
* Note than all elements should have values greater than zero. Any elements that would have their value
* reduced to zero should instead be removed.
*/
map<string, int> defaultUsageWaits;
std::map<std::string, int> defaultUsageWaits;

static bool isSuppliedByProvider(const string &outputName, GenericDataProvider *provider) {
const vector<string> &available = provider->get_available_variable_names();
static bool isSuppliedByProvider(const std::string &outputName, GenericDataProvider *provider) {
const std::vector<std::string> &available = provider->get_available_variable_names();
return find(available.begin(), available.end(), outputName) != available.end();
}

inline bool isSuppliedByWrappedProvider(const string &outputName) {
inline bool isSuppliedByWrappedProvider(const std::string &outputName) {
return wrapped_provider != nullptr && isSuppliedByProvider(outputName, wrapped_provider);
}

Expand Down
4 changes: 2 additions & 2 deletions include/realizations/catchment/AbstractCLibBmiAdapter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace models {
* @param registration_func The name for the @see bmi_registration_function.
* @param output The output stream handler.
*/
AbstractCLibBmiAdapter(const string &type_name, std::string library_file_path, std::string bmi_init_config,
AbstractCLibBmiAdapter(const std::string &type_name, std::string library_file_path, std::string bmi_init_config,
std::string forcing_file_path, bool allow_exceed_end, bool has_fixed_time_step,
std::string registration_func, utils::StreamHandler output)
: Bmi_Adapter<C>(type_name, std::move(bmi_init_config), std::move(forcing_file_path),
Expand Down Expand Up @@ -91,7 +91,7 @@ namespace models {
if (!utils::FileChecker::file_is_readable(bmi_lib_file)) {
//Try alternative extension...
size_t idx = bmi_lib_file.rfind(".");
if(idx == string::npos){
if(idx == std::string::npos){
idx = bmi_lib_file.length()-1;
}
std::string alt_bmi_lib_file;
Expand Down
Loading