38 #ifndef GMM_FEEDBACK_MANAGEMENT_H__
39 #define GMM_FEEDBACK_MANAGEMENT_H__
51 struct warning_level {
52 static int level(
int l = -2)
53 {
static int level_ = 3;
return (l != -2) ? (level_ = l) : level_; }
56 inline void set_warning_level(
int l) { warning_level::level(l>0 ? l : 0); }
57 inline int get_warning_level(
void) {
return warning_level::level(-2); }
65 static int level(
int l = -2)
66 {
static int level_ = 3;
return (l != -2) ? (level_ = l) : level_; }
69 inline void set_traces_level(
int l) { traces_level::level(l>0 ? l : 0); }
70 inline int get_traces_level(
void) {
return traces_level::level(); }
77 enum class FeedbackType {
89 struct base_feedback_handler {
90 virtual ~base_feedback_handler() =
default;
91 virtual void send(
const std::string &message, FeedbackType messageType,
size_t level) = 0;
92 virtual size_t traces_level() {
return get_traces_level(); }
93 virtual size_t warning_level() {
return get_warning_level(); }
94 virtual void terminating_action() = 0;
99 struct default_feedback_handler final :
public base_feedback_handler {
100 void send(
const std::string &message, FeedbackType,
size_t)
override {
101 std::cerr << message << std::endl;
103 void terminating_action()
override {
110 class feedback_manager {
127 static base_feedback_handler* manage(
enum Action action=GET, base_feedback_handler *pHandler=
nullptr);
128 static void send(
const std::string &message, FeedbackType type,
size_t level);
129 static size_t traces_level();
130 static size_t warning_level();
132 static void terminating_action();
137 inline base_feedback_handler* feedback_manager::manage(
enum Action action, base_feedback_handler *pHandler) {
138 static std::unique_ptr<base_feedback_handler> pHandler_ =
139 std::move(std::unique_ptr<base_feedback_handler>(
new default_feedback_handler));
140 base_feedback_handler *rethandler =
nullptr;
143 pHandler_.reset(pHandler !=
nullptr ? pHandler :
new default_feedback_handler);
144 rethandler = pHandler_.get();
147 rethandler = pHandler_.get();
150 rethandler = pHandler_.release();
151 pHandler_.reset(pHandler !=
nullptr ? pHandler :
new default_feedback_handler);
157 inline void feedback_manager::send(
const std::string &message, FeedbackType type,
size_t level) {
158 feedback_manager::manage()->send(message, type, level);
161 inline void feedback_manager::terminating_action() {
162 feedback_manager::manage()->terminating_action();
165 inline size_t feedback_manager::traces_level() {
166 return feedback_manager::manage()->traces_level();
169 inline size_t feedback_manager::warning_level() {
170 return feedback_manager::manage()->warning_level();