diff options
author | Anton Samokhvalov <pg83@yandex.ru> | 2022-02-10 16:45:15 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:15 +0300 |
commit | 72cb13b4aff9bc9cf22e49251bc8fd143f82538f (patch) | |
tree | da2c34829458c7d4e74bdfbdf85dff449e9e7fb8 /library/cpp/getopt/small/ygetopt.cpp | |
parent | 778e51ba091dc39e7b7fcab2b9cf4dbedfb6f2b5 (diff) | |
download | ydb-72cb13b4aff9bc9cf22e49251bc8fd143f82538f.tar.gz |
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/getopt/small/ygetopt.cpp')
-rw-r--r-- | library/cpp/getopt/small/ygetopt.cpp | 194 |
1 files changed, 97 insertions, 97 deletions
diff --git a/library/cpp/getopt/small/ygetopt.cpp b/library/cpp/getopt/small/ygetopt.cpp index 1f52827f74..8952faeeae 100644 --- a/library/cpp/getopt/small/ygetopt.cpp +++ b/library/cpp/getopt/small/ygetopt.cpp @@ -1,108 +1,108 @@ -#include "opt.h" -#include "ygetopt.h" - +#include "opt.h" +#include "ygetopt.h" + #include <util/generic/string.h> #include <util/generic/vector.h> #include <util/generic/yexception.h> - -class TGetOpt::TImpl: public TSimpleRefCount<TImpl> { -public: - inline TImpl(int argc, const char* const* argv, const TString& fmt) - : args(argv, argv + argc) - , format(fmt) - { - if (argc == 0) { - ythrow yexception() << "zero argc"; - } - } - - inline ~TImpl() = default; - - TVector<TString> args; - const TString format; -}; - -class TGetOpt::TIterator::TIterImpl: public TSimpleRefCount<TIterImpl> { -public: - inline TIterImpl(const TGetOpt* parent) - : Args_(parent->Impl_->args) - , ArgsPtrs_(new char*[Args_.size() + 1]) - , Format_(parent->Impl_->format) - , OptLet_(0) - , Arg_(nullptr) - { - for (size_t i = 0; i < Args_.size(); ++i) { - ArgsPtrs_.Get()[i] = Args_[i].begin(); - } - - ArgsPtrs_.Get()[Args_.size()] = nullptr; + +class TGetOpt::TImpl: public TSimpleRefCount<TImpl> { +public: + inline TImpl(int argc, const char* const* argv, const TString& fmt) + : args(argv, argv + argc) + , format(fmt) + { + if (argc == 0) { + ythrow yexception() << "zero argc"; + } + } + + inline ~TImpl() = default; + + TVector<TString> args; + const TString format; +}; + +class TGetOpt::TIterator::TIterImpl: public TSimpleRefCount<TIterImpl> { +public: + inline TIterImpl(const TGetOpt* parent) + : Args_(parent->Impl_->args) + , ArgsPtrs_(new char*[Args_.size() + 1]) + , Format_(parent->Impl_->format) + , OptLet_(0) + , Arg_(nullptr) + { + for (size_t i = 0; i < Args_.size(); ++i) { + ArgsPtrs_.Get()[i] = Args_[i].begin(); + } + + ArgsPtrs_.Get()[Args_.size()] = nullptr; Opt_.Reset(new Opt((int)Args_.size(), ArgsPtrs_.Get(), Format_.data())); - } - - inline ~TIterImpl() = default; - - inline void Next() { - OptLet_ = Opt_->Get(); - Arg_ = Opt_->Arg; - } - - inline char Key() const noexcept { - return (char)OptLet_; - } - - inline const char* Arg() const noexcept { - return Arg_; - } - - inline bool AtEnd() const noexcept { - return OptLet_ == EOF; - } - -private: - TVector<TString> Args_; - TArrayHolder<char*> ArgsPtrs_; - const TString Format_; - THolder<Opt> Opt_; - int OptLet_; - const char* Arg_; -}; - + } + + inline ~TIterImpl() = default; + + inline void Next() { + OptLet_ = Opt_->Get(); + Arg_ = Opt_->Arg; + } + + inline char Key() const noexcept { + return (char)OptLet_; + } + + inline const char* Arg() const noexcept { + return Arg_; + } + + inline bool AtEnd() const noexcept { + return OptLet_ == EOF; + } + +private: + TVector<TString> Args_; + TArrayHolder<char*> ArgsPtrs_; + const TString Format_; + THolder<Opt> Opt_; + int OptLet_; + const char* Arg_; +}; + TGetOpt::TIterator::TIterator() noexcept : Impl_(nullptr) -{ -} - -TGetOpt::TIterator::TIterator(const TGetOpt* parent) - : Impl_(new TIterImpl(parent)) -{ - Next(); -} - -void TGetOpt::TIterator::Next() { - Impl_->Next(); -} - +{ +} + +TGetOpt::TIterator::TIterator(const TGetOpt* parent) + : Impl_(new TIterImpl(parent)) +{ + Next(); +} + +void TGetOpt::TIterator::Next() { + Impl_->Next(); +} + char TGetOpt::TIterator::Key() const noexcept { - return Impl_->Key(); -} - + return Impl_->Key(); +} + bool TGetOpt::TIterator::AtEnd() const noexcept { - if (Impl_.Get()) { - return Impl_->AtEnd(); - } - - return true; -} - + if (Impl_.Get()) { + return Impl_->AtEnd(); + } + + return true; +} + const char* TGetOpt::TIterator::Arg() const noexcept { - if (Impl_.Get()) { - return Impl_->Arg(); - } - + if (Impl_.Get()) { + return Impl_->Arg(); + } + return nullptr; -} - +} + TGetOpt::TGetOpt(int argc, const char* const* argv, const TString& format) - : Impl_(new TImpl(argc, argv, format)) -{ -} + : Impl_(new TImpl(argc, argv, format)) +{ +} |