Log4cpp is a Log4J's C portable version, open source and completely free. Like the Log4J cross-platform, log4cpp is also committed to writing cross-platform C programs. Log4CPP is mainly used in the C program to write log files. At the same time, there are many useful class libraries in log4cpp. For those who write cross-platform C programs, they can be used directly, or as they write cross-platform classes. reference.
The cross-platform libraries in log4cpp have obvious Java traces, such as Class, Object, Loader, Locale, etc. The classes in the log4cpp can be found in the class NEW, and the way the implementation and the MFC are as follows: through C powerful macro.
The cross-platform class libraries in log4cpp are mainly:
Signal class: Condition (Broadcast, Signal, Wait), Criticalsection (Lock, Unlock), Waitaccess, Event (SET, RESET, WAIT), MUTEX (LOCK, UNLOCK), SEMAPHORE (Wait, Trywait, POST)
Network Class: Inetaddress, Socket, Serversocket, DataGramsocket, SocketInputStream, Socketputstream
Date-class: DateFormat, DateTimedateFormat, System (CurrentTimeMillis)
Document class: FileWatchDog (DoonChange)
Memory operation class: Intelligent pointer based on reference counting mechanism ObjectPTRT
String Operation Class: Strictmath, Stringhelper (Touppercase, Toolcase, Trim, Equalsignore, Endswith, Format, StringTokenizer
Thread class: thread (Start, Run, Join)
With the above class, you don't have to consider the Handle issues such as Thread Handle, Event Handle, Socket Handle, all of which have been packaged. Very easy to use, right?
The deficiency is that there is no GUI class. ANSI C has weak processing functions such as file systems such as directory, and there is no directory processing class. In addition, Socket's read (Void * BUF, SIZE_T LEN) cannot set Timeout, and if the number of read data is less than le, the read function will be blocked, it is not very easy to use, it is a pity. In the actual use, you can consider making a socket subclass to override the read () function.
The following is an example program that compiles the compilation in VC6, and there is a Chinese full-width space in the code.
#include "stdafx.h"
#include
#include
Class myoutputer {private: mutex m_outputlock; public: void output (const char * msg) {m_outputlock.lock (); cout << msg << endl; m_outputlock.unlock ();}};
Class mythread: public thread {private; m_running; myoutputer m_out; public: mythread () {m_running = false;} Virtual ~ mythread () {}
Virtual void Run () {m_running = true; // Ten times, execution ten second for (int i = 0; i <10 && m_running; i ) {m_out.output ("Mythread Running ..."); thread: : SLEEP (1000);}}
Void Stop () {m_running = false;}}; typedef ObjectPTRT
INT Main (int Argc, char * argv []) {myoutputer out; out.output ("main begin ...");
Vector Out.Output ("Main Start All Threads ..."); for (i = 0; i Out.output ("Main Sleep 4 Seconds ..."); // Waiting for 4 seconds, stop all thread thread :: Sleep (4000); Out.Output ("Main Stop All Threads ..."); for (i = 0; i Out.output ("main end"); Return 0;}