Directory: | ./ |
---|---|
File: | demos/four_int_values.cpp |
Date: | 2022-06-30 06:29:57 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 26 | 30 | 86.7% |
Branches: | 9 | 18 | 50.0% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /** | ||
2 | * @file four_int_values.cpp | ||
3 | * @author Vincent Berenz | ||
4 | * @license License BSD-3-Clause | ||
5 | * @copyright Copyright (c) 2019, New York University and Max Planck | ||
6 | * Gesellschaft. | ||
7 | * @date 2019-05-22 | ||
8 | * | ||
9 | * @brief Demonstrate how to create a message with the exchange manager | ||
10 | */ | ||
11 | #include "shared_memory/demos/four_int_values.hpp" | ||
12 | |||
13 | namespace shared_memory | ||
14 | { | ||
15 |
1/2✓ Branch 2 taken 79 times.
✗ Branch 3 not taken.
|
79 | Four_int_values::Four_int_values() : values_(4) |
16 | { | ||
17 | 79 | } | |
18 | |||
19 |
1/2✓ Branch 2 taken 1002 times.
✗ Branch 3 not taken.
|
1002 | Four_int_values::Four_int_values(int a, int b, int c, int d) : values_(4) |
20 | { | ||
21 | 1002 | id_ = Four_int_values::next_id(); | |
22 | 1002 | values_[0] = a; | |
23 | 1002 | values_[1] = b; | |
24 | 1002 | values_[2] = c; | |
25 | 1002 | values_[3] = d; | |
26 | 1002 | } | |
27 | |||
28 | ✗ | void Four_int_values::print() const | |
29 | { | ||
30 | ✗ | std::cout << id_ << " | "; | |
31 | ✗ | for (int i = 0; i < 4; i++) std::cout << values_[i] << " "; | |
32 | ✗ | std::cout << "\n"; | |
33 | } | ||
34 | |||
35 | 1000 | int Four_int_values::get_id() const | |
36 | { | ||
37 | 1000 | return id_; | |
38 | } | ||
39 | |||
40 | 1002 | int Four_int_values::next_id() | |
41 | { | ||
42 | static int id = 0; | ||
43 | 1002 | id++; | |
44 | 1002 | return id; | |
45 | } | ||
46 | |||
47 | 2 | bool Four_int_values::equal(const Four_int_values &other) const | |
48 | { | ||
49 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 2 times.
|
10 | for (int i = 0; i < 4; i++) |
50 | { | ||
51 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 8 times.
|
8 | if (values_[i] != other.values_[i]) return false; |
52 | } | ||
53 | 2 | return true; | |
54 | } | ||
55 | |||
56 | 2 | bool Four_int_values::same(const Four_int_values &other) const | |
57 | { | ||
58 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
|
2 | if (!this->equal(other)) return false; |
59 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (id_ != other.id_) return false; |
60 | 2 | return true; | |
61 | } | ||
62 | |||
63 | 1000 | void Four_int_values::set_id(int id) | |
64 | { | ||
65 | 1000 | this->id_ = id; | |
66 | 1000 | } | |
67 |
2/4✓ Branch 1 taken 54 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 54 times.
✗ Branch 4 not taken.
|
162 | } // namespace shared_memory |
68 |