PluginFrame.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00012 #ifndef ZYPP_PLUGINFRAME_H
00013 #define ZYPP_PLUGINFRAME_H
00014
00015 #include <iosfwd>
00016 #include <string>
00017 #include <map>
00018
00019 #include "zypp/base/PtrTypes.h"
00020 #include "zypp/base/SafeBool.h"
00021
00022 #include "zypp/PluginFrameException.h"
00023
00025 namespace zypp
00026 {
00027
00041 class PluginFrame : private base::SafeBool<PluginFrame>
00042 {
00043 friend std::ostream & operator<<( std::ostream & str, const PluginFrame & obj );
00044 friend bool operator==( const PluginFrame & lhs, const PluginFrame & rhs );
00045
00046 public:
00048 typedef PluginFrameException Exception;
00049
00051 PluginFrame();
00052
00056 PluginFrame( const std::string & command_r );
00057
00061 PluginFrame( const std::string & command_r, const std::string body_r );
00062
00067 PluginFrame( std::istream & stream_r );
00068
00069 public:
00071 bool empty() const;
00072
00074 using base::SafeBool<PluginFrame>::operator bool_type;
00075
00076 public:
00078 const std::string & command() const;
00079
00083 void setCommand( const std::string & command_r );
00084
00086 const std::string & body() const;
00087
00096 std::string & bodyRef();
00097
00099 void setBody( const std::string & body_r );
00100
00101 public:
00103 typedef std::multimap<std::string, std::string> HeaderList;
00104
00106 typedef HeaderList::const_iterator HeaderListIterator;
00107
00108 private:
00110 HeaderList & headerList();
00111
00112 public:
00114 const HeaderList & headerList() const;
00115
00117 bool headerEmpty() const
00118 { return headerList().empty(); }
00119
00121 unsigned headerSize() const
00122 { return headerList().size(); }
00123
00125 HeaderListIterator headerBegin() const
00126 { return headerList().begin(); }
00127
00129 HeaderListIterator headerEnd() const
00130 { return headerList().end(); }
00131
00133 void headerClear()
00134 { headerList().clear(); }
00135
00136
00138 bool hasKey( const std::string & key_r ) const
00139 { return keyEmpty( key_r ); }
00140
00142 bool keyEmpty( const std::string & key_r ) const
00143 { return headerList().find( key_r ) == headerEnd(); }
00144
00146 bool keySize( const std::string & key_r ) const
00147 { return headerList().count( key_r ); }
00148
00150 HeaderListIterator keyBegin( const std::string & key_r ) const
00151 { return headerList().lower_bound( key_r ); }
00152
00154 HeaderListIterator keyEnd( const std::string & key_r ) const
00155 { return headerList().upper_bound( key_r ); }
00156
00157
00162 const std::string & getHeader( const std::string & key_r ) const;
00163
00167 const std::string & getHeader( const std::string & key_r, const std::string & default_r ) const;
00168
00170 const std::string & getHeaderNT( const std::string & key_r, const std::string & default_r = std::string() ) const;
00171
00176 void setHeader( const std::string & key_r, const std::string & value_r = std::string() );
00177
00182 void addHeader( const std::string & key_r, const std::string & value_r = std::string() );
00183
00185 void clearHeader( const std::string & key_r );
00186
00187 public:
00191 std::ostream & writeTo( std::ostream & stream_r ) const;
00192
00194 static std::ostream & writeTo( std::ostream & stream_r, const PluginFrame & frame_r )
00195 { return frame_r.writeTo( stream_r ); }
00196
00200 std::istream & readFrom( std::istream & stream_r )
00201 { *this = PluginFrame( stream_r ); return stream_r; }
00202
00204 static std::istream & readFrom( std::istream & stream_r, PluginFrame & frame_r )
00205 { frame_r = PluginFrame( stream_r ); return stream_r; }
00206
00207 private:
00208 friend base::SafeBool<PluginFrame>::operator bool_type() const;
00210 bool boolTest() const
00211 { return empty(); }
00212 public:
00214 class Impl;
00215 private:
00217 RWCOW_pointer<Impl> _pimpl;
00218 };
00219
00221 std::ostream & operator<<( std::ostream & str, const PluginFrame & obj );
00222
00224 inline std::ostream & dumpOn( std::ostream & str, const PluginFrame & obj )
00225 { return PluginFrame::writeTo( str, obj ); }
00226
00228 inline std::istream & operator>>( std::istream & str, PluginFrame & obj )
00229 { return PluginFrame::readFrom( str, obj ); }
00230
00232 bool operator==( const PluginFrame & lhs, const PluginFrame & rhs );
00233
00235 inline bool operator!=( const PluginFrame & lhs, const PluginFrame & rhs )
00236 { return( ! operator==( lhs, rhs ) ); }
00237
00239 }
00241 #endif // ZYPP_PLUGINFRAME_H