pal_statistics_macros.h
Go to the documentation of this file.
1 
26 #ifndef PAL_STATISTICS_MACROS_H
27 #define PAL_STATISTICS_MACROS_H
30 
31 constexpr char DEFAULT_STATISTICS_TOPIC[] = "pal_statistics";
32 
33 namespace pal_statistics
34 {
35 boost::shared_ptr<StatisticsRegistry> getRegistry(const std::string &topic);
36 } //namespace pal_statistics
37 
38 
39 //Trick to use macros with optional argument, in practice there are three version of the macro:
40 //REGISTER_VARIABLE(TOPIC, ID, VARIABLE, BOOKKEEPING) -> full specification of arguments
41 //REGISTER_VARIABLE(TOPIC, ID, VARIABLE) -> No bookkeeping
42 
43 //https://stackoverflow.com/questions/3046889/optional-parameters-with-c-macros?
44 #define REGISTER_VARIABLE_3_ARGS(TOPIC, ID, VARIABLE) \
45  customRegister(*pal_statistics::getRegistry(TOPIC), ID, VARIABLE);
46 #define REGISTER_VARIABLE_4_ARGS(TOPIC, ID, VARIABLE, BOOKKEEPING) \
47  customRegister(*pal_statistics::getRegistry(TOPIC), ID, VARIABLE, BOOKKEEPING);
48 
49 #define GET_5TH_ARG(arg1, arg2, arg3, arg4, arg5, ...) arg5
50 #define REGISTER_MACRO_CHOOSER(...) \
51  GET_5TH_ARG(__VA_ARGS__, REGISTER_VARIABLE_4_ARGS, \
52  REGISTER_VARIABLE_3_ARGS)
53 
54 #define REGISTER_VARIABLE(...) REGISTER_MACRO_CHOOSER(__VA_ARGS__)(__VA_ARGS__)
55 
56 // Register the variable with the same name as the variable name
57 #define REGISTER_VARIABLE_SIMPLE(TOPIC, VARIABLE, BOOKKEEPING) \
58  customRegister(*pal_statistics::getRegistry(TOPIC), #VARIABLE, VARIABLE, BOOKKEEPING);
59 
60 
61 #define PUBLISH_STATISTICS(TOPIC) pal_statistics::getRegistry(TOPIC)->publish();
62 
63 #define PUBLISH_ASYNC_STATISTICS(TOPIC) pal_statistics::getRegistry(TOPIC)->publishAsync();
64 
65 #define START_PUBLISH_THREAD(TOPIC) pal_statistics::getRegistry(TOPIC)->startPublishThread();
66 
67 #define PUBLISH_CUSTOM_STATISTIC(TOPIC, ID, VALUE) pal_statistics::getRegistry(TOPIC)->publishCustomStatistic(ID, VALUE)
68 
69 #define PUBLISH_CUSTOM_STATISTICS_MSG(TOPIC, MSG) pal_statistics::getRegistry(TOPIC)->publishCustomStatistics(MSG)
70 
71 
72 #define UNREGISTER_VARIABLE_2_ARGS(TOPIC, ID) \
73  pal_statistics::getRegistry(TOPIC)->unregisterVariable(ID);
74 #define UNREGISTER_VARIABLE_3_ARGS(TOPIC, ID, BOOKKEEPING) \
75  pal_statistics::getRegistry(TOPIC)->unregisterVariable(ID, BOOKKEEPING);
76 
77 #define GET_4TH_ARG(arg1, arg2, arg3, arg4, ...) arg4
78 #define UNREGISTER_MACRO_CHOOSER(...) \
79  GET_4TH_ARG(__VA_ARGS__, UNREGISTER_VARIABLE_3_ARGS, \
80  UNREGISTER_VARIABLE_2_ARGS)
81 
82 //UNREGISTER_VARIABLE(TOPIC, ID, BOOKKEEPING) -> full specification of arguments
83 //UNREGISTER_VARIABLE(TOPIC, ID) -> No bookkeeping
84 #define UNREGISTER_VARIABLE(...) UNREGISTER_MACRO_CHOOSER(__VA_ARGS__)(__VA_ARGS__)
85 
86 
87 #endif // PAL_STATISTICS_MACROS_H
boost::shared_ptr
registration_utils.h
pal_statistics::getRegistry
boost::shared_ptr< StatisticsRegistry > getRegistry(const std::string &topic)
Definition: pal_statistics_macros.cpp:12
DEFAULT_STATISTICS_TOPIC
constexpr char DEFAULT_STATISTICS_TOPIC[]
Definition: pal_statistics_macros.h:31
pal_statistics.h
pal_statistics
Definition: extract_rosbag_signals.h:14


pal_statistics
Author(s):
autogenerated on Fri Aug 2 2024 08:29:35