Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/acl-dev/acl
Browse files Browse the repository at this point in the history
  • Loading branch information
akzi committed Jan 4, 2017
2 parents abe75b4 + f16b62d commit 8a4c782
Show file tree
Hide file tree
Showing 12 changed files with 147 additions and 549 deletions.
72 changes: 72 additions & 0 deletions app/gson/test/test3/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,81 @@ static void deserialize(void)
}
}

static void test1(void)
{
union
{
struct user_male* m;
struct user_female* f;
struct people* p;
} obj;

struct user_male* m = new struct user_male;
(*m).favorite = "pingpang";
(*m).height = 170;
(*m).name = "zsxxsz";
(*m).age = 11;
(*m).male = true;

(*m).province_name = "山东省";
(*m).position = "山东省";

(*m).shcool = "山东工业大学";
(*m).class_name = "热处理专业";

obj.m = m;
acl::json json;

// 将 user 对象转换为 json 对象
acl::json_node& node = acl::gson(json, obj.m);

printf("serialize:\r\n");
printf("json: %s\r\n", node.to_string().c_str());
printf("\r\n");

delete obj.p;
}

static void test2(void)
{
const char *s = "{\"shcool\": \"山东工业大学\", \"class_name\": \"热处理专业\", \"province_name\": \"山东省\", \"position\": \"山东省\", \"name\": \"zsxxsz\", \"age\": 11, \"male\": true, \"favorite\": \"pingpang\", \"height\": 170}";
printf("deserialize:\r\n");

acl::json json;
json.update(s);
user_male u;

// 将 json 对象转换为 user 对象
std::pair<bool, std::string> ret = acl::gson(json.get_root(), u);

// 如果转换失败,则打印转换失败原因
if (ret.first == false)
printf("error: %s\r\n", ret.second.c_str());
else
{
printf("name: %s, age: %d, male: %s, favorite: %s, height: %d\r\n",
u.name.c_str(), u.age, u.male ? "yes" : "no",
u.get_favorite(), u.get_height());
printf("province_name: %s, position: %s\r\n",
u.province_name.c_str(), u.position.c_str());
printf("shcool: %s, class_name: %s\r\n",
u.shcool.c_str(), u.class_name.c_str());
}
}

int main(void)
{
printf("------------------------serialize----------------------\r\n");
serialize();

printf("------------------------deserialize--------------------\r\n");
deserialize();

printf("------------------------test1--------------------------\r\n");
test1();

printf("------------------------test2--------------------------\r\n");
test2();

return 0;
}
38 changes: 37 additions & 1 deletion app/gson/test/test3/struct.stub
Original file line number Diff line number Diff line change
@@ -1,21 +1,57 @@
#pragma once
#include <string>

struct student
struct people
{
people(void) {}
virtual ~people(void) {}
};

struct student : people
{
std::string shcool;
std::string class_name;

student(void) {}
virtual ~student(void) {}
};

struct province
{
std::string province_name;
std::string position;

province(void) {}
virtual ~province(void) {}
};

struct user : student, province
{
std::string name;
int age;
bool male;

user(void) {}
virtual ~user(void) {}
};

struct user_male : user
{
std::string favorite;
int height;

const char* get_favorite(void) const
{
return favorite.c_str();
}
int get_height(void) const
{
return height;
}
};

struct user_female : user
{
std::string favorite;
int weigtht;
};
14 changes: 9 additions & 5 deletions app/gson/test/test5/struct.stub
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,21 @@ struct user
male = v;
return *this;
}
const char* get_name(void)

const char* get_name(void) const
{
return name.c_str();
}

/*
const char* get_name(void) const
bool is_male(void) const
{
return name.c_str();
return male;
}

int get_age(void) const
{
return age;
}
*/

//Gson@skip
acl::string nick;
Expand Down
Binary file removed dist/master/libexec/linux64/acl_master
Binary file not shown.
Loading

0 comments on commit 8a4c782

Please sign in to comment.