libzypp 17.37.10

Errno.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12#ifndef ZYPP_BASE_ERRNO_H
13#define ZYPP_BASE_ERRNO_H
14
15#include <cerrno>
16#include <iosfwd>
17
18#include <zypp-core/base/String.h>
19
21 namespace zypp
22{
23
25 class Errno
26 {
27 public:
29 Errno() : _errno( errno ) {}
30
39 Errno( bool error_r ) : _errno( error_r ? errno : 0 ) {}
40
42 Errno( int errno_r ) : _errno( errno_r ) {}
43
44 public:
46 int get() const { return _errno; }
47
49 operator int() const { return get(); }
50
52 std::string asString() const { return str::form( "[%d-%s]", _errno, ::strerror(_errno) ); }
53
54 private:
55 int _errno;
56 };
57
59 inline std::ostream & operator<<( std::ostream & str, const Errno & obj )
60 { return str << obj.asString(); }
61
63} // namespace zypp
65#endif // ZYPP_BASE_ERRNO_H
zypp::Errno::Errno
Errno(int errno_r)
Ctor taking an explicit errno value.
Definition Errno.h:42
zypp::Errno::get
int get() const
Return the stored errno.
Definition Errno.h:46
zypp::Errno::asString
std::string asString() const
Return human readable error string.
Definition Errno.h:52
zypp::Errno::Errno
Errno(bool error_r)
Ctor set to errno if error condition, else 0.
Definition Errno.h:39
zypp::Errno::operator<<
std::ostream & operator<<(std::ostream &str, const Errno &obj)
Stream output.
Definition Errno.h:59
zypp::Errno::_errno
int _errno
Definition Errno.h:55
zypp::Errno::Errno
Errno()
Default ctor: errno.
Definition Errno.h:29
str
String related utilities and Regular expression matching.
zypp::str::form
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
Definition String.cc:39
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition Application.cc:20
String.h