OpenBarnyard
 
Loading...
Searching...
No Matches
T2CommandLine Class Reference

#include <T2CommandLine.h>

Public Member Functions

 T2CommandLine ()
 
 T2CommandLine (T2StringView a_pchCommandLine)
 
void Create (T2StringView a_pchCommandLine)
 
TBOOL HasParameter (const TCHAR *a_pszParameter, TINT *a_pIndex=nullptr) const
 
TString8 GetParameterValue (const TCHAR *a_pszParameter, const TCHAR *a_pszDefaultValue=nullptr) const
 
const TCHARGetNextParameter (const TCHAR *a_pszParameter) const
 

Detailed Description

Definition at line 22 of file T2CommandLine.h.

Constructor & Destructor Documentation

◆ T2CommandLine() [1/2]

T2CommandLine::T2CommandLine ( )

Definition at line 17 of file T2CommandLine.cpp.

18{
19 m_szCommandLine[ 0 ] = '\0';
20 m_bInitialised = TFALSE;
21}
#define TFALSE
Definition Typedefs.h:24

◆ T2CommandLine() [2/2]

T2CommandLine::T2CommandLine ( T2StringView a_pchCommandLine)

Definition at line 12 of file T2CommandLine.cpp.

13{
14 Create( a_pchCommandLine );
15}
void Create(T2StringView a_pchCommandLine)

Member Function Documentation

◆ Create()

void T2CommandLine::Create ( T2StringView a_pchCommandLine)

Definition at line 23 of file T2CommandLine.cpp.

24{
25 if ( a_pchCommandLine )
26 {
27 TSIZE uiCommandLineLength = a_pchCommandLine.Length();
28 m_szCommandLine.Copy( a_pchCommandLine );
29 m_bInitialised = TTRUE;
30
31 m_Parser.SetBuffer( a_pchCommandLine, uiCommandLineLength );
32
33 // Parse the parameters
34 m_ParsedParams.Clear();
35
36 char szToken[ 1024 ];
37 while ( !m_Parser.IsOver() )
38 {
39 TBOOL bReadToken = m_Parser.ReadToken( szToken, sizeof( szToken ) );
40
41 if ( bReadToken )
42 m_ParsedParams.Push( szToken );
43 }
44 }
45}
size_t TSIZE
Definition Typedefs.h:9
#define TTRUE
Definition Typedefs.h:25
bool TBOOL
Definition Typedefs.h:6
TFORCEINLINE TSIZE Length() const
Definition T2String.h:36

◆ GetNextParameter()

const TCHAR * T2CommandLine::GetNextParameter ( const TCHAR * a_pszParameter) const

Definition at line 80 of file T2CommandLine.cpp.

81{
82 TINT iParamIndex;
83 TBOOL bHasParam = HasParameter( a_pszParameter, &iParamIndex );
84
85 if ( bHasParam && iParamIndex + 1 < m_ParsedParams.Size() )
86 {
87 return m_ParsedParams[ iParamIndex + 1 ];
88 }
89
90 return TNULL;
91}
#define TNULL
Definition Typedefs.h:23
int TINT
Definition Typedefs.h:7
TBOOL HasParameter(const TCHAR *a_pszParameter, TINT *a_pIndex=nullptr) const

◆ GetParameterValue()

TString8 T2CommandLine::GetParameterValue ( const TCHAR * a_pszParameter,
const TCHAR * a_pszDefaultValue = nullptr ) const

Definition at line 68 of file T2CommandLine.cpp.

69{
70 TASSERT( m_bInitialised );
71
72 const TCHAR* pszValue = GetNextParameter( a_pszParameter );
73
74 if ( pszValue )
75 return pszValue;
76
77 return a_pszDefaultValue;
78}
#define TASSERT(X,...)
Definition Defines.h:138
char TCHAR
Definition Typedefs.h:20
const TCHAR * GetNextParameter(const TCHAR *a_pszParameter) const

◆ HasParameter()

TBOOL T2CommandLine::HasParameter ( const TCHAR * a_pszParameter,
TINT * a_pIndex = nullptr ) const

Definition at line 47 of file T2CommandLine.cpp.

48{
49 TASSERT( m_bInitialised );
50
51 if ( a_pIndex )
52 *a_pIndex = -1;
53
54 TARRAY_FOREACH( m_ParsedParams, it )
55 {
56 if ( it.Get() == a_pszParameter )
57 {
58 if ( a_pIndex )
59 *a_pIndex = it.Index();
60
61 return TTRUE;
62 }
63 }
64
65 return TFALSE;
66}
#define TARRAY_FOREACH(vecName, iteratorName)
Definition TArray.h:3

The documentation for this class was generated from the following files: