Commit dc243414 authored by Janis Born's avatar Janis Born

add reference wrappers for ObjectIterator and ObjectRange

parent 1111cf45
Pipeline #2279 passed with stage
in 78 minutes and 35 seconds
......@@ -1260,4 +1260,8 @@ ObjectRange objects(IteratorRestriction _restriction, DataType _dataType) {
return ObjectRange(_restriction, _dataType);
}
ObjectReferenceRange objectReferences(IteratorRestriction _restriction, DataType _dataType) {
return ObjectReferenceRange(_restriction, _dataType);
}
} // End namespace PluginFunctions
......@@ -518,9 +518,71 @@ class DLLEXPORT ObjectIterator {
* It stops at the root node.
*/
inline void proceedToNextBaseObjectData(BaseObject*& _object);
};
/**
* \brief Helper class that wraps an ObjectIterator to return a reference
* instead of a pointer
*/
class DLLEXPORT ObjectReferenceIterator : std::iterator<std::forward_iterator_tag, BaseObjectData>
{
public:
ObjectReferenceIterator(IteratorRestriction _restriction = ALL_OBJECTS, DataType _dataType = DATA_ALL) :
it_(_restriction, _dataType)
{
}
explicit ObjectReferenceIterator(BaseObjectData* _pos = NULL, IteratorRestriction _restriction = ALL_OBJECTS, DataType _dataType = DATA_ALL) :
it_(_pos, _restriction, _dataType)
{
}
ObjectReferenceIterator(const ObjectReferenceIterator& _rhs) :
it_(_rhs.it_)
{
}
ObjectReferenceIterator& operator=(const ObjectReferenceIterator& _rhs)
{
if (this != &_rhs) {
it_ = _rhs.it_;
}
return *this;
}
ObjectReferenceIterator& operator++() {
++it_;
return *this;
}
ObjectReferenceIterator operator++(int) {
ObjectReferenceIterator copy(*this);
operator++();
return copy;
}
bool operator==(const ObjectReferenceIterator& _rhs) const {
return it_ == _rhs.it_;
}
bool operator!=(const ObjectReferenceIterator& _rhs) const {
return it_ != _rhs.it_;
}
BaseObjectData& operator*() {
return **it_;
}
BaseObjectData* operator->() {
return *it_;
}
private:
ObjectIterator it_;
};
/** \brief Range adapter for ObjectIterator
*
* An iterator range suitable for iterating over objects using a C++11
......@@ -551,6 +613,52 @@ private:
};
/** \brief Range adapter for ObjectIterator
*
* An iterator range suitable for iterating over objects using a C++11
* range-based for loop.
*
* \note Use the PluginFunction::objectReferences factory function as a shorthand for
* creating object ranges.
**/
class DLLEXPORT ObjectReferenceRange {
public:
explicit ObjectReferenceRange(IteratorRestriction _restriction = ALL_OBJECTS , DataType _dataType = DATA_ALL) :
restriction_(_restriction),
dataType_(_dataType)
{
}
ObjectReferenceIterator begin() const {
return ObjectReferenceIterator(restriction_, dataType_);
}
ObjectReferenceIterator end() const {
return ObjectReferenceIterator(0);
}
private:
IteratorRestriction restriction_;
DataType dataType_;
};
/** \brief Iterable object range
*
* Creates an iterator range suitable for iterating over objects using a C++11
* range-based for loop.
*
* \note Usage:
* \code
* for (auto& object : PluginFunctions::objectReferences(..., ...) {
* ...
* }
* \endcode
**/
DLLEXPORT
ObjectReferenceRange objectReferences(IteratorRestriction _restriction = ALL_OBJECTS , DataType _dataType = DATA_ALL);
/** \brief Iterable object range
*
* Creates an iterator range suitable for iterating over objects using a C++11
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment