-
Notifications
You must be signed in to change notification settings - Fork 1
/
ArgumentList.h
80 lines (59 loc) · 1.71 KB
/
ArgumentList.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
/*
* $Header: /Book/ArgumentList.h 12 5.09.99 13:06 Oslph312 $
*
* Command-line parsing.
*
* The command line parameter to the ArgumentList constructor is
* unused; it's left in for the benefit of implementations that
* don't have access to argc/argv and need to do their own parsing.
*/
#pragma once
#include "String.h"
#include "AutoArray.h"
class ArgumentList {
private:
int m_argc;
AutoArray< LPCTSTR > m_argv;
#ifdef _DEBUG
bool isValid( void ) const;
#endif // _DEBUG
public:
ArgumentList( LPCTSTR /* pszCmdLine */ );
int getNumArgs( void ) const;
LPCTSTR getArg( int nArg ) const;
LPCTSTR getArg( int nArg, bool bConsume = false );
bool isOption( int nArg ) const; // ??
bool hasOption( LPCTSTR pszOption );
void consume( int nArg );
};
inline int ArgumentList::getNumArgs( void ) const {
assert( isValid() );
return m_argc;
}
inline LPCTSTR ArgumentList::getArg( int nArg ) const {
assert( isValid() );
assert( 0 <= nArg && nArg < m_argc );
return m_argv[ nArg ];
}
inline LPCTSTR ArgumentList::getArg( int nArg, bool bConsume ) {
assert( isValid() );
assert( 0 <= nArg && nArg < m_argc );
const LPCTSTR pszArgument = m_argv[ nArg ];
if ( bConsume ) {
consume( nArg );
}
return pszArgument;
}
/**
* An argument is considered an option
* if preceeded by a slash or a minus.
* The point of call can choose to consider unrecognized
* options to be file names. TextEdit does this.
*/
inline bool ArgumentList::isOption( int nArg ) const {
assert( isValid() );
assert( 0 <= nArg && nArg < m_argc );
LPCTSTR const pszArg = getArg( nArg );
return _T( '/' ) == *pszArg || _T( '-' ) == *pszArg;
}
// end of file