-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathreference_logger.cpp
More file actions
61 lines (55 loc) · 1.83 KB
/
Copy pathreference_logger.cpp
File metadata and controls
61 lines (55 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright 2024 Simon Sagmeister
#include "tsl_logger_cpp/reference_logger.hpp"
#include <iostream>
#include "tsl_logger_cpp/base.hpp"
// DISCLAIMER:
/// ================================================================================================
// For certain applications (e.g. logging is triggered asynchronously) it
// may be beneficial use a reference logger instead of a value logger.
// The reference logger does not directly store the logged values but instead
// stores raw pointers to the values to be logged. If you want to get the logged values,
// the reference manager dereferences the pointers and returns the values.
// However: YOU ARE RESPONSIBLE FOR KEEPING THE PTR VALID
//
//
// =================================================================================================
class MySoftwareModule
{
private:
int a = 0, b = 0, c = 0;
tam::tsl::ReferenceLogger::SharedPtr logger_ptr_ = std::make_shared<tam::tsl::ReferenceLogger>();
public:
MySoftwareModule()
{
setup_logger(); // You only need to call this once, since we store the ptr to the values
}
void setup_logger()
{
logger_ptr_->log("a", &a);
logger_ptr_->log("b", &b);
logger_ptr_->log("c", &c);
}
void step()
{
a++;
b++;
c++;
// No need to explicitly loog the signals here, since the reference logger already stores the
// memory location
}
tam::tsl::LoggerAccessInterface::SharedPtr get_logger() { return logger_ptr_; }
};
int main()
{
MySoftwareModule module;
for (int i = 0; i < 3; i++) {
module.step();
// Print the logged values
std::cout << "For iteration " << i << " we logged the following signals:";
for (auto const & signal : module.get_logger()->get_data()) {
std::cout << " " << signal.first << ":" << std::get<int>(signal.second);
}
std::cout << std::endl;
}
return 0;
}