ygetopt.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #pragma once
  2. #include <util/generic/fwd.h>
  3. #include <util/generic/ptr.h>
  4. class TGetOpt {
  5. public:
  6. class TIterator {
  7. friend class TGetOpt;
  8. public:
  9. char Key() const noexcept;
  10. const char* Arg() const noexcept;
  11. inline bool HaveArg() const noexcept {
  12. return Arg();
  13. }
  14. inline void operator++() {
  15. Next();
  16. }
  17. inline bool operator==(const TIterator& r) const noexcept {
  18. return AtEnd() == r.AtEnd();
  19. }
  20. inline bool operator!=(const TIterator& r) const noexcept {
  21. return !(*this == r);
  22. }
  23. inline TIterator& operator*() noexcept {
  24. return *this;
  25. }
  26. inline const TIterator& operator*() const noexcept {
  27. return *this;
  28. }
  29. inline TIterator* operator->() noexcept {
  30. return this;
  31. }
  32. inline const TIterator* operator->() const noexcept {
  33. return this;
  34. }
  35. private:
  36. TIterator() noexcept;
  37. TIterator(const TGetOpt* parent);
  38. void Next();
  39. bool AtEnd() const noexcept;
  40. private:
  41. class TIterImpl;
  42. TSimpleIntrusivePtr<TIterImpl> Impl_;
  43. };
  44. TGetOpt(int argc, const char* const* argv, const TString& format);
  45. inline TIterator Begin() const {
  46. return TIterator(this);
  47. }
  48. inline TIterator End() const noexcept {
  49. return TIterator();
  50. }
  51. private:
  52. class TImpl;
  53. TSimpleIntrusivePtr<TImpl> Impl_;
  54. };