00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00026 #ifndef _UCOMMON_COUNTER_H_
00027 #define _UCOMMON_COUNTER_H_
00028
00029 #ifndef _UCOMMON_CONFIG_H_
00030 #include <ucommon/platform.h>
00031 #endif
00032
00033 NAMESPACE_UCOMMON
00034
00042 class __EXPORT counter
00043 {
00044 private:
00045 unsigned value, cycle;
00046
00047 public:
00051 counter();
00052
00057 counter(unsigned limit);
00058
00063 unsigned get(void);
00064
00069 inline unsigned range(void)
00070 {return cycle;};
00071
00076 inline unsigned operator*()
00077 {return get();};
00078
00083 inline operator unsigned()
00084 {return get();};
00085
00090 void operator=(unsigned value);
00091 };
00092
00100 class __EXPORT SeqCounter : protected counter
00101 {
00102 private:
00103 void *item;
00104 size_t offset;
00105
00106 protected:
00107 SeqCounter(void *start, size_t size, unsigned count);
00108
00109 void *get(void);
00110
00111 void *get(unsigned idx);
00112
00113 public:
00118 inline void operator=(unsigned inc_offset)
00119 {counter::operator=(inc_offset);};
00120 };
00121
00126 class __EXPORT toggle
00127 {
00128 private:
00129 bool value;
00130
00131 public:
00132 inline toggle()
00133 {value = false;};
00134
00135 bool get(void);
00136
00137 inline bool operator*()
00138 {return get();};
00139
00140 inline void operator=(bool v)
00141 {value = v;};
00142
00143 inline operator bool()
00144 {return get();};
00145
00146 };
00147
00154 template <class T>
00155 class sequence : public SeqCounter
00156 {
00157 protected:
00158 inline T *get(unsigned idx)
00159 {return static_cast<T *>(SeqCounter::get(idx));};
00160
00161 public:
00167 inline sequence(T *array, unsigned size) :
00168 SeqCounter(array, sizeof(T), size) {};
00169
00174 inline T* get(void)
00175 {return static_cast<T *>(SeqCounter::get());};
00176
00181 inline T& operator*()
00182 {return *get();};
00183
00188 inline operator T&()
00189 {return *get();};
00190
00196 inline T& operator[](unsigned offset)
00197 {return *get(offset);};
00198 };
00199
00203 typedef counter counter_t;
00204
00208 typedef toggle toggle_t;
00209
00210 END_NAMESPACE
00211
00212 #endif