libzypp  11.13.5
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 #include "zypp/base/SafeBool.h"
21 
23 
25 namespace zypp
26 {
27 
41  class PluginFrame : private base::SafeBool<PluginFrame>
42  {
43  friend std::ostream & operator<<( std::ostream & str, const PluginFrame & obj );
44  friend bool operator==( const PluginFrame & lhs, const PluginFrame & rhs );
45 
46  public:
48  static const std::string & ackCommand();
50  static const std::string & errorCommand();
51 
52  public:
55 
57  PluginFrame();
58 
62  PluginFrame( const std::string & command_r );
63 
67  PluginFrame( const std::string & command_r, const std::string body_r );
68 
73  PluginFrame( std::istream & stream_r );
74 
75  public:
77  bool empty() const;
78 
81 
82  public:
84  const std::string & command() const;
85 
89  void setCommand( const std::string & command_r );
90 
92  bool isAckCommand() const
93  { return command() == ackCommand(); }
94 
96  bool isErrorCommand() const
97  {return command() == errorCommand(); }
98 
100  const std::string & body() const;
101 
110  std::string & bodyRef();
111 
113  void setBody( const std::string & body_r );
114 
115  public:
117  typedef std::multimap<std::string, std::string> HeaderList;
118 
120  typedef HeaderList::const_iterator HeaderListIterator;
121 
122  private:
125 
126  public:
128  const HeaderList & headerList() const;
129 
131  bool headerEmpty() const
132  { return headerList().empty(); }
133 
135  unsigned headerSize() const
136  { return headerList().size(); }
137 
140  { return headerList().begin(); }
141 
144  { return headerList().end(); }
145 
147  void headerClear()
148  { headerList().clear(); }
149 
150 
152  bool hasKey( const std::string & key_r ) const
153  { return keyEmpty( key_r ); }
154 
156  bool keyEmpty( const std::string & key_r ) const
157  { return headerList().find( key_r ) == headerEnd(); }
158 
160  bool keySize( const std::string & key_r ) const
161  { return headerList().count( key_r ); }
162 
164  HeaderListIterator keyBegin( const std::string & key_r ) const
165  { return headerList().lower_bound( key_r ); }
166 
168  HeaderListIterator keyEnd( const std::string & key_r ) const
169  { return headerList().upper_bound( key_r ); }
170 
171 
176  const std::string & getHeader( const std::string & key_r ) const;
177 
181  const std::string & getHeader( const std::string & key_r, const std::string & default_r ) const;
182 
184  const std::string & getHeaderNT( const std::string & key_r, const std::string & default_r = std::string() ) const;
185 
190  void setHeader( const std::string & key_r, const std::string & value_r = std::string() );
191 
196  void addHeader( const std::string & key_r, const std::string & value_r = std::string() );
197 
199  void clearHeader( const std::string & key_r );
200 
201  public:
205  std::ostream & writeTo( std::ostream & stream_r ) const;
206 
208  static std::ostream & writeTo( std::ostream & stream_r, const PluginFrame & frame_r )
209  { return frame_r.writeTo( stream_r ); }
210 
214  std::istream & readFrom( std::istream & stream_r )
215  { *this = PluginFrame( stream_r ); return stream_r; }
216 
218  static std::istream & readFrom( std::istream & stream_r, PluginFrame & frame_r )
219  { frame_r = PluginFrame( stream_r ); return stream_r; }
220 
221  private:
224  bool boolTest() const
225  { return empty(); }
226  public:
228  class Impl;
229  private:
232  };
233 
235  std::ostream & operator<<( std::ostream & str, const PluginFrame & obj );
236 
238  inline std::ostream & dumpOn( std::ostream & str, const PluginFrame & obj )
239  { return PluginFrame::writeTo( str, obj ); }
240 
242  inline std::istream & operator>>( std::istream & str, PluginFrame & obj )
243  { return PluginFrame::readFrom( str, obj ); }
244 
246  bool operator==( const PluginFrame & lhs, const PluginFrame & rhs );
247 
249  inline bool operator!=( const PluginFrame & lhs, const PluginFrame & rhs )
250  { return( ! operator==( lhs, rhs ) ); }
251 
253 } // namespace zypp
255 #endif // ZYPP_PLUGINFRAME_H