Realm
A distributed, event-based tasking library
Loading...
Searching...
No Matches
cmdline.h
Go to the documentation of this file.
1/*
2 * Copyright 2025 Stanford University, NVIDIA Corporation
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18// command-line processing helpers
19
20#ifndef REALM_CMDLINE_H
21#define REALM_CMDLINE_H
22
23#include "realm/realm_config.h"
24
25#include "realm/realm_c.h"
26
27#include <vector>
28#include <string>
29
30namespace Realm {
31
32 class CommandLineOption;
33
35 public:
36 CommandLineParser(void) = default;
38
39 template <typename T>
40 CommandLineParser &add_option_int(const std::string &optname, T &target,
41 bool keep = false);
42
43 template <typename T>
44 CommandLineParser &add_option_int_units(const std::string &optname, T &target,
45 char default_unit = 0, bool binary = true,
46 bool keep = false);
47
48 template <typename T>
49 CommandLineParser &add_option_string(const std::string &optname, T &target,
50 bool keep = false);
51
52 CommandLineParser &add_option_string(const std::string &optname, char *target,
53 size_t maxlen, bool keep = false);
54
55 template <typename T>
56 CommandLineParser &add_option_stringlist(const std::string &optname, T &target,
57 bool keep = false);
58
59 CommandLineParser &add_option_bool(const std::string &optname, bool &target,
60 bool keep = false);
61
62 template <typename T>
63 CommandLineParser &add_option_method(const std::string &optname, T *target,
64 bool (T::*method)(const std::string &),
65 bool keep = false);
66
67 RealmStatus parse_command_line_v2(std::vector<std::string> &cmdline);
68 RealmStatus parse_command_line_v2(int argc, const char *argv[]);
69 RealmStatus parse_command_line_v2(int argc, char *argv[]);
70
71 bool parse_command_line(std::vector<std::string> &cmdline);
72 bool parse_command_line(int argc, const char *argv[]);
73 bool parse_command_line(int argc, char *argv[]);
74
75 protected:
76 std::vector<CommandLineOption *> options;
77 };
78
80 public:
81 CommandLineOption(const std::string &_optname, bool _keep);
82 virtual ~CommandLineOption(void);
83
84 virtual bool match(const std::string &s);
85 virtual bool keep_arg(void) const;
86
87 virtual int parse_argument(std::vector<std::string> &cmdline,
88 std::vector<std::string>::iterator &pos) = 0;
89 virtual int parse_argument(int &pos, int argc, const char *argv[]) = 0;
90
91 protected:
92 std::string optname;
93 bool keep;
94 };
95
96 template <typename T>
98 : public CommandLineOption {
99 public:
100 IntegerCommandLineOption(const std::string &_optname, bool _keep, T &_target);
101
102 virtual int parse_argument(std::vector<std::string> &cmdline,
103 std::vector<std::string>::iterator &pos);
104 virtual int parse_argument(int &pos, int argc, const char *argv[]);
105
106 protected:
108 };
109
110 template <typename T>
112 : public CommandLineOption {
113 public:
114 IntegerUnitsCommandLineOption(const std::string &_optname, char _default_unit,
115 bool _binary, bool _keep, T &_target);
116
117 virtual int parse_argument(std::vector<std::string> &cmdline,
118 std::vector<std::string>::iterator &pos);
119 virtual int parse_argument(int &pos, int argc, const char *argv[]);
120
121 protected:
123 bool binary;
125 };
126
128 : public CommandLineOption {
129 public:
130 StringCommandLineOption(const std::string &_optname, bool _keep,
131 std::string &_target);
132 StringCommandLineOption(const std::string &_optname, bool _keep, char *_target,
133 size_t _maxlen);
134
135 virtual int parse_argument(std::vector<std::string> &cmdline,
136 std::vector<std::string>::iterator &pos);
137 virtual int parse_argument(int &pos, int argc, const char *argv[]);
138
139 protected:
140 std::string *target_str;
143 };
144
146 : public CommandLineOption {
147 public:
148 StringListCommandLineOption(const std::string &_optname, bool _keep,
149 std::vector<std::string> &_target);
150
151 virtual int parse_argument(std::vector<std::string> &cmdline,
152 std::vector<std::string>::iterator &pos);
153 virtual int parse_argument(int &pos, int argc, const char *argv[]);
154
155 protected:
156 std::vector<std::string> &target;
157 };
158
160 : public CommandLineOption {
161 public:
162 BooleanCommandLineOption(const std::string &_optname, bool _keep, bool &_target);
163
164 virtual int parse_argument(std::vector<std::string> &cmdline,
165 std::vector<std::string>::iterator &pos);
166 virtual int parse_argument(int &pos, int argc, const char *argv[]);
167
168 protected:
169 bool &target;
170 };
171
172 template <typename T>
174 : public CommandLineOption {
175 public:
176 MethodCommandLineOption(const std::string &_optname, bool _keep, T *_target,
177 bool (T::*_method)(const std::string &));
178
179 virtual int parse_argument(std::vector<std::string> &cmdline,
180 std::vector<std::string>::iterator &pos);
181 virtual int parse_argument(int &pos, int argc, const char *argv[]);
182
183 protected:
185 bool (T::*method)(const std::string &);
186 };
187
188}; // namespace Realm
189
190#include "realm/cmdline.inl"
191
192#endif // ifndef REALM_CMDLINE_H
Definition cmdline.h:160
virtual int parse_argument(std::vector< std::string > &cmdline, std::vector< std::string >::iterator &pos)
virtual int parse_argument(int &pos, int argc, const char *argv[])
BooleanCommandLineOption(const std::string &_optname, bool _keep, bool &_target)
bool & target
Definition cmdline.h:169
Definition cmdline.h:79
virtual bool match(const std::string &s)
virtual bool keep_arg(void) const
bool keep
Definition cmdline.h:93
std::string optname
Definition cmdline.h:92
virtual int parse_argument(std::vector< std::string > &cmdline, std::vector< std::string >::iterator &pos)=0
CommandLineOption(const std::string &_optname, bool _keep)
virtual int parse_argument(int &pos, int argc, const char *argv[])=0
virtual ~CommandLineOption(void)
Definition cmdline.h:34
CommandLineParser & add_option_stringlist(const std::string &optname, T &target, bool keep=false)
CommandLineParser & add_option_string(const std::string &optname, T &target, bool keep=false)
CommandLineParser & add_option_int_units(const std::string &optname, T &target, char default_unit=0, bool binary=true, bool keep=false)
CommandLineParser & add_option_method(const std::string &optname, T *target, bool(T::*method)(const std::string &), bool keep=false)
RealmStatus parse_command_line_v2(std::vector< std::string > &cmdline)
CommandLineParser(void)=default
CommandLineParser & add_option_string(const std::string &optname, char *target, size_t maxlen, bool keep=false)
std::vector< CommandLineOption * > options
Definition cmdline.h:76
bool parse_command_line(int argc, char *argv[])
RealmStatus parse_command_line_v2(int argc, char *argv[])
CommandLineParser & add_option_bool(const std::string &optname, bool &target, bool keep=false)
bool parse_command_line(int argc, const char *argv[])
bool parse_command_line(std::vector< std::string > &cmdline)
CommandLineParser & add_option_int(const std::string &optname, T &target, bool keep=false)
RealmStatus parse_command_line_v2(int argc, const char *argv[])
Definition cmdline.h:98
T & target
Definition cmdline.h:107
virtual int parse_argument(int &pos, int argc, const char *argv[])
IntegerCommandLineOption(const std::string &_optname, bool _keep, T &_target)
virtual int parse_argument(std::vector< std::string > &cmdline, std::vector< std::string >::iterator &pos)
Definition cmdline.h:112
T & target
Definition cmdline.h:124
char default_unit
Definition cmdline.h:122
virtual int parse_argument(std::vector< std::string > &cmdline, std::vector< std::string >::iterator &pos)
bool binary
Definition cmdline.h:123
virtual int parse_argument(int &pos, int argc, const char *argv[])
IntegerUnitsCommandLineOption(const std::string &_optname, char _default_unit, bool _binary, bool _keep, T &_target)
Definition cmdline.h:174
T * target
Definition cmdline.h:184
virtual int parse_argument(std::vector< std::string > &cmdline, std::vector< std::string >::iterator &pos)
virtual int parse_argument(int &pos, int argc, const char *argv[])
MethodCommandLineOption(const std::string &_optname, bool _keep, T *_target, bool(T::*_method)(const std::string &))
Definition cmdline.h:128
StringCommandLineOption(const std::string &_optname, bool _keep, std::string &_target)
char * target_array
Definition cmdline.h:141
virtual int parse_argument(int &pos, int argc, const char *argv[])
std::string * target_str
Definition cmdline.h:140
virtual int parse_argument(std::vector< std::string > &cmdline, std::vector< std::string >::iterator &pos)
StringCommandLineOption(const std::string &_optname, bool _keep, char *_target, size_t _maxlen)
size_t target_arrlen
Definition cmdline.h:142
Definition cmdline.h:146
virtual int parse_argument(int &pos, int argc, const char *argv[])
virtual int parse_argument(std::vector< std::string > &cmdline, std::vector< std::string >::iterator &pos)
StringListCommandLineOption(const std::string &_optname, bool _keep, std::vector< std::string > &_target)
std::vector< std::string > & target
Definition cmdline.h:156
#define REALM_INTERNAL_API_EXTERNAL_LINKAGE
Definition compiler_support.h:218
#define REALM_PUBLIC_API
Definition compiler_support.h:217
Definition activemsg.h:38
Definition indexspace.h:1279
realm_status_t RealmStatus
Definition realm_c.h:355