#include #include #include #include #include "Helpers.h" #include "Pet.h" using namespace std; using namespace Tizen::ArtikCloud; Pet::Pet() { //__init(); } Pet::~Pet() { //__cleanup(); } void Pet::__init() { //id = long(0); //category = new Category(); //name = std::string(); //new std::list()std::list> photoUrls; //new std::list()std::list> tags; //status = std::string(); } void Pet::__cleanup() { //if(id != NULL) { // //delete id; //id = NULL; //} //if(category != NULL) { // //delete category; //category = NULL; //} //if(name != NULL) { // //delete name; //name = NULL; //} //if(photoUrls != NULL) { //photoUrls.RemoveAll(true); //delete photoUrls; //photoUrls = NULL; //} //if(tags != NULL) { //tags.RemoveAll(true); //delete tags; //tags = NULL; //} //if(status != NULL) { // //delete status; //status = NULL; //} // } void Pet::fromJson(char* jsonStr) { JsonObject *pJsonObject = json_node_get_object(json_from_string(jsonStr,NULL)); JsonNode *node; const gchar *idKey = "id"; node = json_object_get_member(pJsonObject, idKey); if (node !=NULL) { if (isprimitive("long long")) { jsonToValue(&id, node, "long long", ""); } else { } } const gchar *categoryKey = "category"; node = json_object_get_member(pJsonObject, categoryKey); if (node !=NULL) { if (isprimitive("Category")) { jsonToValue(&category, node, "Category", "Category"); } else { Category* obj = static_cast (&category); obj->fromJson(json_to_string(node, false)); } } const gchar *nameKey = "name"; node = json_object_get_member(pJsonObject, nameKey); if (node !=NULL) { if (isprimitive("std::string")) { jsonToValue(&name, node, "std::string", ""); } else { } } const gchar *photoUrlsKey = "photoUrls"; node = json_object_get_member(pJsonObject, photoUrlsKey); if (node !=NULL) { { JsonArray* arr = json_node_get_array(node); JsonNode* temp_json; list new_list; std::string inst; for (guint i=0;i new_list; Tag inst; for (guint i=0;ifromJson(json); } char* Pet::toJson() { JsonObject *pJsonObject = json_object_new(); JsonNode *node; if (isprimitive("long long")) { long long obj = getId(); node = converttoJson(&obj, "long long", ""); } else { } const gchar *idKey = "id"; json_object_set_member(pJsonObject, idKey, node); if (isprimitive("Category")) { Category obj = getCategory(); node = converttoJson(&obj, "Category", ""); } else { Category obj = static_cast (getCategory()); GError *mygerror; mygerror = NULL; node = json_from_string(obj.toJson(), &mygerror); } const gchar *categoryKey = "category"; json_object_set_member(pJsonObject, categoryKey, node); if (isprimitive("std::string")) { std::string obj = getName(); node = converttoJson(&obj, "std::string", ""); } else { } const gchar *nameKey = "name"; json_object_set_member(pJsonObject, nameKey, node); if (isprimitive("std::string")) { list new_list = static_cast > (getPhotoUrls()); node = converttoJson(&new_list, "std::string", "array"); } else { node = json_node_alloc(); list new_list = static_cast > (getPhotoUrls()); JsonArray* json_array = json_array_new(); GError *mygerror; } const gchar *photoUrlsKey = "photoUrls"; json_object_set_member(pJsonObject, photoUrlsKey, node); if (isprimitive("Tag")) { list new_list = static_cast > (getTags()); node = converttoJson(&new_list, "Tag", "array"); } else { node = json_node_alloc(); list new_list = static_cast > (getTags()); JsonArray* json_array = json_array_new(); GError *mygerror; for (list::iterator it = new_list.begin(); it != new_list.end(); it++) { mygerror = NULL; Tag obj = *it; JsonNode *node_temp = json_from_string(obj.toJson(), &mygerror); json_array_add_element(json_array, node_temp); g_clear_error(&mygerror); } json_node_init_array(node, json_array); json_array_unref(json_array); } const gchar *tagsKey = "tags"; json_object_set_member(pJsonObject, tagsKey, node); if (isprimitive("std::string")) { std::string obj = getStatus(); node = converttoJson(&obj, "std::string", ""); } else { } const gchar *statusKey = "status"; json_object_set_member(pJsonObject, statusKey, node); node = json_node_alloc(); json_node_init(node, JSON_NODE_OBJECT); json_node_take_object(node, pJsonObject); char * ret = json_to_string(node, false); json_node_free(node); return ret; } long long Pet::getId() { return id; } void Pet::setId(long long id) { this->id = id; } Category Pet::getCategory() { return category; } void Pet::setCategory(Category category) { this->category = category; } std::string Pet::getName() { return name; } void Pet::setName(std::string name) { this->name = name; } std::list Pet::getPhotoUrls() { return photoUrls; } void Pet::setPhotoUrls(std::list photoUrls) { this->photoUrls = photoUrls; } std::list Pet::getTags() { return tags; } void Pet::setTags(std::list tags) { this->tags = tags; } std::string Pet::getStatus() { return status; } void Pet::setStatus(std::string status) { this->status = status; }