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