From bf51517efb15acdf09dae248d20910d21c1a9166 Mon Sep 17 00:00:00 2001 From: Donald Johnson Date: Tue, 14 Jun 2022 17:43:48 +0000 Subject: [PATCH 1/4] Remove un needed messages from unit conversion library. --- src/NGen.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/NGen.cpp b/src/NGen.cpp index 5734820960..d52ecb95b3 100644 --- a/src/NGen.cpp +++ b/src/NGen.cpp @@ -69,6 +69,8 @@ int main(int argc, char *argv[]) { << ngen_VERSION_PATCH << std::endl; std::ios::sync_with_stdio(false); + ut_set_error_message_handler(ut_ignore); + #ifdef ACTIVATE_PYTHON // Start Python interpreter via the manager singleton // Need to bind to a variable so that the underlying reference count From 2c201c27e0c041a702e602fc2dfd6f2b369ae0d0 Mon Sep 17 00:00:00 2001 From: Donald Johnson Date: Wed, 26 Apr 2023 17:16:48 +0000 Subject: [PATCH 2/4] Fix instances of std::string being copied without cause. --- include/core/HY_Features.hpp | 4 ++-- include/core/HY_Features_MPI.hpp | 6 +++--- include/core/network.hpp | 4 ++-- include/geojson/FeatureCollection.hpp | 22 +++++++++++----------- include/geojson/features/FeatureBase.hpp | 22 +++++++++++----------- 5 files changed, 29 insertions(+), 29 deletions(-) diff --git a/include/core/HY_Features.hpp b/include/core/HY_Features.hpp index c5f205b685..0f4d5b2c00 100644 --- a/include/core/HY_Features.hpp +++ b/include/core/HY_Features.hpp @@ -102,7 +102,7 @@ namespace hy_features { * @param id * @return std::shared_ptr */ - std::shared_ptr nexus_at(std::string id) + std::shared_ptr nexus_at(const std::string& id) { if( _nexuses.find(id) != _nexuses.end() ) return _nexuses[id]; @@ -131,7 +131,7 @@ namespace hy_features { * @param id * @return std::vector> */ - inline std::vector> destination_nexuses(std::string id) + inline std::vector> destination_nexuses(const std::string& id) { std::vector> downstream; if( _catchments.find(id) != _catchments.end()) diff --git a/include/core/HY_Features_MPI.hpp b/include/core/HY_Features_MPI.hpp index e69e08853a..cd92e5584a 100644 --- a/include/core/HY_Features_MPI.hpp +++ b/include/core/HY_Features_MPI.hpp @@ -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> destination_nexuses(std::string id) { + inline std::vector> destination_nexuses(const std::string& id) { std::vector> downstream; if (_catchments.find(id) != _catchments.end()) { for(const auto& nex_id : _catchments[id]->get_outflow_nexuses()) { @@ -43,7 +43,7 @@ namespace hy_features { return downstream; } - std::shared_ptr nexus_at(std::string id) { + std::shared_ptr nexus_at(const std::string& id) { return (_nexuses.find(id) != _nexuses.end()) ? _nexuses[id] : nullptr; } diff --git a/include/core/network.hpp b/include/core/network.hpp index 625f3d543d..728bc3ebde 100644 --- a/include/core/network.hpp +++ b/include/core/network.hpp @@ -228,7 +228,7 @@ namespace network { * @param id * @return std::vector */ - std::vector get_origination_ids(std::string id); + std::vector get_origination_ids(const std::string& id); /** * @brief Get the destination (downstream) ids (immediate neighbors) of all vertices with an edge from @p id @@ -236,7 +236,7 @@ namespace network { * @param id * @return std::vector */ - std::vector get_destination_ids(std::string id); + std::vector get_destination_ids(const std::string& id); /** * @brief The number of features in the network (number of vertices) diff --git a/include/geojson/FeatureCollection.hpp b/include/geojson/FeatureCollection.hpp index 39ad439556..fa420ae75b 100644 --- a/include/geojson/FeatureCollection.hpp +++ b/include/geojson/FeatureCollection.hpp @@ -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); @@ -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(); diff --git a/include/geojson/features/FeatureBase.hpp b/include/geojson/features/FeatureBase.hpp index 4f37ac0f8e..7df0c8a423 100644 --- a/include/geojson/features/FeatureBase.hpp +++ b/include/geojson/features/FeatureBase.hpp @@ -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); @@ -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; } @@ -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); } @@ -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)); } @@ -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)); } @@ -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)); } @@ -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)); } @@ -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)); } @@ -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)); } @@ -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 all_keys = this->keys(); for(auto member_key : all_keys) { From 21bb32bf23bcb9253718a65d30ed0b31b5ab7825 Mon Sep 17 00:00:00 2001 From: Donald Johnson Date: Wed, 26 Apr 2023 18:42:03 +0000 Subject: [PATCH 3/4] More files with string fixes --- src/core/network.cpp | 4 ++-- src/geojson/FeatureCollection.cpp | 23 ++++++++++++----------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/core/network.cpp b/src/core/network.cpp index 17f7d2b900..9dfcf39f5c 100644 --- a/src/core/network.cpp +++ b/src/core/network.cpp @@ -154,7 +154,7 @@ std::size_t Network::size(){ return num_vertices(this->graph); } -std::vector Network::get_origination_ids(std::string id){ +std::vector 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 ids; @@ -165,7 +165,7 @@ std::vector Network::get_origination_ids(std::string id){ return ids; } -std::vector Network::get_destination_ids(std::string id){ +std::vector 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 ids; diff --git a/src/geojson/FeatureCollection.cpp b/src/geojson/FeatureCollection.cpp index 18af0b848c..b2b10cfb66 100644 --- a/src/geojson/FeatureCollection.cpp +++ b/src/geojson/FeatureCollection.cpp @@ -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); } @@ -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()); @@ -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()); @@ -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()); @@ -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)); } From 27e492c25618f41601affc42d5ef4a608f0a5ae6 Mon Sep 17 00:00:00 2001 From: Donald Johnson Date: Wed, 26 Apr 2023 19:31:05 +0000 Subject: [PATCH 4/4] Revert "Remove un needed messages from unit conversion library." This reverts commit bf51517efb15acdf09dae248d20910d21c1a9166. --- src/NGen.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/NGen.cpp b/src/NGen.cpp index d52ecb95b3..5734820960 100644 --- a/src/NGen.cpp +++ b/src/NGen.cpp @@ -69,8 +69,6 @@ int main(int argc, char *argv[]) { << ngen_VERSION_PATCH << std::endl; std::ios::sync_with_stdio(false); - ut_set_error_message_handler(ut_ignore); - #ifdef ACTIVATE_PYTHON // Start Python interpreter via the manager singleton // Need to bind to a variable so that the underlying reference count