MAK Data Logger API Documentation for HLA
lgrAppCmdLine.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 1992-2010 VT MAK
3 ** All rights reserved.
4 ******************************************************************************/
5 
8 
9 #pragma once
10 
11 #include <cmdLine/cmdLine.h>
12 #include "lgrConsole.h"
13 #include "vlutil/vlFilename.h"
14 
15 namespace MAKLogger
16 {
19  class DtLgrCmdLine : public DtCmdLine::CmdLine
20  {
21  public:
22  explicit DtLgrCmdLine(const std::string& message,
23  const char delimiter = ' ',
24  const std::string& version = "none");
25 
30  void addUnlabeled( DtCmdLine::Arg* a );
31 
35  inline bool parseInput(int argc, char* const * argv);
36 
37  protected:
38 
40  DtCmdLine::Arg* myUnlabeledArgument;
41  };
42 
43  inline DtLgrCmdLine::DtLgrCmdLine(const std::string& message,
44  const char delimiter, const std::string& version) :
45  CmdLine(message,delimiter,version),
46  myUnlabeledArgument(0)
47  {
48  }
49 
50  inline void DtLgrCmdLine::addUnlabeled( DtCmdLine::Arg* a )
51  {
53  add(a);
54  }
55 
56  inline bool DtLgrCmdLine::parseInput(int argc, char* const * argv)
57  {
58  try
59  {
60  std::vector<std::string> args;
61  int requiredCount = 0;
62  int i=1;
63 
64  DtFilename progName = argv[0];
65  progName.stripPath();
66  _progName = progName.c_str();
67 
69  for (i = 1; i < argc; i++)
70  args.push_back(argv[i]);
71 
72  for (i = 0; static_cast<unsigned>(i) < args.size(); i++)
73  {
74  bool matched = false;
75  for (DtCmdLine::ArgListIterator it = _argList.begin(); !matched && it != _argList.end(); it++)
76  {
77  if ( (*it)->processArg( &i, args ) )
78  {
79  if ((*it) == myUnlabeledArgument
80  && args[i].size() > 0 && args[i][0] == myUnlabeledArgument->flagStartChar())
81  {
82  throw(DtCmdLine::CmdLineParseException("Is not recognized!",
83  args[i]));
84  }
85  requiredCount += _xorHandler.check( *it );
86  matched = true;
87  }
88  }
89 
92  if ( !matched && _emptyCombined( args[i] ) )
93  matched = true;
94 
95  if ( !matched && !DtCmdLine::Arg::ignoreRest() )
96  throw(DtCmdLine::CmdLineParseException("Couldn't find match for argument",
97  args[i]));
98  }
99 
100  if ( requiredCount < _numRequired )
101  throw(DtCmdLine::CmdLineParseException("One or more required arguments missing!"));
102 
103  if ( requiredCount > _numRequired )
104  throw(DtCmdLine::CmdLineParseException("Too many arguments!"));
105 
106  return true;
107 
108  }
109  catch ( DtCmdLine::ArgException& e )
110  {
112  _output->failure(*this,e);
113 
114  int oldNotifyLevel = DtNotifyLevel;
115  DtNotifyLevel = 3;
116 
117  if (myPressAnyKey)
118  {
119  DtInfo << "Press any key to continue" << std::endl;
120 
121  while (DtPollBlockingInputChar() == '\0')
122  {
123  DtSleep(0.1);
124  }
125  }
126 
127  DtNotifyLevel = oldNotifyLevel;
128  return false;
129  }
130  }
131 }
132 

Document ID: Generated on Thu Apr 10 18:53:01 EDT 2014 from SVN revision 138105
Copyright © 2005-2012 VT MÄK. All Rights Reserved (www.mak.com)