TRF Language Model
wb-log.h File Reference

a definition of a class Log, which can output to the cmd window and the log file simultaneously. In wb-log.cpp, there are a Log variable "lout", which can be directly used just like "cout". For example: More...

#include <iostream>
#include <fstream>
#include <iomanip>
#include <ctime>
#include <cstring>
#include "wb-linux.h"

Go to the source code of this file.

Classes

class  wb::ProgressBar
 a progress bar class More...
 
class  wb::Log
 this class can output to the cmd window and log files simultaneously. In wb-log.cpp, there are a Log variable "lout", which can be directly used just like "cout". For example: More...
 

Namespaces

 wb
 define all the code written by Bin Wang.
 

Macros

#define wbLog_LevelSpace   "\t"
 
#define wbLog_OutputSpace(io)   for (int i=0; i<m_nLevel; i++) io<<wbLog_LevelSpace;
 
#define wbLog_Output(x)
 
#define lout_variable(x)   {wb::lout<<#x" = "<<x<<endl;}
 
#define lout_variable_precent(x, y)   {wb::lout<<#x" = "<<x<<" ("<<100.0*(x)/(y)<<"%) /"#y<<"="<<y<<endl;}
 
#define lout_variable_rate(x, y)   {wb::lout<<100.0*(x)/(y)<<"%("<<x<<"/"<<y<<")";}
 
#define lout_array(x, n)   {wb::lout<<#x"=[ "; for(int i=0; i<n; i++) wb::lout<<x[i]<<" "; wb::lout<<"]"<<endl; }
 
#define lout_error(x)   {wb::lout.bOutputCmd()=true; wb::lout<<"[ERROR] "<<x<<endl; exit(0);}
 
#define lout_warning(x)   {wb::lout<<"[WARNING] "<<x<<endl;}
 
#define lout_assert(p)   {if(!(p)) lout_error("! ("#p")"); }
 
#define precent(x, n)   (x)<<"("<<100.0*(x)/(n)<<"%)"
 

Detailed Description

a definition of a class Log, which can output to the cmd window and the log file simultaneously. In wb-log.cpp, there are a Log variable "lout", which can be directly used just like "cout". For example:

Author
WangBin
Date
2016-04-28
lout<<"Hello Wrold!"<<endl;
"lout" has the following advantages:
  1. It can output to the cmd and the log file. Besides they can be controled.
  2. It can output the begin and end date of the program.
  3. If the output varialbes are bools, then it will output true/false
  4. If the output variables are char*, then it will detect if the pointer is NULL.
  5. There are some macros, such as lout_variable, lout_error, lout_waring and so on;

Definition in file wb-log.h.