Branch data Line data Source code
1 : : #ifndef AMR_active_element_store_h
2 : : #define AMR_active_element_store_h
3 : :
4 : : #include <set>
5 : : #include <cassert>
6 : :
7 : : namespace AMR {
8 : :
9 : : class active_element_store_t {
10 : : private:
11 : : std::set<size_t> active_elements;
12 : : public:
13 : :
14 : : //! Non-const-ref access to state
15 : 14279 : std::set<size_t>& data() { return active_elements; }
16 : :
17 : : /**
18 : : * @brief Function to add active elements
19 : : *
20 : : * @param id The master_id this should map to
21 : : */
22 : : void add(size_t id)
23 : : {
24 : : // Check if that active element already exists
25 : : // cppcheck-suppress assertWithSideEffect
26 : : assert( !exists(id) );
27 : : active_elements.insert(id);
28 : : }
29 : :
30 : : void erase(size_t id)
31 : : {
32 : : active_elements.erase(id);
33 : : }
34 : :
35 : : /**
36 : : * @brief function to check if an active element exists in the
37 : : * active_elements store
38 : : *
39 : : * @param id The id of the element to check
40 : : *
41 : : * @return A bool for if the element was found or no
42 : : */
43 : : bool exists(size_t id) const
44 : : {
45 [ + + ][ + + ]: 1637056 : if (active_elements.find(id) != active_elements.end())
[ + + ][ + + ]
[ + + ][ + + ]
[ + - ]
46 : : {
47 : : return true;
48 : : }
49 : : return false;
50 : : }
51 : :
52 : : void replace(size_t old_id, size_t new_id)
53 : : {
54 : : erase(old_id);
55 : : add(new_id);
56 : : }
57 : : };
58 : : }
59 : :
60 : : #endif // guard
|