Skip to content

Commit 0f96839

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 138c675 commit 0f96839

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
@@ -199,6 +199,23 @@ void function_call_harness_generatort::validate_options()
199199
"--" FUNCTION_HARNESS_GENERATOR_FUNCTION_OPT};
200200
}
201201

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

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)