123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290 |
- /**
- * @brief
- jason公共头文件
- * @version
- V 1.0.0
- * @author
- * @date
- 创建时间: 2018-04-19\n
- * @note
- 2018-04-19 初次创建。\n
- * @warning
- * @bug
- */
- #ifndef _JSON_COMMON_H_
- #define _JSON_COMMON_H_
- #include <string>
- #include <vector>
- #include <rapidjson/document.h>
- #include <rapidjson/pointer.h>
- #include "constdef.h"
- namespace sys
- {
- /**
- * @brief
- 通用jason包结构体
- */
- struct _JS_PACK_
- {
- public:
- rapidjson::Document m_Doc;//jason文档对象
- public:
- _JS_PACK_()
- {
- }
- /**
- * @brief
- 获得命令字函数。
- * @param [out] std::string& Error 错误信息\n
- * @return 如果成功返回获得的命令字,否则返回空字符串\n
- * @note
- * @warning
- * @bug
- */
- std::string GetCmd( std::string& Error )
- {
- rapidjson::Value::MemberIterator itMember;
- itMember = m_Doc.FindMember( JSON_ROOT_KEY_CMD );
- if ( itMember == m_Doc.MemberEnd() )
- {
- Error = "Error,Failed to find member: ";
- Error += JSON_ROOT_KEY_CMD;
- return "";
- }
- return m_Doc[JSON_ROOT_KEY_CMD].GetString();
- }
- /**
- * @brief
- 获得成员函数。
- * @param [in] const std::string& MemberName 成员名称\n
- * @param [out] rapidjson::Value& Member 获得的成员\n
- * @param [out] std::string& Error 错误信息\n
- * @return 如果成功返回true,否则返回false\n
- * @note
- * @warning
- * @bug
- */
- bool GetMember( const std::string& MemberName, rapidjson::Value& Member, std::string& Error )
- {
- rapidjson::Value::MemberIterator itMember;
- itMember = m_Doc.FindMember( MemberName.c_str() );
- if ( itMember == m_Doc.MemberEnd() )
- {
- Error = "Error,Failed to find member: ";
- Error += MemberName;
- return false;
- }
- rapidjson::Document::AllocatorType allocator;
- Member.CopyFrom( itMember->value, allocator );
- return true;
- }
- /**
- * @brief
- 获得指定成员的值函数。
- * @param [in] const std::string& MemberName 指定成员\n
- * @param [in] const std::string& ValueName 值名称\n
- * @param [out] rapidjson::Value& Member 获得的值\n
- * @param [out] std::string& Error 错误信息\n
- * @return 如果成功返回true,否则返回false\n
- * @note
- * @warning
- * @bug
- */
- bool GetValue( const rapidjson::Value& Member, const std::string& ValueName, rapidjson::Value& Value, std::string& Error )
- {
- rapidjson::Value::ConstMemberIterator itValue;
- itValue = Member.FindMember( ValueName.c_str() );
- if ( itValue == Member.MemberEnd() )
- {
- char szError[256] = { 0 };
- sprintf( szError, "Error,Failed to find: %s", ValueName.c_str() );
- Error = szError;
- return false;
- }
- rapidjson::Document::AllocatorType allocator;
- Value.CopyFrom( itValue->value, allocator );
- return true;
- }
- /**
- * @brief
- 根据jason pointer获得指定的值函数。
- * @param [in] const char* JPointer 指定的jason pointer\n
- * @return 返回获得的值\n
- * @note
- * @warning
- * @bug
- */
- const rapidjson::Value* GetValueByJP( const char* JPointer )
- {
- if ( 0 == JPointer )
- {
- return 0;
- }
- return rapidjson::GetValueByPointer( m_Doc, rapidjson::Pointer( JPointer ) );
- }
- /**
- * @brief
- 获得所有成员函数。
- * @param 无\n
- * @return 返回获得的所有成员的列表\n
- * @note
- * @warning
- * @bug
- */
- std::vector<std::string> GetMembers()
- {
- std::vector<std::string> vMembers;
- for (auto& m : m_Doc.GetObject())
- {
- vMembers.push_back( m.name.GetString() );
- }
- return vMembers;
- }
- };
- /**
- * @brief
- 分站结构体
- */
- struct _JS_COMMON_
- {
- std::string version;//版本
- _JS_COMMON_()
- {
- }
- };
- /**
- * @brief
- 分站结构体
- */
- struct _JS_STATION_
- {
- int stationid;//分站ID
- _JS_STATION_()
- {
- stationid = 0;
- }
- };
- /**
- * @brief
- 卡结构体
- */
- struct _JS_CARD_
- {
- int cardid;//卡ID
- int cardtype;//卡类型
- _JS_CARD_()
- {
- cardid = 0;
- cardtype = 0;
- }
- };
- /**
- * @brief
- 呼叫结构体
- */
- struct _JS_CALL_CARD_REQ_ : public _JS_COMMON_
- {
- int call_type_id;//呼叫类型(0 全员, 1定员)
- int call_time_out;//呼叫时长(单位分钟)
- int call_level_id;//呼叫级别(0一般呼叫,1紧急呼叫)
- std::string user_name;//用户
- long long call_time_interval;//呼叫间隔
- std::vector<_JS_STATION_> stations;//分站列表
- std::vector<_JS_CARD_> cards;//呼叫的卡列表
- _JS_CALL_CARD_REQ_()
- {
- call_type_id = 0;
- call_time_out = 0;
- call_level_id = 0;
- call_time_interval = 0;
- }
- };
- /**
- * @brief
- 取消呼叫结构体
- */
- struct _JS_CALL_CARD_CANCEL_REQ_ : public _JS_COMMON_
- {
- int call_type_id;//呼叫类型(0 全员, 1定员)
- std::string user_name;//用户
- long long call_time;//取消时间
- std::vector<_JS_STATION_> stations;//分站列表
- std::vector<_JS_CARD_> cards;//呼叫的卡列表
- _JS_CALL_CARD_CANCEL_REQ_()
- {
- call_type_id = 0;
- call_time = 0;
- }
- };
- /**
- * @brief
- 数据库连接设置结构体
- */
- struct _JS_LOGIN_
- {
- std::string user_name;//用户名
- std::string user_password;//密码
- _JS_LOGIN_()
- {
- }
- };
- }
- #endif//_JSON_COMMON_H_
|