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 static const std::string & ackCommand();
00050 static const std::string & errorCommand();
00051
00052 public:
00054 typedef PluginFrameException Exception;
00055
00057 PluginFrame();
00058
00062 PluginFrame( const std::string & command_r );
00063
00067 PluginFrame( const std::string & command_r, const std::string body_r );
00068
00073 PluginFrame( std::istream & stream_r );
00074
00075 public:
00077 bool empty() const;
00078
00080 using base::SafeBool<PluginFrame>::operator bool_type;
00081
00082 public:
00084 const std::string & command() const;
00085
00089 void setCommand( const std::string & command_r );
00090
00092 bool isAckCommand() const
00093 { return command() == ackCommand(); }
00094
00096 bool isErrorCommand() const
00097 {return command() == errorCommand(); }
00098
00100 const std::string & body() const;
00101
00110 std::string & bodyRef();
00111
00113 void setBody( const std::string & body_r );
00114
00115 public:
00117 typedef std::multimap<std::string, std::string> HeaderList;
00118
00120 typedef HeaderList::const_iterator HeaderListIterator;
00121
00122 private:
00124 HeaderList & headerList();
00125
00126 public:
00128 const HeaderList & headerList() const;
00129
00131 bool headerEmpty() const
00132 { return headerList().empty(); }
00133
00135 unsigned headerSize() const
00136 { return headerList().size(); }
00137
00139 HeaderListIterator headerBegin() const
00140 { return headerList().begin(); }
00141
00143 HeaderListIterator headerEnd() const
00144 { return headerList().end(); }
00145
00147 void headerClear()
00148 { headerList().clear(); }
00149
00150
00152 bool hasKey( const std::string & key_r ) const
00153 { return keyEmpty( key_r ); }
00154
00156 bool keyEmpty( const std::string & key_r ) const
00157 { return headerList().find( key_r ) == headerEnd(); }
00158
00160 bool keySize( const std::string & key_r ) const
00161 { return headerList().count( key_r ); }
00162
00164 HeaderListIterator keyBegin( const std::string & key_r ) const
00165 { return headerList().lower_bound( key_r ); }
00166
00168 HeaderListIterator keyEnd( const std::string & key_r ) const
00169 { return headerList().upper_bound( key_r ); }
00170
00171
00176 const std::string & getHeader( const std::string & key_r ) const;
00177
00181 const std::string & getHeader( const std::string & key_r, const std::string & default_r ) const;
00182
00184 const std::string & getHeaderNT( const std::string & key_r, const std::string & default_r = std::string() ) const;
00185
00190 void setHeader( const std::string & key_r, const std::string & value_r = std::string() );
00191
00196 void addHeader( const std::string & key_r, const std::string & value_r = std::string() );
00197
00199 void clearHeader( const std::string & key_r );
00200
00201 public:
00205 std::ostream & writeTo( std::ostream & stream_r ) const;
00206
00208 static std::ostream & writeTo( std::ostream & stream_r, const PluginFrame & frame_r )
00209 { return frame_r.writeTo( stream_r ); }
00210
00214 std::istream & readFrom( std::istream & stream_r )
00215 { *this = PluginFrame( stream_r ); return stream_r; }
00216
00218 static std::istream & readFrom( std::istream & stream_r, PluginFrame & frame_r )
00219 { frame_r = PluginFrame( stream_r ); return stream_r; }
00220
00221 private:
00222 friend base::SafeBool<PluginFrame>::operator bool_type() const;
00224 bool boolTest() const
00225 { return empty(); }
00226 public:
00228 class Impl;
00229 private:
00231 RWCOW_pointer<Impl> _pimpl;
00232 };
00233
00235 std::ostream & operator<<( std::ostream & str, const PluginFrame & obj );
00236
00238 inline std::ostream & dumpOn( std::ostream & str, const PluginFrame & obj )
00239 { return PluginFrame::writeTo( str, obj ); }
00240
00242 inline std::istream & operator>>( std::istream & str, PluginFrame & obj )
00243 { return PluginFrame::readFrom( str, obj ); }
00244
00246 bool operator==( const PluginFrame & lhs, const PluginFrame & rhs );
00247
00249 inline bool operator!=( const PluginFrame & lhs, const PluginFrame & rhs )
00250 { return( ! operator==( lhs, rhs ) ); }
00251
00253 }
00255 #endif // ZYPP_PLUGINFRAME_H