Directory: | ./ |
---|---|
File: | Core/indexed_object.hpp |
Date: | 2024-04-14 07:32:34 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 21 | 24 | 87.5% |
Branches: | 4 | 10 | 40.0% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | // ______ ______ _ _ _____ ______ | ||
2 | // | ____| ____| | (_)/ ____| | ____| | ||
3 | // | |__ | |__ | | _| (___ ___| |__ | ||
4 | // | __| | __| | | | |\___ \ / __| __| | ||
5 | // | | | |____| |____| |____) | (__| |____ | ||
6 | // |_| |______|______|_|_____/ \___|______| | ||
7 | // Finite Elements for Life Sciences and Engineering | ||
8 | // | ||
9 | // License: LGL2.1 License | ||
10 | // FELiScE default license: LICENSE in root folder | ||
11 | // | ||
12 | // Main authors: Vicente Mataix Ferrandiz | ||
13 | // | ||
14 | // | ||
15 | |||
16 | #if !defined(FELISCE_INDEXED_OBJECT_H_INCLUDED ) | ||
17 | #define FELISCE_INDEXED_OBJECT_H_INCLUDED | ||
18 | |||
19 | // System includes | ||
20 | |||
21 | // External includes | ||
22 | |||
23 | // Project includes | ||
24 | #include "Core/felisce.hpp" | ||
25 | #include "Core/shared_pointers.hpp" | ||
26 | |||
27 | namespace felisce | ||
28 | { | ||
29 | |||
30 | ///@name felisce Globals | ||
31 | ///@{ | ||
32 | |||
33 | ///@} | ||
34 | ///@name Type Definitions | ||
35 | ///@{ | ||
36 | |||
37 | ///@} | ||
38 | ///@name Enum's | ||
39 | ///@{ | ||
40 | |||
41 | ///@} | ||
42 | ///@name Functions | ||
43 | ///@{ | ||
44 | |||
45 | ///@} | ||
46 | ///@name felisce Classes | ||
47 | ///@{ | ||
48 | |||
49 | /** | ||
50 | * @class IndexedObject | ||
51 | * @ingroup Core | ||
52 | * @brief This object defines an indexed object | ||
53 | * @details It is used as base of any class which must be indexed | ||
54 | * @author Vicente Mataix Ferrandiz | ||
55 | */ | ||
56 | class IndexedObject | ||
57 | { | ||
58 | public: | ||
59 | ///@name Type Definitions | ||
60 | ///@{ | ||
61 | |||
62 | /// Pointer definition of IndexedObject | ||
63 | FELISCE_CLASS_POINTER_DEFINITION(IndexedObject); | ||
64 | |||
65 | /// This defines the index type | ||
66 | typedef std::size_t IndexType; | ||
67 | |||
68 | ///@} | ||
69 | ///@name Life Cycle | ||
70 | ///@{ | ||
71 | |||
72 | /// Default constructor. | ||
73 | 6 | explicit IndexedObject(IndexType NewId = 0) : mId(NewId) {} | |
74 | |||
75 | /// Destructor. | ||
76 | 14 | virtual ~IndexedObject() {} | |
77 | |||
78 | /// Copy constructor. | ||
79 | 1 | IndexedObject(IndexedObject const& rOther) : mId(rOther.mId) {} | |
80 | |||
81 | ///@} | ||
82 | ///@name Operators | ||
83 | ///@{ | ||
84 | |||
85 | /// Assignment operator. | ||
86 | 1 | IndexedObject& operator=(IndexedObject const& rOther) | |
87 | { | ||
88 | 1 | mId = rOther.mId; | |
89 | |||
90 | 1 | return *this; | |
91 | } | ||
92 | |||
93 | template<class TObjectType> | ||
94 | 2 | IndexType operator()(TObjectType const& rThisObject) const | |
95 | { | ||
96 | 2 | return rThisObject.Id(); | |
97 | } | ||
98 | |||
99 | ///@} | ||
100 | ///@name Operations | ||
101 | ///@{ | ||
102 | |||
103 | ///@} | ||
104 | ///@name Access | ||
105 | ///@{ | ||
106 | |||
107 | 18 | IndexType Id() const | |
108 | { | ||
109 | 18 | return mId; | |
110 | } | ||
111 | |||
112 | 4 | IndexType GetId() const | |
113 | { | ||
114 | 4 | return mId; | |
115 | } | ||
116 | |||
117 | 1 | virtual void SetId(IndexType NewId) | |
118 | { | ||
119 | 1 | mId = NewId; | |
120 | 1 | } | |
121 | |||
122 | ///@} | ||
123 | ///@name Inquiry | ||
124 | ///@{ | ||
125 | |||
126 | ///@} | ||
127 | ///@name Input and output | ||
128 | ///@{ | ||
129 | |||
130 | /// Turn back information as a string. | ||
131 | 2 | virtual std::string Info() const | |
132 | { | ||
133 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | std::stringstream buffer; |
134 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | buffer << "indexed object # " |
135 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | << mId; |
136 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
4 | return buffer.str(); |
137 | 2 | } | |
138 | |||
139 | /// Print information about this object. | ||
140 | ✗ | virtual void PrintInfo(std::ostream& rOStream) const | |
141 | { | ||
142 | ✗ | rOStream << Info(); | |
143 | } | ||
144 | |||
145 | /// Print object's data. | ||
146 | ✗ | virtual void PrintData(std::ostream& rOStream) const | |
147 | { | ||
148 | IGNORE_UNUSED_ARGUMENT(rOStream); | ||
149 | } | ||
150 | |||
151 | ///@} | ||
152 | ///@name Friends | ||
153 | ///@{ | ||
154 | |||
155 | ///@} | ||
156 | |||
157 | protected: | ||
158 | ///@name Protected static Member Variables | ||
159 | ///@{ | ||
160 | |||
161 | ///@} | ||
162 | ///@name Protected member Variables | ||
163 | ///@{ | ||
164 | |||
165 | ///@} | ||
166 | ///@name Protected Operators | ||
167 | ///@{ | ||
168 | |||
169 | ///@} | ||
170 | ///@name Protected Operations | ||
171 | ///@{ | ||
172 | |||
173 | ///@} | ||
174 | ///@name Protected Access | ||
175 | ///@{ | ||
176 | |||
177 | ///@} | ||
178 | ///@name Protected Inquiry | ||
179 | ///@{ | ||
180 | |||
181 | ///@} | ||
182 | ///@name Protected LifeCycle | ||
183 | ///@{ | ||
184 | |||
185 | ///@} | ||
186 | private: | ||
187 | ///@name Static Member Variables | ||
188 | ///@{ | ||
189 | |||
190 | ///@} | ||
191 | ///@name Member Variables | ||
192 | ///@{ | ||
193 | |||
194 | IndexType mId; | ||
195 | |||
196 | ///@} | ||
197 | ///@name Private Operators | ||
198 | ///@{ | ||
199 | |||
200 | ///@} | ||
201 | ///@name Private Operations | ||
202 | ///@{ | ||
203 | |||
204 | ///@} | ||
205 | ///@name Private Access | ||
206 | ///@{ | ||
207 | |||
208 | ///@} | ||
209 | ///@name Private Inquiry | ||
210 | ///@{ | ||
211 | |||
212 | ///@} | ||
213 | ///@name Un accessible methods | ||
214 | ///@{ | ||
215 | |||
216 | ///@} | ||
217 | |||
218 | }; // Class IndexedObject | ||
219 | |||
220 | ///@} | ||
221 | |||
222 | ///@name Type Definitions | ||
223 | ///@{ | ||
224 | |||
225 | |||
226 | ///@} | ||
227 | ///@name Input and output | ||
228 | ///@{ | ||
229 | |||
230 | |||
231 | /// input stream function | ||
232 | inline std::istream& operator >> (std::istream& rIStream, | ||
233 | IndexedObject& rThis); | ||
234 | |||
235 | /// output stream function | ||
236 | inline std::ostream& operator << (std::ostream& rOStream, | ||
237 | const IndexedObject& rThis) | ||
238 | { | ||
239 | rThis.PrintInfo(rOStream); | ||
240 | rOStream << std::endl; | ||
241 | rThis.PrintData(rOStream); | ||
242 | |||
243 | return rOStream; | ||
244 | } | ||
245 | ///@} | ||
246 | |||
247 | |||
248 | } // namespace felisce. | ||
249 | |||
250 | #endif // FELISCE_INDEXED_OBJECT_H_INCLUDED defined | ||
251 | |||
252 | |||
253 |