libzypp  13.10.6
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  public:
47  static const std::string & ackCommand();
49  static const std::string & errorCommand();
50 
51  public:
54 
56  PluginFrame();
57 
61  PluginFrame( const std::string & command_r );
62 
66  PluginFrame( const std::string & command_r, const std::string body_r );
67 
72  PluginFrame( std::istream & stream_r );
73 
74  public:
76  bool empty() const;
77 
79  explicit operator bool() const
80  { return empty(); }
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  public:
223  class Impl;
224  private:
227  };
228 
230  std::ostream & operator<<( std::ostream & str, const PluginFrame & obj );
231 
233  inline std::ostream & dumpOn( std::ostream & str, const PluginFrame & obj )
234  { return PluginFrame::writeTo( str, obj ); }
235 
237  inline std::istream & operator>>( std::istream & str, PluginFrame & obj )
238  { return PluginFrame::readFrom( str, obj ); }
239 
241  bool operator==( const PluginFrame & lhs, const PluginFrame & rhs );
242 
244  inline bool operator!=( const PluginFrame & lhs, const PluginFrame & rhs )
245  { return( ! operator==( lhs, rhs ) ); }
246 
248 } // namespace zypp
250 #endif // ZYPP_PLUGINFRAME_H
bool keySize(const std::string &key_r) const
Return number of header entires for key_r.
Definition: PluginFrame.h:160
friend bool operator==(const PluginFrame &lhs, const PluginFrame &rhs)
Definition: PluginFrame.cc:303
PluginFrame()
Default ctor (empty frame)
Definition: PluginFrame.cc:237
Command frame for communication with PluginScript.
Definition: PluginFrame.h:40
void setCommand(const std::string &command_r)
Set the frame command.
Definition: PluginFrame.cc:259
const std::string & command() const
Return the frame command.
Definition: PluginFrame.cc:256
std::istream & operator>>(std::istream &str, PluginFrame &obj)
Definition: PluginFrame.h:237
HeaderListIterator keyEnd(const std::string &key_r) const
Return iterator pointing behind the last header for key_r.
Definition: PluginFrame.h:168
std::ostream & dumpOn(std::ostream &str, const PluginFrame &obj)
Definition: PluginFrame.h:233
bool operator!=(const PluginFrame &lhs, const PluginFrame &rhs)
Definition: PluginFrame.h:244
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:164
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:292
bool isErrorCommand() const
Convenience to identify an ERROR command.
Definition: PluginFrame.h:96
static std::istream & readFrom(std::istream &stream_r, PluginFrame &frame_r)
Definition: PluginFrame.h:218
static const std::string & errorCommand()
&quot;ERROR&quot; command.
Definition: PluginFrame.cc:231
void headerClear()
Clear the list of headers.
Definition: PluginFrame.h:147
std::ostream & operator<<(std::ostream &str, const Exception &obj)
Definition: Exception.cc:120
bool keyEmpty(const std::string &key_r) const
Definition: PluginFrame.h:156
unsigned headerSize() const
Return size of the header list.
Definition: PluginFrame.h:135
Base class for PluginFrame Exception.
bool isAckCommand() const
Convenience to identify an ACK command.
Definition: PluginFrame.h:92
friend std::ostream & operator<<(std::ostream &str, const PluginFrame &obj)
Definition: PluginFrame.cc:300
bool headerEmpty() const
Whether header list is empty.
Definition: PluginFrame.h:131
static const std::string & ackCommand()
&quot;ACK&quot; command.
Definition: PluginFrame.cc:225
RWCOW_pointer< Impl > _pimpl
Pointer to implementation.
Definition: PluginFrame.h:223
bool operator==(const StrMatcher &lhs, const StrMatcher &rhs)
Definition: StrMatcher.cc:309
void setBody(const std::string &body_r)
Set the frame body.
Definition: PluginFrame.cc:268
HeaderListIterator headerEnd() const
Return iterator pointing behind the last header.
Definition: PluginFrame.h:143
std::multimap< std::string, std::string > HeaderList
The header list.
Definition: PluginFrame.h:117
const std::string & getHeader(const std::string &key_r) const
Return header value for key_r.
Definition: PluginFrame.cc:280
bool hasKey(const std::string &key_r) const
Whether the header list contains at least one entry for key_r.
Definition: PluginFrame.h:152
HeaderList::const_iterator HeaderListIterator
Header list iterator.
Definition: PluginFrame.h:120
HeaderListIterator headerBegin() const
Return iterator pointing to the 1st header (or headerEnd)
Definition: PluginFrame.h:139
void setHeader(const std::string &key_r, const std::string &value_r=std::string())
Set header for key_r removing all other occurences of key_r.
Definition: PluginFrame.cc:289
HeaderList & headerList()
Modifyalble header list for internal use only.
Definition: PluginFrame.cc:274
PluginFrame implementation.
Definition: PluginFrame.cc:29
std::ostream & writeTo(std::ostream &stream_r) const
Write frame to stream.
Definition: PluginFrame.cc:271
std::istream & readFrom(std::istream &stream_r)
Read frame from stream.
Definition: PluginFrame.h:214
std::string & bodyRef()
Return a reference to the frame body.
Definition: PluginFrame.cc:265
bool empty() const
Whether this is an empty frame.
Definition: PluginFrame.cc:253
void clearHeader(const std::string &key_r)
Remove all headers for key_r.
Definition: PluginFrame.cc:295
static std::ostream & writeTo(std::ostream &stream_r, const PluginFrame &frame_r)
Definition: PluginFrame.h:208
PluginFrameException Exception
Default exception type.
Definition: PluginFrame.h:53
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:286
RW_pointer supporting &#39;copy on write&#39; functionality.
Definition: PtrTypes.h:438
const std::string & body() const
Return the frame body.
Definition: PluginFrame.cc:262