diff options
Diffstat (limited to 'src/usr/targeting/iterators')
-rw-r--r-- | src/usr/targeting/iterators/rangefilter.C | 89 | ||||
-rw-r--r-- | src/usr/targeting/iterators/targetiterator.C | 88 |
2 files changed, 177 insertions, 0 deletions
diff --git a/src/usr/targeting/iterators/rangefilter.C b/src/usr/targeting/iterators/rangefilter.C new file mode 100644 index 000000000..64ceb1f78 --- /dev/null +++ b/src/usr/targeting/iterators/rangefilter.C @@ -0,0 +1,89 @@ + +/** + * @file rangefilter.C + * + * @brief Implementation of an object which takes an iterator range and + * allows caller to iterate through the elements which match a supplied + * predicate (filter) + */ + +//****************************************************************************** +// Includes +//****************************************************************************** + +// STD + +// Other Host Boot Components + +// Targeting Component +#include <targeting/iterators/rangefilter.H> + +//****************************************************************************** +// Macros +//****************************************************************************** + +#undef TARG_NAMESPACE +#undef TARG_CLASS +#undef TARG_FUNC + +//****************************************************************************** +// Implementation +//****************************************************************************** + +namespace TARGETING +{ + +#define TARG_NAMESPACE "TARGETING::" + +#define TARG_CLASS "RangeFilter<IteratorType>::" + +//****************************************************************************** +// RangeFilter<IteratorType>::advance +//****************************************************************************** + +template<typename IteratorType> +void RangeFilter<IteratorType>::advance() +{ + if(iv_current != iv_end) + { + while( (++iv_current) != iv_end ) + { + if( (!iv_pPredicate) + || ((*iv_pPredicate)(*iv_current))) + { + break; + } + } + } +} + +//****************************************************************************** +// RangeFilter<IteratorType>::advanceIfNoMatch +//****************************************************************************** + +template<typename IteratorType> +void RangeFilter<IteratorType>::advanceIfNoMatch() +{ + if( (iv_current != iv_end) + && ( (iv_pPredicate) + && (!((*iv_pPredicate)(*iv_current))))) + { + advance(); + } +} + +//****************************************************************************** +// Explicit template class member function instantiations +//****************************************************************************** + +template void RangeFilter<TargetIterator>::advance(); +template void RangeFilter<ConstTargetIterator>::advance(); + +template void RangeFilter<TargetIterator>::advanceIfNoMatch(); +template void RangeFilter<ConstTargetIterator>::advanceIfNoMatch(); + +#undef TARG_CLASS +#undef TARG_NAMESPACE + +} // End namespace TARGETING + diff --git a/src/usr/targeting/iterators/targetiterator.C b/src/usr/targeting/iterators/targetiterator.C new file mode 100644 index 000000000..f3549a633 --- /dev/null +++ b/src/usr/targeting/iterators/targetiterator.C @@ -0,0 +1,88 @@ + +/** + * @file targetiterator.C + * + * @brief Implementation of iterator/const iterator used to iterate through + * target service targets + */ + +//****************************************************************************** +// Includes +//****************************************************************************** + +// STD + +// Other Host Boot Components + +// Targeting Component +#include <targeting/iterators/targetiterator.H> +#include <targeting/targetservice.H> + +//****************************************************************************** +// Macros +//****************************************************************************** + +#undef TARG_NAMESPACE +#undef TARG_CLASS +#undef TARG_FUNC + +//****************************************************************************** +// Implementation +//****************************************************************************** + +namespace TARGETING +{ + +#define TARG_NAMESPACE "TARGETING::" + +#define TARG_CLASS "_TargetIterator<T>::" + +//****************************************************************************** +// TargetIterator::advance +//****************************************************************************** + +template<typename T> +void _TargetIterator<T>::advance() +{ + TargetService& l_targetService = targetService(); + + // If cursor points to end()/NULL, do nothing. Otherwise, check to see if + // it should advance (possibly to NULL) + if(iv_pCurrent != NULL) + { + // Advance to end() if no targets available. Otherwise, check to see if + // it should advance (possibly to NULL) + if (l_targetService.iv_maxTargets > 0) + { + // If at or past last element, advance to end() else advance + if(iv_pCurrent >= + &(*l_targetService.iv_targets)[l_targetService.iv_maxTargets-1]) + { + iv_pCurrent = NULL; + } + else + { + iv_pCurrent++; + } + } + else + { + iv_pCurrent = NULL; + } + } +} + +//****************************************************************************** +// Explicit template class member function instantiations +//****************************************************************************** + +template void _TargetIterator<Target*>::advance(); +template void _TargetIterator<const Target*>::advance(); + +#undef TARG_CLASS +#undef TARG_NAMESPACE + +} // End namespace TARGETING + + + |