forked from panda3d/panda3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogramBase.h
More file actions
165 lines (137 loc) · 6.01 KB
/
programBase.h
File metadata and controls
165 lines (137 loc) · 6.01 KB
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
/**
* PANDA 3D SOFTWARE
* Copyright (c) Carnegie Mellon University. All rights reserved.
*
* All use of this software is subject to the terms of the revised BSD
* license. You should have received a copy of this license along
* with this source code in a file named "LICENSE."
*
* @file programBase.h
* @author drose
* @date 2000-02-13
*/
#ifndef PROGRAMBASE_H
#define PROGRAMBASE_H
#include "pandatoolbase.h"
#include "distanceUnit.h"
#include "pathReplace.h"
#include "pathStore.h"
#include "filename.h"
#include "pointerTo.h"
#include "vector_string.h"
#include "pvector.h"
#include "pdeque.h"
#include "pmap.h"
/**
* This is intended to be the base class for most general-purpose utility
* programs in the PANDATOOL tree. It automatically handles things like
* command-line arguments in a portable way.
*/
class ProgramBase {
public:
ProgramBase(const std::string &name = std::string());
virtual ~ProgramBase();
void show_description();
void show_usage();
void show_options();
INLINE void show_text(const std::string &text);
void show_text(const std::string &prefix, int indent_width, std::string text);
void write_man_page(std::ostream &out);
virtual void parse_command_line(int argc, char **argv);
std::string get_exec_command() const;
typedef pdeque<std::string> Args;
Filename _program_name;
Args _program_args;
protected:
typedef bool (*OptionDispatchFunction)(const std::string &opt, const std::string &parm, void *data);
typedef bool (*OptionDispatchMethod)(ProgramBase *self, const std::string &opt, const std::string &parm, void *data);
virtual bool handle_args(Args &args);
virtual bool post_command_line();
void set_program_brief(const std::string &brief);
void set_program_description(const std::string &description);
void clear_runlines();
void add_runline(const std::string &runline);
void clear_options();
void add_option(const std::string &option, const std::string &parm_name,
int index_group, const std::string &description,
OptionDispatchFunction option_function,
bool *bool_var = nullptr,
void *option_data = nullptr);
void add_option(const std::string &option, const std::string &parm_name,
int index_group, const std::string &description,
OptionDispatchMethod option_method,
bool *bool_var = nullptr,
void *option_data = nullptr);
bool redescribe_option(const std::string &option, const std::string &description);
bool remove_option(const std::string &option);
void add_path_replace_options();
void add_path_store_options();
static bool dispatch_none(const std::string &opt, const std::string &arg, void *);
static bool dispatch_true(const std::string &opt, const std::string &arg, void *var);
static bool dispatch_false(const std::string &opt, const std::string &arg, void *var);
static bool dispatch_count(const std::string &opt, const std::string &arg, void *var);
static bool dispatch_int(const std::string &opt, const std::string &arg, void *var);
static bool dispatch_int_pair(const std::string &opt, const std::string &arg, void *var);
static bool dispatch_int_quad(const std::string &opt, const std::string &arg, void *var);
static bool dispatch_double(const std::string &opt, const std::string &arg, void *var);
static bool dispatch_double_pair(const std::string &opt, const std::string &arg, void *var);
static bool dispatch_double_triple(const std::string &opt, const std::string &arg, void *var);
static bool dispatch_double_quad(const std::string &opt, const std::string &arg, void *var);
static bool dispatch_color(const std::string &opt, const std::string &arg, void *var);
static bool dispatch_string(const std::string &opt, const std::string &arg, void *var);
static bool dispatch_vector_string(const std::string &opt, const std::string &arg, void *var);
static bool dispatch_vector_string_comma(const std::string &opt, const std::string &arg, void *var);
static bool dispatch_filename(const std::string &opt, const std::string &arg, void *var);
static bool dispatch_search_path(const std::string &opt, const std::string &arg, void *var);
static bool dispatch_coordinate_system(const std::string &opt, const std::string &arg, void *var);
static bool dispatch_units(const std::string &opt, const std::string &arg, void *var);
static bool dispatch_image_type(const std::string &opt, const std::string &arg, void *var);
static bool dispatch_path_replace(const std::string &opt, const std::string &arg, void *var);
static bool dispatch_path_store(const std::string &opt, const std::string &arg, void *var);
static bool handle_help_option(const std::string &opt, const std::string &arg, void *);
static void format_text(std::ostream &out, bool &last_newline,
const std::string &prefix, int indent_width,
const std::string &text, int line_width);
PT(PathReplace) _path_replace;
bool _got_path_store;
bool _got_path_directory;
private:
void sort_options();
void get_terminal_width();
class Option {
public:
std::string _option;
std::string _parm_name;
int _index_group;
int _sequence;
std::string _description;
OptionDispatchFunction _option_function;
OptionDispatchMethod _option_method;
bool *_bool_var;
void *_option_data;
};
class SortOptionsByIndex {
public:
bool operator () (const Option *a, const Option *b) const;
};
std::string _name;
std::string _brief;
std::string _description;
typedef vector_string Runlines;
Runlines _runlines;
typedef pmap<std::string, Option> OptionsByName;
typedef pvector<const Option *> OptionsByIndex;
OptionsByName _options_by_name;
OptionsByIndex _options_by_index;
int _next_sequence;
bool _sorted_options;
typedef pmap<std::string, std::string> GotOptions;
GotOptions _got_options;
bool _last_newline;
int _terminal_width;
bool _got_terminal_width;
int _option_indent;
bool _got_option_indent;
};
#include "programBase.I"
#endif