diff --git a/ext/ghoul b/ext/ghoul index b362a77feb..7dceb82a9e 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit b362a77feb81c751519386d42615ba04e0c92d1c +Subproject commit 7dceb82a9ed8fff66ecf3d0f9dfd5f032b3e3e13 diff --git a/src/properties/propertyowner.cpp b/src/properties/propertyowner.cpp index 2e57409394..cf459cfbf0 100644 --- a/src/properties/propertyowner.cpp +++ b/src/properties/propertyowner.cpp @@ -36,8 +36,7 @@ namespace properties { namespace { const char* _loggerCat = "PropertyOwner"; - bool propertyLess(Property* lhs, Property* rhs) - { + bool propertyLess(Property* lhs, Property* rhs) { return lhs->identifier() < rhs->identifier(); } @@ -73,19 +72,10 @@ std::vector PropertyOwner::propertiesRecursive() const { } Property* PropertyOwner::property(const std::string& id) const { - ghoul_assert( - std::is_sorted(_properties.begin(), _properties.end(), propertyLess), - "Property list must be sorted" - ); - - // As the _properties list is sorted, just finding the lower bound is sufficient - std::vector::const_iterator it = std::lower_bound( + std::vector::const_iterator it = std::find_if( _properties.begin(), _properties.end(), - id, - [](Property* prop, const std::string& str) { - return prop->identifier() < str; - } + [&id](Property* prop) { return prop->identifier() == id; } ); if (it == _properties.end() || (*it)->identifier() != id) { @@ -124,19 +114,10 @@ std::vector PropertyOwner::propertySubOwners() const { } PropertyOwner* PropertyOwner::propertySubOwner(const std::string& name) const { - ghoul_assert( - std::is_sorted(_subOwners.begin(), _subOwners.end(), subOwnerLess), - "List of subowners must be sorted" - ); - - // As the _subOwners list is sorted, getting the lower bound is sufficient - std::vector::const_iterator it = std::lower_bound( + std::vector::const_iterator it = std::find_if( _subOwners.begin(), _subOwners.end(), - name, - [](PropertyOwner* owner, const std::string& str) { - return owner->name() < str; - } + [&name](PropertyOwner* owner) { return owner->name() == name; } ); if (it == _subOwners.end() || (*it)->name() != name) { @@ -167,29 +148,16 @@ std::string PropertyOwner::propertyGroupName(const std::string& groupID) const { void PropertyOwner::addProperty(Property* prop) { ghoul_assert(prop != nullptr, "prop must not be nullptr"); - ghoul_assert( - std::is_sorted(_properties.begin(), _properties.end(), propertyLess), - "Property list must be sorted" - ); - ghoul_assert( - std::is_sorted(_subOwners.begin(), _subOwners.end(), subOwnerLess), - "Subowner list must be sorted" - ); if (prop->identifier().empty()) { LERROR("No property identifier specified"); return; } - // See if we can find the identifier of the property to add in the properties list - // The _properties list is sorted, so getting the lower bound is sufficient - std::vector::iterator it = std::lower_bound( + std::vector::const_iterator it = std::find_if( _properties.begin(), _properties.end(), - prop->identifier(), - [](Property* prop, const std::string& str) { - return prop->identifier() < str; - } + [id = prop->identifier()](Property* prop) { return prop->identifier() == id; } ); // If we found the property identifier, we need to bail out @@ -206,8 +174,7 @@ void PropertyOwner::addProperty(Property* prop) { return; } else { - // now have found the correct position to add it in - _properties.insert(it, prop); + _properties.push_back(prop); prop->setPropertyOwner(this); } } @@ -219,23 +186,13 @@ void PropertyOwner::addProperty(Property& prop) { void PropertyOwner::addPropertySubOwner(openspace::properties::PropertyOwner* owner) { ghoul_assert(owner != nullptr, "owner must not be nullptr"); - ghoul_assert( - std::is_sorted(_properties.begin(), _properties.end(), propertyLess), - "Property list must be sorted" - ); - ghoul_assert( - std::is_sorted(_subOwners.begin(), _subOwners.end(), subOwnerLess), - "Subowner list must be sorted" - ); - ghoul_assert(!owner->name().empty(), "PropertyOwner must have a name"); // See if we can find the name of the propertyowner to add using the lower bound - std::vector::iterator it = std::lower_bound( - _subOwners.begin(), _subOwners.end(), owner->name(), - [](PropertyOwner* owner, const std::string& str) { - return owner->name() < str; - } + std::vector::const_iterator it = std::find_if( + _subOwners.begin(), + _subOwners.end(), + [name = owner->name()](PropertyOwner* owner) { return owner->name() == name; } ); // If we found the propertyowner's name, we need to bail out @@ -252,8 +209,7 @@ void PropertyOwner::addPropertySubOwner(openspace::properties::PropertyOwner* ow return; } else { - // Otherwise we have found the correct position to add it in - _subOwners.insert(it, owner); + _subOwners.push_back(owner); owner->setPropertyOwner(this); } } @@ -267,13 +223,10 @@ void PropertyOwner::removeProperty(Property* prop) { ghoul_assert(prop != nullptr, "prop must not be nullptr"); // See if we can find the identifier of the property to add in the properties list - std::vector::iterator it = std::lower_bound( + std::vector::const_iterator it = std::find_if( _properties.begin(), _properties.end(), - prop->identifier(), - [](Property* prop, const std::string& str) { - return prop->identifier() < str; - } + [id = prop->identifier()](Property* prop) { return prop->identifier() == id; } ); // If we found the property identifier, we can delete it @@ -294,13 +247,10 @@ void PropertyOwner::removePropertySubOwner(openspace::properties::PropertyOwner* ghoul_assert(owner != nullptr, "owner must not be nullptr"); // See if we can find the name of the propertyowner to add - std::vector::iterator it = std::lower_bound( + std::vector::const_iterator it = std::find_if( _subOwners.begin(), _subOwners.end(), - owner->name(), - [](PropertyOwner* owner, const std::string& str) { - return owner->name() < str; - } + [name = owner->name()](PropertyOwner* owner) { return owner->name() == name; } ); // If we found the propertyowner, we can delete it