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

String passing fixes #520

Merged
merged 4 commits into from
Apr 26, 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
4 changes: 2 additions & 2 deletions include/core/HY_Features.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ namespace hy_features {
* @param id
* @return std::shared_ptr<HY_HydroNexus>
*/
std::shared_ptr<HY_HydroNexus> nexus_at(std::string id)
std::shared_ptr<HY_HydroNexus> nexus_at(const std::string& id)
{
if( _nexuses.find(id) != _nexuses.end() )
return _nexuses[id];
Expand Down Expand Up @@ -131,7 +131,7 @@ namespace hy_features {
* @param id
* @return std::vector<std::shared_ptr<HY_HydroNexus>>
*/
inline std::vector<std::shared_ptr<HY_HydroNexus>> destination_nexuses(std::string id)
inline std::vector<std::shared_ptr<HY_HydroNexus>> destination_nexuses(const std::string& id)
{
std::vector<std::shared_ptr<HY_HydroNexus>> downstream;
if( _catchments.find(id) != _catchments.end())
Expand Down
6 changes: 3 additions & 3 deletions include/core/HY_Features_MPI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ namespace hy_features {
return network.filter("cat");
}

inline bool is_remote_sender_nexus(std::string id) {
inline bool is_remote_sender_nexus(const std::string& id) {
return _nexuses.find(id) != _nexuses.end() && _nexuses[id]->is_remote_sender();
}

inline std::vector<std::shared_ptr<HY_HydroNexus>> destination_nexuses(std::string id) {
inline std::vector<std::shared_ptr<HY_HydroNexus>> destination_nexuses(const std::string& id) {
std::vector<std::shared_ptr<HY_HydroNexus>> downstream;
if (_catchments.find(id) != _catchments.end()) {
for(const auto& nex_id : _catchments[id]->get_outflow_nexuses()) {
Expand All @@ -43,7 +43,7 @@ namespace hy_features {
return downstream;
}

std::shared_ptr<HY_HydroNexus> nexus_at(std::string id) {
std::shared_ptr<HY_HydroNexus> nexus_at(const std::string& id) {
return (_nexuses.find(id) != _nexuses.end()) ? _nexuses[id] : nullptr;
}

Expand Down
4 changes: 2 additions & 2 deletions include/core/network.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,15 +228,15 @@ namespace network {
* @param id
* @return std::vector<std::string>
*/
std::vector<std::string> get_origination_ids(std::string id);
std::vector<std::string> get_origination_ids(const std::string& id);

/**
* @brief Get the destination (downstream) ids (immediate neighbors) of all vertices with an edge from @p id
*
* @param id
* @return std::vector<std::string>
*/
std::vector<std::string> get_destination_ids(std::string id);
std::vector<std::string> get_destination_ids(const std::string& id);

/**
* @brief The number of features in the network (number of vertices)
Expand Down
22 changes: 11 additions & 11 deletions include/geojson/FeatureCollection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,19 +152,19 @@ namespace geojson {

void visit_features(FeatureVisitor& visitor);

void set(std::string key, short value);
void set(const std::string& key, short value);

void set(std::string key, int value);
void set(const std::string& key, int value);

void set(std::string key, long value);
void set(const std::string& key, long value);

void set(std::string key, float value);
void set(const std::string& key, float value);

void set(std::string key, double value);
void set(const std::string& key, double value);

void set(std::string key, std::string value);
void set(const std::string& key, std::string value);

void set(std::string key, JSONProperty& property);
void set(const std::string& key, JSONProperty& property);

void add_feature(Feature feature, std::string *id = nullptr);

Expand All @@ -174,13 +174,13 @@ namespace geojson {
* @param id The id used to reference a feature
* @param feature A feature that may be referred to by id
*/
void add_feature_id(std::string id, Feature feature);
void add_feature_id(const std::string& id, Feature feature);

void set_ids_from_member(std::string member_name = "id");
void set_ids_from_member(const std::string& member_name = "id");

void set_ids_from_property(std::string property_name = "id");
void set_ids_from_property(const std::string& property_name = "id");

void set_ids(std::string id_field_name = "id");
void set_ids(const std::string& id_field_name = "id");

void update_ids();

Expand Down
22 changes: 11 additions & 11 deletions include/geojson/features/FeatureBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ namespace geojson {
* @param key The name of the property to get
* @return The property identified by the key
*/
virtual JSONProperty get_property(std::string key) const {
virtual JSONProperty get_property(const std::string& key) const {
if (properties.find(key) == properties.end()) {
std::string error_message = "JSON Property '" + key + "' not found.";
throw std::invalid_argument(error_message);
Expand All @@ -223,7 +223,7 @@ namespace geojson {
*
* @param new_id The new identifier for this feature
*/
virtual void set_id(std::string new_id) {
virtual void set_id(const std::string& new_id) {
id = new_id;
}

Expand All @@ -233,7 +233,7 @@ namespace geojson {
* @param key The name of the foreign member whose value to look for
* @return The member value identified by the key
*/
virtual JSONProperty get(std::string key) const {
virtual JSONProperty get(const std::string& key) const {
return foreign_members.at(key);
}

Expand All @@ -243,7 +243,7 @@ namespace geojson {
* @param key The name of the value to set
* @param value The value to set
*/
virtual void set(std::string key, short value) {
virtual void set(const std::string& key, short value) {
foreign_members.emplace(key, JSONProperty(key, value));
}

Expand All @@ -253,7 +253,7 @@ namespace geojson {
* @param key The name of the value to set
* @param value The value to set
*/
virtual void set(std::string key, int value) {
virtual void set(const std::string& key, int value) {
foreign_members.emplace(key, JSONProperty(key, value));
}

Expand All @@ -263,7 +263,7 @@ namespace geojson {
* @param key The name of the value to set
* @param value The value to set
*/
virtual void set(std::string key, long value) {
virtual void set(const std::string& key, long value) {
foreign_members.emplace(key, JSONProperty(key, value));
}

Expand All @@ -273,7 +273,7 @@ namespace geojson {
* @param key The name of the value to set
* @param value The value to set
*/
virtual void set(std::string key, float value) {
virtual void set(const std::string& key, float value) {
foreign_members.emplace(key, JSONProperty(key, value));
}

Expand All @@ -283,7 +283,7 @@ namespace geojson {
* @param key The name of the value to set
* @param value The value to set
*/
virtual void set(std::string key, double value) {
virtual void set(const std::string& key, double value) {
foreign_members.emplace(key, JSONProperty(key, value));
}

Expand All @@ -293,7 +293,7 @@ namespace geojson {
* @param key The name of the value to set
* @param value The value to set
*/
virtual void set(std::string key, std::string value) {
virtual void set(const std::string& key, std::string value) {
foreign_members.emplace(key, JSONProperty(key, value));
}

Expand All @@ -303,11 +303,11 @@ namespace geojson {
* @param key The name of the value to set
* @param value The value to set
*/
virtual void set(std::string key, JSONProperty property) {
virtual void set(const std::string& key, JSONProperty property) {
foreign_members.emplace(key, property);
}

virtual bool has_key(std::string key) {
virtual bool has_key(const std::string& key) {
std::vector<std::string> all_keys = this->keys();

for(auto member_key : all_keys) {
Expand Down
4 changes: 2 additions & 2 deletions src/core/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ std::size_t Network::size(){
return num_vertices(this->graph);
}

std::vector<std::string> Network::get_origination_ids(std::string id){
std::vector<std::string> Network::get_origination_ids(const std::string& id){
Graph::in_edge_iterator begin, end;
boost::tie(begin, end) = boost::in_edges (this->descriptor_map[id], this->graph);
std::vector<std::string> ids;
Expand All @@ -165,7 +165,7 @@ std::vector<std::string> Network::get_origination_ids(std::string id){
return ids;
}

std::vector<std::string> Network::get_destination_ids(std::string id){
std::vector<std::string> Network::get_destination_ids(const std::string& id){
Graph::out_edge_iterator begin, end;
boost::tie(begin, end) = boost::out_edges (this->descriptor_map[id], this->graph);
std::vector<std::string> ids;
Expand Down
23 changes: 12 additions & 11 deletions src/geojson/FeatureCollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,31 +100,32 @@ void FeatureCollection::visit_features(FeatureVisitor& visitor) {
}
}

void FeatureCollection::set(std::string key, short value) {
void FeatureCollection::set(const std::string& key, short value) {
foreign_members.emplace(key, JSONProperty(key, value));
}

void FeatureCollection::set(std::string key, int value) {
void FeatureCollection::set(const std::string& key, int value) {
foreign_members.emplace(key, JSONProperty(key, value));
}

void FeatureCollection::set(std::string key, long value) {
void FeatureCollection::set(const std::string& key, long value) {
foreign_members.emplace(key, JSONProperty(key, value));
}

void FeatureCollection::set(std::string key, float value) {
void FeatureCollection::set(const std::string& key, float value) {
foreign_members.emplace(key, JSONProperty(key, value));
}

void FeatureCollection::set(std::string key, double value) {
void FeatureCollection::set(const std::string& key, double value) {
foreign_members.emplace(key, JSONProperty(key, value));
}

void FeatureCollection::set(std::string key, std::string value) {
// the 'value' arguement will be copied and then moved so only one copy should occure
void FeatureCollection::set(const std::string& key, std::string value) {
foreign_members.emplace(key, JSONProperty(key, value));
}

void FeatureCollection::set(std::string key, JSONProperty& property) {
void FeatureCollection::set(const std::string& key, JSONProperty& property) {
foreign_members.emplace(key, property);
}

Expand Down Expand Up @@ -208,7 +209,7 @@ void FeatureCollection::add_feature(Feature feature, std::string *id) {
}
}

void FeatureCollection::set_ids_from_member(std::string member_name) {
void FeatureCollection::set_ids_from_member(const std::string& member_name) {
for (auto feature : this->features) {
if(contains(feature->keys(), member_name)) {
feature->set_id(feature->get(member_name).as_string());
Expand All @@ -218,7 +219,7 @@ void FeatureCollection::set_ids_from_member(std::string member_name) {
this->update_ids();
}

void FeatureCollection::set_ids_from_property(std::string property_name) {
void FeatureCollection::set_ids_from_property(const std::string& property_name) {
for (auto feature : this->features) {
if (contains(feature->property_keys(), property_name)) {
feature->set_id(feature->get_property(property_name).as_string());
Expand All @@ -228,7 +229,7 @@ void FeatureCollection::set_ids_from_property(std::string property_name) {
this->update_ids();
}

void FeatureCollection::set_ids(std::string id_field_name) {
void FeatureCollection::set_ids(const std::string& id_field_name) {
for (auto feature : this->features) {
if(contains(feature->property_keys(), id_field_name)) {
feature->set_id(feature->get_property(id_field_name).as_string());
Expand All @@ -250,7 +251,7 @@ void FeatureCollection::update_ids() {
}
}

void FeatureCollection::add_feature_id(std::string id, Feature feature) {
void FeatureCollection::add_feature_id(const std::string& id, Feature feature) {
if (id != "") {
feature_by_id.emplace(id, std::move(feature));
}
Expand Down