aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/getopt/small/last_getopt_parse_result.h
diff options
context:
space:
mode:
authorAnton Samokhvalov <pg83@yandex.ru>2022-02-10 16:45:15 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:45:15 +0300
commit72cb13b4aff9bc9cf22e49251bc8fd143f82538f (patch)
treeda2c34829458c7d4e74bdfbdf85dff449e9e7fb8 /library/cpp/getopt/small/last_getopt_parse_result.h
parent778e51ba091dc39e7b7fcab2b9cf4dbedfb6f2b5 (diff)
downloadydb-72cb13b4aff9bc9cf22e49251bc8fd143f82538f.tar.gz
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/getopt/small/last_getopt_parse_result.h')
-rw-r--r--library/cpp/getopt/small/last_getopt_parse_result.h282
1 files changed, 141 insertions, 141 deletions
diff --git a/library/cpp/getopt/small/last_getopt_parse_result.h b/library/cpp/getopt/small/last_getopt_parse_result.h
index 1ab6f598c9..7f0da9c568 100644
--- a/library/cpp/getopt/small/last_getopt_parse_result.h
+++ b/library/cpp/getopt/small/last_getopt_parse_result.h
@@ -4,58 +4,58 @@
#include "last_getopt_parser.h"
namespace NLastGetopt {
- /**
+ /**
* NLastGetopt::TOptParseResult contains all arguments for exactly one TOpt,
* that have been fetched during parsing
*
* The class is a wraper over a vector of nil-terminated strings.
*/
- class TOptParseResult {
- public:
- typedef TVector<const char*> TValues;
-
- public:
- TOptParseResult(const TOpt* opt = nullptr)
- : Opt_(opt)
- {
- }
-
- public:
- const TOpt& Opt() const {
- return *Opt_;
- }
- const TOpt* OptPtr() const {
- return Opt_;
- }
- const TValues& Values() const {
- return Values_;
- }
- bool Empty() const {
- return Values().empty();
- }
- size_t Count() const {
- return Values_.size();
- }
- void AddValue(const char* val) {
- if (nullptr != val)
- Values_.push_back(val);
- }
- const char* DefVal(const char* def = nullptr) const {
- return Opt().HasDefaultValue() ? Opt().GetDefaultValue().c_str() : def;
- }
- const char* Front(const char* def = nullptr) const {
- return Empty() ? DefVal(def) : Values().front();
- }
- const char* Back(const char* def = nullptr) const {
- return Empty() ? DefVal(def) : Values().back();
- }
-
- private:
- const TOpt* Opt_;
- TValues Values_;
- };
-
- /**
+ class TOptParseResult {
+ public:
+ typedef TVector<const char*> TValues;
+
+ public:
+ TOptParseResult(const TOpt* opt = nullptr)
+ : Opt_(opt)
+ {
+ }
+
+ public:
+ const TOpt& Opt() const {
+ return *Opt_;
+ }
+ const TOpt* OptPtr() const {
+ return Opt_;
+ }
+ const TValues& Values() const {
+ return Values_;
+ }
+ bool Empty() const {
+ return Values().empty();
+ }
+ size_t Count() const {
+ return Values_.size();
+ }
+ void AddValue(const char* val) {
+ if (nullptr != val)
+ Values_.push_back(val);
+ }
+ const char* DefVal(const char* def = nullptr) const {
+ return Opt().HasDefaultValue() ? Opt().GetDefaultValue().c_str() : def;
+ }
+ const char* Front(const char* def = nullptr) const {
+ return Empty() ? DefVal(def) : Values().front();
+ }
+ const char* Back(const char* def = nullptr) const {
+ return Empty() ? DefVal(def) : Values().back();
+ }
+
+ private:
+ const TOpt* Opt_;
+ TValues Values_;
+ };
+
+ /**
* NLastGetopt::TOptsParseResult contains result of parsing argc,argv be parser.
*
* In most common case constructed by argc,argv pair and rules (TOpts).
@@ -64,20 +64,20 @@ namespace NLastGetopt {
* If error during parsing occures, the program aborts with exit code 1.
* Note, that if PERMUTE mode is on, then data, pointed by argv can be changed.
*/
- class TOptsParseResult {
- private:
- THolder<TOptsParser> Parser_; //The instance of parser.
+ class TOptsParseResult {
+ private:
+ THolder<TOptsParser> Parser_; //The instance of parser.
- // XXX: make argc, argv
- typedef TVector<TOptParseResult> TdVec;
+ // XXX: make argc, argv
+ typedef TVector<TOptParseResult> TdVec;
- TdVec Opts_; //Parsing result for all options, that have been explicitly defined in argc/argv
- TdVec OptsDef_; //Parsing result for options, that have been defined by default values only
+ TdVec Opts_; //Parsing result for all options, that have been explicitly defined in argc/argv
+ TdVec OptsDef_; //Parsing result for options, that have been defined by default values only
- private:
- TOptParseResult& OptParseResult();
+ private:
+ TOptParseResult& OptParseResult();
- /**
+ /**
* Searchs for object in given container
*
* @param vec container
@@ -85,49 +85,49 @@ namespace NLastGetopt {
*
* @retunr ptr on corresponding TOptParseResult
*/
- static const TOptParseResult* FindParseResult(const TdVec& vec, const TOpt* opt);
+ static const TOptParseResult* FindParseResult(const TdVec& vec, const TOpt* opt);
- protected:
- /**
+ protected:
+ /**
* Performs parsing of comand line arguments.
*/
- void Init(const TOpts* options, int argc, const char** argv);
+ void Init(const TOpts* options, int argc, const char** argv);
- TOptsParseResult() = default;
+ TOptsParseResult() = default;
- public:
- /**
+ public:
+ /**
* The action in case of parser failure.
* Allows to asjust behavior in derived classes.
* By default prints error string and aborts the program
*/
- virtual void HandleError() const;
+ virtual void HandleError() const;
- /**
+ /**
* Constructs object by parsing arguments with given rules
*
* @param options ptr on parsing rules
* @param argc
* @param argv
*/
- TOptsParseResult(const TOpts* options, int argc, const char* argv[]) {
- Init(options, argc, argv);
- }
+ TOptsParseResult(const TOpts* options, int argc, const char* argv[]) {
+ Init(options, argc, argv);
+ }
- /**
+ /**
* Constructs object by parsing arguments with given rules
*
* @param options ptr on parsing rules
* @param argc
* @param argv
*/
- TOptsParseResult(const TOpts* options, int argc, char* argv[]) {
- Init(options, argc, const_cast<const char**>(argv));
- }
+ TOptsParseResult(const TOpts* options, int argc, char* argv[]) {
+ Init(options, argc, const_cast<const char**>(argv));
+ }
- virtual ~TOptsParseResult() = default;
+ virtual ~TOptsParseResult() = default;
- /**
+ /**
* Search for TOptParseResult that corresponds to given option (TOpt)
*
* @param opt ptr on required object
@@ -135,9 +135,9 @@ namespace NLastGetopt {
*
* @return ptr on result
*/
- const TOptParseResult* FindOptParseResult(const TOpt* opt, bool includeDefault = false) const;
+ const TOptParseResult* FindOptParseResult(const TOpt* opt, bool includeDefault = false) const;
- /**
+ /**
* Search for TOptParseResult that corresponds to given long name
*
* @param name long name of required object
@@ -145,9 +145,9 @@ namespace NLastGetopt {
*
* @return ptr on result
*/
- const TOptParseResult* FindLongOptParseResult(const TString& name, bool includeDefault = false) const;
+ const TOptParseResult* FindLongOptParseResult(const TString& name, bool includeDefault = false) const;
- /**
+ /**
* Search for TOptParseResult that corresponds to given short name
*
* @param c short name of required object
@@ -155,14 +155,14 @@ namespace NLastGetopt {
*
* @return ptr on result
*/
- const TOptParseResult* FindCharOptParseResult(char c, bool includeDefault = false) const;
+ const TOptParseResult* FindCharOptParseResult(char c, bool includeDefault = false) const;
- /**
+ /**
* @return argv[0]
*/
- TString GetProgramName() const;
+ TString GetProgramName() const;
- /**
+ /**
* Print usage string.
*/
void PrintUsage(IOutputStream& os = Cout) const;
@@ -170,97 +170,97 @@ namespace NLastGetopt {
/**
* @return position in [premuted argv] of the first free argument
*/
- size_t GetFreeArgsPos() const;
+ size_t GetFreeArgsPos() const;
- /**
+ /**
* @return number of fetched free arguments
*/
- size_t GetFreeArgCount() const;
+ size_t GetFreeArgCount() const;
- /**
+ /**
* @return all fetched free arguments
*/
- TVector<TString> GetFreeArgs() const;
+ TVector<TString> GetFreeArgs() const;
- /**
+ /**
* @return true if given option exist in results of parsing
*
* @param opt ptr on required object
* @param includeDefault search in results obtained from default values
*
*/
- bool Has(const TOpt* opt, bool includeDefault = false) const;
+ bool Has(const TOpt* opt, bool includeDefault = false) const;
- /**
+ /**
* @return nil terminated string on the last fetched argument of givne option
*
* @param opt ptr on required object
* @param includeDefault search in results obtained from default values
*/
- const char* Get(const TOpt* opt, bool includeDefault = true) const;
+ const char* Get(const TOpt* opt, bool includeDefault = true) const;
- /**
+ /**
* @return nil terminated string on the last fetched argument of givne option
* if option haven't been fetched, given defaultValue will be returned
*
* @param opt ptr on required object
* @param defaultValue
*/
- const char* GetOrElse(const TOpt* opt, const char* defaultValue) const;
+ const char* GetOrElse(const TOpt* opt, const char* defaultValue) const;
- /**
+ /**
* @return true if given option exist in results of parsing
*
* @param name long name of required object
* @param includeDefault search in results obtained from default values
*
*/
- bool Has(const TString& name, bool includeDefault = false) const;
+ bool Has(const TString& name, bool includeDefault = false) const;
- /**
+ /**
* @return nil terminated string on the last fetched argument of givne option
*
* @param name long name of required object
* @param includeDefault search in results obtained from default values
*/
- const char* Get(const TString& name, bool includeDefault = true) const;
+ const char* Get(const TString& name, bool includeDefault = true) const;
- /**
+ /**
* @return nil terminated string on the last fetched argument of givne option
* if option haven't been fetched, given defaultValue will be returned
*
* @param name long name of required object
* @param defaultValue
*/
- const char* GetOrElse(const TString& name, const char* defaultValue) const;
+ const char* GetOrElse(const TString& name, const char* defaultValue) const;
- /**
+ /**
* @return true if given option exist in results of parsing
*
* @param c short name of required object
* @param includeDefault search in results obtained from default values
*
*/
- bool Has(char name, bool includeDefault = false) const;
+ bool Has(char name, bool includeDefault = false) const;
- /**
+ /**
* @return nil terminated string on the last fetched argument of givne option
*
* @param c short name of required object
* @param includeDefault search in results obtained from default values
*/
- const char* Get(char name, bool includeDefault = true) const;
+ const char* Get(char name, bool includeDefault = true) const;
- /**
+ /**
* @return nil terminated string on the last fetched argument of givne option
* if option haven't been fetched, given defaultValue will be returned
*
* @param c short name of required object
* @param defaultValue
*/
- const char* GetOrElse(char name, const char* defaultValue) const;
+ const char* GetOrElse(char name, const char* defaultValue) const;
- /**
+ /**
* for givne option return parsed value of the last fetched argument
* if option haven't been fetched, HandleError action is called
*
@@ -268,18 +268,18 @@ namespace NLastGetopt {
*
* @return FromString<T>(last feteched argument)
*/
- template <typename T, typename TKey>
- T Get(const TKey opt) const {
- const char* value = Get(opt);
- try {
- return NPrivate::OptFromString<T>(value, opt);
- } catch (...) {
- HandleError();
- throw;
- }
+ template <typename T, typename TKey>
+ T Get(const TKey opt) const {
+ const char* value = Get(opt);
+ try {
+ return NPrivate::OptFromString<T>(value, opt);
+ } catch (...) {
+ HandleError();
+ throw;
+ }
}
- /**
+ /**
* for givne option return parsed value of the last fetched argument
* if option haven't been fetched, given defaultValue will be returned
*
@@ -288,34 +288,34 @@ namespace NLastGetopt {
*
* @return FromString<T>(last feteched argument)
*/
- template <typename T, typename TKey>
- T GetOrElse(const TKey opt, const T& defaultValue) const {
- if (Has(opt))
- return Get<T>(opt);
- else
- return defaultValue;
- }
- };
-
- /**
+ template <typename T, typename TKey>
+ T GetOrElse(const TKey opt, const T& defaultValue) const {
+ if (Has(opt))
+ return Get<T>(opt);
+ else
+ return defaultValue;
+ }
+ };
+
+ /**
* NLastGetopt::TOptsParseResultException contains result of parsing argc,argv be parser.
*
* Unlike TOptsParseResult, if error during parsing occures, an exception is thrown.
*
*/
- class TOptsParseResultException: public TOptsParseResult {
- public:
- TOptsParseResultException(const TOpts* options, int argc, const char* argv[]) {
- Init(options, argc, argv);
- }
- TOptsParseResultException(const TOpts* options, int argc, char* argv[]) {
- Init(options, argc, const_cast<const char**>(argv));
- }
- virtual ~TOptsParseResultException() = default;
- void HandleError() const override;
-
- protected:
- TOptsParseResultException() = default;
- };
+ class TOptsParseResultException: public TOptsParseResult {
+ public:
+ TOptsParseResultException(const TOpts* options, int argc, const char* argv[]) {
+ Init(options, argc, argv);
+ }
+ TOptsParseResultException(const TOpts* options, int argc, char* argv[]) {
+ Init(options, argc, const_cast<const char**>(argv));
+ }
+ virtual ~TOptsParseResultException() = default;
+ void HandleError() const override;
+
+ protected:
+ TOptsParseResultException() = default;
+ };
}