KSquare Utilities
CmdLineExpander.h
Go to the documentation of this file.
1 /* CmdLineExpander.h -- Pre-process Command Line parameters.
2  * Copyright (C) 1994-2011 Kurt Kramer
3  * For conditions of distribution and use, see copyright notice in KKB.h
4  */
5 
6 #ifndef _CMDLINEEXPANDER_
7 #define _CMDLINEEXPANDER_
8 
9 #include "RunLog.h"
10 #include "KKStr.h"
11 
12 
13 #if !defined(OS_WINDOWS)
14 // Disable "assignment operator could not be generated" warning.
15 #pragma warning(disable : 4512)
16 #endif
17 
18 
19 namespace KKB
20 {
21  /**
22  *@brief Expands command line parameters, by parsing for special parameters and expanding them to their full value.
23  *@details A couple of parameters are specifically searched for and processed. The "-log" and "-CmdFile" parameters.
24  * The "-log" parameter is provides the name of a file where logging messages are to be written to via the "RunLog"
25  * class. The "-CmdFile" parameter provides the name of a text file that contains more command-line parameters that
26  * are to be processed along with all other parameters; the text in this file will be inserted where the original
27  * -"CmdLine" parameter appeared.
28  *@author Kurt Kramer
29  */
30 
32  {
33  public:
34  /**
35  *@brief Constructor using the parameters passed through on the command line into main().
36  */
37  CmdLineExpander (const KKStr& _applicationName,
38  RunLog& _log,
39  kkint32 argc,
40  char** argv
41  );
42 
43  /**
44  *@brief Pass in the command line as a single string. Will parse first before processing.
45  */
46  CmdLineExpander (const KKStr& _applicationName,
47  RunLog& _log,
48  const KKStr& _cmdLine
49  );
50 
51 
52  ~CmdLineExpander ();
53 
54  void ExpandCmdLine (kkint32 argc,
55  char** argv
56  );
57 
58  const VectorKKStr& ExpandedParameters () const {return expandedParameters;}
59  const vector<KKStrPair>& ExpandedParameterPairs () const {return expandedParameterPairs;}
60  const KKStr& LogFileName () const {return logFileName;}
61  bool ParmsGood () const {return parmsGood;}
62 
63  private:
64  void BuildCmdLineParameters (const VectorKKStr& argv);
65 
66  void BuildExpandedParameterPairs ();
67 
68  void ExtractParametersFromFile (const KKStr& cmdFileName,
69  VectorKKStr& cmdFileParameters,
70  bool& validFile
71  );
72 
73  bool ParameterIsASwitch (const KKStr& parm);
74 
75  KKStr applicationName;
76  VectorKKStr cmdFileStack;
77  vector<KKStrPair> expandedParameterPairs;
78  VectorKKStr expandedParameters;
79  RunLog& log;
80  KKStr logFileName;
81  bool parmsGood;
82  }; /* CmdLineExpander */
83 
84 
86 
87 } /* namespace KKB */
88 
89 
90 #endif
const vector< KKStrPair > & ExpandedParameterPairs() const
CmdLineExpander(const KKStr &_applicationName, RunLog &_log, const KKStr &_cmdLine)
Pass in the command line as a single string. Will parse first before processing.
__int32 kkint32
Definition: KKBaseTypes.h:88
CmdLineExpander(const KKStr &_applicationName, RunLog &_log, kkint32 argc, char **argv)
Constructor using the parameters passed through on the command line into main().
KKTHread * KKTHreadPtr
Expands command line parameters, by parsing for special parameters and expanding them to their full v...
const VectorKKStr & ExpandedParameters() const
static KKStr Concat(const std::vector< std::string > &values)
Concatenates the list of &#39;std::string&#39; strings.
Definition: KKStr.cpp:1082
CmdLineExpander * CmdLineExpanderPtr
bool ParmsGood() const
#define OS_WINDOWS
Definition: FirstIncludes.h:11
Used for logging messages.
Definition: RunLog.h:49
void ExpandCmdLine(kkint32 argc, char **argv)
const KKStr & LogFileName() const