Skip to content

Commit 5870513

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 c67a580 commit 5870513

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
@@ -196,6 +196,23 @@ void function_call_harness_generatort::validate_options()
196196
"--" FUNCTION_HARNESS_GENERATOR_FUNCTION_OPT};
197197
}
198198

199+
std::size_t function_call_harness_generatort::require_one_size_value(
200+
const std::string &option,
201+
const std::list<std::string> &values)
202+
{
203+
static auto const string_value = require_exactly_one_value(option, values);
204+
auto value = string2optional<std::size_t>(string_value, 10);
205+
if(value.has_value())
206+
{
207+
return value.value();
208+
}
209+
else
210+
{
211+
throw invalid_command_line_argument_exceptiont{
212+
"failed to parse `" + string_value + "' as integer", "--" + option};
213+
}
214+
}
215+
199216
const symbolt &
200217
function_call_harness_generatort::implt::lookup_function_to_call()
201218
{

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)