[libcamera-devel] [PATCH 02/30] cam: options: Move Option struct to options.cpp
Kieran Bingham
kieran.bingham at ideasonboard.com
Mon Jul 12 15:29:25 CEST 2021
On 07/07/2021 03:19, Laurent Pinchart wrote:
> The Option structure is an internal implementation detail and shouldn't
> be exposed in the API. Move it to options.cpp. This requires moving the
> inline constructors and destructors for the KeyValueParser and
> OptionsParser classes to options.cpp as well, as they need a full
> definition of the Option structure.
>
> Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham at ideasonboard.com>
> ---
> src/cam/options.cpp | 21 +++++++++++++++++++++
> src/cam/options.h | 22 ++++++----------------
> 2 files changed, 27 insertions(+), 16 deletions(-)
>
> diff --git a/src/cam/options.cpp b/src/cam/options.cpp
> index 417c3ab49bc9..41968caa0ccb 100644
> --- a/src/cam/options.cpp
> +++ b/src/cam/options.cpp
> @@ -17,6 +17,21 @@
> * Option
> */
>
> +struct Option {
> + int opt;
> + OptionType type;
> + const char *name;
> + OptionArgument argument;
> + const char *argumentName;
> + const char *help;
> + KeyValueParser *keyValueParser;
> + bool isArray;
> +
> + bool hasShortOption() const { return isalnum(opt); }
> + bool hasLongOption() const { return name != nullptr; }
> + const char *typeName() const;
> +};
> +
> const char *Option::typeName() const
> {
> switch (type) {
> @@ -129,6 +144,9 @@ template class OptionsBase<std::string>;
> * KeyValueParser
> */
>
> +KeyValueParser::KeyValueParser() = default;
> +KeyValueParser::~KeyValueParser() = default;
> +
> bool KeyValueParser::addOption(const char *name, OptionType type,
> const char *help, OptionArgument argument)
> {
> @@ -349,6 +367,9 @@ std::vector<OptionValue> OptionValue::toArray() const
> * OptionsParser
> */
>
> +OptionsParser::OptionsParser() = default;
> +OptionsParser::~OptionsParser() = default;
> +
> bool OptionsParser::addOption(int opt, OptionType type, const char *help,
> const char *name, OptionArgument argument,
> const char *argumentName, bool array)
> diff --git a/src/cam/options.h b/src/cam/options.h
> index d0defb4bd665..688fe26011f8 100644
> --- a/src/cam/options.h
> +++ b/src/cam/options.h
> @@ -14,6 +14,7 @@
>
> class KeyValueParser;
> class OptionValue;
> +struct Option;
>
> enum OptionArgument {
> ArgumentNone,
> @@ -28,21 +29,6 @@ enum OptionType {
> OptionKeyValue,
> };
>
> -struct Option {
> - int opt;
> - OptionType type;
> - const char *name;
> - OptionArgument argument;
> - const char *argumentName;
> - const char *help;
> - KeyValueParser *keyValueParser;
> - bool isArray;
> -
> - bool hasShortOption() const { return isalnum(opt); }
> - bool hasLongOption() const { return name != nullptr; }
> - const char *typeName() const;
> -};
> -
> template<typename T>
> class OptionsBase
> {
> @@ -73,7 +59,8 @@ public:
> {
> };
>
> - virtual ~KeyValueParser() = default;
> + KeyValueParser();
> + virtual ~KeyValueParser();
>
> bool addOption(const char *name, OptionType type, const char *help,
> OptionArgument argument = ArgumentNone);
> @@ -133,6 +120,9 @@ public:
> {
> };
>
> + OptionsParser();
> + ~OptionsParser();
> +
> bool addOption(int opt, OptionType type, const char *help,
> const char *name = nullptr,
> OptionArgument argument = ArgumentNone,
>
More information about the libcamera-devel
mailing list