MAK Data Logger API Documentation for HLA
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
lgrAppCmdLine.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 1992-2025 MAK Technologies, Inc
3 ** All rights reserved.
4 ******************************************************************************/
5 
8 
9 #pragma once
10 
11 #include <cmdLine/cmdLine.h>
12 #include <lgrCore/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", bool allocateConsole=true);
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;
42  };
43 
44  inline DtLgrCmdLine::DtLgrCmdLine(const std::string& message,
45  const char delimiter, const std::string& version, bool allocateConsole)
46  : CmdLine(message,delimiter,version)
47  , myUnlabeledArgument(0)
48  , myAllocateConsole(allocateConsole)
49  {
50  }
51 
52  inline void DtLgrCmdLine::addUnlabeled( DtCmdLine::Arg* a )
53  {
55  add(a);
56  }
57 
58  inline bool DtLgrCmdLine::parseInput(int argc, char* const * argv)
59  {
60  try
61  {
62  std::vector<std::string> args;
63  int requiredCount = 0;
64  int i=1;
65 
66  DtFilename progName = argv[0];
67  progName.stripPath();
68  _progName = progName.c_str();
69 
71  for (i = 1; i < argc; i++)
72  args.push_back(argv[i]);
73 
74  for (i = 0; static_cast<unsigned>(i) < args.size(); i++)
75  {
76  bool matched = false;
77  for (DtCmdLine::ArgListIterator it = _argList.begin(); !matched && it != _argList.end(); it++)
78  {
79  if ( (*it)->processArg( &i, args ) )
80  {
81  if ((*it) == myUnlabeledArgument
82  && args[i].size() > 0 && args[i][0] == myUnlabeledArgument->flagStartChar())
83  {
84  throw(DtCmdLine::CmdLineParseException("Is not recognized!",
85  args[i]));
86  }
87  requiredCount += _xorHandler.check( *it );
88  matched = true;
89  }
90  }
91 
94  if ( !matched && _emptyCombined( args[i] ) )
95  matched = true;
96 
97  if ( !matched && !DtCmdLine::Arg::ignoreRest() )
98  throw(DtCmdLine::CmdLineParseException("Couldn't find match for argument",
99  args[i]));
100  }
101 
102  if ( requiredCount < _numRequired )
103  throw(DtCmdLine::CmdLineParseException("One or more required arguments missing!"));
104 
105  if ( requiredCount > _numRequired )
106  throw(DtCmdLine::CmdLineParseException("Too many arguments!"));
107 
108  return true;
109 
110  }
111  catch ( DtCmdLine::ArgException& e )
112  {
113  if (myAllocateConsole)
114  {
116  }
117 
118  _output->failure(*this,e);
119 
120  int oldNotifyLevel = DtNotifyLevel;
121  DtNotifyLevel = 3;
122 
123  if (myPressAnyKey)
124  {
125  DtInfo << "Press any key to continue" << std::endl;
126 
127  while (DtPollBlockingInputChar() == '\0')
128  {
129  DtSleep(0.1);
130  }
131  }
132 
133  DtNotifyLevel = oldNotifyLevel;
134  return false;
135  }
136  }
137 }
138 
Contains the MAKLogger::DtLgrConsole subclass of DtRunnable.
DtCmdLine::Arg * myUnlabeledArgument
The unlabeled argument if it exists.
Definition: lgrAppCmdLine.h:40
static void allocateConsole()
void addUnlabeled(DtCmdLine::Arg *a)
Add an unlabeled argument.
Definition: lgrAppCmdLine.h:52
Logger Command line object for parsing command input.
Definition: lgrAppCmdLine.h:19
bool parseInput(int argc, char *const *argv)
Parse the input.
Definition: lgrAppCmdLine.h:58
DtLgrCmdLine(const std::string &message, const char delimiter= ' ', const std::string &version="none", bool allocateConsole=true)
Definition: lgrAppCmdLine.h:44
bool myAllocateConsole
Definition: lgrAppCmdLine.h:41

Document ID: Generated on Thu Dec 18 15:35:09 EST 2025 from SVN revision 282494
Copyright © 2024 MAK Technologies. All Rights Reserved (www.mak.com)