Added StackPoolTest.cpp
This commit is contained in:
parent
7803d1d69a
commit
bf80f220cb
@ -70,6 +70,9 @@ set_example_project_folder("DataType/DataArray" PoolTest)
|
||||
add_executable(MapTest datatype/MapTest.cpp)
|
||||
set_example_project_folder("DataType/DataArray" MapTest)
|
||||
|
||||
add_executable(StackPoolTest datatype/StackPoolTest.cpp)
|
||||
set_example_project_folder("DataType/DataArray" StackPoolTest)
|
||||
|
||||
add_executable(DataBlockTest datatype/DataBlockTest.cpp)
|
||||
set_example_project_folder("DataType/DataArray" DataBlockTest)
|
||||
|
||||
|
62
datatype/StackPoolTest.cpp
Normal file
62
datatype/StackPoolTest.cpp
Normal file
@ -0,0 +1,62 @@
|
||||
#include<hgl/type/DataStackPool.h>
|
||||
#include"UserInfo.h" //测试用结构体
|
||||
#include<iostream>
|
||||
#include<random>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace std;
|
||||
|
||||
template<typename T> void out_series_pool(const SeriesPool<T> *sp)
|
||||
{
|
||||
const int free_count=sp->GetFreeCount();
|
||||
|
||||
cout<<"Series Pool("<<free_count<<"): ";
|
||||
|
||||
const T *p=sp->GetRawData();
|
||||
|
||||
for(int i=0;i<free_count;i++)
|
||||
{
|
||||
if(i>0)cout<<",";
|
||||
cout<<uint(*p++);
|
||||
}
|
||||
|
||||
cout<<endl;
|
||||
}
|
||||
|
||||
#define USE_RANDOM_SERIES_POOL true //使用随机序号池
|
||||
|
||||
int os_main(int,os_char **)
|
||||
{
|
||||
DataStackPool<UserInfo> dsp_userinfo(user_info_array_count); //用户信息数据池
|
||||
|
||||
#ifdef USE_RANDOM_SERIES_POOL
|
||||
{
|
||||
auto *series=dsp_userinfo.GetSeries();
|
||||
|
||||
series->InitRandomSeries();
|
||||
|
||||
out_series_pool(series);
|
||||
}
|
||||
#endif//USE_RANDOM_SERIES_POOL
|
||||
|
||||
{
|
||||
UserInfo *tp;
|
||||
|
||||
for(const UserInfo &sp:user_info_array)
|
||||
{
|
||||
tp=dsp_userinfo.Acquire();
|
||||
|
||||
if(!tp)
|
||||
{
|
||||
cout<<"Acquire UserInfo Error!"<<endl;
|
||||
break;
|
||||
}
|
||||
|
||||
*tp=sp;
|
||||
}
|
||||
|
||||
out_userinfo(dsp_userinfo.GetRawData(),user_info_array_count);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -3,8 +3,6 @@
|
||||
#include<string.h>
|
||||
#include<iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
struct UserInfo
|
||||
{
|
||||
char name[8];
|
||||
@ -45,6 +43,8 @@ static UserInfo user_info_array[]=
|
||||
{"Zack",true,43}
|
||||
};
|
||||
|
||||
constexpr const size_t user_info_array_count=sizeof(user_info_array)/sizeof(UserInfo);
|
||||
|
||||
class UserInfoClass
|
||||
{
|
||||
UserInfo info;
|
||||
@ -57,15 +57,33 @@ public:
|
||||
{
|
||||
memcpy(&info,&ui,sizeof(UserInfo));
|
||||
|
||||
cout<<"UserInfoClass::Set("<<info.name<<")"<<endl;
|
||||
std::cout<<"UserInfoClass::Set("<<info.name<<")"<<std::endl;
|
||||
}
|
||||
|
||||
~UserInfoClass()
|
||||
{
|
||||
cout<<"~UserInfoClass("<<info.name<<")"<<endl;
|
||||
std::cout<<"~UserInfoClass("<<info.name<<")"<<std::endl;
|
||||
}
|
||||
|
||||
const char *GetName ()const{return info.name;}
|
||||
const bool GetSex ()const{return info.sex;}
|
||||
const int GetAge ()const{return info.age;}
|
||||
};
|
||||
|
||||
inline void out_userinfo(const UserInfo *ui)
|
||||
{
|
||||
if(!ui)return;
|
||||
|
||||
std::cout<<"User("<<ui->name<<","<<(ui->sex?"Male":"Female")<<","<<ui->age<<")"<<std::endl;
|
||||
}
|
||||
|
||||
inline void out_userinfo(const UserInfo *ui,const int count)
|
||||
{
|
||||
if(!ui||count<=0)return;
|
||||
|
||||
for(int i=0;i<count;i++)
|
||||
{
|
||||
std::cout<<"User "<<i<<" ("<<ui->name<<","<<(ui->sex?"Male":"Female")<<","<<ui->age<<")"<<std::endl;
|
||||
++ui;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user