args-parser 6.3.3
Loading...
Searching...
No Matches
context.hpp
Go to the documentation of this file.
1
31#ifndef ARGS__CONTEXT_HPP__INCLUDED
32#define ARGS__CONTEXT_HPP__INCLUDED
33
34// C++ include.
35#include <utility>
36
37// Args include.
38#include "utils.hpp"
39#include "types.hpp"
40
41
42namespace Args {
43
44//
45// ContextInternal
46//
47
50
51
52//
53// Context
54//
55
60class Context final {
61public:
63 : m_it( m_context.begin() )
64 {
65 }
66
67 explicit Context( ContextInternal items );
68
70 {
71 m_context = std::move( items );
72
73 m_it = m_context.begin();
74
75 return *this;
76 }
77
79 ContextInternal::iterator begin();
80
82 ContextInternal::iterator end();
83
85 bool atEnd();
86
88 ContextInternal::iterator next();
89
91 void putBack();
92
94 void prepend( const String & what );
95
96private:
98
99
100 ContextInternal m_context;
102 ContextInternal::iterator m_it;
103}; // class Context
104
105
106//
107// Context
108//
109
110inline
112 : m_context( std::move( items ) )
113 , m_it( m_context.begin() )
114{
115}
116
117inline ContextInternal::iterator
119{
120 return m_it;
121}
122
123inline ContextInternal::iterator
125{
126 return m_context.end();
127}
128
129inline bool
131{
132 return ( begin() == end() );
133}
134
135inline ContextInternal::iterator
137{
138 if( atEnd() )
139 return end();
140 else
141 return m_it++;
142}
143
144inline void
146{
147 if( begin() != m_context.begin() )
148 --m_it;
149}
150
151inline void
153{
154 m_it = m_context.insert( m_it, what );
155}
156
157} /* namespace Args */
158
159#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:60
ContextInternal::iterator end()
Definition context.hpp:124
void prepend(const String &what)
Prepend context with new item.
Definition context.hpp:152
ContextInternal::iterator begin()
Definition context.hpp:118
ContextInternal::iterator next()
Definition context.hpp:136
Context & operator=(ContextInternal &&items)
Definition context.hpp:69
void putBack()
Put back last taken item.
Definition context.hpp:145
Definition api.hpp:42
std::string String
String type.
Definition types.hpp:324
std::vector< String > StringList
List of strings.
Definition types.hpp:346
StringList ContextInternal
What Context actually is.
Definition context.hpp:49
#define DISABLE_COPY(Class)
Macro for disabling copy.
Definition utils.hpp:50