[Orxonox-commit 5716] r10376 - code/branches/core7/src/libraries/core/class
landauf at orxonox.net
landauf at orxonox.net
Sun Apr 19 22:13:42 CEST 2015
Author: landauf
Date: 2015-04-19 22:13:42 +0200 (Sun, 19 Apr 2015)
New Revision: 10376
Modified:
code/branches/core7/src/libraries/core/class/Identifier.cc
code/branches/core7/src/libraries/core/class/Identifier.h
Log:
added helper function to reduce code duplication
Modified: code/branches/core7/src/libraries/core/class/Identifier.cc
===================================================================
--- code/branches/core7/src/libraries/core/class/Identifier.cc 2015-04-19 20:07:27 UTC (rev 10375)
+++ code/branches/core7/src/libraries/core/class/Identifier.cc 2015-04-19 20:13:42 UTC (rev 10376)
@@ -204,10 +204,8 @@
for (std::list<const Identifier*>::const_iterator it_parent = this->directParents_.begin(); it_parent != this->directParents_.end(); ++it_parent)
{
for (std::list<const Identifier*>::const_iterator it_parent_parent = const_cast<Identifier*>(*it_parent)->parents_.begin(); it_parent_parent != const_cast<Identifier*>(*it_parent)->parents_.end(); ++it_parent_parent)
- if (std::find(this->parents_.begin(), this->parents_.end(), *it_parent_parent) == this->parents_.end())
- this->parents_.push_back(*it_parent_parent);
- if (std::find(this->parents_.begin(), this->parents_.end(), *it_parent) == this->parents_.end())
- this->parents_.push_back(*it_parent);
+ this->addIfNotExists(this->parents_, *it_parent_parent);
+ this->addIfNotExists(this->parents_, *it_parent);
}
}
else if (!this->isExactlyA(Class(Identifiable)))
@@ -235,6 +233,15 @@
}
/**
+ * Adds @param identifierToAdd to @param list if this identifier is not already contained in the list.
+ */
+ void Identifier::addIfNotExists(std::list<const Identifier*>& list, const Identifier* identifierToAdd) const
+ {
+ if (std::find(list.begin(), list.end(), identifierToAdd) == list.end())
+ list.push_back(identifierToAdd);
+ }
+
+ /**
@brief Returns true, if the Identifier is at least of the given type.
@param identifier The identifier to compare with
*/
Modified: code/branches/core7/src/libraries/core/class/Identifier.h
===================================================================
--- code/branches/core7/src/libraries/core/class/Identifier.h 2015-04-19 20:07:27 UTC (rev 10375)
+++ code/branches/core7/src/libraries/core/class/Identifier.h 2015-04-19 20:13:42 UTC (rev 10376)
@@ -214,6 +214,8 @@
virtual void createSuperFunctionCaller() const = 0;
private:
+ void addIfNotExists(std::list<const Identifier*>& list, const Identifier* identifierToAdd) const;
+
std::list<const Identifier*> directParents_; //!< The direct parents of the class the Identifier belongs to (sorted by their order of initialization)
std::list<const Identifier*> parents_; //!< The parents of the class the Identifier belongs to (sorted by their order of initialization)
More information about the Orxonox-commit
mailing list