libzypp 9.41.1

PluginFrame.h

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
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();
00052       static const std::string & enomethodCommand();
00053 
00054     public:
00056       typedef PluginFrameException Exception;
00057 
00059       PluginFrame();
00060 
00064       PluginFrame( const std::string & command_r );
00065 
00069       PluginFrame( const std::string & command_r, const std::string body_r );
00070 
00075       PluginFrame( std::istream & stream_r );
00076 
00077     public:
00079       bool empty() const;
00080 
00082       using base::SafeBool<PluginFrame>::operator bool_type;
00083 
00084     public:
00086       const std::string & command() const;
00087 
00091       void setCommand( const std::string & command_r );
00092 
00094       bool isAckCommand() const
00095       { return command() == ackCommand(); }
00096 
00098       bool isErrorCommand() const
00099       {return command() == errorCommand(); }
00100 
00102       bool isEnomethodCommand() const
00103       {return command() == enomethodCommand(); }
00104 
00106       const std::string & body() const;
00107 
00116       std::string & bodyRef();
00117 
00119       void setBody( const std::string & body_r );
00120 
00121     public:
00123       typedef std::multimap<std::string, std::string> HeaderList;
00124 
00126       typedef HeaderList::const_iterator HeaderListIterator;
00127 
00128     private:
00130       HeaderList & headerList();
00131 
00132     public:
00134       const HeaderList & headerList() const;
00135 
00137       bool headerEmpty() const
00138       { return headerList().empty(); }
00139 
00141       unsigned headerSize() const
00142       { return headerList().size(); }
00143 
00145       HeaderListIterator headerBegin() const
00146       { return headerList().begin(); }
00147 
00149       HeaderListIterator headerEnd() const
00150       { return headerList().end(); }
00151 
00153       void headerClear()
00154       { headerList().clear(); }
00155 
00156 
00158       bool hasKey( const std::string & key_r ) const
00159       { return keyEmpty( key_r ); }
00160 
00162       bool keyEmpty( const std::string & key_r ) const
00163       { return headerList().find( key_r ) == headerEnd(); }
00164 
00166       bool keySize( const std::string & key_r ) const
00167       { return headerList().count( key_r ); }
00168 
00170       HeaderListIterator keyBegin( const std::string & key_r ) const
00171       { return headerList().lower_bound( key_r ); }
00172 
00174       HeaderListIterator keyEnd( const std::string & key_r ) const
00175       { return headerList().upper_bound( key_r ); }
00176 
00177 
00182       const std::string & getHeader( const std::string & key_r ) const;
00183 
00187       const std::string & getHeader( const std::string & key_r, const std::string & default_r ) const;
00188 
00190       const std::string & getHeaderNT( const std::string & key_r, const std::string & default_r = std::string() ) const;
00191 
00196       void setHeader( const std::string & key_r, const std::string & value_r = std::string() );
00197 
00202       void addHeader( const std::string & key_r, const std::string & value_r = std::string() );
00203 
00205       void clearHeader( const std::string & key_r );
00206 
00207     public:
00211       std::ostream & writeTo( std::ostream & stream_r ) const;
00212 
00214       static std::ostream & writeTo( std::ostream & stream_r, const PluginFrame & frame_r )
00215       { return frame_r.writeTo( stream_r ); }
00216 
00220       std::istream & readFrom( std::istream & stream_r )
00221       { *this = PluginFrame( stream_r ); return stream_r; }
00222 
00224       static std::istream & readFrom( std::istream & stream_r, PluginFrame & frame_r )
00225       { frame_r = PluginFrame( stream_r ); return stream_r; }
00226 
00227     private:
00228       friend base::SafeBool<PluginFrame>::operator bool_type() const;
00230       bool boolTest() const
00231       { return !empty(); }
00232     public:
00234       class Impl;
00235     private:
00237       RWCOW_pointer<Impl> _pimpl;
00238   };
00239 
00241   std::ostream & operator<<( std::ostream & str, const PluginFrame & obj );
00242 
00244   inline std::ostream & dumpOn( std::ostream & str, const PluginFrame & obj )
00245   { if ( str ) try { PluginFrame::writeTo( str, obj ); } catch(...){}; return str; }
00246 
00248   inline std::istream & operator>>( std::istream & str, PluginFrame & obj )
00249   { return PluginFrame::readFrom( str, obj ); }
00250 
00252   bool operator==( const PluginFrame & lhs, const PluginFrame & rhs );
00253 
00255   inline bool operator!=( const PluginFrame & lhs, const PluginFrame & rhs )
00256   { return( ! operator==( lhs, rhs ) ); }
00257 
00259 } // namespace zypp
00261 #endif // ZYPP_PLUGINFRAME_H