added SeriesPool.h
This commit is contained in:
parent
2be810bbe9
commit
4163cf421c
75
inc/hgl/type/SeriesPool.h
Normal file
75
inc/hgl/type/SeriesPool.h
Normal file
@ -0,0 +1,75 @@
|
||||
#pragma once
|
||||
//#include<hgl/type/DataType.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
/**
|
||||
* 序号池
|
||||
*/
|
||||
template<typename T> class SeriesPool
|
||||
{
|
||||
//一定要用带BOM头的UTF8存哦!“量”字在一行的最后,会导致编译器报错,认不出来换行符。
|
||||
|
||||
T max_count; ///<最大数量
|
||||
T *series_data; ///<序列数据
|
||||
T *end; ///<结束指针
|
||||
T *access; ///<访问指针
|
||||
|
||||
public:
|
||||
|
||||
const int GetMaxCount()const{return max_count;}
|
||||
|
||||
public:
|
||||
|
||||
SeriesPool(const T &count)
|
||||
{
|
||||
max_count=count;
|
||||
series_data=new T[max_count];
|
||||
end=series_data+max_count;
|
||||
access=end;
|
||||
|
||||
{
|
||||
T *p=series_data;
|
||||
|
||||
for(T i=0;i<max_count;i++)
|
||||
{
|
||||
*p=i;
|
||||
++p;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual ~SeriesPool()
|
||||
{
|
||||
delete[] series_data;
|
||||
}
|
||||
|
||||
bool Acquire(T *sp)
|
||||
{
|
||||
if(!sp)return(false);
|
||||
|
||||
if(access<=series_data)
|
||||
return(false);
|
||||
|
||||
*sp=*(--access);
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool Release(const T &s)
|
||||
{
|
||||
if(access>=end)
|
||||
return(false);
|
||||
|
||||
*access=s;
|
||||
++access;
|
||||
|
||||
return(true);
|
||||
}
|
||||
};//template<typename T> class SeriesPool
|
||||
|
||||
using SeriesInt=SeriesPool<int>;
|
||||
using SeriesUInt=SeriesPool<uint>;
|
||||
|
||||
using SeriesInt64=SeriesPool<int64>;
|
||||
using SeriesUInt64=SeriesPool<uint64>;
|
||||
}//namespace hgl
|
Loading…
x
Reference in New Issue
Block a user