1 #ifndef CDO_OUTPUT_H
2 #define CDO_OUTPUT_H
3
4 #include "mpmo.h"
5
6 // Debug Switches
7 extern int cdoDebug;
8 extern int cdoDebugExt; // Debug level for the KNMI extensions
9 // Subsystem Debug Switches
10 extern int PROCESS;
11 extern int PIPE;
12 extern int PIPE_STREAM;
13 extern int FILE_STREAM;
14 extern int PTHREAD;
15 extern int PROCESS_MANAGER;
16 extern int PIPE;
17
18 void print_debug_options();
19 void query_user_exit(const char *argument);
20
21 namespace cdo
22 {
23 void set_debug(int p_debug_level);
24 extern void (*exitProgram)(void);
25 extern const char *(*getContext)(void);
26 void set_exit_function(void (*func)(void));
27 void set_context_function(const char *(*func)(void) );
28 } // namespace cdo
29
30 void cdi_open_error(int cdiErrno, const std::string &format, const char *path);
31
32 template <typename... Args>
33 void
cdo_abort(const std::string & format,Args const &...args)34 cdo_abort(const std::string &format, Args const &... args) noexcept
35 {
36 fflush(stdout);
37 MpMO::PrintCerr(Red("\n%s (Abort): ") + format, cdo::getContext(), args...);
38 if (MpMO::exitOnError) cdo::exitProgram();
39 }
40
41 template <typename... Args>
42 void
cdo_warning(const std::string & format,Args const &...args)43 cdo_warning(const std::string &format, Args const &... args) noexcept
44 {
45 if (MpMO::warningsEnabled)
46 {
47 if (MpMO::pedantic)
48 {
49 MpMO::PrintCerr(Red("%s (Warning): ") + format, cdo::getContext(), args...);
50 if (MpMO::exitOnError) cdo::exitProgram();
51 }
52 else
53 {
54 MpMO::PrintCerr(Yellow("%s (Warning): ") + format, cdo::getContext(), args...);
55 }
56 }
57 }
58
59 template <typename... Args>
60 void
cdo_print(const std::string & format,Args const &...args)61 cdo_print(const std::string &format, Args const &... args) noexcept
62 {
63 if (!MpMO::silentMode) MpMO::Print(Green("%s: ") + format, cdo::getContext(), args...);
64 }
65
66 #ifdef WITH_CALLER_NAME
67 #define cdo_sys_error(...) MpMO::SysError_(__func__, __VA_ARGS__)
68 #else
69 #define cdo_sys_error(...) MpMO::SysError_("", __VA_ARGS__)
70 #endif
71
72 #endif
73