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

Add const specifiers to various virtual member functions #849

Merged
2 changes: 1 addition & 1 deletion include/core/catchment/HY_CatchmentRealization.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class HY_CatchmentRealization

std::shared_ptr<HY_Catchment> realized_catchment;

virtual std::string get_catchment_id() = 0;
virtual std::string get_catchment_id() const = 0;

virtual void set_catchment_id(std::string cat_id) = 0;

Expand Down
14 changes: 7 additions & 7 deletions include/forcing/CsvPerFeatureForcingProvider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class CsvPerFeatureForcingProvider : public data_access::GenericDataProvider
*
* @return The inclusive beginning of the period of time over which this instance can provide this data.
*/
long get_data_start_time() override {
long get_data_start_time() const override {
//FIXME: Trace this back and you will find that it is the simulation start time, not having anything to do with the forcing at all.
// Apparently this "worked", but at a minimum the description above is false.
return start_date_time_epoch;
Expand All @@ -57,7 +57,7 @@ class CsvPerFeatureForcingProvider : public data_access::GenericDataProvider
*
* @return The exclusive ending of the period of time over which this instance can provide this data.
*/
long get_data_stop_time() override {
long get_data_stop_time() const override {
return end_date_time_epoch;
}

Expand All @@ -66,7 +66,7 @@ class CsvPerFeatureForcingProvider : public data_access::GenericDataProvider
*
* @return The duration of one record of this forcing source
*/
long record_duration() override {
long record_duration() const override {
return time_epoch_vector[1] - time_epoch_vector[0];
}

Expand All @@ -79,7 +79,7 @@ class CsvPerFeatureForcingProvider : public data_access::GenericDataProvider
* @return The index of the forcing time step that contains the given point in time.
* @throws std::out_of_range If the given point is not in any time step.
*/
size_t get_ts_index_for_time(const time_t &epoch_time) override {
size_t get_ts_index_for_time(const time_t &epoch_time) const override {
if (epoch_time < start_date_time_epoch) {
throw std::out_of_range("Forcing had bad pre-start time for index query: " + std::to_string(epoch_time));
}
Expand Down Expand Up @@ -190,7 +190,7 @@ class CsvPerFeatureForcingProvider : public data_access::GenericDataProvider
* @param name The name of the forcing param for which the current value is desired.
* @return Whether the param's value is an aggregate sum.
*/
inline bool is_param_sum_over_time_step(const std::string& name) {
inline bool is_param_sum_over_time_step(const std::string& name) const {
if (name == CSDMS_STD_NAME_RAIN_VOLUME_FLUX) {
return true;
}
Expand Down Expand Up @@ -218,11 +218,11 @@ class CsvPerFeatureForcingProvider : public data_access::GenericDataProvider
* @param name The name of the forcing property for which the current value is desired.
* @return Whether the property's value is an aggregate sum.
*/
inline bool is_property_sum_over_time_step(const std::string& name) override {
inline bool is_property_sum_over_time_step(const std::string& name) const override {
return is_param_sum_over_time_step(name);
}

boost::span<const std::string> get_available_variable_names() override {
boost::span<const std::string> get_available_variable_names() const override {
return available_forcings;
}

Expand Down
12 changes: 6 additions & 6 deletions include/forcing/DataProvider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,18 @@ namespace data_access

/** Return the variables that are accessable by this data provider */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just noticed a typo here

Suggested change
/** Return the variables that are accessable by this data provider */
/** Return the variables that are accessible by this data provider */

Probably not suitable to fix in this PR.


virtual boost::span<const std::string> get_available_variable_names() = 0;
virtual boost::span<const std::string> get_available_variable_names() const = 0;

/** Return the first valid time for which data from the request variable can be requested */

virtual long get_data_start_time() = 0;
virtual long get_data_start_time() const = 0;

/** Return the last valid time for which data from the requested variable can be requested */

virtual long get_data_stop_time() = 0;
virtual long get_data_stop_time() const = 0;

/** Return the stride in the time dimension */
virtual long record_duration() = 0;
virtual long record_duration() const = 0;

/**
* Get the index of the data time step that contains the given point in time.
Expand All @@ -62,7 +62,7 @@ namespace data_access
* @return The index of the forcing time step that contains the given point in time.
* @throws std::out_of_range If the given point is not in any time step.
*/
virtual size_t get_ts_index_for_time(const time_t &epoch_time) = 0;
virtual size_t get_ts_index_for_time(const time_t &epoch_time) const = 0;

/**
* Get the value of a forcing property for an arbitrary time period, converting units if needed.
Expand Down Expand Up @@ -93,7 +93,7 @@ namespace data_access
*/
virtual std::vector<data_type> get_values(const selection_type& selector, ReSampleMethod m=SUM) = 0;

virtual bool is_property_sum_over_time_step(const std::string& name) {return false; }
virtual bool is_property_sum_over_time_step(const std::string& name) const {return false; }

private:
};
Expand Down
2 changes: 1 addition & 1 deletion include/forcing/DeferredWrappedProvider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ namespace data_access {
* @return The names of the outputs for which this instance is (or will be) able to provide values.
*/

boost::span<const std::string> get_available_variable_names() override {
boost::span<const std::string> get_available_variable_names() const override {
return providedOutputs;
}

Expand Down
10 changes: 5 additions & 5 deletions include/forcing/ForcingsEngineDataProvider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,27 +104,27 @@ struct ForcingsEngineDataProvider

~ForcingsEngineDataProvider() override = default;

boost::span<const std::string> get_available_variable_names() override
boost::span<const std::string> get_available_variable_names() const override
{
return var_output_names_;
}

long get_data_start_time() override
long get_data_start_time() const override
{
return clock_type::to_time_t(time_begin_);
}

long get_data_stop_time() override
long get_data_stop_time() const override
{
return clock_type::to_time_t(time_end_);
}

long record_duration() override
long record_duration() const override
{
return std::chrono::duration_cast<std::chrono::seconds>(time_step_).count();
}

size_t get_ts_index_for_time(const time_t& epoch_time) override
size_t get_ts_index_for_time(const time_t& epoch_time) const override
{
const auto epoch = clock_type::from_time_t(epoch_time);

Expand Down
10 changes: 5 additions & 5 deletions include/forcing/NetCDFPerFeatureDataProvider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,18 @@ namespace data_access
void finalize() override;

/** Return the variables that are accessable by this data provider */
boost::span<const std::string> get_available_variable_names() override;
boost::span<const std::string> get_available_variable_names() const override;

/** return a list of ids in the current file */
const std::vector<std::string>& get_ids() const;

/** Return the first valid time for which data from the request variable can be requested */
long get_data_start_time() override;
long get_data_start_time() const override;

/** Return the last valid time for which data from the requested variable can be requested */
long get_data_stop_time() override;
long get_data_stop_time() const override;

long record_duration() override;
long record_duration() const override;

/**
* Get the index of the data time step that contains the given point in time.
Expand All @@ -94,7 +94,7 @@ namespace data_access
* @return The index of the forcing time step that contains the given point in time.
* @throws std::out_of_range If the given point is not in any time step.
*/
size_t get_ts_index_for_time(const time_t &epoch_time) override;
size_t get_ts_index_for_time(const time_t &epoch_time) const override;

/**
* Get the value of a forcing property for an arbitrary time period, converting units if needed.
Expand Down
12 changes: 6 additions & 6 deletions include/forcing/NullForcingProvider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ class NullForcingProvider : public data_access::GenericDataProvider

// BEGIN DataProvider interface methods

long get_data_start_time() override;
long get_data_start_time() const override;

long get_data_stop_time() override;
long get_data_stop_time() const override;

long record_duration() override;
long record_duration() const override;

size_t get_ts_index_for_time(const time_t &epoch_time) override;
size_t get_ts_index_for_time(const time_t &epoch_time) const override;

double get_value(const CatchmentAggrDataSelector& selector, data_access::ReSampleMethod m) override;

std::vector<double> get_values(const CatchmentAggrDataSelector& selector, data_access::ReSampleMethod m) override;

inline bool is_property_sum_over_time_step(const std::string& name) override;
inline bool is_property_sum_over_time_step(const std::string& name) const override;

boost::span<const std::string> get_available_variable_names() override;
boost::span<const std::string> get_available_variable_names() const override;
};

#endif // NGEN_NULLFORCING_H
12 changes: 6 additions & 6 deletions include/forcing/WrappedDataProvider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ namespace data_access {
* @return const std::vector<std::string>& the names of available data variables
*/

boost::span<const std::string> get_available_variable_names() override {
boost::span<const std::string> get_available_variable_names() const override {
return wrapped_provider->get_available_variable_names();
}

Expand All @@ -68,7 +68,7 @@ namespace data_access {
*
* @return The inclusive beginning of the period of time over which this instance can provide this data.
*/
long get_data_start_time() override {
long get_data_start_time() const override {
return wrapped_provider->get_data_start_time();
}

Expand All @@ -77,11 +77,11 @@ namespace data_access {
*
* @return The exclusive ending of the period of time over which this instance can provide this data.
*/
long get_data_stop_time() override {
long get_data_stop_time() const override {
return wrapped_provider->get_data_stop_time();
}

long record_duration() override {
long record_duration() const override {
return wrapped_provider->record_duration();
}

Expand All @@ -94,7 +94,7 @@ namespace data_access {
* @return The index of the forcing time step that contains the given point in time.
* @throws std::out_of_range If the given point is not in any time step.
*/
size_t get_ts_index_for_time(const time_t &epoch_time) override {
size_t get_ts_index_for_time(const time_t &epoch_time) const override {
return wrapped_provider->get_ts_index_for_time(epoch_time);
}

Expand Down Expand Up @@ -132,7 +132,7 @@ namespace data_access {
* @param name The name of the forcing property for which the current value is desired.
* @return Whether the property's value is an aggregate sum.
*/
bool is_property_sum_over_time_step(const std::string& name) override {
bool is_property_sum_over_time_step(const std::string& name) const override {
return wrapped_provider->is_property_sum_over_time_step(name);
}

Expand Down
10 changes: 5 additions & 5 deletions include/realizations/catchment/Bmi_C_Formulation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ namespace realization {

Bmi_C_Formulation(std::string id, std::shared_ptr<data_access::GenericDataProvider> forcing_provider, utils::StreamHandler output_stream);

std::string get_formulation_type() override;
std::string get_formulation_type() const override;

bool is_bmi_input_variable(const std::string &var_name) override;
bool is_bmi_input_variable(const std::string &var_name) const override;

bool is_bmi_output_variable(const std::string &var_name) override;
bool is_bmi_output_variable(const std::string &var_name) const override;

protected:

Expand All @@ -36,7 +36,7 @@ namespace realization {
*/
std::shared_ptr<models::bmi::Bmi_Adapter> construct_model(const geojson::PropertyMap& properties) override;

time_t convert_model_time(const double &model_time) override {
time_t convert_model_time(const double &model_time) const override {
return (time_t) (get_bmi_model()->convert_model_time_to_seconds(model_time));
}

Expand Down Expand Up @@ -98,7 +98,7 @@ namespace realization {
*
* @return Whether backing model object has been initialize using the BMI standard ``Initialize`` function.
*/
bool is_model_initialized() override;
bool is_model_initialized() const override;

// Unit test access
friend class ::Bmi_Formulation_Test;
Expand Down
10 changes: 5 additions & 5 deletions include/realizations/catchment/Bmi_Cpp_Formulation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ namespace realization {

Bmi_Cpp_Formulation(std::string id, std::shared_ptr<data_access::GenericDataProvider> forcing_provider, utils::StreamHandler output_stream);

std::string get_formulation_type() override;
std::string get_formulation_type() const override;

bool is_bmi_input_variable(const std::string &var_name) override;
bool is_bmi_input_variable(const std::string &var_name) const override;

bool is_bmi_output_variable(const std::string &var_name) override;
bool is_bmi_output_variable(const std::string &var_name) const override;

protected:

std::shared_ptr<models::bmi::Bmi_Adapter> construct_model(const geojson::PropertyMap& properties) override;

time_t convert_model_time(const double &model_time) override {
time_t convert_model_time(const double &model_time) const override {
return (time_t) (get_bmi_model()->convert_model_time_to_seconds(model_time));
}

Expand All @@ -38,7 +38,7 @@ namespace realization {

double get_var_value_as_double(const int& index, const std::string& var_name) override;

bool is_model_initialized() override;
bool is_model_initialized() const override;

// Unit test access
friend class ::Bmi_Formulation_Test;
Expand Down
Loading
Loading