updated MapTest
This commit is contained in:
parent
707710f664
commit
232590e9b7
@ -88,14 +88,39 @@ void StringMapTest()
|
|||||||
});
|
});
|
||||||
|
|
||||||
cout<<endl;
|
cout<<endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void StringObjectMapTest()
|
||||||
|
{
|
||||||
|
ObjectMap<UTF8String,UserInfoClass> ui_map;
|
||||||
|
|
||||||
|
for(auto &ui:user_info_array)
|
||||||
|
{
|
||||||
|
UserInfoClass *uic=new UserInfoClass;
|
||||||
|
|
||||||
|
uic->Set(ui);
|
||||||
|
|
||||||
|
ui_map.Add(ui.name,uic);
|
||||||
|
}
|
||||||
|
|
||||||
|
ui_map.Enum([](const UTF8String &key,UserInfoClass *&ui)
|
||||||
|
{
|
||||||
|
cout<<"["<<key<<","<<(ui->GetSex()?"male":"female")<<","<<ui->GetAge()<<"]"<<endl;
|
||||||
|
});
|
||||||
|
|
||||||
|
cout<<endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int,char **)
|
int main(int,char **)
|
||||||
{
|
{
|
||||||
|
cout<<"Map<int,int> Test"<<endl;
|
||||||
IntMapTest();
|
IntMapTest();
|
||||||
|
|
||||||
|
cout<<"Map<String,UserInfo> Test"<<endl;
|
||||||
StringMapTest();
|
StringMapTest();
|
||||||
|
|
||||||
|
cout<<"ObjectMap<String,UserInfoClass> Test"<<endl;
|
||||||
|
StringObjectMapTest();
|
||||||
|
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
@ -54,29 +54,6 @@ void StructPoolTest()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class UserInfoClass
|
|
||||||
{
|
|
||||||
UserInfo info;
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
UserInfoClass()=default;
|
|
||||||
|
|
||||||
void Set(const UserInfo &ui)
|
|
||||||
{
|
|
||||||
memcpy(&info,&ui,sizeof(UserInfo));
|
|
||||||
|
|
||||||
cout<<"UserInfoClass::Set("<<info.name<<")"<<endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
~UserInfoClass()
|
|
||||||
{
|
|
||||||
cout<<"~UserInfoClass("<<info.name<<")"<<endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *GetName()const{return info.name;}
|
|
||||||
};
|
|
||||||
|
|
||||||
void ShowUserInfoArray(const DataArray<UserInfoClass *> &ua)
|
void ShowUserInfoArray(const DataArray<UserInfoClass *> &ua)
|
||||||
{
|
{
|
||||||
cout<<"user info array "<<ua.GetCount()<<" [";
|
cout<<"user info array "<<ua.GetCount()<<" [";
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include<string.h>
|
||||||
|
#include<iostream>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
struct UserInfo
|
struct UserInfo
|
||||||
{
|
{
|
||||||
char name[32];
|
char name[32];
|
||||||
@ -39,3 +44,28 @@ static UserInfo user_info_array[]=
|
|||||||
{"Yoyo",false,42},
|
{"Yoyo",false,42},
|
||||||
{"Zack",true,43}
|
{"Zack",true,43}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class UserInfoClass
|
||||||
|
{
|
||||||
|
UserInfo info;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
UserInfoClass()=default;
|
||||||
|
|
||||||
|
void Set(const UserInfo &ui)
|
||||||
|
{
|
||||||
|
memcpy(&info,&ui,sizeof(UserInfo));
|
||||||
|
|
||||||
|
cout<<"UserInfoClass::Set("<<info.name<<")"<<endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
~UserInfoClass()
|
||||||
|
{
|
||||||
|
cout<<"~UserInfoClass("<<info.name<<")"<<endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *GetName()const{return info.name;}
|
||||||
|
const bool GetSex()const{return info.sex;}
|
||||||
|
const int GetAge()const{return info.age;}
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user