added ActiveDataManagerTest.cpp
This commit is contained in:
parent
eeec8248a4
commit
9312dc8b39
@ -68,10 +68,10 @@ add_executable(PoolTest datatype/PoolTest.cpp)
|
|||||||
set_example_project_folder("DataType/DataArray" PoolTest)
|
set_example_project_folder("DataType/DataArray" PoolTest)
|
||||||
|
|
||||||
add_executable(ActiveIDManagerTest datatype/ActiveIDManagerTest.cpp)
|
add_executable(ActiveIDManagerTest datatype/ActiveIDManagerTest.cpp)
|
||||||
set_example_project_folder("DataType/DataArray" ActiveIDManagerTest)
|
cm_example_project("DataType/DataArray" ActiveIDManagerTest)
|
||||||
|
|
||||||
add_executable(ActiveDataManagerTest datatype/ActiveDataManagerTest.cpp)
|
add_executable(ActiveDataManagerTest datatype/ActiveDataManagerTest.cpp)
|
||||||
set_example_project_folder("DataType/DataArray" ActiveDataManagerTest)
|
cm_example_project("DataType/DataArray" ActiveDataManagerTest)
|
||||||
|
|
||||||
add_executable(MapTest datatype/MapTest.cpp)
|
add_executable(MapTest datatype/MapTest.cpp)
|
||||||
set_example_project_folder("DataType/DataArray" MapTest)
|
set_example_project_folder("DataType/DataArray" MapTest)
|
||||||
|
121
datatype/ActiveDataManagerTest.cpp
Normal file
121
datatype/ActiveDataManagerTest.cpp
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
#include<iostream>
|
||||||
|
#include<hgl/type/ActiveMemoryBlockManager.h>
|
||||||
|
#include<hgl/type/MemoryBlock.h>
|
||||||
|
#include"UserInfo.h"
|
||||||
|
|
||||||
|
using namespace hgl;
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
void DebugOutputArray(const char *hint,const int **id,const int count)
|
||||||
|
{
|
||||||
|
cout<<"("<<hint<<':'<<count<<")";
|
||||||
|
|
||||||
|
if(count<=0)return;
|
||||||
|
|
||||||
|
const int **p=id;
|
||||||
|
|
||||||
|
for(int i=0;i<count;i++)
|
||||||
|
{
|
||||||
|
cout<<(!i?'[':',')<<*p;
|
||||||
|
++p;
|
||||||
|
}
|
||||||
|
|
||||||
|
cout<<']';
|
||||||
|
}
|
||||||
|
|
||||||
|
void DebugOutputArray(const char *hint,const char **str,const int count)
|
||||||
|
{
|
||||||
|
cout<<"("<<hint<<':'<<count<<")";
|
||||||
|
|
||||||
|
if(count<=0)return;
|
||||||
|
|
||||||
|
const char **p=str;
|
||||||
|
|
||||||
|
for(int i=0;i<count;i++)
|
||||||
|
{
|
||||||
|
cout<<(!i?'[':',')<<*p;
|
||||||
|
++p;
|
||||||
|
}
|
||||||
|
|
||||||
|
cout<<']';
|
||||||
|
}
|
||||||
|
|
||||||
|
void DebugOutputArray(const char *hint,const ActiveMemoryBlockManager &ambm,const int *idp,const int count)
|
||||||
|
{
|
||||||
|
if(count<=0)return;
|
||||||
|
|
||||||
|
char **data=new char *[count];
|
||||||
|
|
||||||
|
ambm.GetDataArrayPointer((void **)data,idp,count);
|
||||||
|
|
||||||
|
DebugOutputArray(hint,(const char **)data,count);
|
||||||
|
|
||||||
|
delete[] data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DebugOutputArray(const char *hint,const ActiveMemoryBlockManager &ambm,const DataArray<int> &da)
|
||||||
|
{
|
||||||
|
DebugOutputArray(hint,ambm,da.GetData(),da.GetCount());
|
||||||
|
}
|
||||||
|
|
||||||
|
void DebugAIMOutput(const char *hint,const ActiveMemoryBlockManager &ambm)
|
||||||
|
{
|
||||||
|
cout<<hint<<' ';
|
||||||
|
|
||||||
|
DebugOutputArray("Active",ambm,ambm.GetActiveArray());
|
||||||
|
cout<<' ';
|
||||||
|
DebugOutputArray("Idle",ambm,ambm.GetIdleArray());
|
||||||
|
|
||||||
|
cout<<endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void WriteUsernameToAIM(ActiveMemoryBlockManager &ambm,const int *id,const int count,const int start)
|
||||||
|
{
|
||||||
|
for(int i=0;i<count;i++)
|
||||||
|
ambm.WriteData(user_info_array[start+i].name,id[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
ActiveMemoryBlockManager ambm(8);
|
||||||
|
|
||||||
|
ambm.Alloc(16);
|
||||||
|
|
||||||
|
int start=0;
|
||||||
|
|
||||||
|
DebugAIMOutput("null",ambm);
|
||||||
|
|
||||||
|
int id0[5];
|
||||||
|
ambm.CreateIdle(id0,5);
|
||||||
|
WriteUsernameToAIM(ambm,id0,5,start);start+=5;
|
||||||
|
DebugAIMOutput("CreateIdle(5)",ambm);
|
||||||
|
|
||||||
|
int id1[5];
|
||||||
|
ambm.CreateActive(id1,5);
|
||||||
|
WriteUsernameToAIM(ambm,id1,5,start);start+=5;
|
||||||
|
DebugAIMOutput("CreateActive(user1,5)",ambm);
|
||||||
|
|
||||||
|
DebugOutputArray("user1",ambm,id1,5);
|
||||||
|
std::cout<<std::endl;
|
||||||
|
|
||||||
|
int id2[3];
|
||||||
|
ambm.Get(id2,3);
|
||||||
|
DebugAIMOutput("Get(user2,3)",ambm);
|
||||||
|
DebugOutputArray("user2",ambm,id2,3);
|
||||||
|
std::cout<<std::endl;
|
||||||
|
|
||||||
|
//int id3[5];
|
||||||
|
//ambm.GetOrCreate(id3,5);
|
||||||
|
//DebugAIMOutput("GetOrCreate(user3,5)",ambm);
|
||||||
|
//DebugOutputArray("user3",ambm,id3,5);
|
||||||
|
//std::cout<<std::endl;
|
||||||
|
|
||||||
|
ambm.Release(id1,5);
|
||||||
|
DebugAIMOutput("Release(user1,5)",ambm);
|
||||||
|
|
||||||
|
ambm.Release(id2,3);
|
||||||
|
DebugAIMOutput("Release(user2,3)",ambm);
|
||||||
|
|
||||||
|
ambm.ReleaseAllActive();
|
||||||
|
DebugAIMOutput("RelaseAllActive()",ambm);
|
||||||
|
}
|
@ -7,7 +7,7 @@ using namespace std;
|
|||||||
|
|
||||||
struct UserInfo
|
struct UserInfo
|
||||||
{
|
{
|
||||||
char name[32];
|
char name[8];
|
||||||
bool sex;
|
bool sex;
|
||||||
int age;
|
int age;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user