args-parser 6.3.6
Loading...
Searching...
No Matches
context.hpp
Go to the documentation of this file.
1
2/*
3 SPDX-FileCopyrightText: 2026 Igor Mironchik <igor.mironchik@gmail.com>
4 SPDX-License-Identifier: MIT
5*/
6
7#ifndef ARGS__CONTEXT_HPP__INCLUDED
8#define ARGS__CONTEXT_HPP__INCLUDED
9
10// C++ include.
11#include <utility>
12
13// Args include.
14#include "types.hpp"
15#include "utils.hpp"
16
17namespace Args
18{
19
20//
21// ContextInternal
22//
23
26
27//
28// Context
29//
30
35class Context final
36{
37public:
39 : m_it(m_context.begin())
40 {
41 }
42
43 explicit Context(ContextInternal items);
44
46 {
47 m_context = std::move(items);
48
49 m_it = m_context.begin();
50
51 return *this;
52 }
53
55 ContextInternal::iterator begin();
56
58 ContextInternal::iterator end();
59
61 bool atEnd();
62
64 ContextInternal::iterator next();
65
67 void putBack();
68
70 void prepend(const String &what);
71
72private:
74
75
76 ContextInternal m_context;
78 ContextInternal::iterator m_it;
79}; // class Context
80
81//
82// Context
83//
84
86 : m_context(std::move(items))
87 , m_it(m_context.begin())
88{
89}
90
91inline ContextInternal::iterator Context::begin()
92{
93 return m_it;
94}
95
96inline ContextInternal::iterator Context::end()
97{
98 return m_context.end();
99}
100
101inline bool Context::atEnd()
102{
103 return (begin() == end());
104}
105
106inline ContextInternal::iterator Context::next()
107{
108 if (atEnd()) {
109 return end();
110 } else {
111 return m_it++;
112 }
113}
114
115inline void Context::putBack()
116{
117 if (begin() != m_context.begin()) {
118 --m_it;
119 }
120}
121
122inline void Context::prepend(const String &what)
123{
124 m_it = m_context.insert(m_it, what);
125}
126
127} /* namespace Args */
128
129#endif // ARGS__CONTEXT_HPP__INCLUDED
Context is a list of words in the command line that user presented with interface for interacting wit...
Definition context.hpp:36
ContextInternal::iterator end()
Definition context.hpp:96
void prepend(const String &what)
Prepend context with new item.
Definition context.hpp:122
ContextInternal::iterator begin()
Definition context.hpp:91
ContextInternal::iterator next()
Definition context.hpp:106
Context & operator=(ContextInternal &&items)
Definition context.hpp:45
void putBack()
Put back last taken item.
Definition context.hpp:115
Definition api.hpp:18
std::string String
String type.
Definition types.hpp:314
StringList ContextInternal
What Context actually is.
Definition context.hpp:25
std::vector< String > StringList
List of strings.
Definition types.hpp:336
#define DISABLE_COPY(Class)
Macro for disabling copy.
Definition utils.hpp:25