294 lines
23 KiB
C++
294 lines
23 KiB
C++
/*
|
|
* 说明: 考试数据协议解析
|
|
*
|
|
* 作者: 杨海洋
|
|
* 日期: 2023-04-06
|
|
*/
|
|
|
|
#ifndef XPARSER_H
|
|
#define XPARSER_H
|
|
|
|
#include "HCommon.h"
|
|
#include "XIParser.h"
|
|
|
|
class JUDGE_API XParser : public XIParser
|
|
{
|
|
public:
|
|
XParser();
|
|
virtual ~XParser();
|
|
|
|
virtual bool parseInitExam (const std::string& data, TInitInfo* info) override;
|
|
virtual bool parseBeginExam (const std::string& data, TStuInfo& info) override;
|
|
virtual bool parseRealExam (const std::string& data, TRealExam& info) override;
|
|
virtual bool parseJudgeData (const std::string& data, TJudgeData& info) override;
|
|
virtual bool parsePerform (const std::string& data, TPerformData& info) override;
|
|
|
|
virtual std::string toDataString(const TInitInfo& data) override;
|
|
virtual std::string toDataString(const TStuInfo& data) override;
|
|
virtual std::string toDataString(const TRealExam& data) override;
|
|
virtual std::string toDataString(const TJudgeData& data) override;
|
|
virtual std::string toDataString(const TPerformData& data) override;
|
|
|
|
public:
|
|
//static bool fromJson(const std::string& data, Json::Value& root) { return Tools::fromJson(data, root); }
|
|
|
|
//for get
|
|
static bool get(Json::Value& object, const char* key, bool& store, bool defaults = false) noexcept;
|
|
static bool get(Json::Value& object, const char* key, int8& store, int8 defaults = 0) noexcept;
|
|
static bool get(Json::Value& object, const char* key, int16& store, int16 defaults = 0) noexcept;
|
|
static bool get(Json::Value& object, const char* key, int32& store, int32 defaults = 0) noexcept;
|
|
static bool get(Json::Value& object, const char* key, int64& store, int64 defaults = 0) noexcept;
|
|
static bool get(Json::Value& object, const char* key, double& store, double defaults = 0.0f) noexcept;
|
|
static bool get(Json::Value& object, const char* key, std::string& store, const std::string& defaults="") noexcept;
|
|
static bool get(Json::Value& object, const char* key, std::vector<int8>& store, const std::vector<int8>& defaults={}) noexcept;
|
|
static bool get(Json::Value& object, const char* key, std::vector<int16>& store, const std::vector<int16>& defaults={}) noexcept;
|
|
static bool get(Json::Value& object, const char* key, std::vector<int32>& store, const std::vector<int32>& defaults={}) noexcept;
|
|
static bool get(Json::Value& object, const char* key, std::vector<int64>& store, const std::vector<int64>& defaults={}) noexcept;
|
|
static bool get(Json::Value& object, const char* key, std::vector<double>& store, const std::vector<double>& defaults={}) noexcept;
|
|
static bool get(Json::Value& object, const char* key, std::vector<std::string>& store, const std::vector<std::string>& defaults={}) noexcept;
|
|
|
|
static bool get(Json::Value& object, const char* key, TKfXm& store, const TKfXm& defaults={}) noexcept;
|
|
static bool get(Json::Value& object, const char* key, TEventItemMark& store, const TEventItemMark& defaults={}) noexcept;
|
|
static bool get(Json::Value& object, const char* key, TEventExamFinish& store, const TEventExamFinish& defaults={}) noexcept;
|
|
static bool get(Json::Value& object, const char* key, std::vector<TKfXm>& store, const std::vector<TKfXm>& defaults={}) noexcept;
|
|
static bool get(Json::Value& object, const char* key, std::vector<TRadarWay>& store, const std::vector<TRadarWay>& defaults={}) noexcept;
|
|
static bool get(Json::Value& object, const char* key, std::vector<TRadarShow>& store, const std::vector<TRadarShow>& defaults={}) noexcept;
|
|
static bool get(Json::Value& object, const char* key, std::vector<Pointi>& store, const std::vector<Pointi>& defaults={}) noexcept;
|
|
static bool get(Json::Value& object, const char* key, TRadarFront& store, const TRadarFront& defaults={}) noexcept;
|
|
static bool get(Json::Value& object, const char* key, TGpsInfo& store, const TGpsInfo& defaults={}) noexcept;
|
|
static bool get(Json::Value& object, const char* key, TSensorInfo& store, const TSensorInfo& defaults={}) noexcept;
|
|
static bool get(Json::Value& object, const char* key, TItemExam& store, const TItemExam& defaults={}) noexcept;
|
|
static bool get(Json::Value& object, const char* key, std::vector<TItemExam>& store, const std::vector<TItemExam>& defaults={}) noexcept;
|
|
static bool get(Json::Value& object, const char* key, std::vector<TItemArg>& store, const std::vector<TItemArg>& defaults={}) noexcept;
|
|
static bool get(Json::Value& object, const char* key, std::vector<TMarkRule>& store, const std::vector<TMarkRule>& defaults={}) noexcept;
|
|
static bool get(Json::Value& object, const char* key, std::vector<TSysset>& store, const std::vector<TSysset>& defaults={}) noexcept;
|
|
static bool get(Json::Value& object, const char* key, TExamXm& store, const TExamXm& defaults={}) noexcept;
|
|
static bool get(Json::Value& object, const char* key, TEventFinishItem& store, const TEventFinishItem& defaults={}) noexcept;
|
|
static bool get(Json::Value& object, const char* key, TEventSound& store, const TEventSound& defaults={}) noexcept;
|
|
static bool get(Json::Value& object, const char* key, TEventLane& store, const TEventLane& defaults={}) noexcept;
|
|
static bool get(Json::Value& object, const char* key, TExamWay& store, const TExamWay& defaults={}) noexcept;
|
|
|
|
|
|
static bool get(Json::Value& object, const char* key, TDBItemInfo& store, const TDBItemInfo& defaults={}) noexcept;
|
|
static bool get(Json::Value& object, const char* key, std::vector<TDBItemInfo>& store, const std::vector<TDBItemInfo>& defaults={}) noexcept;
|
|
static inline bool set(Json::Value& object, const char* key, const TDBItemInfo& store) noexcept;
|
|
static inline bool set(Json::Value& object, const char* key, const std::vector<TDBItemInfo>& store) noexcept;
|
|
|
|
static bool get(Json::Value& object, const char* key, TDBCarInfo& store, const TDBCarInfo& defaults={}) noexcept;
|
|
static bool get(Json::Value& object, const char* key, std::vector<TDBCarInfo>& store, const std::vector<TDBCarInfo>& defaults={}) noexcept;
|
|
static inline bool set(Json::Value& object, const char* key, const TDBCarInfo& store) noexcept;
|
|
static inline bool set(Json::Value& object, const char* key, const std::vector<TDBCarInfo>& store) noexcept;
|
|
|
|
static bool get(Json::Value& object, const char* key, TSystemparm& store, const TSystemparm& defaults={}) noexcept;
|
|
static bool get(Json::Value& object, const char* key, std::vector<TSystemparm>& store, const std::vector<TSystemparm>& defaults={}) noexcept;
|
|
static inline bool set(Json::Value& object, const char* key, const TSystemparm& store) noexcept;
|
|
static inline bool set(Json::Value& object, const char* key, const std::vector<TSystemparm>& store) noexcept;
|
|
|
|
static bool get(Json::Value& object, const char* key, TMap_Point& store, const TMap_Point& defaults={}) noexcept;
|
|
static bool get(Json::Value& object, const char* key, TMap_Points& store, const TMap_Points& defaults={}) noexcept;
|
|
static inline bool set(Json::Value& object, const char* key, const TMap_Point& store) noexcept;
|
|
static bool set(Json::Value& object, const char* key, const TMap_Points& store) noexcept;
|
|
|
|
static bool get(Json::Value& object, const char* key, TMap_Point_Item& store, const TMap_Point_Item& defaults={}) noexcept;
|
|
static bool get(Json::Value& object, const char* key, TMap_Point_Items& store, const TMap_Point_Items& defaults={}) noexcept;
|
|
static inline bool set(Json::Value& object, const char* key, const TMap_Point_Item& store) noexcept;
|
|
static bool set(Json::Value& object, const char* key, const TMap_Point_Items& store) noexcept;
|
|
|
|
|
|
//for set
|
|
static inline bool set(Json::Value& object, const char* key, const bool& store) noexcept;
|
|
static inline bool set(Json::Value& object, const char* key, const int8& store) noexcept;
|
|
static inline bool set(Json::Value& object, const char* key, const int16& store) noexcept;
|
|
static inline bool set(Json::Value& object, const char* key, const int32& store) noexcept;
|
|
static inline bool set(Json::Value& object, const char* key, const int64& store) noexcept;
|
|
static inline bool set(Json::Value& object, const char* key, const double& store) noexcept;
|
|
static inline bool set(Json::Value& object, const char* key, const std::string& store) noexcept;
|
|
static inline bool set(Json::Value& object, const char* key, const std::vector<int8>& store) noexcept;
|
|
static inline bool set(Json::Value& object, const char* key, const std::vector<int16>& store) noexcept;
|
|
static inline bool set(Json::Value& object, const char* key, const std::vector<int32>& store) noexcept;
|
|
static inline bool set(Json::Value& object, const char* key, const std::vector<int64>& store) noexcept;
|
|
static inline bool set(Json::Value& object, const char* key, const std::vector<double>& store) noexcept;
|
|
static inline bool set(Json::Value& object, const char* key, const std::vector<std::string>& store) noexcept;
|
|
|
|
static inline bool set(Json::Value& object, const char* key, const TKfXm& store) noexcept;
|
|
static inline bool set(Json::Value& object, const char* key, const TEventItemMark& store) noexcept;
|
|
static inline bool set(Json::Value& object, const char* key, const TEventExamFinish& store) noexcept;
|
|
static inline bool set(Json::Value& object, const char* key, const std::vector<TKfXm>& store) noexcept;
|
|
static inline bool set(Json::Value& object, const char* key, const std::vector<TRadarWay>& store) noexcept;
|
|
static inline bool set(Json::Value& object, const char* key, const std::vector<TRadarShow>& store) noexcept;
|
|
static inline bool set(Json::Value& object, const char* key, const std::vector<Pointi>& store) noexcept;
|
|
static inline bool set(Json::Value& object, const char* key, const TRadarFront& store) noexcept;
|
|
static inline bool set(Json::Value& object, const char* key, const TGpsInfo& store) noexcept;
|
|
static inline bool set(Json::Value& object, const char* key, const TSensorInfo& store) noexcept;
|
|
static inline bool set(Json::Value& object, const char* key, const TItemExam& store) noexcept;
|
|
static inline bool set(Json::Value& object, const char* key, const std::vector<TItemExam>& store) noexcept;
|
|
static inline bool set(Json::Value& object, const char* key, const std::vector<TItemArg>& store) noexcept;
|
|
static inline bool set(Json::Value& object, const char* key, const std::vector<TMarkRule>& store) noexcept;
|
|
static inline bool set(Json::Value& object, const char* key, const std::vector<TSysset>& store) noexcept;
|
|
static inline bool set(Json::Value& object, const char* key, const TExamXm& store) noexcept;
|
|
static inline bool set(Json::Value& object, const char* key, const TEventFinishItem& store) noexcept;
|
|
static inline bool set(Json::Value& object, const char* key, const TEventSound& store) noexcept;
|
|
static inline bool set(Json::Value& object, const char* key, const TEventLane& store) noexcept;
|
|
static inline bool set(Json::Value& object, const char* key, const TExamWay& store) noexcept;
|
|
|
|
|
|
//存储验证数据用
|
|
static bool set(Json::Value& object, const char* key, const std::vector<TModelPoint>& store) noexcept;
|
|
static bool set(Json::Value& object, const char* key, const Pointi& store) noexcept;
|
|
static bool set(Json::Value& object, const char* key, const std::vector<TModelLine>& store) noexcept;
|
|
static bool set(Json::Value& object, const char* key, const TModelLine& store) noexcept;
|
|
static bool set(Json::Value& object, const char* key, const std::vector<TModelPolygon>& store) noexcept;
|
|
static bool set(Json::Value& object, const char* key, const TModelPolygon& store) noexcept;
|
|
static bool set(Json::Value& object, const char* key, const TMapRoadRecs& store) noexcept;
|
|
static bool set(Json::Value& object, const char* key, const TMapRoadRec& store) noexcept;
|
|
static bool set(Json::Value& object, const char* key, const TMapSubItemRecs& store) noexcept;
|
|
static bool set(Json::Value& object, const char* key, const TMapSubItemRec& store) noexcept;
|
|
static bool set(Json::Value& object, const char* key, const TMeshDefines& store) noexcept;
|
|
//static bool set(Json::Value& object, const char* key, const TMeshDefine& store) noexcept;
|
|
|
|
|
|
private:
|
|
|
|
template<typename T>
|
|
static inline bool setT(Json::Value& object, const char* key, const T& store) noexcept
|
|
{
|
|
object[key] = Json::Value(store);
|
|
return true;
|
|
}
|
|
|
|
template<typename T>
|
|
static inline bool setV(Json::Value& object, const char* key, const std::vector<T>& store) noexcept
|
|
{
|
|
Json::Value array(Json::arrayValue);
|
|
for(size_t i = 0; i < store.size(); i++)
|
|
{
|
|
array.append(store[i]);
|
|
}
|
|
object[key] = array;
|
|
return true;
|
|
}
|
|
|
|
//**************************************************************************************************
|
|
|
|
#define CHECK_STRICT_GET_PARAM(object,key,store,strict) \
|
|
{ \
|
|
bool ok = true; \
|
|
if(ok && !object.isMember(key)) \
|
|
{ \
|
|
logerror("CHECK_GET_PARAM key=%s store=%s not member.", key, #store); \
|
|
ok = false; \
|
|
} \
|
|
if(ok && object[key].isNull()) \
|
|
{ \
|
|
logerror("CHECK_GET_PARAM key=%s store=%s is null.", key, #store); \
|
|
ok = false; \
|
|
} \
|
|
if(ok && !get(object, key, store)) \
|
|
{ \
|
|
logerror("CHECK_GET_PARAM key=%s store=%s get error.", key, #store); \
|
|
ok = false; \
|
|
} \
|
|
if(strict && !ok) \
|
|
{ \
|
|
return false; \
|
|
} \
|
|
} \
|
|
|
|
#define CHECK_STRICT_GET_BASIC(expr,strict) \
|
|
{ \
|
|
bool ok = (strict) ? false : true; \
|
|
store = defaults; \
|
|
if(object.isMember(key)) \
|
|
{ \
|
|
Json::Value& v = object[key]; \
|
|
{ expr; } \
|
|
} \
|
|
else \
|
|
{ \
|
|
logerror("CHECK_GET_BASIC key=%s expr=%s error not member.", key, #expr); \
|
|
} \
|
|
return ok; \
|
|
} \
|
|
|
|
#define CHECK_STRICT_GET_OBJECT(expr,strict,parted) \
|
|
{ \
|
|
bool ok = (strict) ? false : true; \
|
|
if(!parted){store = defaults;} \
|
|
if(object.isMember(key)) \
|
|
{ \
|
|
Json::Value& value = object[key]; \
|
|
if(value.isObject()) \
|
|
{ \
|
|
{ expr; } \
|
|
ok = true; \
|
|
} \
|
|
else \
|
|
{ \
|
|
logerror("CHECK_GET_OBJECT key=%s expr=%s error not object.", key, #expr); \
|
|
} \
|
|
} \
|
|
else \
|
|
{ \
|
|
logerror("CHECK_GET_OBJECT key=%s expr=%s error not member.", key, #expr); \
|
|
} \
|
|
if(!parted || !ok) {return ok;} \
|
|
} \
|
|
|
|
#define CHECK_STRICT_GET_ARRAY(expr,check,strict) \
|
|
{ \
|
|
bool ok = (strict) ? false : true; \
|
|
store = defaults; \
|
|
if(object.isMember(key)) \
|
|
{ \
|
|
Json::Value& value = object[key]; \
|
|
if(value.isArray()) \
|
|
{ \
|
|
int size = value.size(); \
|
|
if(check == false || size > 0) \
|
|
{ \
|
|
for(int i = 0; i < size; i++) \
|
|
{ \
|
|
Json::Value& v = value[i]; \
|
|
{ expr; } \
|
|
} \
|
|
ok = true; \
|
|
} \
|
|
else \
|
|
{ \
|
|
logerror("CHECK_GET_ARRAY key=%s expr=%s error size.", key, #expr); \
|
|
} \
|
|
} \
|
|
else \
|
|
{ \
|
|
logerror("CHECK_GET_ARRAY key=%s expr=%s error not array.", key, #expr); \
|
|
} \
|
|
} \
|
|
else \
|
|
{ \
|
|
logerror("CHECK_GET_ARRAY key=%s expr=%s error not member.", key, #expr); \
|
|
} \
|
|
return ok; \
|
|
} \
|
|
|
|
|
|
#ifdef JUDGE_USE_STRICT
|
|
# define CHECK_GET_PARAM(object,key,store) CHECK_STRICT_GET_PARAM(object,key,store,true)
|
|
# define CHECK_GET_BASIC(expr) CHECK_STRICT_GET_BASIC(expr,true)
|
|
# define CHECK_GET_OBJECT(expr) CHECK_STRICT_GET_OBJECT(expr,true,false)
|
|
# define CHECK_GET_OBJECT_V2(expr) CHECK_STRICT_GET_OBJECT(expr,true,true)
|
|
# define CHECK_GET_ARRAY(expr) CHECK_STRICT_GET_ARRAY(expr,false,true)
|
|
# define CHECK_GET_ARRAY_SIZE(expr) CHECK_STRICT_GET_ARRAY(expr,true,true)
|
|
#else
|
|
# define CHECK_GET_PARAM(object,key,store) CHECK_STRICT_GET_PARAM(object,key,store,false)
|
|
# define CHECK_GET_BASIC(expr) CHECK_STRICT_GET_BASIC(expr,false)
|
|
# define CHECK_GET_OBJECT(expr) CHECK_STRICT_GET_OBJECT(expr,false,false)
|
|
# define CHECK_GET_OBJECT_V2(expr) CHECK_STRICT_GET_OBJECT(expr,false,true)
|
|
# define CHECK_GET_ARRAY(expr) CHECK_STRICT_GET_ARRAY(expr,false,false)
|
|
# define CHECK_GET_ARRAY_SIZE(expr) CHECK_STRICT_GET_ARRAY(expr,true,false)
|
|
#endif //JUDGE_USE_STRICT
|
|
|
|
|
|
};
|
|
|
|
#endif // XPARSER_H
|