VTK-m  2.2
OptionParserArguments.h
Go to the documentation of this file.
1 //============================================================================
2 // Copyright (c) Kitware, Inc.
3 // All rights reserved.
4 // See LICENSE.txt for details.
5 //
6 // This software is distributed WITHOUT ANY WARRANTY; without even
7 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8 // PURPOSE. See the above copyright notice for more information.
9 //============================================================================
10 #ifndef vtk_m_cont_internal_OptionParserArguments_h
11 #define vtk_m_cont_internal_OptionParserArguments_h
12 
13 #include <vtkm/cont/Logging.h>
15 
16 namespace vtkm
17 {
18 namespace cont
19 {
20 namespace internal
21 {
22 namespace option
23 {
24 
26 enum OptionIndex
27 {
28  // special option for dealing with unknown arguments
29  UNKNOWN,
30 
31  // general vtkm arguments
32  HELP,
33  DEVICE,
34  LOGLEVEL, // not parsed by this parser, but by loguru
35 
36  // All RuntimeDeviceConfiguration specific options
37  NUM_THREADS,
38  NUMA_REGIONS,
39  DEVICE_INSTANCE
40 };
41 
42 struct VtkmArg : public option::Arg
43 {
44  static option::ArgStatus Required(const option::Option& option, bool msg)
45  {
46  if (option.arg == nullptr)
47  {
48  if (msg)
49  {
51  "Missing argument after option '"
52  << std::string(option.name, static_cast<size_t>(option.namelen))
53  << "'.\n");
54  }
55  return option::ARG_ILLEGAL;
56  }
57  else
58  {
59  return option::ARG_OK;
60  }
61  }
62 
63  // Method used for guessing whether an option that do not support (perhaps that calling
64  // program knows about it) has an option attached to it (which should also be ignored).
65  static option::ArgStatus UnknownOption(const option::Option& option, bool msg)
66  {
67  // If we don't have an arg, obviously we don't have an arg.
68  if (option.arg == nullptr)
69  {
70  return option::ARG_NONE;
71  }
72 
73  // The option::Arg::Optional method will return that the ARG is OK if and only if
74  // the argument is attached to the option (e.g. --foo=bar). If that is the case,
75  // then we definitely want to report that the argument is OK.
76  if (option::Arg::Optional(option, msg) == option::ARG_OK)
77  {
78  return option::ARG_OK;
79  }
80 
81  // Now things get tricky. Maybe the next argument is an option or maybe it is an
82  // argument for this option. We will guess that if the next argument does not
83  // look like an option, we will treat it as such.
84  if (option.arg[0] == '-')
85  {
86  return option::ARG_NONE;
87  }
88  else
89  {
90  return option::ARG_OK;
91  }
92  }
93 };
94 
95 } // namespace vtkm::cont::internal::option
96 } // namespace vtkm::cont::internal
97 } // namespace vtkm::cont
98 } // namespace vtkm
99 
100 #endif // vtk_m_cont_internal_OptionParserArguments_h
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
VTKM_LOG_ALWAYS_S
#define VTKM_LOG_ALWAYS_S(level,...)
Definition: Logging.h:215
vtkm::cont::LogLevel::Error
@ Error
Important but non-fatal errors, such as device fail-over.
OptionParser.h
Logging.h
Logging utilities.