From patchwork Mon Jan 28 00:41:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 423 Return-Path: Received: from vsp-unauthed02.binero.net (vsp-unauthed02.binero.net [195.74.38.227]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id CF3F560B2D for ; Mon, 28 Jan 2019 01:41:32 +0100 (CET) X-Halon-ID: 67576cce-2295-11e9-911a-0050569116f7 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (unknown [89.233.230.99]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id 67576cce-2295-11e9-911a-0050569116f7; Mon, 28 Jan 2019 01:41:09 +0100 (CET) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Mon, 28 Jan 2019 01:41:05 +0100 Message-Id: <20190128004109.25860-3-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190128004109.25860-1-niklas.soderlund@ragnatech.se> References: <20190128004109.25860-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/6] cam: options: create a template class for options X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 Jan 2019 00:41:33 -0000 In preparation to adding more parsers create a template class to hold the parsed information. The rational for making it a template are that different parsers can index the options using different data types. The OptionsParser index its options using an int while the upcoming KeyValyeParser will index its options using strings for example. Signed-off-by: Niklas Söderlund Reviewed-by: Laurent Pinchart --- src/cam/options.cpp | 24 ------------------------ src/cam/options.h | 28 ++++++++++++++++------------ 2 files changed, 16 insertions(+), 36 deletions(-) diff --git a/src/cam/options.cpp b/src/cam/options.cpp index 83601270207b67b3..b24964a8ce413a85 100644 --- a/src/cam/options.cpp +++ b/src/cam/options.cpp @@ -166,27 +166,3 @@ void OptionsParser::usage() } } } - -OptionsParser::Options::Options() -{ -} - -bool OptionsParser::Options::valid() const -{ - return !values_.empty(); -} - -bool OptionsParser::Options::isSet(int opt) const -{ - return values_.find(opt) != values_.end(); -} - -const std::string &OptionsParser::Options::operator[](int opt) const -{ - return values_.find(opt)->second; -} - -void OptionsParser::Options::clear() -{ - values_.clear(); -} diff --git a/src/cam/options.h b/src/cam/options.h index 491f6a316fffbe5b..a08bfea1ba74c96b 100644 --- a/src/cam/options.h +++ b/src/cam/options.h @@ -17,21 +17,25 @@ enum OptionArgument { ArgumentOptional, }; +template +class OptionsBase +{ +public: + bool valid() const { return !values_.empty(); }; + bool isSet(T opt) const { return values_.find(opt) != values_.end(); }; + const std::string &operator[](T opt) const { return values_.find(opt)->second; }; + +private: + friend class OptionsParser; + std::map values_; + void clear() { values_.clear(); }; +}; + class OptionsParser { public: - class Options { - public: - Options(); - - bool valid() const; - bool isSet(int opt) const; - const std::string &operator[](int opt) const; - - private: - friend class OptionsParser; - std::map values_; - void clear(); + class Options : public OptionsBase + { }; void addOption(int opt, const char *help, const char *name = nullptr,