GCC Code Coverage Report


Directory: codebase/
File: codebase/system/include/private/sys.Heap.hpp
Date: 2023-03-16 04:37:09
Exec Total Coverage
Lines: 21 22 95.5%
Functions: 6 6 100.0%
Branches: 4 6 66.7%

Line Branch Exec Source
1 /**
2 * @file sys.Heap.hpp
3 * @author Sergey Baigudin, sergey@baigudin.software
4 * @copyright 2022, Sergey Baigudin, Baigudin Software
5 */
6 #ifndef SYS_HEAP_HPP_
7 #define SYS_HEAP_HPP_
8
9 #include "sys.NonCopyable.hpp"
10 #include "api.Heap.hpp"
11
12 namespace eoos
13 {
14 namespace sys
15 {
16
17 /**
18 * @class Heap.
19 * @brief Heap class.
20 */
21 class Heap : public NonCopyable, public api::Heap
22 {
23 typedef NonCopyable Parent;
24
25 public:
26
27 /**
28 * @brief Constructor.
29 */
30 184 Heap()
31 184 : NonCopyable()
32 184 , api::Heap() {
33
1/2
✓ Branch 1 taken 184 times.
✗ Branch 2 not taken.
184 bool_t const isConstructed( construct() );
34 184 setConstructed( isConstructed );
35 184 }
36
37 /**
38 * @brief Destructor.
39 */
40 368 virtual ~Heap()
41 {
42 }
43
44 /**
45 * @copydoc eoos::api::Object::isConstructed()
46 */
47 368 virtual bool_t isConstructed() const ///< SCA MISRA-C++:2008 Justified Rule 10-3-1
48 {
49 368 return Parent::isConstructed();
50 }
51
52 /**
53 * @copydoc eoos::api::Heap::allocate(size_t,void*)
54 */
55 593 virtual void* allocate(size_t const size, void* ptr)
56 {
57 static_cast<void>(ptr); // Avoid MISRA-C++:2008 Rule 0–1–3 and AUTOSAR C++14 Rule A0-1-4
58 #ifdef EOOS_ENABLE_DYNAMIC_HEAP_MEMORY
59 593 return new ucell_t[size];
60 #else
61 static_cast<void>(size); // Avoid MISRA-C++:2008 Rule 0–1–3 and AUTOSAR C++14 Rule A0-1-4
62 return NULLPTR;
63 #endif // EOOS_ENABLE_DYNAMIC_HEAP_MEMORY
64 }
65
66 /**
67 * @copydoc eoos::api::Heap::free(void*)
68 */
69 588 virtual void free(void* ptr)
70 {
71 #ifdef EOOS_ENABLE_DYNAMIC_HEAP_MEMORY
72 588 ucell_t* const mem( reinterpret_cast<ucell_t* const>(ptr) ); ///< SCA MISRA-C++:2008 Justified Rule 5-2-8
73
2/2
✓ Branch 0 taken 587 times.
✓ Branch 1 taken 1 times.
588 delete[] mem;
74 #else
75 static_cast<void>(ptr); // Avoid MISRA-C++:2008 Rule 0–1–3 and AUTOSAR C++14 Rule A0-1-4
76 #endif // EOOS_ENABLE_DYNAMIC_HEAP_MEMORY
77 588 }
78
79 private:
80
81 /**
82 * @brief Constructor.
83 *
84 * @return True if object has been constructed successfully.
85 */
86 184 bool_t construct() const
87 {
88 184 bool_t res( false );
89 while(true)
90 {
91
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 184 times.
184 if( !isConstructed() )
92 { ///< UT Justified Branch: HW dependency
93 break;
94 }
95 184 res = true;
96 184 break;
97 }
98 184 return res;
99 }
100
101 };
102
103 } // namespace sys
104 } // namespace eoos
105 #endif // SYS_HEAP_HPP_
106