YSTest  PreAlpha_b400_20130424
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
ycounter.hpp
浏览该文件的文档.
1 /*
2  Copyright (C) by Franksoft 2010 - 2012.
3 
4  This file is part of the YSLib project, and may only be used,
5  modified, and distributed under the terms of the YSLib project
6  license, LICENSE.TXT. By continuing to use, modify, or distribute
7  this file you indicate that you have read the license and
8  understand and accept it fully.
9 */
10 
28 #ifndef YSL_INC_CORE_YCOUNTER_H_
29 #define YSL_INC_CORE_YCOUNTER_H_ 1
30 
31 #include "ysdef.h"
32 
34 
39 template<class _type, typename count_t = u32>
40 class GMCounter
41 {
42 private:
43  static count_t nCount, nTotal;
44  count_t nID;
45 
46 public:
53  : nID(nCount++)
54  {
55  ++nTotal;
56  }
62  inline
64  : nID(nCount++)
65  {
66  ++nTotal;
67  }
72  inline DefDeMoveCtor(GMCounter)
73 
74 protected:
81  {
82  --nTotal;
83  }
84 
85 public:
87 
88  static DefGetter(ynothrow, count_t, Count, nCount)
89  static DefGetter(ynothrow, count_t, Total, nTotal)
91  yconstfn DefGetter(const ynothrow, count_t, ObjectID, nID)
92 
93 protected:
98  static void
99  ResetCount() ynothrow
100  {
101  nCount = 0;
102  }
103 
108  static void
109  ResetTotal() ynothrow
110  {
111  nTotal = 0;
112  }
113 
118  void
119  ResetID() ynothrow
120  {
121  nID = 0;
122  }
123 };
124 
125 template<class _type, typename count_t>
126 count_t GMCounter<_type, count_t>::nCount(0);
127 
128 template<class _type, typename count_t>
129 count_t GMCounter<_type, count_t>::nTotal(0);
130 
131 YSL_END
132 
133 #endif
134