Skip to content

Commit

Permalink
Abominate remaining 'using namespace std' from headers
Browse files Browse the repository at this point in the history
Conflicts:
	include/realizations/catchment/Bmi_Module_Formulation.hpp

(Removed `check_internal_providers` method dropped in NOAA-OWP#599 - @mattw-nws )
  • Loading branch information
PhilMiller authored and mattw-nws committed Aug 15, 2023
1 parent 2da5a9e commit 928eee1
Show file tree
Hide file tree
Showing 17 changed files with 101 additions and 103 deletions.
2 changes: 1 addition & 1 deletion include/forcing/DeferredWrappedProvider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ namespace data_access {
}

// Confirm this will provide everything needed
const vector<string> &available = provider->get_available_variable_names();
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;
Expand Down
8 changes: 4 additions & 4 deletions include/forcing/OptionalWrappedDataProvider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ namespace data_access {
msg += ", " + providedOutputs[i];
}
msg += "])";
throw runtime_error(msg);
throw std::runtime_error(msg);
}
}
}
Expand Down Expand Up @@ -105,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 Down Expand Up @@ -199,11 +199,11 @@ namespace data_access {

// 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
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
38 changes: 18 additions & 20 deletions include/realizations/catchment/Bmi_Adapter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
#include "State_Exception.hpp"
#include "StreamHandler.hpp"

using namespace std;

namespace models {
namespace bmi {
/**
Expand All @@ -21,7 +19,7 @@ namespace models {
class Bmi_Adapter : public ::bmi::Bmi {
public:

Bmi_Adapter(string model_name, string bmi_init_config, string forcing_file_path, bool allow_exceed_end,
Bmi_Adapter(std::string model_name, std::string bmi_init_config, std::string forcing_file_path, bool allow_exceed_end,
bool has_fixed_time_step, utils::StreamHandler output)
: model_name(std::move(model_name)),
bmi_init_config(std::move(bmi_init_config)),
Expand All @@ -37,7 +35,7 @@ namespace models {
if (!utils::FileChecker::file_is_readable(this->bmi_init_config)) {
init_exception_msg = "Cannot create and initialize " + this->model_name + " using unreadable file '"
+ this->bmi_init_config + "'";
throw runtime_error(init_exception_msg);
throw std::runtime_error(init_exception_msg);
}
}

Expand Down Expand Up @@ -93,7 +91,7 @@ namespace models {
* @param time_convert_factor A reference to set to the determined conversion factor.
*/
void acquire_time_conversion_factor(double &time_convert_factor) {
string time_units = GetTimeUnits();
std::string time_units = GetTimeUnits();
if (time_units == "s" || time_units == "sec" || time_units == "second" || time_units == "seconds")
time_convert_factor = 1.0;
else if (time_units == "m" || time_units == "min" || time_units == "minute" ||
Expand All @@ -104,7 +102,7 @@ namespace models {
else if (time_units == "d" || time_units == "day" || time_units == "days")
time_convert_factor = 86400.0;
else
throw runtime_error(
throw std::runtime_error(
"Invalid model time step units ('" + time_units + "') in " + model_name + ".");
}

Expand Down Expand Up @@ -177,7 +175,7 @@ namespace models {
// If there was previous init attempt but w/ failure exception, throw runtime error and include previous
// message
if (model_initialized && !init_exception_msg.empty()) {
throw runtime_error(
throw std::runtime_error(
"Previous " + model_name + " init attempt had exception: \n\t" + init_exception_msg);
}
// If there was previous init attempt w/ (implicitly) no exception on previous attempt, just return
Expand All @@ -187,7 +185,7 @@ namespace models {
else if (!utils::FileChecker::file_is_readable(bmi_init_config)) {
init_exception_msg = "Cannot initialize " + model_name + " using unreadable file '"
+ bmi_init_config + "'";
throw runtime_error(init_exception_msg);
throw std::runtime_error(init_exception_msg);
}
else {
try {
Expand All @@ -198,7 +196,7 @@ namespace models {
acquire_time_conversion_factor(bmi_model_time_convert_factor);
}
// Record the exception message before re-throwing to handle subsequent function calls properly
catch (exception& e) {
catch (std::exception& e) {
// Make sure this is set to 'true' after this function call finishes
model_initialized = true;
throw e;
Expand All @@ -224,9 +222,9 @@ namespace models {
* @throws models::external::State_Exception If `initialize()` in nested model is not successful.
* @throws runtime_error If already initialized but using a different file than the passed argument.
*/
void Initialize(string config_file) override {
void Initialize(std::string config_file) override {
if (config_file != bmi_init_config && model_initialized) {
throw runtime_error(
throw std::runtime_error(
"Model init previously attempted; cannot change config from " + bmi_init_config + " to "
+ config_file);
}
Expand All @@ -243,7 +241,7 @@ namespace models {
throw e;
}
catch (std::exception &e) {
throw runtime_error(e.what());
throw std::runtime_error(e.what());
}
}

Expand All @@ -270,28 +268,28 @@ namespace models {
/** Whether model ``Update`` calls are allowed and handled in some way by the backing model. */
bool allow_model_exceed_end_time = false;
/** Path (as a string) to the BMI config file for initializing the backing model (empty if none). */
string bmi_init_config;
std::string bmi_init_config;
/** Pointer to backing BMI model instance. */
shared_ptr<T> bmi_model = nullptr;
std::shared_ptr<T> bmi_model = nullptr;
/** Whether this particular model has a time step size that cannot be changed internally or externally. */
bool bmi_model_has_fixed_time_step = true;
/** Conversion factor for converting values for model time in model's unit type to equivalent in seconds. */
double bmi_model_time_convert_factor;
/** Pointer to stored time step size value of backing model, if it is fixed and has been retrieved. */
shared_ptr<double> bmi_model_time_step_size = nullptr;
std::shared_ptr<double> bmi_model_time_step_size = nullptr;
/** Whether this particular model implementation directly reads input data from the forcing file. */
bool bmi_model_uses_forcing_file;
string forcing_file_path;
std::string forcing_file_path;
/** Message from an exception (if encountered) on the first attempt to initialize the backing model. */
string init_exception_msg;
std::string init_exception_msg;
/** Pointer to collection of input variable names for backing model, used by ``GetInputVarNames()``. */
shared_ptr<vector<string>> input_var_names;
std::shared_ptr<std::vector<std::string>> input_var_names;
/** Whether the backing model has been initialized yet, which is always initially ``false``. */
bool model_initialized = false;
string model_name;
std::string model_name;
utils::StreamHandler output;
/** Pointer to collection of output variable names for backing model, used by ``GetOutputVarNames()``. */
shared_ptr<vector<string>> output_var_names;
std::shared_ptr<std::vector<std::string>> output_var_names;

/**
* Construct the backing BMI model object, then call its BMI-native ``Initialize()`` function.
Expand Down
8 changes: 4 additions & 4 deletions include/realizations/catchment/Bmi_C_Adapter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace models {
* @param registration_func The name for the @see bmi_registration_function.
* @param output The output stream handler.
*/
explicit Bmi_C_Adapter(const string &type_name, std::string library_file_path, std::string forcing_file_path,
explicit Bmi_C_Adapter(const std::string &type_name, std::string library_file_path, std::string forcing_file_path,
bool allow_exceed_end, bool has_fixed_time_step,
const std::string& registration_func, utils::StreamHandler output);

Expand All @@ -53,7 +53,7 @@ namespace models {
* @param registration_func The name for the @see bmi_registration_function.
* @param output The output stream handler.
*/
Bmi_C_Adapter(const string &type_name, std::string library_file_path, std::string bmi_init_config,
Bmi_C_Adapter(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);

Expand Down Expand Up @@ -81,7 +81,7 @@ namespace models {
* @param output The output stream handler.
* @param do_initialization Whether initialization should be performed during construction or deferred.
*/
Bmi_C_Adapter(const string &type_name, std::string library_file_path, std::string bmi_init_config,
Bmi_C_Adapter(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, bool do_initialization);

Expand Down Expand Up @@ -124,7 +124,7 @@ namespace models {
finalizeForCAdapter();
}

string GetComponentName() override;
std::string GetComponentName() override;

/**
* Get the backing model's current time.
Expand Down
2 changes: 1 addition & 1 deletion include/realizations/catchment/Bmi_Cpp_Adapter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ namespace models {
finalizeForCppAdapter();
}

string GetComponentName() override;
std::string GetComponentName() override;

/**
* Get the backing model's current time.
Expand Down
30 changes: 15 additions & 15 deletions include/realizations/catchment/Bmi_Module_Formulation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ namespace realization {
* @see ForcingProvider
*/
//const vector<std::string> &get_available_forcing_outputs() {
const vector<std::string> &get_available_variable_names() override {
const std::vector<std::string> &get_available_variable_names() override {
if (is_model_initialized() && available_forcings.empty()) {
for (const std::string &output_var_name : get_bmi_model()->GetOutputVarNames()) {
available_forcings.push_back(output_var_name);
Expand All @@ -97,7 +97,7 @@ namespace realization {
*/
time_t get_variable_time_begin(const std::string &variable_name) {
// TODO: come back and implement if actually necessary for this type; for now don't use
throw runtime_error("Bmi_Modular_Formulation does not yet implement get_variable_time_begin");
throw std::runtime_error("Bmi_Modular_Formulation does not yet implement get_variable_time_begin");
}

/**
Expand Down Expand Up @@ -126,16 +126,16 @@ namespace realization {
//time_t get_forcing_output_time_end(const std::string &output_name) {
time_t get_variable_time_end(const std::string &varibale_name) {
// TODO: come back and implement if actually necessary for this type; for now don't use
throw runtime_error("Bmi_Module_Formulation does not yet implement get_variable_time_end");
throw std::runtime_error("Bmi_Module_Formulation does not yet implement get_variable_time_end");
}

long get_data_stop_time() override {
// TODO: come back and implement if actually necessary for this type; for now don't use
throw runtime_error("Bmi_Module_Formulation does not yet implement get_data_stop_time");
throw std::runtime_error("Bmi_Module_Formulation does not yet implement get_data_stop_time");
}

long record_duration() override {
throw runtime_error("Bmi_Module_Formulation does not yet implement record_duration");
throw std::runtime_error("Bmi_Module_Formulation does not yet implement record_duration");
}

/**
Expand All @@ -156,7 +156,7 @@ namespace realization {
return get_bmi_model()->GetEndTime();
}

const vector<std::string> &get_required_parameters() override {
const std::vector<std::string> &get_required_parameters() override {
return REQUIRED_PARAMETERS;
}

Expand Down Expand Up @@ -197,7 +197,7 @@ namespace realization {
*/
size_t get_ts_index_for_time(const time_t &epoch_time) override {
// TODO: come back and implement if actually necessary for this type; for now don't use
throw runtime_error("Bmi_Singular_Formulation does not yet implement get_ts_index_for_time");
throw std::runtime_error("Bmi_Singular_Formulation does not yet implement get_ts_index_for_time");
}

/**
Expand All @@ -222,7 +222,7 @@ namespace realization {
//const std::vector<std::string> forcing_outputs = get_available_forcing_outputs();
const std::vector<std::string> forcing_outputs = get_available_variable_names();
if (std::find(forcing_outputs.begin(), forcing_outputs.end(), output_name) == forcing_outputs.end()) {
throw runtime_error(get_formulation_type() + " received invalid output forcing name " + output_name);
throw std::runtime_error(get_formulation_type() + " received invalid output forcing name " + output_name);
}
// TODO: do this, or something better, later; right now, just assume anything using this as a provider is
// consistent with times
Expand Down Expand Up @@ -291,7 +291,7 @@ namespace realization {
//const std::vector<std::string> forcing_outputs = get_available_forcing_outputs();
const std::vector<std::string> forcing_outputs = get_available_variable_names();
if (std::find(forcing_outputs.begin(), forcing_outputs.end(), output_name) == forcing_outputs.end()) {
throw runtime_error(get_formulation_type() + " received invalid output forcing name " + output_name);
throw std::runtime_error(get_formulation_type() + " received invalid output forcing name " + output_name);
}
// TODO: do this, or something better, later; right now, just assume anything using this as a provider is
// consistent with times
Expand Down Expand Up @@ -363,11 +363,11 @@ namespace realization {
return true;
}

const vector<string> get_bmi_input_variables() override {
const std::vector<std::string> get_bmi_input_variables() override {
return get_bmi_model()->GetInputVarNames();
}

const vector<string> get_bmi_output_variables() override {
const std::vector<std::string> get_bmi_output_variables() override {
return get_bmi_model()->GetOutputVarNames();
}

Expand Down Expand Up @@ -449,7 +449,7 @@ namespace realization {
return allow_model_exceed_end_time;
}

const string &get_bmi_init_config() const {
const std::string &get_bmi_init_config() const {
return bmi_init_config;
}

Expand All @@ -462,7 +462,7 @@ namespace realization {
return bmi_model;
}

const string &get_forcing_file_path() const override {
const std::string &get_forcing_file_path() const override {
return forcing_file_path;
}

Expand Down Expand Up @@ -733,7 +733,7 @@ namespace realization {
allow_model_exceed_end_time = allow_exceed_end;
}

void set_bmi_init_config(const string &init_config) {
void set_bmi_init_config(const std::string &init_config) {
bmi_init_config = init_config;
}

Expand Down Expand Up @@ -763,7 +763,7 @@ namespace realization {
bmi_using_forcing_file = uses_forcing_file;
}

void set_forcing_file_path(const string &forcing_path) {
void set_forcing_file_path(const std::string &forcing_path) {
forcing_file_path = forcing_path;
}

Expand Down
Loading

0 comments on commit 928eee1

Please sign in to comment.