ulib  1.0
S.W. Lee's essential C++ library
 All Classes Namespaces Files Functions Variables Typedefs Macros Pages
ucounter.h
Go to the documentation of this file.
1 #ifndef ___ucounter___
2 #define ___ucounter___
3 
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
7 #include <time.h>
8 
9 #include <string>
10 #include <map>
11 #include <list>
12 
13 
14 namespace ulib {
15 
27  class CUCounter {
28  public:
29  CUCounter();
30  unsigned long GetNumItem();
31  unsigned long GetTotalCount();
32  void AddItem( char *item, unsigned long num = 1 );
33  void AddItem( long item, unsigned long num = 1 );
34  bool GetCount( char *item, unsigned long &ret );
35  void Print( FILE *fp, char mode[]="IC", char sort='I' );
36 
37  std::map<std::string, unsigned long> str_cnt_map;
38 
39  private:
40  unsigned long total_count;
41 
42  typedef class _str_cnt {
43  public:
44  std::string str;
45  unsigned long cnt;
46  _str_cnt( std::string arg_str, unsigned long arg_cnt ) {
47  str = arg_str;
48  cnt = arg_cnt;
49  }
50 
51  } CStrCnt;
52 
53  typedef class _str_cnt_less {
54  public:
55  bool operator() ( const CStrCnt &a, const CStrCnt &b ) const {
56  return a.cnt > b.cnt;
57  }
58  } CStrCntSort;
59  };
60 }
61 
62 #endif
63