Directory: | ./ |
---|---|
File: | Core/singleton.tpp |
Date: | 2024-04-14 07:32:34 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 4 | 8 | 50.0% |
Branches: | 6 | 14 | 42.9% |
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: Cedric Doucet | ||
13 | // | ||
14 | |||
15 | #ifndef SINGLETON_TPP | ||
16 | #define SINGLETON_TPP | ||
17 | |||
18 | #ifndef SINGLETON_HPP | ||
19 | #error Include singleton.hpp instead | ||
20 | #endif | ||
21 | |||
22 | // System includes | ||
23 | #include <cstddef> | ||
24 | |||
25 | // External includes | ||
26 | |||
27 | // Project includes | ||
28 | |||
29 | namespace felisce | ||
30 | { | ||
31 | |||
32 | template<class T> | ||
33 | ✗ | Singleton<T>::~Singleton() | |
34 | { | ||
35 | ✗ | for (auto& r_map : m_instance) { | |
36 | ✗ | delete r_map.second; | |
37 | } | ||
38 | ✗ | m_instance.clear(); | |
39 | } | ||
40 | |||
41 | /***********************************************************************************/ | ||
42 | /***********************************************************************************/ | ||
43 | |||
44 | template<class T> | ||
45 | 96428224 | T& Singleton<T>::instance(const std::size_t instanceIndex) { | |
46 |
3/4✓ Branch 2 taken 67213797 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 432 times.
✓ Branch 6 taken 67213365 times.
|
96428224 | if (m_instance.find(instanceIndex) == m_instance.end()) { |
47 |
3/6✓ Branch 2 taken 428 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 428 times.
✗ Branch 7 not taken.
|
948 | m_instance.insert({instanceIndex, new T(instanceIndex)}); |
48 | } | ||
49 | 96428224 | return *m_instance[instanceIndex]; | |
50 | } | ||
51 | |||
52 | /***********************************************************************************/ | ||
53 | /***********************************************************************************/ | ||
54 | |||
55 | template <class T> | ||
56 | std::unordered_map<std::size_t, T*> Singleton<T>::m_instance; | ||
57 | |||
58 | } // namespace felisce | ||
59 | |||
60 | |||
61 | #endif // SINGLETON_TPP | ||
62 |