summaryrefslogtreecommitdiffstats
path: root/src/include/usr/targeting/common/iterators
diff options
context:
space:
mode:
authorNick Bofferding <bofferdn@us.ibm.com>2012-04-17 22:30:59 -0500
committerA. Patrick Williams III <iawillia@us.ibm.com>2012-04-24 15:48:42 -0500
commit4157b5631a1bbfcc7f9f95480b54e9ade7abce7d (patch)
tree423f4f13a4a0e2d6e76898992a37b4d2db302b3b /src/include/usr/targeting/common/iterators
parent5631ede5d2e63fa8585505eb29c6d86f420c9344 (diff)
downloadtalos-hostboot-4157b5631a1bbfcc7f9f95480b54e9ade7abce7d.tar.gz
talos-hostboot-4157b5631a1bbfcc7f9f95480b54e9ade7abce7d.zip
Support targeting code commonality
- Moved common targeting code to own subtrees - Updated many components with header file changes - Implemented abstract pointer class - Implemented Hostboot specific support for targeting commonality - Changed attribute VMM base address to 4 GB (From 3 GB) - Removed tabs, fixed > 80 character lines Change-Id: Ie5a6956670bfa4f262f7691b4f0ce5a20ed289fe RTC: 35569 Reviewed-on: http://gfw160.austin.ibm.com:8080/gerrit/909 Tested-by: Jenkins Server Reviewed-by: A. Patrick Williams III <iawillia@us.ibm.com>
Diffstat (limited to 'src/include/usr/targeting/common/iterators')
-rw-r--r--src/include/usr/targeting/common/iterators/iterators.H39
-rw-r--r--src/include/usr/targeting/common/iterators/rangefilter.H341
-rw-r--r--src/include/usr/targeting/common/iterators/targetiterator.H279
3 files changed, 659 insertions, 0 deletions
diff --git a/src/include/usr/targeting/common/iterators/iterators.H b/src/include/usr/targeting/common/iterators/iterators.H
new file mode 100644
index 000000000..5339b33dd
--- /dev/null
+++ b/src/include/usr/targeting/common/iterators/iterators.H
@@ -0,0 +1,39 @@
+// IBM_PROLOG_BEGIN_TAG
+// This is an automatically generated prolog.
+//
+// $Source: src/include/usr/targeting/common/iterators/iterators.H $
+//
+// IBM CONFIDENTIAL
+//
+// COPYRIGHT International Business Machines Corp. 2012
+//
+// p1
+//
+// Object Code Only (OCO) source materials
+// Licensed Internal Code Source Materials
+// IBM HostBoot Licensed Internal Code
+//
+// The source code for this program is not published or other-
+// wise divested of its trade secrets, irrespective of what has
+// been deposited with the U.S. Copyright Office.
+//
+// Origin: 30
+//
+// IBM_PROLOG_END
+
+#ifndef __TARGETING_COMMON_ITERATORS_H
+#define __TARGETING_COMMON_ITERATORS_H
+
+/**
+ * @file targeting/common/iterators/iterators.H
+ *
+ * @brief Header file which aggregates all the iterator header files.
+ */
+
+#include <targeting/common/iterators/targetiterator.H>
+#include <targeting/common/iterators/rangefilter.H>
+
+// please keep up to date...
+
+#endif // __TARGETING_COMMON_ITERATORS_H
+
diff --git a/src/include/usr/targeting/common/iterators/rangefilter.H b/src/include/usr/targeting/common/iterators/rangefilter.H
new file mode 100644
index 000000000..b29cfa07d
--- /dev/null
+++ b/src/include/usr/targeting/common/iterators/rangefilter.H
@@ -0,0 +1,341 @@
+// IBM_PROLOG_BEGIN_TAG
+// This is an automatically generated prolog.
+//
+// $Source: src/include/usr/targeting/iterators/rangefilter.H $
+//
+// IBM CONFIDENTIAL
+//
+// COPYRIGHT International Business Machines Corp. 2011
+//
+// p1
+//
+// Object Code Only (OCO) source materials
+// Licensed Internal Code Source Materials
+// IBM HostBoot Licensed Internal Code
+//
+// The source code for this program is not published or other-
+// wise divested of its trade secrets, irrespective of what has
+// been deposited with the U.S. Copyright Office.
+//
+// Origin: 30
+//
+// IBM_PROLOG_END
+
+#ifndef __TARGETING_COMMON_RANGEFILTER_H
+#define __TARGETING_COMMON_RANGEFILTER_H
+
+/**
+ * @file targeting/common/iterators/rangefilter.H
+ *
+ * @brief Interface describing 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/common/target.H>
+#include <targeting/common/predicates/predicatebase.H>
+#include <targeting/common/iterators/targetiterator.H>
+
+//******************************************************************************
+// Macros
+//******************************************************************************
+
+#undef TARG_NAMESPACE
+#undef TARG_CLASS
+#undef TARG_FUNC
+
+//******************************************************************************
+// Interface
+//******************************************************************************
+
+namespace TARGETING
+{
+
+#define TARG_NAMESPACE "TARGETING::"
+
+#define TARG_CLASS "RangeFilter<IteratorType>::"
+
+/**
+ * @brief Templated class which which takes an iterator range of arbitrary type
+ * and allows caller to iterate through the elements which match a supplied
+ * predicate (filter)
+ */
+template<typename IteratorType>
+class RangeFilter
+{
+ public:
+
+ /**
+ * @var Forward the type of iterated elements to help build the
+ * class generically
+ */
+ typedef typename IteratorType::value_type value_type;
+
+ /**
+ * @var fake_bool is a pointer to a member function of RangeFilter
+ * which takes no arguments and returns void.
+ * Used to implement ability to check if range iterator is valid
+ */
+ typedef void (RangeFilter::*fake_bool)() const;
+
+ /**
+ * @brief Create a range object and locate first item in the range that
+ * matches the predicate (or the first if no predicate)
+ *
+ * @param[in] i_begin Iterator pointing to first item in range
+ * @param[in] i_end Iterator pointing to last item in range
+ * @param[in] i_pPredicate Predicate evaluated against each pointed to
+ * item
+ *
+ * @note Begin iterator must point to element prior to end iterator,
+ * otherwise result is undefined
+ */
+ RangeFilter(
+ const IteratorType& i_begin,
+ const IteratorType& i_end,
+ const PredicateBase* i_pPredicate = NULL);
+
+ /**
+ * @brief Destroy a range object (nothing to do)
+ */
+ ~RangeFilter()
+ {
+ }
+
+ /**
+ * @brief Dummy function used to implement ability to check if range
+ * iterator is valid
+ */
+ operator fake_bool() const;
+
+ /**
+ * @brief Pre-increment operator which advances the range's iterator
+ * to point to the next valid element
+ *
+ * @return Reference to this range filter
+ */
+ RangeFilter& operator++();
+
+ /**
+ * @brief Dereference the range filter, returning the element pointed
+ *
+ * @return The element pointed to by the range filter
+ */
+ value_type operator*() const
+ {
+ return *iv_current;
+ }
+
+ /**
+ * @brief Dereference the range filter, returning the element pointed
+ * for use by the dereference and call member operator
+ *
+ * @return The element pointed to by the range filter
+ */
+ value_type operator->() const
+ {
+ return *iv_current;
+ }
+
+ /**
+ * @brief Reset the range's internal iterator to point to the first
+ * item in the range that matches the predicate (or the first if no
+ * predicate)
+ */
+ void reset();
+
+ /**
+ * @brief Set the range's predicate filter
+ *
+ * @param[in] i_pPredicate Predicate to evaluate against elements
+ * pointed to by the range
+ */
+ void setPredicate(
+ const PredicateBase* i_pPredicate);
+
+ /**
+ * @brief Assignment operator; assign one range filter to another
+ *
+ * @param[in] i_rhs Range filter to assign
+ */
+ RangeFilter& operator=(
+ const RangeFilter& i_rhs);
+
+ /**
+ * @brief Copy constructor; create range filter using another range
+ * filter as a prototype for it
+ *
+ * @param[in] i_rhs Range filter to assign on create
+ */
+ RangeFilter(
+ const RangeFilter& i_rhs);
+
+ private:
+
+ /**
+ * @brief Update internal cursor to point to the next element of the
+ * underlying range
+ *
+ * @note If the internal cursor is at the end of the range, then do
+ * nothing
+ */
+ void advance();
+
+ /**
+ * @brief Update internal cursor to point to the next element of the
+ * underlying range only if not past the end of the range and the
+ * predicate doesn't match the current item
+ *
+ * @note If the internal cursor is at the end of the range, then do
+ * nothing
+ */
+ void advanceIfNoMatch();
+
+ /**
+ * @brief Dummy function used to implement ability to check if range
+ * iterator is valid
+ */
+ void notComparable() const
+ {
+ }
+
+ IteratorType iv_current; ///< Iterator pointing to the
+ ///< current element
+ IteratorType iv_begin; ///< Iterator pointing to first
+ ///< element in range
+ IteratorType iv_end; ///< Iterator to past the end
+ ///< element in range
+ const PredicateBase* iv_pPredicate; ///< Range filter
+};
+
+typedef RangeFilter<TargetIterator> TargetRangeFilter;
+typedef RangeFilter<ConstTargetIterator> ConstTargetRangeFilter;
+
+//******************************************************************************
+// RangeFilter::RangeFilter
+//******************************************************************************
+
+template<typename IteratorType>
+RangeFilter<IteratorType>::RangeFilter(
+ const IteratorType& i_begin,
+ const IteratorType& i_end,
+ const PredicateBase* const i_pPredicate)
+: iv_current(i_begin),
+ iv_begin(i_begin),
+ iv_end(i_end),
+ iv_pPredicate(i_pPredicate)
+{
+ advanceIfNoMatch();
+}
+
+//******************************************************************************
+// RangeFilter::operator=
+//******************************************************************************
+
+template<typename IteratorType>
+RangeFilter<IteratorType>& RangeFilter<IteratorType>::operator=(
+ const RangeFilter& i_rhs)
+{
+ iv_current = i_rhs.iv_current;
+ iv_begin = i_rhs.iv_begin;
+ iv_end = i_rhs.iv_end;
+ iv_pPredicate = i_rhs.iv_pPredicate;
+}
+
+//******************************************************************************
+// RangeFilter::RangeFilter (copy constructor)
+//******************************************************************************
+
+template<typename IteratorType>
+RangeFilter<IteratorType>::RangeFilter(
+ const RangeFilter& i_rhs)
+: iv_current(i_rhs.iv_current),
+ iv_begin(i_rhs.iv_begin),
+ iv_end(i_rhs.iv_end),
+ iv_pPredicate(i_rhs.iv_pPredicate)
+{
+}
+
+//******************************************************************************
+// RangeFilter::setPredicate
+//******************************************************************************
+
+template<typename IteratorType>
+void RangeFilter<IteratorType>::setPredicate(
+ const PredicateBase* const i_pPredicate)
+{
+ iv_pPredicate = i_pPredicate;
+ advanceIfNoMatch();
+}
+
+//******************************************************************************
+// RangeFilter::reset
+//******************************************************************************
+
+template<typename IteratorType>
+void RangeFilter<IteratorType>::reset()
+{
+ iv_current = iv_begin;
+ advanceIfNoMatch();
+}
+
+//******************************************************************************
+// RangeFilter::operator++
+//******************************************************************************
+
+template<typename IteratorType>
+RangeFilter<IteratorType>& RangeFilter<IteratorType>::operator++()
+{
+ advance();
+ return *this;
+}
+
+/**
+ * @brief Disable meaningless "bool" comparisons that can occur when
+ * evaluating a range as a bool by forcing a compilation failure.
+ * Function interfaces not documented since they are not used.
+ */
+template <typename T>
+bool operator!=(const TargetRangeFilter& i_lhs, const T& i_rhs)
+{
+ i_lhs.notComparable();
+ return false;
+}
+
+template <typename T>
+bool operator==(const TargetRangeFilter& i_lhs, const T& i_rhs)
+{
+ i_lhs.notComparable();
+ return false;
+}
+
+template <typename T>
+bool operator!=(const ConstTargetRangeFilter& i_lhs, const T& i_rhs)
+{
+ i_lhs.notComparable();
+ return false;
+}
+
+template <typename T>
+bool operator==(const ConstTargetRangeFilter& i_lhs, const T& i_rhs)
+{
+ i_lhs.notComparable();
+ return false;
+}
+
+#undef TARG_CLASS
+#undef TARG_NAMESPACE
+
+} // End namespace TARGETING
+
+#endif // __TARGETING_COMMON_RANGEFILTER
+
diff --git a/src/include/usr/targeting/common/iterators/targetiterator.H b/src/include/usr/targeting/common/iterators/targetiterator.H
new file mode 100644
index 000000000..5abb21f81
--- /dev/null
+++ b/src/include/usr/targeting/common/iterators/targetiterator.H
@@ -0,0 +1,279 @@
+// IBM_PROLOG_BEGIN_TAG
+// This is an automatically generated prolog.
+//
+// $Source: src/include/usr/targeting/iterators/targetiterator.H $
+//
+// IBM CONFIDENTIAL
+//
+// COPYRIGHT International Business Machines Corp. 2011
+//
+// p1
+//
+// Object Code Only (OCO) source materials
+// Licensed Internal Code Source Materials
+// IBM HostBoot Licensed Internal Code
+//
+// The source code for this program is not published or other-
+// wise divested of its trade secrets, irrespective of what has
+// been deposited with the U.S. Copyright Office.
+//
+// Origin: 30
+//
+// IBM_PROLOG_END
+
+#ifndef __TARGETING_COMMON_TARGETITERATOR_H
+#define __TARGETING_COMMON_TARGETITERATOR_H
+
+/**
+ * @file targeting/common/iterators/targetiterator.H
+ *
+ * @brief Interface describing iterator/const iterator used to iterate through
+ * target service targets
+ */
+
+//******************************************************************************
+// Includes
+//******************************************************************************
+
+// STD
+#include <stddef.h>
+
+// Other Host Boot Components
+#include <builtins.h>
+
+// Targeting Component
+
+//******************************************************************************
+// Macros
+//******************************************************************************
+
+#undef TARG_NAMESPACE
+#undef TARG_CLASS
+#undef TARG_FUNC
+
+//******************************************************************************
+// Interface
+//******************************************************************************
+
+namespace TARGETING
+{
+
+#define TARG_NAMESPACE "TARGETING::"
+
+#define TARG_CLASS "_TargetIterator<T>::"
+
+class Target;
+
+/**
+ * @brief Class which iterates through targets managed by the target service.
+ * Provides "Target*" and "const Target*" versions via templates
+ */
+template<typename T>
+class _TargetIterator
+{
+ public:
+
+ /**
+ * @brief Maps type of iterated element to common alias (Target* or
+ * const Target*)
+ */
+ typedef T iterator;
+ typedef T value_type;
+
+ /**
+ * @brief Create an iterator to a (const/non-const) target handle.
+ * Defaults to end()
+ */
+ ALWAYS_INLINE
+ _TargetIterator()
+ : iv_pCurrent(NULL)
+ {
+ }
+
+ /**
+ * @brief Create an iterator to a (const/non-const) target handle
+ *
+ * @param[in] i_pTarget Target handle (pointer or const pointer
+ * depending on flavor) the iterator should reference
+ */
+ ALWAYS_INLINE
+ explicit _TargetIterator(T i_pTarget)
+ : iv_pCurrent(i_pTarget)
+ {
+ }
+
+ /**
+ * @brief Destroy an iterator to a (const/non-const) target handle
+ *
+ * @note Iterator does not own any resources to destroy
+ */
+ ALWAYS_INLINE
+ ~_TargetIterator()
+ {
+ }
+
+ /**
+ * @brief Dereference the iterator (return what it points to)
+ *
+ * @return Target handle in form of Target* or const Target*
+ *
+ * @note Returns NULL if it points to end(), should not be
+ * dereferenced in this case.
+ */
+ ALWAYS_INLINE
+ T operator* () const
+ {
+ // Only return copy of the target pointer (instead of a reference)
+ // because a reference will go out of scope when the iterator
+ // advances
+ return iv_pCurrent;
+ }
+
+ /**
+ * @brief Dereference the iterator (return what it points to)
+ * and (outside this function) call a function/member of
+ * the referenced target
+ *
+ * @return Target handle in form of Target* or const Target*
+ *
+ * @note Returns NULL if it points to end(), causing an
+ * assert when automatically dereferenced.
+ */
+ ALWAYS_INLINE
+ T operator->() const
+ {
+ // Only return copy of the target pointer (instead of a reference)
+ // because a reference will go out of scope when the iterator
+ // advances
+ return iv_pCurrent;
+ }
+
+ /**
+ * @brief Pre-increment the iterator
+ *
+ * @return The reference to the same iterator after advancing it
+ */
+ ALWAYS_INLINE
+ _TargetIterator& operator++();
+
+ /**
+ * @brief Post-increment the iterator
+ *
+ * @param[in] UNNAMED Dummy parameter used to distinguish
+ * this interface from pre-increment
+ *
+ * @return Copy of the original iterator before it advanced
+ */
+ ALWAYS_INLINE
+ _TargetIterator operator++(int);
+
+ /**
+ * @brief Determine if two iterators of same type are logically equal
+ *
+ * @param[in] i_rhs The other iterator to compare
+ *
+ * @return bool indicating whether the iterators point to the same
+ * entity
+ *
+ * @retval true Iterators point to same entity
+ * @retval false Iterators do not point to same entity
+ */
+ ALWAYS_INLINE
+ bool operator==(const _TargetIterator& i_rhs) const
+ {
+ return (iv_pCurrent == i_rhs.iv_pCurrent);
+ }
+
+ /**
+ * @brief Determine if two iterators of same type are logically not
+ * equal
+ *
+ * @param[in] i_rhs The other iterator to compare
+ *
+ * @return bool indicating whether the iterators point to a different
+ * logical entity
+ *
+ * @retval true Iterators point to different entity
+ * @retval false Iterators point to same entity
+ */
+ ALWAYS_INLINE
+ bool operator!=(const _TargetIterator& i_rhs) const
+ {
+ return (iv_pCurrent != i_rhs.iv_pCurrent);
+ }
+
+ /**
+ * @brief Assignment operator; assign iterator to another (such that
+ * they logically point to same entity)
+ *
+ * @param[in] i_rhs The iterator to assign
+ *
+ * @return Reference to the iterator, now updated to point to the same
+ * entity as the input iterator points to
+ */
+ ALWAYS_INLINE
+ _TargetIterator& operator=(const _TargetIterator& i_rhs)
+ {
+ iv_pCurrent = i_rhs.iv_pCurrent;
+ return *this;
+ }
+
+ /**
+ * @brief Copy constructor; assign iterator to a new iterator (such
+ * that they logically point to same entity)
+ *
+ * @param[in] i_rhs The iterator to assign
+ */
+ ALWAYS_INLINE
+ _TargetIterator(const _TargetIterator& i_rhs)
+ : iv_pCurrent(i_rhs.iv_pCurrent)
+ {
+ }
+
+ private:
+
+ /**
+ * @brief Advance the iterator to point to the next item maintained by
+ * the target service (or end() if end of list)
+ */
+ void advance();
+
+ T iv_pCurrent; // Pointer to current target
+};
+
+/**
+ * @brief Type aliases to simplify user code
+ */
+typedef _TargetIterator<Target*> TargetIterator;
+typedef _TargetIterator<const Target*> ConstTargetIterator;
+
+//******************************************************************************
+// _TargetIterator::operator++ (postincrement)
+//******************************************************************************
+
+template<typename T>
+_TargetIterator<T> _TargetIterator<T>::operator++(int)
+{
+ _TargetIterator l_originalIterator(*this);
+ advance();
+ return l_originalIterator;
+}
+
+//******************************************************************************
+// _TargetIterator::operator++ (preincrement)
+//******************************************************************************
+
+template<typename T>
+_TargetIterator<T>& _TargetIterator<T>::operator++()
+{
+ advance();
+ return *this;
+}
+
+#undef TARG_CLASS
+#undef TARG_NAMESPACE
+
+} // End namespace TARGETING
+
+#endif // __TARGETING_COMMON_TARGETITERATOR_H
+
OpenPOWER on IntegriCloud