-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcmddefs.h
367 lines (247 loc) · 10.8 KB
/
cmddefs.h
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
// --------------------------------------------------------------------
//
// This file is part of Luna.
//
// LUNA is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Luna is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Luna. If not, see <http://www.gnu.org/licenses/>.
//
// Please see LICENSE.txt for more details.
//
// --------------------------------------------------------------------
#ifndef __LUNA_CMDDEFS_H__
#define __LUNA_CMDDEFS_H__
#include <string>
#include <map>
#include "eval.h"
#include "helper/helper.h"
#include <vector>
#include <set>
#include <sstream>
//
// cmddefs_t handles a) help, listing parametes and output for each command,
// b) groups commands by domains
// c) provides a validation of known parameters for a command check()
// d) tracks whether a given output table (or all) should be dumped as a plain-text file or no out_plaintext()
struct strata_t;
struct tfac_t {
// need to handle: baseline strata (no factors), augemnted TAGs (i.e something plus TAGs)
// still has same rules
// RULE::: TAGs will always start
// The following are *ignored* when constructing a tfac_t:
// factors that start with underscore '_', as these as command names
// factors that are listed as TAGs here
// i.e. as we already know command name, and the TAGs will not define the variables to use
tfac_t( const std::string & s , const std::string & delim = "," ) ;
tfac_t( const strata_t & s );
std::string as_string( const std::string & delim = "," ) const;
// LT operator
bool operator< ( const tfac_t & rhs ) const;
// EQ operator
bool operator== ( const tfac_t & rhs ) const;
// key (non-command, non-tag) factors that represent the virtual table
std::set<std::string> fac;
};
class cmddefs_t
{
public:
cmddefs_t();
#ifdef __clang__
void __attribute__((optnone)) init();
#else
#ifdef __GNUC__
void __attribute__((optimize(0))) init();
#else
void init();
#endif
#endif
// domain description
void add_domain( const std::string & domain , const std::string & label , const std::string & desc );
bool is_domain( const std::string & d ) ;
// command description
void add_cmd( const std::string & domain , const std::string & cmd , const std::string & desc , const bool hide = false );
// hidden command description
void hidden_cmd( const std::string & domain , const std::string & cmd , const std::string & desc );
bool is_cmd( const std::string & c ) ;
// command URLs , e.g. zzz.bwh.harvard.edu/luna/ref/
void add_url( const std::string & cmd , const std::string & url ) ;
void add_note( const std::string & cmd , const std::string & note ) ;
// parameters for this command
void add_param( const std::string & cmd , const std::string & param ,
const std::string & ex , // "" if none
const std::string & desc ,
const std::string & requirements = "" ,
const bool hide = false );
// hide parameter for this command
void hidden_param( const std::string & cmd , const std::string & param ,
const std::string & ex , // "" if none
const std::string & desc ,
const std::string & requirements = "" );
// output from this command , "CMD" , "F,B,CH,E" , "desc" , is compressed Y/N
void add_table( const std::string & cmd , const std::string & factors , const std::string & desc , bool isz = false , bool hide = false );
void hidden_table( const std::string & cmd , const std::string & factors , const std::string & desc , bool isz = false );
// ensure table (from REPORT)
void ensure_table( const std::string & cmd , const std::string & factors );
// add variable
void add_var( const std::string & cmd , const std::string & factors , const std::string & var , const std::string & desc , const bool hide = false );
// add hidden variable
void hidden_var( const std::string & cmd , const std::string & factors , const std::string & var , const std::string & desc );
// register extra col for output (controlled by caller)
void register_var( const std::string & cmd , const std::string & factors , const std::string & var , const bool value = true );
//
// check parameters
//
bool check( const std::string & cmd ) const ; // command
bool check( const std::string & cmd , const std::set<std::string> & k , std::set<std::string> * ) const ; // params
//
// add 'hidden' commands cmd/tables/vars/param
//
void add_cmd1( const std::string & domain ,
const std::string & cmd ,
const std::string & desc ,
const bool hide = false );
void add_param1( const std::string & cmd , const std::string & param ,
const std::string & ex , // "" if none
const std::string & desc ,
const std::string & requirements = "" ,
const bool hide = false );
void add_table1( const std::string & cmd ,
const std::string & factors ,
const std::string & desc ,
bool isz = false ,
bool hide = false );
void add_var1( const std::string & cmd ,
const std::string & factors ,
const std::string & var ,
const std::string & desc ,
const bool hide = false );
//
// show help
//
// describe one command
std::string help( const std::string & cmd , bool show_domain_label = true , bool verbose = false , bool primary = false ) const;
// list all domains
std::string help_domains() const;
// desc for a domain
std::string help_domain( const std::string & d ) const;
// list all commands in a domain
std::string help_commands( const std::string & d , const bool primary ) const;
// list all commands
std::string help_commands() const;
//
// hide/show variables
//
void hide_all();
void hide_cmd( const std::string & cmd );
void hide_table( const std::string & cmd , const std::string & factors );
void hide_table( const std::string & cmd , const tfac_t & factors );
void hide_var( const std::string & cmd , const std::string & factors , const std::string & var );
void hide_var( const std::string & cmd , const tfac_t & factors , const std::string & var );
void show_all( const bool status = true );
void show_cmd( const std::string & cmd , const bool status = true );
void show_table( const std::string & cmd , const std::string & factors , const bool status = true );
void show_table( const std::string & cmd , const tfac_t & factors , const bool status = true );
void show_var( const std::string & cmd, const std::string & factors, const std::string & var, const bool status = true );
void show_var( const std::string & cmd, const tfac_t & factors, const std::string & var, const bool status = true );
//
// indicate whether table should be compressed or no
//
void all_compressed( bool b ) ;
bool all_compressed() const ;
void none_compressed( bool b );
bool none_compressed() const ;
// allow change after table has been registered
void set_compressed( const std::string & cmd ,
const tfac_t & tfac ,
const bool b = true
);
void set_compressed( const std::string & cmd ,
const bool b = true
);
bool out_compressed( const std::string & cmd ,
const tfac_t & tfac ) const;
bool exists( const std::string & cmd ,
const tfac_t & tfac ) const;
//
// list factors
//
void add_tag( const std::string & tag );
void clear_tags();
bool is_tag( const std::string & tag ) const ;
std::set<std::string> variables( const std::string & cmd , const param_t * param , const tfac_t & tfac );
private:
// domain->human label ->desc
std::map<std::string,std::string> domain_label;
std::map<std::string,std::string> domain_desc;
// domain->cmds
std::map<std::string,std::set<std::string> > dcmds;
// cmd->desc
std::map<std::string,std::string> cmds;
// cmd->notes
std::map<std::string,std::string> cnotes;
// cmd->url
std::map<std::string,std::string> curl;
std::string url_root;
// cmd->domain
std::map<std::string,std::string> cdomain;
//cmd->param->param->example
std::map<std::string,std::map<std::string,std::string> > pdesc;
//cmd->param->param->example
std::map<std::string,std::map<std::string,std::string> > px;
// cmd->param->param->requirements (free-text)
std::map<std::string,std::map<std::string,std::string> > preq;
//
// primary cmd/tables/params/vars (i.e. for help function)
//
bool is_primary_cmd( const std::string & cmd ) const;
bool is_primary_par( const std::string & cmd , const std::string & param ) const;
bool is_primary_tbl( const std::string & cmd , const tfac_t & tfac ) const;
bool is_primary_var( const std::string & cmd , const tfac_t & tfac , const std::string & var ) const;
std::set<std::string> pri_cmd;
std::map<std::string,std::set<std::string> > pri_par;
std::map<std::string,std::set<tfac_t> > pri_tbl;
std::map<std::string,std::map<tfac_t,std::set<std::string> > > pri_var;
//
// output
//
// cmd->table->desc
std::map<std::string,std::map<tfac_t,std::string> > otables;
// cmd->{table-set}->compressed table T/F
std::map<std::string,std::map<tfac_t,bool> > ofacs;
// cmd->table->var->desc
std::map<std::string,std::map<tfac_t,std::map<std::string,std::string> > > ovars;
// cmd->table->var->tout
std::map<std::string,std::map<tfac_t,std::map<std::string,std::string> > > otout;
//
// hidden status (i.e. not reported in output)
//
std::map<std::string,bool> chide; // cmds
std::map<std::string,std::map<std::string,bool> > phide; // parameters
std::map<std::string,std::map<tfac_t,bool> > ohide; // tables
std::map<std::string,std::map<tfac_t,std::map<std::string,bool> > > vhide; // variables
bool is_hidden_cmd( const std::string & c ) const;
bool is_hidden_param( const std::string & c , const std::string & p ) const;
bool is_hidden_table( const std::string & c , const tfac_t & tfac ) const;
public:
bool is_hidden_var( const std::string & c , const tfac_t & tfac , const std::string & v ) const;
private:
// all, or no, output should be compressed
bool allz;
bool nonez;
//
// TAGs, need to keep track of these so they can be ignored when determining
// the table to write to (i.e. these do not determine which variables will be
// present, they will just add extra strata/rows
//
std::set<std::string> tags;
};
#endif