aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/getopt/small/ygetopt.h
blob: 615d3dd18eec43c47f7e047cb028a2398cc60d56 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#pragma once

#include <util/generic/fwd.h>
#include <util/generic/ptr.h>

class TGetOpt {
public:
    class TIterator {
        friend class TGetOpt;

    public:
        char Key() const noexcept;
        const char* Arg() const noexcept;

        inline bool HaveArg() const noexcept {
            return Arg();
        }

        inline void operator++() {
            Next();
        }

        inline bool operator==(const TIterator& r) const noexcept {
            return AtEnd() == r.AtEnd();
        }

        inline bool operator!=(const TIterator& r) const noexcept {
            return !(*this == r);
        }

        inline TIterator& operator*() noexcept {
            return *this;
        }

        inline const TIterator& operator*() const noexcept {
            return *this;
        }

        inline TIterator* operator->() noexcept {
            return this;
        }

        inline const TIterator* operator->() const noexcept {
            return this;
        }

    private:
        TIterator() noexcept;
        TIterator(const TGetOpt* parent);

        void Next();
        bool AtEnd() const noexcept;

    private:
        class TIterImpl;
        TSimpleIntrusivePtr<TIterImpl> Impl_;
    };

    TGetOpt(int argc, const char* const* argv, const TString& format);

    inline TIterator Begin() const {
        return TIterator(this);
    }

    inline TIterator End() const noexcept {
        return TIterator();
    }

private:
    class TImpl;
    TSimpleIntrusivePtr<TImpl> Impl_;
};