libzypp  17.14.0
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 
22 
24 namespace zypp
25 {
26 
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:
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:
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 
158  { return headerList().begin(); }
159 
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:
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