-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCmdLineParser.h
96 lines (75 loc) · 2.54 KB
/
CmdLineParser.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
//---------------------------------------------------------------------------
#ifndef CmdLineParserH
#define CmdLineParserH
#include <System.hpp>
// si usa boost::tuple e non std::boost tuple per problemi di move semantics
// con String
#include <boost/tuple/tuple.hpp>
#include <string>
#if 0
#if defined( _UNICODE )
// #define stdtstr std::wstring
#define tcout std::wcout
#define tcerr std::wcerr
#else
// #define stdtstr std::string
#define tcout std::cout
#define tcerr std::cerr
#endif
#endif
//---------------------------------------------------------------------------
namespace CmdLineParser {
//---------------------------------------------------------------------------
using OptionType =
boost::tuple<
String,
String,
bool,
bool,
bool,
String,
String,
String
>;
enum class OptPar {
Name, Desc, Found, Mandatory, ValueRequired, ValueDesc, ValueLongDesc,
Value
};
extern void ParseCmdLine( OptionType* const Options, size_t OptionCount );
extern void Validate( OptionType const * const Options, size_t OptionCount );
extern String GetHelpText( OptionType const * const Options, size_t OptionCount );
constexpr size_t ToIdx( OptPar Val ) { return static_cast<size_t>( Val ); }
template<typename T>
size_t GetTextLen( T const & Txt ) {
return static_cast<size_t>( Txt.Length() );
}
template<typename T>
bool IsTextEmpty( T const & Txt ) { return Txt.IsEmpty(); }
inline bool WasFound( OptionType const & Opt ) {
return boost::get<ToIdx( OptPar::Found )>( Opt );
}
inline bool IsMandatory( OptionType const & Opt ) {
return boost::get<ToIdx( OptPar::Mandatory )>( Opt );
}
inline bool IsValueRequired( OptionType const & Opt ) {
return boost::get<ToIdx( OptPar::ValueRequired )>( Opt );
}
inline String GetName( OptionType const & Opt ) {
return boost::get<ToIdx( OptPar::Name )>( Opt );
}
inline String GetDesc( OptionType const & Opt ) {
return boost::get<ToIdx( OptPar::Desc )>( Opt );
}
inline String GetValue( OptionType const & Opt ) {
return boost::get<ToIdx( OptPar::Value )>( Opt );
}
inline String GetValueDesc( OptionType const & Opt ) {
return boost::get<ToIdx( OptPar::ValueDesc )>( Opt );
}
inline String GetValueLongDesc( OptionType const & Opt ) {
return boost::get<ToIdx( OptPar::ValueLongDesc )>( Opt );
}
//---------------------------------------------------------------------------
}; // End of namespace CmdLineParser
//---------------------------------------------------------------------------
#endif