libzypp: zypp/PluginFrame.h Source File

libzypp 17.25.10

PluginFrame.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #ifndef ZYPP_PLUGINFRAME_H
13 #define ZYPP_PLUGINFRAME_H
14
15 #include <iosfwd>
16 #include <string>
17 #include <map>
18
19 #include <zypp/base/PtrTypes.h>
20
21 #include <zypp/PluginFrameException.h>
22
24 namespace zypp
25 {
26
40 class PluginFrame
41 {
42 friend std::ostream & operator<<( std::ostream & str, const PluginFrame & obj );
43 friend bool operator==( const PluginFrame & lhs, const PluginFrame & rhs );
44
45 typedef const std::initializer_list<std::pair<std::string,std::string>> & HeaderInitializerList;
46
47 public:
49 static const std::string & ackCommand();
51 static const std::string & errorCommand();
53 static const std::string & enomethodCommand();
54
55 public:
57 typedef PluginFrameException Exception;
58
60 PluginFrame();
61
65 PluginFrame( const std::string & command_r );
66
70 PluginFrame( const std::string & command_r, const std::string & body_r );
71
75 PluginFrame( const std::string & command_r, HeaderInitializerList contents_r );
76
80 PluginFrame( const std::string & command_r, const std::string & body_r, HeaderInitializerList contents_r );
81
86 PluginFrame( std::istream & stream_r );
87
88 public:
90 bool empty() const;
91
93 explicit operator bool() const
94 { return !empty(); }
95
96 public:
98 const std::string & command() const;
99
103 void setCommand( const std::string & command_r );
104
106 bool isAckCommand() const
107 { return command() == ackCommand(); }
108
110 bool isErrorCommand() const
111 {return command() == errorCommand(); }
112
114 bool isEnomethodCommand() const
115 {return command() == enomethodCommand(); }
116
118 const std::string & body() const;
119
128 std::string & bodyRef();
129
131 void setBody( const std::string & body_r );
132
133 public:
135 typedef std::multimap<std::string, std::string> HeaderList;
136
138 typedef HeaderList::const_iterator HeaderListIterator;
139
140 private:
142 HeaderList & headerList();
143
144 public:
146 const HeaderList & headerList() const;
147
149 bool headerEmpty() const
150 { return headerList().empty(); }
151
153 unsigned headerSize() const
154 { return headerList().size(); }
155
157 HeaderListIterator headerBegin() const
158 { return headerList().begin(); }
159
161 HeaderListIterator headerEnd() const
162 { return headerList().end(); }
163
165 void headerClear()
166 { headerList().clear(); }
167
168
170 bool hasKey( const std::string & key_r ) const
171 { return ! keyEmpty( key_r ); }
172
174 bool keyEmpty( const std::string & key_r ) const
175 { return headerList().find( key_r ) == headerEnd(); }
176
178 bool keySize( const std::string & key_r ) const
179 { return headerList().count( key_r ); }
180
182 HeaderListIterator keyBegin( const std::string & key_r ) const
183 { return headerList().lower_bound( key_r ); }
184
186 HeaderListIterator keyEnd( const std::string & key_r ) const
187 { return headerList().upper_bound( key_r ); }
188
189
194 const std::string & getHeader( const std::string & key_r ) const;
195
199 const std::string & getHeader( const std::string & key_r, const std::string & default_r ) const;
200
202 const std::string & getHeaderNT( const std::string & key_r, const std::string & default_r = std::string() ) const;
203
208 void setHeader( const std::string & key_r, const std::string & value_r = std::string() );
209
214 void setHeader( HeaderInitializerList contents_r )
215 { headerList().clear(); addHeader( contents_r ); }
216
221 void addHeader( const std::string & key_r, const std::string & value_r = std::string() );
223 void addHeader( HeaderInitializerList contents_r );
224
226 void clearHeader( const std::string & key_r );
227
228 public:
232 std::ostream & writeTo( std::ostream & stream_r ) const;
233
235 static std::ostream & writeTo( std::ostream & stream_r, const PluginFrame & frame_r )
236 { return frame_r.writeTo( stream_r ); }
237
241 std::istream & readFrom( std::istream & stream_r )
242 { *this = PluginFrame( stream_r ); return stream_r; }
243
245 static std::istream & readFrom( std::istream & stream_r, PluginFrame & frame_r )
246 { frame_r = PluginFrame( stream_r ); return stream_r; }
247
248 public:
250 struct Impl;
251 private:
253 RWCOW_pointer<Impl> _pimpl;
254 };
255
257 std::ostream & operator<<( std::ostream & str, const PluginFrame & obj );
258
260 inline std::ostream & dumpOn( std::ostream & str, const PluginFrame & obj )
261 { if ( str ) try { PluginFrame::writeTo( str, obj ); } catch(...){}; return str; }
262
264 inline std::istream & operator>>( std::istream & str, PluginFrame & obj )
265 { return PluginFrame::readFrom( str, obj ); }
266
268 bool operator==( const PluginFrame & lhs, const PluginFrame & rhs );
269
271 inline bool operator!=( const PluginFrame & lhs, const PluginFrame & rhs )
272 { return( ! operator==( lhs, rhs ) ); }
273
275 } // namespace zypp
277 #endif // ZYPP_PLUGINFRAME_H
PluginFrameException.h
PtrTypes.h
Impl
zypp::PluginFrameException
Base class for PluginFrame Exception.
Definition: PluginFrameException.h:30
zypp::PluginFrame
Command frame for communication with PluginScript.
Definition: PluginFrame.h:41
zypp::PluginFrame::HeaderInitializerList
const std::initializer_list< std::pair< std::string, std::string > > & HeaderInitializerList
Definition: PluginFrame.h:45
zypp::PluginFrame::ackCommand
static const std::string & ackCommand()
"ACK" command.
Definition: PluginFrame.cc:241
zypp::PluginFrame::setCommand
void setCommand(const std::string &command_r)
Set the frame command.
Definition: PluginFrame.cc:289
zypp::PluginFrame::operator==
friend bool operator==(const PluginFrame &lhs, const PluginFrame &rhs)
Definition: PluginFrame.cc:336
zypp::PluginFrame::setBody
void setBody(const std::string &body_r)
Set the frame body.
Definition: PluginFrame.cc:298
zypp::PluginFrame::body
const std::string & body() const
Return the frame body.
Definition: PluginFrame.cc:292
zypp::PluginFrame::keyBegin
HeaderListIterator keyBegin(const std::string &key_r) const
Return iterator pointing to the 1st header for key_r (or keyEnd(key_r))
Definition: PluginFrame.h:182
zypp::PluginFrame::PluginFrame
PluginFrame()
Default ctor (empty frame)
Definition: PluginFrame.cc:259
zypp::PluginFrame::headerClear
void headerClear()
Clear the list of headers.
Definition: PluginFrame.h:165
zypp::PluginFrame::bodyRef
std::string & bodyRef()
Return a reference to the frame body.
Definition: PluginFrame.cc:295
zypp::PluginFrame::setHeader
void setHeader(HeaderInitializerList contents_r)
Set a new header list.
Definition: PluginFrame.h:214
zypp::PluginFrame::headerEmpty
bool headerEmpty() const
Whether header list is empty.
Definition: PluginFrame.h:149
zypp::PluginFrame::clearHeader
void clearHeader(const std::string &key_r)
Remove all headers for key_r.
Definition: PluginFrame.cc:328
zypp::PluginFrame::HeaderListIterator
HeaderList::const_iterator HeaderListIterator
Header list iterator.
Definition: PluginFrame.h:138
zypp::PluginFrame::readFrom
static std::istream & readFrom(std::istream &stream_r, PluginFrame &frame_r)
Definition: PluginFrame.h:245
zypp::PluginFrame::keyEmpty
bool keyEmpty(const std::string &key_r) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: PluginFrame.h:174
zypp::PluginFrame::headerSize
unsigned headerSize() const
Return size of the header list.
Definition: PluginFrame.h:153
zypp::PluginFrame::isErrorCommand
bool isErrorCommand() const
Convenience to identify an ERROR command.
Definition: PluginFrame.h:110
zypp::PluginFrame::empty
bool empty() const
Whether this is an empty frame.
Definition: PluginFrame.cc:283
zypp::PluginFrame::enomethodCommand
static const std::string & enomethodCommand()
"_ENOMETHOD" command.
Definition: PluginFrame.cc:253
zypp::PluginFrame::keySize
bool keySize(const std::string &key_r) const
Return number of header entries for key_r.
Definition: PluginFrame.h:178
zypp::PluginFrame::readFrom
std::istream & readFrom(std::istream &stream_r)
Read frame from stream.
Definition: PluginFrame.h:241
zypp::PluginFrame::writeTo
static std::ostream & writeTo(std::ostream &stream_r, const PluginFrame &frame_r)
Definition: PluginFrame.h:235
zypp::PluginFrame::dumpOn
std::ostream & dumpOn(std::ostream &str, const PluginFrame &obj)
Stream output writing all data for logging (no throw)
Definition: PluginFrame.h:260
zypp::PluginFrame::command
const std::string & command() const
Return the frame command.
Definition: PluginFrame.cc:286
zypp::PluginFrame::addHeader
void addHeader(const std::string &key_r, const std::string &value_r=std::string())
Add header for key_r leaving already existing headers for key_r unchanged.
Definition: PluginFrame.cc:322
zypp::PluginFrame::_pimpl
RWCOW_pointer< Impl > _pimpl
Pointer to implementation.
Definition: PluginFrame.h:250
zypp::PluginFrame::isEnomethodCommand
bool isEnomethodCommand() const
Convenience to identify an _ENOMETHOD command.
Definition: PluginFrame.h:114
zypp::PluginFrame::keyEnd
HeaderListIterator keyEnd(const std::string &key_r) const
Return iterator pointing behind the last header for key_r.
Definition: PluginFrame.h:186
zypp::PluginFrame::errorCommand
static const std::string & errorCommand()
"ERROR" command.
Definition: PluginFrame.cc:247
zypp::PluginFrame::HeaderList
std::multimap< std::string, std::string > HeaderList
The header list.
Definition: PluginFrame.h:135
zypp::PluginFrame::operator!=
bool operator!=(const PluginFrame &lhs, const PluginFrame &rhs)
Comparison based on content.
Definition: PluginFrame.h:271
zypp::PluginFrame::headerEnd
HeaderListIterator headerEnd() const
Return iterator pointing behind the last header.
Definition: PluginFrame.h:161
zypp::PluginFrame::getHeader
const std::string & getHeader(const std::string &key_r) const
Return header value for key_r.
Definition: PluginFrame.cc:310
zypp::PluginFrame::operator>>
std::istream & operator>>(std::istream &str, PluginFrame &obj)
Construct from stream.
Definition: PluginFrame.h:264
zypp::PluginFrame::headerList
HeaderList & headerList()
Modifyalble header list for internal use only.
Definition: PluginFrame.cc:304
zypp::PluginFrame::operator<<
friend std::ostream & operator<<(std::ostream &str, const PluginFrame &obj)
Definition: PluginFrame.cc:333
zypp::PluginFrame::setHeader
void setHeader(const std::string &key_r, const std::string &value_r=std::string())
Set header for key_r removing all other occurrences of key_r.
Definition: PluginFrame.cc:319
zypp::PluginFrame::getHeaderNT
const std::string & getHeaderNT(const std::string &key_r, const std::string &default_r=std::string()) const
Not throwing version returing one of the matching header values or default_r string.
Definition: PluginFrame.cc:316
zypp::PluginFrame::isAckCommand
bool isAckCommand() const
Convenience to identify an ACK command.
Definition: PluginFrame.h:106
zypp::PluginFrame::headerBegin
HeaderListIterator headerBegin() const
Return iterator pointing to the 1st header (or headerEnd)
Definition: PluginFrame.h:157
zypp::PluginFrame::Exception
PluginFrameException Exception
Default exception type.
Definition: PluginFrame.h:57
zypp::PluginFrame::writeTo
std::ostream & writeTo(std::ostream &stream_r) const
Write frame to stream.
Definition: PluginFrame.cc:301
zypp::PluginFrame::hasKey
bool hasKey(const std::string &key_r) const
Whether the header list contains at least one entry for key_r.
Definition: PluginFrame.h:170
str
String related utilities and Regular expression matching.
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
zypp::operator==
bool operator==(const SetRelation::Enum &lhs, const SetCompare &rhs)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: SetRelationMixin.h:84
zypp::operator<<
std::ostream & operator<<(std::ostream &str, const Exception &obj)
Definition: Exception.cc:147
zypp::RWCOW_pointer
RW_pointer supporting 'copy on write' functionality.
Definition: PtrTypes.h:459