TRF Language Model
wb-win.h
Go to the documentation of this file.
1 // You may obtain a copy of the License at
2 //
3 // http://www.apache.org/licenses/LICENSE-2.0
4 //
5 // Unless required by applicable law or agreed to in writing, software
6 // distributed under the License is distributed on an "AS IS" BASIS,
7 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
8 // See the License for the specific language governing permissions and
9 // limitations under the License.
10 //
11 // Copyright 2014-2015 Tsinghua University
12 // Author: wb.th08@gmail.com (Bin Wang), ozj@tsinghua.edu.cn (Zhijian Ou)
13 //
14 // All h, cpp, cc, and script files (e.g. bat, sh, pl, py) should include the above
15 // license declaration. Different coding language may use different comment styles.
16 
17 
30 #pragma once
31 #include <iostream>
32 #include <iomanip>
33 #include <fstream>
34 #include <cstdio>
35 #include <cstdlib>
36 #include <ctime>
37 #include <cmath>
38 #include <omp.h>
39 #ifndef __linux
40 #include <conio.h>
41 #endif
42 using namespace std;
43 #include "wb-vector.h"
44 
45 
46 
47 
49 #define F_RETURN(b) {if(!(b)) {cout<<"<F_RETURN>Error = "<<__FILE__<<" (line "<<__LINE__<<")"<<endl; return 0;} }
50 
51 
52 namespace wb
53 {
58  const int cn_title_max_len = 500;
59 
65  class Title
66  {
67  public:
68  static string m_global_title;
69  static long long m_precent_max;
70  static long long m_precent_cur;
71  static int m_precent_last;
72  static string m_precent_label;
73  public:
75  static void SetGlobalTitle(const char *pstr);
77  static const char* GetGlobalTitle();
79  static void Puts(const char *pStr);
81  static void Precent(long long n = m_precent_cur+1, bool bNew = false, long long nTotal = 100, const char* label = "");
83  static void Precent(ifstream &ifile, bool bNew = false, const char* label = "");
85  static void Precent(FILE *fp, bool bNew = false, const char* label = "");
87  static void Fraction(long long n = m_precent_cur + 1, bool bNew = false, long long nTotal = 100, const char* label = "");
88  };
89 
95  class Clock
96  {
97  protected:
98  clock_t m_nBeginTime;
99  clock_t m_nEndTime;
100  bool m_bWork;
101  public:
102  Clock(void);
103  ~Clock(void);
105  void Clean();
107  clock_t Begin();
109  clock_t End();
111  clock_t Get();
113  void Sleep(clock_t n);
115  static double ToSecond(clock_t t)
116  {
117 #ifdef __linux
118  return 1.0*t / omp_get_max_threads() / CLOCKS_PER_SEC;
119 #else
120  return 1.0*t / CLOCKS_PER_SEC;
121 #endif
122  }
123  };
124 
125 #ifndef _linux
126 
127 #define MAX_PATH_LEN 256
128 
140  class Path
141  {
142  protected:
143  string m_input;
145  public:
146  Path(const char *path=NULL);
147  ~Path();
148 
150  void Reset(const char *path = NULL);
152  bool GetPath(char *path);
153  private:
155  void SearchFiles();
156  };
157 #endif //__linux
158 
160  void Pause();
162  void outPrecent(long long n, bool bNew = false, long long nTotal = 100, const char* title = "Process");
164  void outPrecent(ifstream &ifile, bool bNew = false, const char* title = "Process");
166  void outPrecent(FILE *fp, bool bNew = false, const char* title = "Process");
167 
169 }
void outPrecent(long long n, bool bNew, long long nTotal, const char *title)
print precent in the cmd window
Definition: wb-win.cpp:251
static long long m_precent_cur
for Precent function, the current value
Definition: wb-win.h:70
A queue based the dynamic memory mangement.
Definition: wb-vector.h:431
const int cn_title_max_len
Definition: wb-win.h:58
Queue< char * > * m_paFiles
store all the files find in the queue
Definition: wb-win.h:144
clock_t m_nBeginTime
Definition: wb-win.h:98
clock - used to record the time
Definition: wb-win.h:95
static string m_precent_label
the precent output label
Definition: wb-win.h:72
void Pause()
pause
Definition: wb-win.cpp:246
static long long m_precent_max
for Precent function, the maxiumn value
Definition: wb-win.h:69
static double ToSecond(clock_t t)
transform the clock_t to second
Definition: wb-win.h:115
clock_t m_nEndTime
Definition: wb-win.h:99
static string m_global_title
the global title. All the other information are follow the global title
Definition: wb-win.h:68
title class - output to the title
Definition: wb-win.h:65
string m_input
stroe the input string
Definition: wb-win.h:143
static int m_precent_last
record the last output precent value (from 0 to 100)
Definition: wb-win.h:71
Analize the path including "*" and "?" and "+" symbols.
Definition: wb-win.h:140
bool m_bWork
Definition: wb-win.h:100
define all the code written by Bin Wang.
Definition: wb-file.cpp:21
Defination of simple dynamic array/stack/queue and so on.