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_Initialize_h
11 #define vtk_m_cont_Initialize_h
12 
13 #include <vtkm/cont/DeviceAdapterTag.h>
14 #include <vtkm/cont/vtkm_cont_export.h>
15 #include <vtkm/internal/ExportMacros.h>
16 
17 #include <string>
18 #include <type_traits>
19 #include <vector>
20 
21 namespace vtkm
22 {
23 namespace cont
24 {
25 
26 struct InitializeResult
27 {
28   /// Device passed into -d, or undefined
29   DeviceAdapterId Device = DeviceAdapterTagUndefined{};
30 
31   /// Usage statement for arguments parsed by VTK-m
32   std::string Usage;
33 };
34 
35 enum class InitializeOptions
36 {
37   None = 0x00,
38 
39   /// Issue an error if the device argument is not specified.
40   RequireDevice = 0x01,
41 
42   /// If no device is specified, treat it as if the user gave --device=Any. This means that
43   /// DeviceAdapterTagUndefined will never be return in the result.
44   DefaultAnyDevice = 0x02,
45 
46   /// Add a help argument. If -h or --help is provided, prints a usage statement. Of course,
47   /// the usage statement will only print out arguments processed by VTK-m.
48   AddHelp = 0x04,
49 
50   /// If an unknown option is encountered, the program terminates with an error and a usage
51   /// statement is printed. If this option is not provided, any unknown options are returned
52   /// in argv. If this option is used, it is a good idea to use AddHelp as well.
53   ErrorOnBadOption = 0x08,
54 
55   /// If an extra argument is encountered, the program terminates with an error and a usage
56   /// statement is printed. If this option is not provided, any unknown arguments are returned
57   /// in argv.
58   ErrorOnBadArgument = 0x10,
59 
60   /// If supplied, Initialize treats its own arguments as the only ones supported by the
61   /// application and provides an error if not followed exactly. This is a convenience
62   /// option that is a combination of ErrorOnBadOption, ErrorOnBadArgument, and AddHelp.
63   Strict = ErrorOnBadOption | ErrorOnBadArgument | AddHelp
64 };
65 
66 // Allow options to be used as a bitfield
67 inline InitializeOptions operator|(const InitializeOptions& lhs, const InitializeOptions& rhs)
68 {
69   using T = std::underlying_type<InitializeOptions>::type;
70   return static_cast<InitializeOptions>(static_cast<T>(lhs) | static_cast<T>(rhs));
71 }
72 inline InitializeOptions operator&(const InitializeOptions& lhs, const InitializeOptions& rhs)
73 {
74   using T = std::underlying_type<InitializeOptions>::type;
75   return static_cast<InitializeOptions>(static_cast<T>(lhs) & static_cast<T>(rhs));
76 }
77 
78 /**
79  * Initialize the VTKm library, parsing arguments when provided:
80  * - Sets log level names when logging is configured.
81  * - Sets the calling thread as the main thread for logging purposes.
82  * - Sets the default log level to the argument provided to -v.
83  * - Forces usage of the device name passed to -d or --device.
84  * - Prints usage when -h is passed.
85  *
86  * The parameterless version only sets up log level names.
87  *
88  * Additional options may be supplied via the @a opts argument, such as
89  * requiring the -d option.
90  *
91  * Results are available in the returned InitializeResult.
92  *
93  * @note This method may call exit() on parse error.
94  * @{
95  */
96 VTKM_CONT_EXPORT
97 VTKM_CONT
98 InitializeResult Initialize(int& argc,
99                             char* argv[],
100                             InitializeOptions opts = InitializeOptions::None);
101 VTKM_CONT_EXPORT
102 VTKM_CONT
103 InitializeResult Initialize();
104 /**@}*/
105 }
106 } // end namespace vtkm::cont
107 
108 
109 #endif // vtk_m_cont_Initialize_h
110