Skip to content

Commit 298daec

Browse files
Add helper to get exactly one size value
Small helper to convert a program argument to size_t and throw an exception if it doesn't work. Co-authored-by: Fotis Koutoulakis <[email protected]> Co-authored-by: Hannes Steffenhagen <[email protected]>
1 parent 2c4c545 commit 298daec

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/goto-harness/function_call_harness_generator.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,23 @@ void function_call_harness_generatort::validate_options()
184184
"--" FUNCTION_HARNESS_GENERATOR_FUNCTION_OPT};
185185
}
186186

187+
std::size_t function_call_harness_generatort::require_one_size_value(
188+
const std::string &option,
189+
const std::list<std::string> &values)
190+
{
191+
static auto const string_value = require_exactly_one_value(option, values);
192+
auto value = string2optional<std::size_t>(string_value, 10);
193+
if(value.has_value())
194+
{
195+
return value.value();
196+
}
197+
else
198+
{
199+
throw invalid_command_line_argument_exceptiont{
200+
"failed to parse `" + string_value + "' as integer", "--" + option};
201+
}
202+
}
203+
187204
const symbolt &
188205
function_call_harness_generatort::implt::lookup_function_to_call()
189206
{

src/goto-harness/function_call_harness_generator.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ class function_call_harness_generatort : public goto_harness_generatort
3636
void validate_options() override;
3737

3838
private:
39+
std::size_t require_one_size_value(
40+
const std::string &option,
41+
const std::list<std::string> &values);
3942
struct implt;
4043
std::unique_ptr<implt> p_impl;
4144
};

0 commit comments

Comments
 (0)