KSquare Utilities
KKB::CmdLineExpander Class Reference

Expands command line parameters, by parsing for special parameters and expanding them to their full value. More...

#include <CmdLineExpander.h>

Public Member Functions

 CmdLineExpander (const KKStr &_applicationName, RunLog &_log, kkint32 argc, char **argv)
 Constructor using the parameters passed through on the command line into main(). More...
 
 CmdLineExpander (const KKStr &_applicationName, RunLog &_log, const KKStr &_cmdLine)
 Pass in the command line as a single string. Will parse first before processing. More...
 
 ~CmdLineExpander ()
 
void ExpandCmdLine (kkint32 argc, char **argv)
 
const vector< KKStrPair > & ExpandedParameterPairs () const
 
const VectorKKStrExpandedParameters () const
 
const KKStrLogFileName () const
 
bool ParmsGood () const
 

Detailed Description

Expands command line parameters, by parsing for special parameters and expanding them to their full value.

A couple of parameters are specifically searched for and processed. The "-log" and "-CmdFile" parameters. The "-log" parameter is provides the name of a file where logging messages are to be written to via the "RunLog" class. The "-CmdFile" parameter provides the name of a text file that contains more command-line parameters that are to be processed along with all other parameters; the text in this file will be inserted where the original -"CmdLine" parameter appeared.

Author
Kurt Kramer

Definition at line 31 of file CmdLineExpander.h.

Constructor & Destructor Documentation

CmdLineExpander::CmdLineExpander ( const KKStr _applicationName,
RunLog _log,
kkint32  argc,
char **  argv 
)

Constructor using the parameters passed through on the command line into main().

Definition at line 38 of file CmdLineExpander.cpp.

References ExpandCmdLine(), and KKB::KKStr::KKStr().

42  :
43 
44  applicationName (_applicationName),
45  log (_log)
46 
47 {
48  ExpandCmdLine (argc, argv);
49 }
void ExpandCmdLine(kkint32 argc, char **argv)
CmdLineExpander::CmdLineExpander ( const KKStr _applicationName,
RunLog _log,
const KKStr _cmdLine 
)

Pass in the command line as a single string. Will parse first before processing.

Definition at line 54 of file CmdLineExpander.cpp.

References KKB::KKStr::Concat(), KKB::KKStr::Empty(), KKB::KKStr::ExtractQuotedStr(), KKB::KKStr::KKStr(), KKB::KKStr::TrimLeft(), and KKB::KKStr::TrimRight().

57  :
58  applicationName (_applicationName),
59  log (_log)
60 
61 {
62  VectorKKStr initialParameters;
63 
64  KKStr cmdLine (_cmdLine);
65 
66  cmdLine.TrimLeft ();
67  while (!cmdLine.Empty ())
68  {
69  KKStr nextField = cmdLine.ExtractQuotedStr ("\n\r\t ", false); // false = Do not decode escape characters
70  nextField.TrimRight ();
71  if (!nextField.Empty ())
72  initialParameters.push_back (nextField);
73  cmdLine.TrimLeft ();
74  }
75 
76  BuildCmdLineParameters (initialParameters);
77  BuildExpandedParameterPairs ();
78 }
KKStr & TrimRight(const char *whiteSpaceChars="\n\r\t ")
Definition: KKStr.cpp:1695
bool Empty() const
Definition: KKStr.h:241
KKStr ExtractQuotedStr(const char *delChars, bool decodeEscapeCharacters)
Definition: KKStr.cpp:3282
CmdLineExpander::~CmdLineExpander ( )

Definition at line 84 of file CmdLineExpander.cpp.

85 {
86 }

Member Function Documentation

void CmdLineExpander::ExpandCmdLine ( kkint32  argc,
char **  argv 
)

Definition at line 92 of file CmdLineExpander.cpp.

Referenced by CmdLineExpander().

95 {
96  parmsGood = true;
97 
98  VectorKKStr initialParameters;
99  {
100  kkint32 y;
101  for (y = 1; y < argc; y++)
102  initialParameters.push_back (argv[y]);
103  }
104 
105  BuildCmdLineParameters (initialParameters);
106  BuildExpandedParameterPairs ();
107 
108  return;
109 } /* ExpandCmdLine */
__int32 kkint32
Definition: KKBaseTypes.h:88
const vector<KKStrPair>& KKB::CmdLineExpander::ExpandedParameterPairs ( ) const
inline

Definition at line 59 of file CmdLineExpander.h.

59 {return expandedParameterPairs;}
const VectorKKStr& KKB::CmdLineExpander::ExpandedParameters ( ) const
inline

Definition at line 58 of file CmdLineExpander.h.

58 {return expandedParameters;}
const KKStr& KKB::CmdLineExpander::LogFileName ( ) const
inline

Definition at line 60 of file CmdLineExpander.h.

60 {return logFileName;}
bool KKB::CmdLineExpander::ParmsGood ( ) const
inline

Definition at line 61 of file CmdLineExpander.h.

61 {return parmsGood;}

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