libzypp  10.5.0
Errno.h
Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00012 #ifndef ZYPP_BASE_ERRNO_H
00013 #define ZYPP_BASE_ERRNO_H
00014 
00015 #include <cerrno>
00016 #include <iosfwd>
00017 
00018 #include <zypp/base/String.h>
00019 
00021 namespace zypp
00022 { 
00023 
00025   class Errno
00026   {
00027     public:
00029       Errno() : _errno( errno ) {}
00030 
00039       Errno( bool error_r ) : _errno( error_r ? errno : 0 ) {}
00040 
00042       Errno( int errno_r ) : _errno( errno_r ) {}
00043 
00044     public:
00046       int get() const { return _errno; }
00047 
00049       operator int() const { return get(); }
00050 
00052       std::string asString() const { return str::form( "[%d-%s]", _errno, ::strerror(_errno) ); }
00053 
00054     private:
00055       int _errno;
00056   };
00057 
00059   inline std::ostream & operator<<( std::ostream & str, const Errno & obj )
00060   { return str << obj.asString(); }
00061 
00063 } // namespace zypp
00065 #endif // ZYPP_BASE_ERRNO_H