GCC Code Coverage Report


Directory: codebase/
File: codebase/interface/include/public/api.ListIterator.hpp
Date: 2023-03-16 04:37:09
Exec Total Coverage
Lines: 1 1 100.0%
Functions: 1 2 50.0%
Branches: 0 0 -%

Line Branch Exec Source
1 /**
2 * @file api.ListIterator.hpp
3 * @author Sergey Baigudin, sergey@baigudin.software
4 * @copyright 2016-2022, Sergey Baigudin, Baigudin Software
5 */
6 #ifndef API_LISTITERATOR_HPP_
7 #define API_LISTITERATOR_HPP_
8
9 #include "api.Iterator.hpp"
10
11 namespace eoos
12 {
13 namespace api
14 {
15
16 /**
17 * @class ListIterator<T>
18 * @brief List iterator interface.
19 *
20 * @tparam T Data type of list iterator element.
21 */
22 template <typename T>
23 class ListIterator : public Iterator<T>
24 {
25
26 public:
27
28 static const int32_t ERROR_INDEX = -2147483646;
29
30 /**
31 * @brief Destructor.
32 */
33 virtual ~ListIterator() = 0;
34
35 /**
36 * @brief Inserts the specified element into the list.
37 *
38 * Function inserts a given element before the element
39 * that will be returned by the getNext() function.
40 * Therefore subsequent call to getNext() will be unaffected,
41 * and a subsequent call to getPrevious() will return the inserted element.
42 *
43 * @note A passed element must be copied to an internal data structure of
44 * a realizing class by calling a copy constructor so that the element
45 * might be invalidated after the function called.
46 *
47 * @param element An inserting element.
48 * @return True if element is added.
49 */
50 virtual bool_t add(T const& element) = 0;
51
52 /**
53 * @brief Returns previous element and advances the cursor backwards.
54 *
55 * @return Reference to element.
56 *
57 * @todo Declare constant function to satisfy MISRA-C++:2008 Rule 9–3–1
58 */
59 virtual T& getPrevious() = 0;
60
61 /**
62 * @brief Tests if this iteration may return a previous element.
63 *
64 * @return True if previous element is had.
65 */
66 virtual bool_t hasPrevious() const = 0;
67
68 /**
69 * @brief Returns the index of the element that would be returned by a subsequent call to getNext().
70 *
71 * @return For LinkedList: Index of the next element or list size if the list iterator is at the end of the list.
72 * For CircularList: Index of the previous element or -1 if the list is empty.
73 * On error ERROR_INDEX is returned.
74 */
75 virtual int32_t getNextIndex() const = 0;
76
77 /**
78 * @brief Returns the index of the element that would be returned by a subsequent call to getPrevious().
79 *
80 * @return For LinkedList: Index of the previous element or -1 if the the iterator is at the beginning of the list.
81 * For CircularList: Index of the previous element or -1 if the list is empty.
82 * On error ERROR_INDEX is returned.
83 */
84 virtual int32_t getPreviousIndex() const = 0;
85
86 };
87
88 template <typename T> ///< SCA MISRA-C++:2008 Defected Rule 7-3-1
89 72 inline ListIterator<T>::~ListIterator() {}
90
91 } // namespace api
92 } // namespace eoos
93 #endif // API_LISTITERATOR_HPP_
94