diff options
author | Nick Bofferding <bofferdn@us.ibm.com> | 2011-08-16 12:40:36 -0500 |
---|---|---|
committer | Nicholas E. Bofferding <bofferdn@us.ibm.com> | 2011-08-23 14:10:24 -0500 |
commit | 213b45cd7d8b0367f85ee68b79941f6d548c1e9c (patch) | |
tree | 8f78e3999420f6b1b2ca00ccb79f88cf54441d5c /src/usr/targeting/iterators | |
parent | 91b39e52483cc5a8cc1cb7c7d15c281a150d9572 (diff) | |
download | talos-hostboot-213b45cd7d8b0367f85ee68b79941f6d548c1e9c.tar.gz talos-hostboot-213b45cd7d8b0367f85ee68b79941f6d548c1e9c.zip |
Add target iterator and predicate support
Change-Id: I728bb312277591d81c0575e74878fba9f816b962
Reviewed-on: http://gfw160.austin.ibm.com:8080/gerrit/260
Tested-by: Jenkins Server
Reviewed-by: A. Patrick Williams III <iawillia@us.ibm.com>
Reviewed-by: MIKE J. JONES <mjjones@us.ibm.com>
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 + + + |