forked from microsoft/winget-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInvocation.h
More file actions
48 lines (38 loc) · 1.73 KB
/
Invocation.h
File metadata and controls
48 lines (38 loc) · 1.73 KB
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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#pragma once
#include <map>
#include <vector>
namespace AppInstaller::CLI
{
// Contains the raw command line arguments and functionality to iterate and consume them.
struct Invocation
{
Invocation(std::vector<std::string>&& args) : m_args(std::move(args)) {}
struct iterator
{
iterator(size_t arg, std::vector<std::string>& args) : m_arg(arg), m_args(args) {}
iterator(const iterator&) = default;
iterator& operator=(const iterator&) = default;
iterator operator++() { return { ++m_arg, m_args }; }
iterator operator++(int) { return { m_arg++, m_args }; }
iterator operator--() { return { --m_arg, m_args }; }
iterator operator--(int) { return { m_arg--, m_args }; }
bool operator==(const iterator& other) const { return m_arg == other.m_arg; }
bool operator!=(const iterator& other) const { return m_arg != other.m_arg; }
const std::string& operator*() const { return m_args[m_arg]; }
const std::string* operator->() const { return &(m_args[m_arg]); }
size_t index() const { return m_arg; }
private:
size_t m_arg;
std::vector<std::string>& m_args;
};
size_t size() const { return m_args.size(); }
iterator begin() { return { m_currentFirstArg, m_args }; }
iterator end() { return { m_args.size(), m_args }; }
void consume(const iterator& i) { m_currentFirstArg = i.index() + 1; }
private:
std::vector<std::string> m_args;
size_t m_currentFirstArg = 0;
};
}