Do not sort properties and propertyowners automatically (closes #269)

This commit is contained in:
Alexander Bock
2017-06-09 11:26:38 -04:00
parent f1b4d6ddc7
commit 7775435eab
2 changed files with 18 additions and 68 deletions

View File

@@ -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<Property*> 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<Property*>::const_iterator it = std::lower_bound(
std::vector<Property*>::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*> 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<PropertyOwner*>::const_iterator it = std::lower_bound(
std::vector<PropertyOwner*>::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<Property*>::iterator it = std::lower_bound(
std::vector<Property*>::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<PropertyOwner*>::iterator it = std::lower_bound(
_subOwners.begin(), _subOwners.end(), owner->name(),
[](PropertyOwner* owner, const std::string& str) {
return owner->name() < str;
}
std::vector<PropertyOwner*>::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<Property*>::iterator it = std::lower_bound(
std::vector<Property*>::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<PropertyOwner*>::iterator it = std::lower_bound(
std::vector<PropertyOwner*>::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