GCC Code Coverage Report


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

Line Branch Exec Source
1 /**
2 * @file api.List.hpp
3 * @author Sergey Baigudin, sergey@baigudin.software
4 * @copyright 2014-2022, Sergey Baigudin, Baigudin Software
5 */
6 #ifndef API_LIST_HPP_
7 #define API_LIST_HPP_
8
9 #include "api.Collection.hpp"
10 #include "api.IllegalValue.hpp"
11 #include "api.ListIterator.hpp"
12
13 namespace eoos
14 {
15 namespace api
16 {
17
18 /**
19 * @class List<T>
20 * @brief List interface.
21 *
22 * @tparam T Data type of list element.
23 */
24 template <typename T>
25 class List : public Collection<T>, public IllegalValue<T>
26 {
27
28 public:
29
30 static const int32_t ERROR_INDEX = -2147483647;
31
32 /**
33 * @brief Destructor.
34 */
35 virtual ~List() = 0;
36
37 /**
38 * @brief Inserts new element to the end of this container.
39 *
40 * @note A passed element must be copied to an internal data structure of
41 * a realizing class by calling a copy constructor so that the element
42 * might be invalidated after the function called.
43 *
44 * @param element An inserting element.
45 * @return True if element is added.
46 */
47 virtual bool_t add(T const& element) = 0;
48
49 /**
50 * @brief Inserts new element to the specified position in this container.
51 *
52 * @note A passed element must be copied to an internal data structure of
53 * a realizing class by calling a copy constructor so that the element
54 * might be invalidated after the function called.
55 *
56 * @param index A position in this container.
57 * @param element An inserting element.
58 * @return True if element is inserted.
59 */
60 virtual bool_t add(int32_t index, T const& element) = 0;
61
62 /**
63 * @brief Removes all elements from this container.
64 */
65 virtual void clear() = 0;
66
67 /**
68 * @brief Removes the element at the specified position in this container.
69 *
70 * @param index Position in this container.
71 * @return True if an element is removed successfully.
72 */
73 virtual bool_t remove(int32_t index) = 0;
74
75 /**
76 * @brief Removes the first element from this container.
77 *
78 * @return True if an element is removed successfully.
79 */
80 virtual bool_t removeFirst() = 0;
81
82 /**
83 * @brief Removes the last element from this container.
84 *
85 * @return True if an element is removed successfully.
86 */
87 virtual bool_t removeLast() = 0;
88
89 /**
90 * @brief Removes the first occurrence of the specified element from this container.
91 *
92 * @param element Reference to element.
93 * @return True if an element is removed successfully.
94 */
95 virtual bool_t removeElement(T const& element) = 0;
96
97 /**
98 * @brief Returns an element from this container by index.
99 *
100 * @param index Position in this container.
101 * @return Indexed element of this container.
102 *
103 * @todo Declare constant function to satisfy MISRA-C++:2008 Rule 9–3–1
104 */
105 virtual T& get(int32_t index) = 0;
106
107 /**
108 * @brief Returns the first element in this container.
109 *
110 * @return The first element in this container.
111 *
112 * @todo Declare constant function to satisfy MISRA-C++:2008 Rule 9–3–1
113 */
114 virtual T& getFirst() = 0;
115
116 /**
117 * @brief Returns the last element in this container.
118 *
119 * @return The last element in this container.
120 *
121 * @todo Declare constant function to satisfy MISRA-C++:2008 Rule 9–3–1
122 */
123 virtual T& getLast() = 0;
124
125 /**
126 * @brief Returns a list iterator of this container elements.
127 *
128 * @note Either the delete operator must be called for returned value when
129 * the iterating of a collection has been completed, or returned raw pointer
130 * assigned to a smart pointer.
131 *
132 * @note Given index must not be out of bounds (index < 0 || index > length()) for LinkedList
133 * and out of bounds (index < 0 || index >= length()) for CircularList
134 *
135 * @note Modification of the list by the list functions is not desirable
136 * if operability of the returned iterator has to be.
137 *
138 * @param index Start position in this container.
139 * @return Pointer to new list iterator.
140 *
141 * @todo Declare constant function to satisfy MISRA-C++:2008 Rule 9–3–1
142 */
143 virtual ListIterator<T>* getListIterator(int32_t index=0) = 0;
144
145 /**
146 * @brief Returns the index of the first occurrence of the specified element in this container.
147 *
148 * @param element Reference to the element.
149 * @return Index or ERROR_INDEX if this container does not contain the element.
150 */
151 virtual int32_t getIndexOf(T const& element) const = 0;
152
153 /**
154 * @brief Tests if given index is available.
155 *
156 * @param index Checking position in this container.
157 * @return True if index is present.
158 */
159 virtual bool_t isIndex(int32_t index) const = 0;
160
161 };
162
163 template <typename T> ///< SCA MISRA-C++:2008 Defected Rule 7-3-1
164 152 inline List<T>::~List() {}
165
166 } // namespace api
167 } // namespace eoos
168 #endif // API_LIST_HPP_
169