123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471 |
- #include "schema.h"
- #include "rapidjson\rapidjson.h"
- #include "rapidjson\document.h"
- #include "rapidjson\writer.h"
- #include "rapidjson\stringbuffer.h"
- namespace schema{
- namespace serializor {
- namespace {
- template<class AllocatorType> static inline void serialize(rapidjson::Value& json, AllocatorType & allocator, const char * name, const char v[]);
- template<class AllocatorType> static inline void serialize(rapidjson::Value& json, AllocatorType & allocator, const char * name, const std::string& v);
- template<class AllocatorType, typename T> static inline void serialize(rapidjson::Value& json, AllocatorType & allocator, const char * name, const T& v);
- template<class AllocatorType, typename T> static void serialize(rapidjson::Value& json, AllocatorType & allocator, const SCHEMA_RECT_FIELD<T>& schema_element);
- template<class AllocatorType, typename T> static void serialize(rapidjson::Value& json, AllocatorType & allocator, const char * name, const std::vector<T>& schema_elements);
- template<class AllocatorType> static void serialize(rapidjson::Value& json, AllocatorType & allocator, const SCHEMA_QUESTION& schema_element);
- template<class AllocatorType> static void serialize(rapidjson::Value& json, AllocatorType & allocator, const SCHEMA_ELEMENT_FIELD& schema_element);
- template<class AllocatorType> static void serialize(rapidjson::Value& json, AllocatorType & allocator, const SCHEMA_MATRIX& schema_element);
- template<class AllocatorType> static void serialize(rapidjson::Value& json, AllocatorType & allocator, const SCHEMA_MATRIX_KEGUANTI& schema_element);
- template<class AllocatorType> static void serialize(rapidjson::Value& json, AllocatorType & allocator, const SCHEMA_LOCATE_POINT& schema_element);
- template<class AllocatorType> static void serialize(rapidjson::Value& json, AllocatorType & allocator, const SCHEMA_LOCATE_AREA& schema_element);
- template<class AllocatorType> static void serialize(rapidjson::Value& json, AllocatorType & allocator, const SCHEMA_LOACTE_CROSS& schema_element);
- template<class AllocatorType> static void serialize(rapidjson::Value& json, AllocatorType & allocator, const SCHEMA_MATRIX_TIANTUKAOHAO& schema_element);
- template<class AllocatorType> static void serialize(rapidjson::Value& json, AllocatorType & allocator, const SCHEMA_MATRIX_QUEKAOBIAOJI& schema_element);
- template<class AllocatorType> static void serialize(rapidjson::Value& json, AllocatorType & allocator, const SCHEMA_MATRIX_ABJUANBIAOJI& schema_element);
- template<class AllocatorType> static void serialize(rapidjson::Value& json, AllocatorType & allocator, const SCHEMA_MATRIX_XUANZUOTI& schema_element);
- template<class AllocatorType> static void serialize(rapidjson::Value& json, AllocatorType & allocator, const SCHEMA_CODE& schema_element);
- template<class AllocatorType> static void serialize(rapidjson::Value& json, AllocatorType & allocator, const SCHEMA_CLIP& schema_element);
- template<class AllocatorType> static void serialize(rapidjson::Value& json, AllocatorType & allocator, const SCHEMA_PAGE& schema_element);
- template<class AllocatorType> static void serialize(rapidjson::Value& json, AllocatorType & allocator, const char * name, const SCHEMA_VERSION& version);
- template<class AllocatorType> static void serialize(rapidjson::Value& json, AllocatorType & allocator, const char * name, const SCHEMA& schema_element);
- static inline void deserialize(float&dst, const rapidjson::Value &json);
- static inline void deserialize(double&dst, const rapidjson::Value &json);
- static inline void deserialize(bool&dst, const rapidjson::Value &json);
- static inline void deserialize(int&dst, const rapidjson::Value &json);
- static inline void deserialize(char dst[], const rapidjson::Value &json);
- static inline void deserialize(std::string & dst, const rapidjson::Value &json);
- template<typename T>static inline void deserialize(T&dst, const rapidjson::Value &json);
- template<typename T>static inline void deserialize(T dst[], int& count, int group_size[], int& group_count, const rapidjson::Value &json);
- template<typename T>static inline void deserialize(T dst[], int& count, const rapidjson::Value &json);
- template<typename T>static bool deserialize(const rapidjson::Value &json, SCHEMA_RECT_FIELD<T> &schema_element);
- template<typename T>static bool deserialize(std::vector<T> &schema_elements, const rapidjson::Value &json);
- static bool deserialize(const rapidjson::Value &json, SCHEMA_ELEMENT_FIELD &schema_element);
- static bool deserialize(const rapidjson::Value &json, SCHEMA_MATRIX &schema_element);
- static bool deserialize(const rapidjson::Value &json, SCHEMA_CLIP &schema_element);
- static bool deserialize(const rapidjson::Value &json, SCHEMA_CODE &schema_element);
- static bool deserialize(const rapidjson::Value &json, SCHEMA_MATRIX_KEGUANTI &schema_element);
- static bool deserialize(const rapidjson::Value &json, SCHEMA_LOCATE_AREA &schema_element);
- static bool deserialize(const rapidjson::Value &json, SCHEMA_LOACTE_CROSS &schema_element);
- static bool deserialize(const rapidjson::Value &json, SCHEMA_LOCATE_POINT &schema_element);
- static bool deserialize(const rapidjson::Value &json, SCHEMA_MATRIX_QUEKAOBIAOJI &schema_element);
- static bool deserialize(const rapidjson::Value &json, SCHEMA_MATRIX_TIANTUKAOHAO &schema_element);
- static bool deserialize(const rapidjson::Value &json, SCHEMA_MATRIX_ABJUANBIAOJI &schema_element);
- static bool deserialize(const rapidjson::Value &json, SCHEMA_MATRIX_XUANZUOTI &schema_element);
- static bool deserialize(const rapidjson::Value &json, SCHEMA_PAGE &schema_element);
- static bool deserialize(const rapidjson::Value &json, SCHEMA_QUESTION &schema_element);
- static bool deserialize(const rapidjson::Value &json, SCHEMA &_schema);
- static bool deserialize(const rapidjson::Value &json, SCHEMA_VERSION &version);
- /*************************************/
- template<class AllocatorType> static inline void serialize(rapidjson::Value& json, AllocatorType & allocator, const char * name, const char v[]){
- json.AddMember(rapidjson::Value::StringRefType(name), rapidjson::Value::StringRefType(static_cast<const char*>(v)), allocator);
- }
- template<class AllocatorType> static inline void serialize(rapidjson::Value& json, AllocatorType & allocator, const char * name, const std::string& v){
- json.AddMember(rapidjson::Value::StringRefType(name), rapidjson::Value::StringRefType(v.c_str(), v.length()), allocator);
- }
- template<class AllocatorType, typename T> static inline void serialize(rapidjson::Value& json, AllocatorType & allocator, const char * name, const T& v){
- json.AddMember(rapidjson::Value::StringRefType(name), v, allocator);
- }
- template<class AllocatorType> static void serialize(rapidjson::Value& json, AllocatorType & allocator, const SCHEMA_QUESTION& schema_element){
- serialize(json, allocator, "nID", schema_element.nID);
- serialize(json, allocator, "question_code", schema_element.question_code);
- serialize(json, allocator, "question_code_new", schema_element.question_code_new);
- serialize(json, allocator, "newqt", schema_element.newqt);
- serialize(json, allocator, "xiaowen", schema_element.xiaowen);
- serialize(json, allocator, "maxQuestionNO", schema_element.maxQuestionNO);
- serialize(json, allocator, "tigan", schema_element.tigan);
- serialize(json, allocator, "answers", schema_element.answers);
- serialize(json, allocator, "answerA", schema_element.answerA);
- serialize(json, allocator, "answerB", schema_element.answerB);
- serialize(json, allocator, "jiexi", schema_element.jiexi);
- serialize(json, allocator, "zhishidian", schema_element.zhishidian);
- serialize(json, allocator, "courseCode", schema_element.courseCode);
- serialize(json, allocator, "score", schema_element.score);
- serialize(json, allocator, "halfScore", schema_element.halfScore);
- serialize(json, allocator, "doubleEvl", schema_element.doubleEvl);
- serialize(json, allocator, "holdValue", schema_element.holdValue);
- serialize(json, allocator, "questionType", schema_element.questionType);
- serialize(json, allocator, "nMarkUnit", schema_element.nMarkUnit);
- serialize(json, allocator, "openOption", schema_element.openOption);
- serialize(json, allocator, "nLevelOne", schema_element.qtLevelOne);
- serialize(json, allocator, "nLevelTwo", schema_element.qtLevelTwo);
- serialize(json, allocator, "nPostLevelOne", schema_element.qtPostLevelOne);
- serialize(json, allocator, "nPostLevelTwo", schema_element.qtPostLevelTwo);
- serialize(json, allocator, "showMarkTypeIndex", schema_element.showMarkTypeIndex);
- serialize(json, allocator, "postMarkTypeID", schema_element.postMarkTypeID);
- serialize(json, allocator, "showSubjectTypeIndex", schema_element.showSubjectTypeIndex);
- serialize(json, allocator, "postSubjectTypeID", schema_element.postSubjectTypeID);
- }
- template<class AllocatorType, typename T> static void serialize(rapidjson::Value& json, AllocatorType & allocator, const SCHEMA_RECT_FIELD<T>& schema_element){
- serialize(json, allocator, "centerx", schema_element.centerx);
- serialize(json, allocator, "centery", schema_element.centery);
- serialize(json, allocator, "height", schema_element.height);
- serialize(json, allocator, "width", schema_element.width);
- }
- template<class AllocatorType> static void serialize(rapidjson::Value& json, AllocatorType & allocator, const SCHEMA_ELEMENT_FIELD& schema_element){
- serialize(json, allocator, "nID", schema_element.nID);
- serialize(json, allocator, static_cast<const SCHEMA_RECT_FIELD<float>&>(schema_element));
- }
- template<class AllocatorType> static void serialize(rapidjson::Value& json, AllocatorType & allocator, const SCHEMA_MATRIX& schema_element){
- serialize(json, allocator, "nRows", schema_element.nRows);
- serialize(json, allocator, "nCols", schema_element.nCols);
- serialize(json, allocator, "optionWidth", schema_element.optionWidth);
- serialize(json, allocator, "optionHeight", schema_element.optionHeight);
- serialize(json, allocator, "direction", schema_element.direction);
- serialize(json, allocator, "outputchars", schema_element.outputchars);
- serialize(json, allocator, "outputcharsnew", schema_element.outputcharsnew);
- serialize(json, allocator, static_cast<const SCHEMA_ELEMENT_FIELD&>(schema_element));
- }
- template<class AllocatorType> static void serialize(rapidjson::Value& json, AllocatorType & allocator, const SCHEMA_MATRIX_KEGUANTI& schema_element){
- rapidjson::Value question_groups(rapidjson::kArrayType);
- for (int idx_i = 0, idx_q = 0; idx_i < schema_element.group_count; idx_i++)
- {
- rapidjson::Value question_ids(rapidjson::kArrayType);
- for (int idx_j = 0; idx_j < schema_element.group_size[idx_i]; idx_j++, idx_q++){
- question_ids.PushBack(schema_element.question_ids[idx_q], allocator);
- }
- question_groups.PushBack(question_ids, allocator);
- }
- json.AddMember("question_ids", question_groups, allocator);
- serialize(json, allocator, "question_type", schema_element.question_type);
- serialize(json, allocator, static_cast<const SCHEMA_MATRIX&>(schema_element));
- }
- template<class AllocatorType> static void serialize(rapidjson::Value& json, AllocatorType & allocator, const SCHEMA_LOCATE_POINT& schema_element){
- serialize(json, allocator, static_cast<const SCHEMA_ELEMENT_FIELD&>(schema_element));
- }
- template<class AllocatorType> static void serialize(rapidjson::Value& json, AllocatorType & allocator, const SCHEMA_LOCATE_AREA& schema_element){
- serialize(json, allocator, static_cast<const SCHEMA_ELEMENT_FIELD&>(schema_element));
- }
- /*SCHEMA_LOACTE_CROSS*/
- template<class AllocatorType> static void serialize(rapidjson::Value& json, AllocatorType & allocator, const SCHEMA_LOACTE_CROSS& schema_element){
- serialize(json, allocator, "sign", schema_element.sign);
- serialize(json, allocator, "angle", schema_element.angle);
- serialize(json, allocator, static_cast<const SCHEMA_ELEMENT_FIELD&>(schema_element));
- }
- template<class AllocatorType> static void serialize(rapidjson::Value& json, AllocatorType & allocator, const SCHEMA_MATRIX_TIANTUKAOHAO& schema_element){
- serialize(json, allocator, static_cast<const SCHEMA_MATRIX&>(schema_element));
- }
- template<class AllocatorType> static void serialize(rapidjson::Value& json, AllocatorType & allocator, const SCHEMA_MATRIX_QUEKAOBIAOJI& schema_element){
- serialize(json, allocator, static_cast<const SCHEMA_MATRIX&>(schema_element));
- }
- template<class AllocatorType> static void serialize(rapidjson::Value& json, AllocatorType & allocator, const SCHEMA_MATRIX_ABJUANBIAOJI& schema_element){
- serialize(json, allocator, static_cast<const SCHEMA_MATRIX&>(schema_element));
- }
- template<class AllocatorType> static void serialize(rapidjson::Value& json, AllocatorType & allocator, const SCHEMA_MATRIX_XUANZUOTI& schema_element){
- serialize(json, allocator, "xuantishu", schema_element.xuantishu);
- serialize(json, allocator, "err_handler_type", schema_element.err_handler_type);
- serialize(json, allocator, static_cast<const SCHEMA_MATRIX&>(schema_element));
- }
- template<class AllocatorType> static void serialize(rapidjson::Value& json, AllocatorType & allocator, const SCHEMA_CODE& schema_element){
- serialize(json, allocator, "bDirection", schema_element.bDirection);
- serialize(json, allocator, static_cast<const SCHEMA_ELEMENT_FIELD&>(schema_element));
- }
- template<class AllocatorType> static void serialize(rapidjson::Value& json, AllocatorType & allocator, const SCHEMA_CLIP& schema_element){
- rapidjson::Value question_ids(rapidjson::kArrayType);
- for (int idx_i = 0; idx_i < schema_element.question_count; idx_i++)
- {
- question_ids.PushBack(schema_element.question_ids[idx_i], allocator);
- }
- serialize(json, allocator, "area_name", schema_element.area_name);
- serialize(json, allocator, "markUnit", schema_element.markUnit);
- serialize(json, allocator, "issplit", schema_element.issplit);
- serialize(json, allocator, "markUnitPart", schema_element.markUnitPart);
- serialize(json, allocator, "question_type", schema_element.question_type);
- serialize(json, allocator, "area_name_by_questionNo", schema_element.area_name_by_questionNo);
- serialize(json, allocator, "area_name_by_questionNoNew", schema_element.area_name_by_questionNoNew);
- serialize(json, allocator, "xuanzutiArea", schema_element.xuanzutiArea);
- json.AddMember("question_ids", question_ids, allocator);
- serialize(json, allocator, static_cast<const SCHEMA_ELEMENT_FIELD&>(schema_element));
- }
- template<class AllocatorType> static void serialize(rapidjson::Value& json, AllocatorType & allocator, const SCHEMA_PAGE& schema_element){
- serialize(json, allocator, "abjuanbjiaoji", schema_element.abjuanbjiaoji);
- serialize(json, allocator, "clips", schema_element.clips);
- serialize(json, allocator, "clips2", schema_element.clips2);
- serialize(json, allocator, "codes", schema_element.codes);
- serialize(json, allocator, "keguantiMatrix", schema_element.keguantiMatrix);
- serialize(json, allocator, "locateAreas", schema_element.locateAreas);
- serialize(json, allocator, "locateCrosses", schema_element.locateCrosses);
- serialize(json, allocator, "locatePoints", schema_element.locatePoints);
- serialize(json, allocator, "matrixs", schema_element.matrixs);
- serialize(json, allocator, "quekaobiaoji", schema_element.quekaobiaoji);
- serialize(json, allocator, "tiantukaohao", schema_element.tiantukaohao);
- serialize(json, allocator, "xuanzuoti", schema_element.xuanzuoti);
- serialize(json, allocator, "angle", schema_element.angle);
- serialize(json, allocator, "height", schema_element.height);
- serialize(json, allocator, "index", schema_element.index);
- serialize(json, allocator, "nID", schema_element.nID);
- serialize(json, allocator, "width", schema_element.width);
- }
- template<class AllocatorType, typename T> static void serialize(rapidjson::Value& json, AllocatorType & allocator, const char * name, const std::vector<T>& schema_elements){
- rapidjson::Value array_(rapidjson::kArrayType);
- for (int idx_i = 0; idx_i < schema_elements.size(); idx_i++)
- {
- rapidjson::Value elment(rapidjson::kObjectType);
- const T & element_ = schema_elements[idx_i];
- serialize(elment, allocator, element_);
- array_.PushBack(elment, allocator);
- }
- json.AddMember(rapidjson::Value::StringRefType(name), array_, allocator);
- }
- template<class AllocatorType> static void serialize(rapidjson::Value& json, AllocatorType & allocator, const char * name, const SCHEMA_VERSION& version){
- rapidjson::Value object_(rapidjson::kObjectType);
- serialize(object_, allocator, "majorNum", version.majorNum);
- serialize(object_, allocator, "minorNum", version.minorNum);
- serialize(object_, allocator, "company", version.company);
- json.AddMember(rapidjson::Value::StringRefType(name), object_, allocator);
- }
- template<class AllocatorType> static void serialize(rapidjson::Value& json, AllocatorType & allocator, const char * name, const SCHEMA& schema_element){
- rapidjson::Value object_(rapidjson::kObjectType);
- serialize(object_, allocator, "course_code", schema_element.course_code);
- // serialize(object_, allocator, "strTimu", schema_element.strTiMuTotal);
- serialize(object_, allocator, "lastKeGuanTiDirection", schema_element.lastKeGuanTiDirection);
- serialize(object_, allocator, "nNextObjID", schema_element.nNextObjID);
- serialize(object_, allocator, "state", schema_element.state);
- serialize(object_, allocator, "totalScore", schema_element.totalScore);
- serialize(object_, allocator, "pages", schema_element.pages);
- serialize(object_, allocator, "questions", schema_element.questions);
- json.AddMember(rapidjson::Value::StringRefType(name), object_, allocator);
- }
- template<typename T>static inline void deserialize(T&dst, const rapidjson::Value &json){
- dst = (T)json.GetInt();
- }
- static inline void deserialize(float&dst, const rapidjson::Value &json){
- dst = json.GetDouble();
- }
- static inline void deserialize(double&dst, const rapidjson::Value &json){
- dst = json.GetDouble();
- }
- static inline void deserialize(bool&dst, const rapidjson::Value &json){
- dst = json.GetBool();
- }
- static inline void deserialize(int&dst, const rapidjson::Value &json){
- dst = json.GetInt();
- }
- static inline void deserialize(char dst[], const rapidjson::Value &json){
- strcpy(dst, json.GetString());
- }
- template<typename T>static inline void deserialize(T dst[], int& count, int group_size[], int& group_count, const rapidjson::Value &json){
- group_count = json.Size();
- count = 0;
- for (int idx_i = 0, idx_x = 0; idx_i < json.Size(); idx_i++)
- {
- const rapidjson::Value &json2 = json[idx_i];
- group_size[idx_i] = json2.Size();
- for (int idx_j = 0; idx_j < group_size[idx_i]; idx_j++, idx_x++)
- {
- deserialize(dst[idx_x], json2[idx_j]);
- count++;
- }
- }
- }
- template<typename T>static inline void deserialize(T dst[], int& count, const rapidjson::Value &json){
- count = json.Size();
- for (int idx_i = 0; idx_i < count; idx_i++)
- {
- deserialize(dst[idx_i], json[idx_i]);
- }
- }
- static inline void deserialize(std::string & dst, const rapidjson::Value &json){
- dst = json.GetString();
- }
- template<typename T>static bool deserialize(const rapidjson::Value &json, SCHEMA_RECT_FIELD<T> &schema_element){
- deserialize(schema_element.centerx, json["centerx"]);
- deserialize(schema_element.centery, json["centery"]);
- deserialize(schema_element.width, json["width"]);
- deserialize(schema_element.height, json["height"]);
- return true;
- }
- static bool deserialize(const rapidjson::Value &json, SCHEMA_ELEMENT_FIELD &schema_element){
- deserialize(schema_element.nID, json["nID"]);
- deserialize(json, static_cast<SCHEMA_RECT_FIELD<float>&>(schema_element));
- return true;
- }
- static bool deserialize(const rapidjson::Value &json, SCHEMA_MATRIX &schema_element){
- deserialize(schema_element.nRows, json["nRows"]);
- deserialize(schema_element.nCols, json["nCols"]);
- deserialize(schema_element.optionWidth, json["optionWidth"]);
- deserialize(schema_element.optionHeight, json["optionHeight"]);
- deserialize(schema_element.direction, json["direction"]);
- deserialize(schema_element.outputchars, json["outputchars"]);
- deserialize(schema_element.outputcharsnew, json["outputcharsnew"]);
- deserialize(json, static_cast<SCHEMA_ELEMENT_FIELD&>(schema_element));
- return true;
- }
- static bool deserialize(const rapidjson::Value &json, SCHEMA_CLIP &schema_element){
- deserialize(schema_element.area_name, json["area_name"]);
- deserialize(schema_element.markUnit, json["markUnit"]);
- deserialize(schema_element.issplit, json["issplit"]);
- deserialize(schema_element.markUnitPart, json["markUnitPart"]);
- deserialize(schema_element.question_type, json["question_type"]);
- deserialize(schema_element.area_name_by_questionNo, json["area_name_by_questionNo"]);
- deserialize(schema_element.area_name_by_questionNoNew, json["area_name_by_questionNoNew"]);
- deserialize(schema_element.question_ids, schema_element.question_count, json["question_ids"]);
- if (json.HasMember("xuanzutiArea"))
- deserialize(schema_element.xuanzutiArea, json["xuanzutiArea"]);
- deserialize(json, static_cast<SCHEMA_ELEMENT_FIELD&>(schema_element));
- return true;
- }
- static bool deserialize(const rapidjson::Value &json, SCHEMA_CODE &schema_element){
- deserialize(schema_element.bDirection, json["bDirection"]);
- deserialize(json, static_cast<SCHEMA_ELEMENT_FIELD&>(schema_element));
- return true;
- }
- static bool deserialize(const rapidjson::Value &json, SCHEMA_LOCATE_AREA &schema_element){
- deserialize(json, static_cast<SCHEMA_ELEMENT_FIELD&>(schema_element));
- return true;
- }
- static bool deserialize(const rapidjson::Value &json, SCHEMA_LOACTE_CROSS &schema_element){
- if (json.FindMember("sign") != json.MemberEnd())deserialize(schema_element.sign, json["sign"]);
- if (json.FindMember("angle") != json.MemberEnd())deserialize(schema_element.angle, json["angle"]);
- deserialize(json, static_cast<SCHEMA_ELEMENT_FIELD&>(schema_element));
- return true;
- }
- static bool deserialize(const rapidjson::Value &json, SCHEMA_LOCATE_POINT &schema_element){
- deserialize(json, static_cast<SCHEMA_ELEMENT_FIELD&>(schema_element));
- return true;
- }
- static bool deserialize(const rapidjson::Value &json, SCHEMA_MATRIX_QUEKAOBIAOJI &schema_element){
- deserialize(json, static_cast<SCHEMA_MATRIX&>(schema_element));
- return true;
- }
- static bool deserialize(const rapidjson::Value &json, SCHEMA_MATRIX_TIANTUKAOHAO &schema_element){
- deserialize(json, static_cast<SCHEMA_MATRIX&>(schema_element));
- return true;
- }
- static bool deserialize(const rapidjson::Value &json, SCHEMA_MATRIX_ABJUANBIAOJI &schema_element){
- deserialize(json, static_cast<SCHEMA_MATRIX&>(schema_element));
- return true;
- }
- static bool deserialize(const rapidjson::Value &json, SCHEMA_MATRIX_KEGUANTI &schema_element){
- deserialize(schema_element.question_type, json["question_type"]);
- deserialize(schema_element.question_ids, schema_element.question_count, schema_element.group_size, schema_element.group_count, json["question_ids"]);
- deserialize(json, static_cast<SCHEMA_MATRIX&>(schema_element));
- return true;
- }
- static bool deserialize(const rapidjson::Value &json, SCHEMA_MATRIX_XUANZUOTI &schema_element){
- deserialize(schema_element.xuantishu, json["xuantishu"]);
- deserialize(schema_element.err_handler_type, json["err_handler_type"]);
- deserialize(json, static_cast<SCHEMA_MATRIX&>(schema_element));
- return true;
- }
- static bool deserialize(const rapidjson::Value &json, SCHEMA_PAGE &schema_element){
- deserialize(schema_element.abjuanbjiaoji, json["abjuanbjiaoji"]);
- deserialize(schema_element.angle, json["angle"]);
- deserialize(schema_element.clips, json["clips"]);
- deserialize(schema_element.clips2, json["clips2"]);
- deserialize(schema_element.codes, json["codes"]);
- deserialize(schema_element.height, json["height"]);
- deserialize(schema_element.index, json["index"]);
- deserialize(schema_element.keguantiMatrix, json["keguantiMatrix"]);
- deserialize(schema_element.locateAreas, json["locateAreas"]);
- deserialize(schema_element.locateCrosses, json["locateCrosses"]);
- deserialize(schema_element.locatePoints, json["locatePoints"]);
- deserialize(schema_element.matrixs, json["matrixs"]);
- deserialize(schema_element.nID, json["nID"]);
- deserialize(schema_element.quekaobiaoji, json["quekaobiaoji"]);
- deserialize(schema_element.tiantukaohao, json["tiantukaohao"]);
- deserialize(schema_element.width, json["width"]);
- deserialize(schema_element.xuanzuoti, json["xuanzuoti"]);
- return true;
- }
- static bool deserialize(const rapidjson::Value &json, SCHEMA_QUESTION &schema_element){
- deserialize(schema_element.answerA, json["answerA"]);
- deserialize(schema_element.answerB, json["answerB"]);
- deserialize(schema_element.answers, json["answers"]);
- deserialize(schema_element.courseCode, json["courseCode"]);
- deserialize(schema_element.doubleEvl, json["doubleEvl"]);
- deserialize(schema_element.halfScore, json["halfScore"]);
- deserialize(schema_element.holdValue, json["holdValue"]);
- deserialize(schema_element.jiexi, json["jiexi"]);
- deserialize(schema_element.nID, json["nID"]);
- deserialize(schema_element.nMarkUnit, json["nMarkUnit"]);
- deserialize(schema_element.openOption, json["openOption"]);
- deserialize(schema_element.questionType, json["questionType"]);
- deserialize(schema_element.question_code, json["question_code"]);
- deserialize(schema_element.question_code_new, json["question_code_new"]);
- deserialize(schema_element.newqt, json["newqt"]);
- deserialize(schema_element.xiaowen, json["xiaowen"]);
- if (json.HasMember("maxQuestionNO"))
- deserialize(schema_element.maxQuestionNO, json["maxQuestionNO"]);
- deserialize(schema_element.score, json["score"]);
- deserialize(schema_element.tigan, json["tigan"]);
- deserialize(schema_element.zhishidian, json["zhishidian"]);
- deserialize(schema_element.qtLevelOne, json["nLevelOne"]);
- deserialize(schema_element.qtLevelTwo, json["nLevelTwo"]);
- deserialize(schema_element.qtPostLevelOne, json["nPostLevelOne"]);
- deserialize(schema_element.qtPostLevelTwo, json["nPostLevelTwo"]);
- deserialize(schema_element.showMarkTypeIndex, json["showMarkTypeIndex"]);
- deserialize(schema_element.postMarkTypeID, json["postMarkTypeID"]);
- deserialize(schema_element.showSubjectTypeIndex, json["showSubjectTypeIndex"]);
- deserialize(schema_element.postSubjectTypeID, json["postSubjectTypeID"]);
- return true;
- }
- template<typename T>static bool deserialize(std::vector<T> &schema_elements, const rapidjson::Value &json){
- schema_elements.resize(json.Size());
- for (int idx_i = 0; idx_i < json.Size(); idx_i++)
- {
- deserialize(json[idx_i], schema_elements[idx_i]);
- }
- return true;
- }
- static bool deserialize(const rapidjson::Value &json, SCHEMA &_schema){
- deserialize(_schema.course_code, json["course_code"]);
- //deserialize(_schema.strTiMuTotal, json["strTimu"]);
- deserialize(_schema.nNextObjID, json["nNextObjID"]);
- deserialize(_schema.state, json["state"]);
- deserialize(_schema.totalScore, json["totalScore"]);
- deserialize(_schema.questions, json["questions"]);
- deserialize(_schema.pages, json["pages"]);
- return true;
- }
- static bool deserialize(const rapidjson::Value &json, SCHEMA_VERSION &version){
- deserialize(version.majorNum, json["majorNum"]);
- deserialize(version.minorNum, json["minorNum"]);
- deserialize(version.company, json["company"]);
- return true;
- }
- }
- void SchemJsonSerializor::serialize(std::string &json, const schema::SCHEMA & _schema, const SCHEMA_VERSION &version /*= CURRENT_SCHEMA_VERSTION*/)
- {
- rapidjson::Document document;
- rapidjson::Document::AllocatorType & allocator = document.GetAllocator();
- rapidjson::Value root(rapidjson::kObjectType);
- ::schema::serializor::serialize(root, allocator,"schemaVersion", version);
- ::schema::serializor::serialize(root, allocator, "schema", _schema);
- rapidjson::StringBuffer buffer;
- rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
- root.Accept(writer);
- json = buffer.GetString();
- }
- bool SchemJsonSerializor::deserialize(const std::string &json, schema::SCHEMA & _schema, SCHEMA_VERSION &version)
- {
- rapidjson::Document document;
- document.Parse(json.c_str());
- if (document.IsObject()){
- bool success = ::schema::serializor::deserialize(document["schemaVersion"], version);
- if (!success) return false;
- success = ::schema::serializor::deserialize(document["schema"], _schema);
- if (!success) return false;
- return true;
- }
- return false;
- }
- }
- }
|