GCC Code Coverage Report


Directory: codebase/
File: codebase/library/include/public/lib.Object.hpp
Date: 2023-03-16 04:37:09
Exec Total Coverage
Lines: 33 33 100.0%
Functions: 18 20 90.0%
Branches: 12 18 66.7%

Line Branch Exec Source
1 /**
2 * @file Object.hpp
3 * @author Sergey Baigudin, sergey@baigudin.software
4 * @copyright 2014-2022, Sergey Baigudin, Baigudin Software
5 */
6 #ifndef LIB_OBJECT_HPP_
7 #define LIB_OBJECT_HPP_
8
9 #include "api.Object.hpp"
10 #include "lib.ObjectAllocator.hpp"
11
12 namespace eoos
13 {
14 namespace lib
15 {
16
17 /**
18 * @class Object<A>
19 * @brief Root class of the class hierarchy.
20 *
21 * @tparam A Heap memory allocator class.
22 */
23 template <class A = Allocator>
24 class Object : public ObjectAllocator<A>, public api::Object
25 {
26
27 public:
28
29 /**
30 * @brief Constructor.
31 */
32 2354 Object() : ObjectAllocator<A>(), api::Object(),
33 2354 isConstructed_ (true){
34 2354 }
35
36 /**
37 * @brief Destructor.
38 */
39 4594 virtual ~Object()
40 {
41 4590 isConstructed_ = false;
42
0/2
✗ Branch 1 not taken.
✗ Branch 2 not taken.
4594 }
43
44 /**
45 * @brief Copy constructor.
46 *
47 * @param obj Reference to a source object.
48 */
49 28 Object(Object const& obj) : ObjectAllocator<A>(obj), api::Object(obj),
50 28 isConstructed_(obj.isConstructed_){
51 28 }
52
53
54 /**
55 * @brief Copy assignment operator.
56 *
57 * @param obj Reference to a source object.
58 * @return Reference to this object.
59 */
60 15 Object& operator=(Object const& obj)
61 {
62
3/6
✓ Branch 1 taken 15 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 15 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 15 times.
✗ Branch 6 not taken.
15 if( isConstructed() && (this != &obj) )
63 {
64 15 isConstructed_ = obj.isConstructed_;
65 }
66 15 return *this;
67 }
68
69 #if EOOS_CPP_STANDARD >= 2011
70
71 /**
72 * @brief Move constructor.
73 *
74 * @param obj Right reference to a source object.
75 */
76 5 Object(Object&& obj) noexcept :
77 5 isConstructed_(obj.isConstructed_){
78 5 obj.setConstructed(false);
79 5 }
80
81 /**
82 * @brief Move assignment operator.
83 *
84 * @param obj Right reference to a source object.
85 * @return Reference to this object.
86 */
87 32 Object& operator=(Object&& obj) & noexcept
88 {
89
5/6
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 31 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 31 times.
✓ Branch 6 taken 1 times.
32 if( this != &obj && isConstructed() )
90 {
91 31 isConstructed_ = obj.isConstructed_;
92 31 obj.setConstructed(false);
93 }
94 32 return *this;
95 }
96
97 #endif // EOOS_CPP_STANDARD >= 2011
98
99 /**
100 * @copydoc eoos::api::Object::isConstructed()
101 */
102 11219 virtual bool_t isConstructed() const
103 {
104 11219 return isConstructed_;
105 }
106
107 /**
108 * @brief Tests if an object has been constructed.
109 *
110 * @param obj Object to be tested.
111 * @return True if object has been constructed successfully.
112 */
113 67 static bool_t isConstructed(api::Object* const obj)
114 {
115 67 bool_t isConstructed( false );
116
2/2
✓ Branch 0 taken 65 times.
✓ Branch 1 taken 2 times.
67 if(obj != NULLPTR)
117 {
118 65 isConstructed = obj->isConstructed();
119 }
120 67 return isConstructed;
121 }
122
123 protected:
124
125 /**
126 * @brief Sets the object constructed flag.
127 *
128 * @param flag A new constructed flag.
129 */
130 1924 void setConstructed(bool_t const flag)
131 {
132
2/2
✓ Branch 0 taken 1842 times.
✓ Branch 1 taken 6 times.
1924 if( isConstructed_ == true )
133 {
134 1918 isConstructed_ = flag;
135 }
136 1924 }
137
138 private:
139
140 /**
141 * @brief This object constructed flag.
142 */
143 bool_t isConstructed_;
144
145 };
146
147 } // namespace lib
148 } // namespace eoos
149
150 #endif // LIB_OBJECT_HPP_
151