The aim of ++Unix is to allow C++ programs to use Unix facilities, such as sockets, whose interface includes a lot of pointers and other low-level stuff, and might vary on different kinds of Unix, in a nice, simple and consistent way.
One of the goals: There should be no need
for preprocessor conditionals (#if) other than as
include guards in a C++ programs that uses
++Unix.
<incu/log.hh>
Stream out to syslog as simply as to any ostream. Almost.
#include <incu/log.hh>
int
main(int argc, char* argv[]) {
if(log_to_syslog)
incu::Log::addDevice(new incu::SysLog(argv[0]));
else
incu::Log::addDevice(new incu::StreamLog(clog));
Log() << "A message";
try { ... }
catch(const exception &err) {
Log() << "Something went wrong: " << err;
}
}
<incu/pipe.hh>
A pipe created in an object. Really just a constructor / destructor pair for convenience.
<incu/socket.hh>
Some classes to help out in using sockets. A client looks basically like this:
incu::SockaddrIn addr;
addr.addr("servername").port(4711);
incu::Socket socket(PF_INET, SOCK_STREAM, "tcp");
socket.connect(addr);
ifstream in(socket.fd());
ofstream out(socket.fd());
<incu/system.hh>
<incu/time.hh>
Contains the classes TimeVal, which is just a
constructor for struct timeval, and Time
which works like a time_t, but more convenient.
The following will print the current time in a user-friendly format:
cout << "Time is " << Time() << endl;
<incu/error.hh>
Mainly used by the other parts of incu, a
c_error is thrown when something goes wrong the
errno way.
Skriv en kommentar
Din epostadress kommer inte att visas. Du kan inte använda markup i kommentaren, men en dubbel radmating blir en styckesbrytning.