-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApplicationUsage.h
More file actions
112 lines (75 loc) · 4.47 KB
/
Copy pathApplicationUsage.h
File metadata and controls
112 lines (75 loc) · 4.47 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
// ApplicationUsage.h — Singleton that collects and renders CLI usage/help information.
//
// Part of Sourcy — CNS -> Lua compiler for MUGEN-style characters.
// Licensed under the MIT License. See LICENSE in the project root.
//
// Author: Miguel Angel Exposito Sanchez (radexx), 2012.
#define _CRT_SECURE_NO_WARNINGS
#ifndef _APPLICATIONUSAGE_H_
#define _APPLICATIONUSAGE_H_
#include <map>
#include <string>
#include <ostream>
class ApplicationUsage
{
public:
static ApplicationUsage* instance();
ApplicationUsage() {}
ApplicationUsage(const std::string& commandLineUsage);
typedef std::map<std::string,std::string> UsageMap;
/** The ApplicationName is often displayed when logging errors, and frequently incorporated into the Description (below). */
void setApplicationName(const std::string& name) { _applicationName = name; }
const std::string& getApplicationName() const { return _applicationName; }
/** If non-empty, the Description is typically shown by the Help Handler
* as text on the Help display (which also lists keyboard abbreviations. */
void setDescription(const std::string& desc) { _description = desc; }
const std::string& getDescription() const { return _description; }
enum Type
{
NO_HELP = 0x0,
COMMAND_LINE_OPTION = 0x1,
ENVIRONMENTAL_VARIABLE = 0x2,
KEYBOARD_MOUSE_BINDING = 0x4,
HELP_ALL = KEYBOARD_MOUSE_BINDING|ENVIRONMENTAL_VARIABLE|COMMAND_LINE_OPTION
};
void addUsageExplanation(Type type,const std::string& option,const std::string& explanation);
void setCommandLineUsage(const std::string& explanation) { _commandLineUsage=explanation; }
const std::string& getCommandLineUsage() const { return _commandLineUsage; }
void addCommandLineOption(const std::string& option,const std::string& explanation, const std::string &defaultValue = "");
void setCommandLineOptions(const UsageMap& usageMap) { _commandLineOptions=usageMap; }
const UsageMap& getCommandLineOptions() const { return _commandLineOptions; }
void setCommandLineOptionsDefaults(const UsageMap& usageMap) { _commandLineOptionsDefaults=usageMap; }
const UsageMap& getCommandLineOptionsDefaults() const { return _commandLineOptionsDefaults; }
void addEnvironmentalVariable(const std::string& option,const std::string& explanation, const std::string& defaultValue = "");
void setEnvironmentalVariables(const UsageMap& usageMap) { _environmentalVariables=usageMap; }
const UsageMap& getEnvironmentalVariables() const { return _environmentalVariables; }
void setEnvironmentalVariablesDefaults(const UsageMap& usageMap) { _environmentalVariablesDefaults=usageMap; }
const UsageMap& getEnvironmentalVariablesDefaults() const { return _environmentalVariablesDefaults; }
void addKeyboardMouseBinding(const std::string& option,const std::string& explanation);
void setKeyboardMouseBindings(const UsageMap& usageMap) { _keyboardMouse=usageMap; }
const UsageMap& getKeyboardMouseBindings() const { return _keyboardMouse; }
void getFormattedString(std::string& str, const UsageMap& um,unsigned int widthOfOutput=80,bool showDefaults=false,const UsageMap& ud=UsageMap());
void write(std::ostream& output,const UsageMap& um,unsigned int widthOfOutput=80,bool showDefaults=false,const UsageMap& ud=UsageMap());
void write(std::ostream& output,unsigned int type=COMMAND_LINE_OPTION, unsigned int widthOfOutput=80,bool showDefaults=false);
void writeEnvironmentSettings(std::ostream& output);
protected:
virtual ~ApplicationUsage() {}
std::string _applicationName;
std::string _description;
std::string _commandLineUsage;
UsageMap _commandLineOptions;
UsageMap _environmentalVariables;
UsageMap _keyboardMouse;
UsageMap _environmentalVariablesDefaults;
UsageMap _commandLineOptionsDefaults;
};
class ApplicationUsageProxy
{
public:
/** register an explanation of commandline/environmentvariable/keyboard mouse usage.*/
ApplicationUsageProxy(ApplicationUsage::Type type,const std::string& option,const std::string& explanation)
{
ApplicationUsage::instance()->addUsageExplanation(type,option,explanation);
}
};
#endif