Skip to content

Commit

Permalink
Merge pull request #4010 from NREL/4007_sorted
Browse files Browse the repository at this point in the history
#4007 - Model objects returned in inconsistent order
  • Loading branch information
tijcolem authored Jul 10, 2020
2 parents e876c5a + 118b1be commit 0607f87
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/model/Model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ class MODEL_API Model : public openstudio::Workspace {
* speed up the search. This method will only work for concrete model objects (leaves in the
* ModelObject inheritance tree), hence the name. */
template <typename T>
std::vector<T> getConcreteModelObjects() const
std::vector<T> getConcreteModelObjects(bool sorted=false) const
{
std::vector<T> result;
std::vector<WorkspaceObject> objects = this->getObjectsByType(T::iddObjectType());
Expand All @@ -311,6 +311,9 @@ class MODEL_API Model : public openstudio::Workspace {
std::shared_ptr<typename T::ImplType> p = it->getImpl<typename T::ImplType>();
if (p) { result.push_back(T(p)); }
}
if (sorted) {
std::sort(result.begin(), result.end());
}
return result;
}

Expand Down
10 changes: 5 additions & 5 deletions src/model/Model_Common_Include.i
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
%init %{
rb_eval_string("OpenStudio::IdfObject.class_eval { define_method(:to_" #_name ") { OpenStudio::Model::to" #_name "(self); } }");
rb_eval_string("OpenStudio::Model::Model.class_eval { define_method(:get" #_name ") { |handle| OpenStudio::Model::get" #_name "(self, handle); } }");
rb_eval_string("OpenStudio::Model::Model.class_eval { define_method(:get" #_name "s) { OpenStudio::Model::get" #_name "s(self); } }");
rb_eval_string("OpenStudio::Model::Model.class_eval { define_method(:get" #_name "s) { | sorted = false | OpenStudio::Model::get" #_name "s(self, sorted); } }");
rb_eval_string("OpenStudio::Model::Model.class_eval { define_method(:get" #_name "ByName) { |name| OpenStudio::Model::get" #_name "ByName(self, name); } }");
rb_eval_string("OpenStudio::Model::Model.class_eval { define_method(:get" #_name "sByName) { |name, exactMatch| OpenStudio::Model::get" #_name "sByName(self, name, exactMatch); } }");
%}
Expand Down Expand Up @@ -202,7 +202,7 @@

boost::optional<_name> to##_name(const openstudio::IdfObject& idfObject);
boost::optional<_name> get##_name(const Model &t_model, const openstudio::Handle &t_handle);
std::vector<_name> get##_name##s(const Model &t_model);
std::vector<_name> get##_name##s(const Model &t_model, bool sorted);
boost::optional<_name> get##_name##ByName(const Model &t_model, const std::string &t_name);
std::vector<_name> get##_name##sByName(const Model &t_model, const std::string &t_name, bool t_exactMatch);
}
Expand All @@ -216,11 +216,11 @@
boost::optional<_name> get##_name(const Model &t_model, const openstudio::Handle &t_handle) {
return t_model.getModelObject<_name>(t_handle);
}
std::vector<_name> get##_name##s(const Model &t_model) {
std::vector<_name> get##_name##s(const Model &t_model, bool sorted) {
%#if _isConcrete
return t_model.getConcreteModelObjects<_name>();
return t_model.getConcreteModelObjects<_name>(sorted);
%#else
return t_model.getModelObjects<_name>();
return t_model.getModelObjects<_name>(sorted);
%#endif
}
boost::optional<_name> get##_name##ByName(const Model &t_model, const std::string &t_name) {
Expand Down

0 comments on commit 0607f87

Please sign in to comment.