-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfoxrps.hh
183 lines (149 loc) · 4.99 KB
/
foxrps.hh
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/****** file guifox-refpersys/foxrps.hh ******
* SPDX-License-Identifier: MIT
* © Copyright 2023 Basile Starynkevitch
*
* A Fox toolkit graphical interface (see fox-toolkit.org)
* to the RefPerSys open source (GPLv3+ licensed) inference engine
*
* See refpersys.org and code on https://github.com/RefPerSys/
*
***************************************************/
#ifndef FOXRPS_INCLUDED
#define FOXRPS_INCLUDED 1
#ifndef GIT_ID
#error GIT_ID should be defined by compilation command
#endif
#ifndef SHORTGIT_ID
#error SHORTGIT_ID should be defined by compilation command
#endif
#if __cplusplus < 201412L
#error expecting C++17 standard
#endif
/// C++ standard headers
#include <map>
#include <vector>
#include <set>
#include <iostream>
#include <functional>
#include <string>
#include <cstring>
#include <ostream>
#include <sstream>
/// POSIX headers
#include <getopt.h>
#include <libgen.h>
#include <dlfcn.h>
#include <errno.h>
#include <strings.h>
#include <unistd.h>
#include <sys/stat.h>
#include <elf.h>
#include <sys/types.h>
#include <dirent.h>
#include <fcntl.h>
#include <assert.h>
#include <signal.h>
/// from GNU libunistring
#include <unitypes.h>
#include <unistr.h>
/// libjansson
#include "jansson.h"
/// fox-toolkit.org
#include "fx.h"
extern "C" const char*fxrps_progname;
extern "C" const char fxrps_git_id[];
extern "C" const char fxrps_shortgit_id[];
extern "C" char fxrps_myhostname[];
extern "C" const char fxrps_host[];
extern "C" const char fxrps_foxversion[];
extern "C" const char fxrps_arch[];
extern "C" const char fxrps_opersys[];
extern "C" const char fxrps_timestamp[];
extern "C" void* fxrps_dlhandle;
extern "C" bool fxrps_stderr_istty;
extern "C" [[noreturn]] void fxrps_fatal_stop_at(const char*fil, int lin);
#define FXRPS_TERMINAL_NORMAL_ESCAPE \
("\033[0m")
#define FXRPS_TERMINAL_BOLD_ESCAPE \
("\033[1m")
#define FXRPS_TERMINAL_FAINT_ESCAPE \
("\033[2m")
#define FXRPS_TERMINAL_ITALICS_ESCAPE \
("\033[3m")
#define FXRPS_TERMINAL_UNDERLINE_ESCAPE \
("\033[4m")
#define FXRPS_TERMINAL_BLINK_ESCAPE \
("\033[5m")
//////////////// fatal error - aborting
extern "C" void rps_fatal_stop_at (const char *, int) __attribute__((noreturn));
#define FXRPS_FATAL_AT_BIS(Fil,Lin,Fmt,...) do { \
bool ontty = fxrps_stderr_istty; \
fprintf(stderr, "\n\n" \
"%s*** foxrps FATAL:%s%s:%d: {%s}\n " Fmt "\n\n", \
(ontty?FXRPS_TERMINAL_BOLD_ESCAPE:""), \
(ontty?FXRPS_TERMINAL_NORMAL_ESCAPE:""), \
Fil, Lin, __PRETTY_FUNCTION__, \
##__VA_ARGS__); \
}; \
fxrps_fatal_stop_at (Fil,Lin); } while(0)
#define FXRPS_FATAL_AT(Fil,Lin,Fmt,...) FXRPS_FATAL_AT_BIS(Fil,Lin,Fmt,##__VA_ARGS__)
#define FXRPS_FATAL(Fmt,...) FXRPS_FATAL_AT(__FILE__,__LINE__,Fmt,##__VA_ARGS__)
#define FXRPS_FATALOUT_AT_BIS(Fil,Lin,...) do { \
std::ostringstream outl##Lin; \
outl##Lin << __VA_ARGS__ << std::flush; \
outl##Lin.flush(); \
bool ontty = fxrps_stderr_istty; \
fprintf(stderr, "\n\n" \
"%s*** fxrps FATAL:%s%s:%d: {%s}\n %s\n\n", \
(ontty?FXRPS_TERMINAL_BOLD_ESCAPE:""), \
(ontty?FXRPS_TERMINAL_NORMAL_ESCAPE:""), \
Fil, Lin, __PRETTY_FUNCTION__, \
outl##Lin.str().c_str()); \
fxrps_fatal_stop_at (Fil,Lin); } while(0)
#define FXRPS_FATALOUT_AT(Fil,Lin,...) FXRPS_FATALOUT_AT_BIS(Fil,Lin,##__VA_ARGS__)
// typical usage would be FXRPS_FATALOUT("x=" << x)
#define FXRPS_FATALOUT(...) FXRPS_FATALOUT_AT(__FILE__,__LINE__,##__VA_ARGS__)
////////////////////////////////////////////////////////////////
//// debug messages
extern "C" bool fxrps_debug;
#define FXRPS_DEBUGOUT_AT_BIS(Fil,Lin,...) do { \
if (fxrps_debug) \
std::clog << (Fil) << ":" << (Lin) << "*" \
<< __VA_ARGS__ << std::endl; \
} while(0)
#define FXRPS_DEBUGOUT_AT(Fil,Lin,...) FXRPS_DEBUGOUT_AT_BIS(Fil,Lin,##__VA_ARGS__)
// typical usage would be FXRPS_DEBUGOUT("x=" << x)
#define FXRPS_DEBUGOUT(...) FXRPS_DEBUGOUT_AT(__FILE__,__LINE__,##__VA_ARGS__)
class FoxRpsWindow : public FXMainWindow
{
// Macro for class hierarchy declarations
FXDECLARE(FoxRpsWindow);
private:
FXVerticalFrame win_vertframe;
FXMenuBar*win_menubar;
FXMenuTitle*win_menulabel;
FXMenuPane*app_menu;
FXMenuPane*edit_menu;
FXLabel*win_toplabel;
FXHorizontalSeparator*win_firstsep;
protected:
FoxRpsWindow()
: win_vertframe(this),
win_menubar(nullptr),
win_menulabel(nullptr),
app_menu(nullptr),
edit_menu(nullptr),
win_toplabel(nullptr),
win_firstsep(nullptr) {};
public:
virtual void create(void);
virtual ~FoxRpsWindow();
FoxRpsWindow(FXApp*app, int width, int height);
static FoxRpsWindow*main_window(void);
enum
{
ID__FIRST= FXMainWindow::ID_LAST,
};
}; // end class FoxRpsWindow
#endif /* FOXRPS_INCLUDED */
// end of header file foxrps.hh