Home > Mobile >  RapidJson implementation Json file read and write
RapidJson implementation Json file read and write

Time:09-20

Don't say on other direct code: here are. H file code:
# pragma once
#include
#include
using namespace std;
//the camera parameters
Struct mInsideParam
{
Double F;
Double Dx.
Double Dy.
Double K1.
Double K2.
Double K3.
Double B1.
Double B2.
Double E1;
Double E2.
};
Struct mOutsideParam
{
Bool standcamera;//whether the benchmark camera
Int outsideparamStyle;//reference mode
Float Matrix [50];//parameter
};
Struct CameraSettingData
{
Int m_CameraStyle;//camera type

Int m_ImageWidth;//image width

Int m_ImageHeight;//image height

Int m_PictureStyle;//picture type

QString m_CameraSN; No./SN/camera

Int m_TrigStyle;//the trigger type

Int m_SampleStyle;//acquisition type

QString m_pCameraName;//the camera name

Float m_pFocusDis;//the focal length

Double m_pPixelSize;//like yuan size

Bool m_pColorful;//whether color

MInsideParam m_pInsideParam;//internal

MOutsideParam m_pOutsideParam;//reference
};
The class CameraContext
{
Public:
CameraContext ()
{

}
~ CameraContext ()
{

}
CameraSettingData m_pCSD;//camera data
Bool Load_Setting_File (QString FilePath);//read the Json file
Bool Write_CameraParam (STD: : from & lt; CameraSettingData> IParam, QString pJsonFile);//write Json file
};
Next is the code for the CPP file:

# include "SettingJsonReader. H"
#include
# include "qtextcodec. H"
# include "rapidjson/document. H"//rapidjson 's DOM - style API
# include "rapidjson/prettywriter. H"//for stringify JSON
# include "rapidjson/filereadstream. H"
# include "rapidjson \ istreamwrapper h"
# include "rapidjson/filewritestream. H"
#include
#include
#include
#include
Using the namespace rapidjson;
using namespace std;

//text parser
Struct DeviceSettingParseHandler
: public BaseReaderHandler DeviceSettingParseHandler>
{
DeviceSettingParseHandler () : objstate_ (ALL_NONE), name_ ()
{
This - & gt; Vec_CameraParam=make_shared & lt; CameraSettingData> (a);
return;
}
Typedef QMap MapDef;//define temporary keys to

Bool StartObject ()
{

This - & gt; NowObjMap=make_shared & lt; MapDef> (a);//create a new temporary keys to
If (objstate_==ALL_NONE)
{
//Do nothing in totalHeader
//return true;
}
This - & gt; MapStack. Push_back (NowObjMap);


If (name_==QStringLiteral (" camera "))
{
Objstate_=ObjState: : Camera_Parser;

return true;

}
Else if (name_==QStringLiteral (" camera inside ")) {
Objstate_=ObjState: : Camera_InsideParam_Parser;
return true;
}
Else if (name_==QStringLiteral (" camera outside the cords ")) {
Objstate_=ObjState: : Camera_OutsideParam_Parser;
return true;
}
The else {
//not the type of
return true;
}

}

Bool EndObject (SizeType) {
//end of the current object and data encapsulation

//the pop-up
This - & gt; NowObjMap=MapStack. Last ();
This - & gt; MapStack. Pop_back ();

The switch (this - & gt; Objstate_)
{
Case ALL_NONE:
{
//parsing out
break;
}
Case ObjState: : Camera_Parser:
{
Auto & amp; P=* this - & gt; Vec_CameraParam;
P. _CameraStyle=NowObjMap - & gt; Find (QStringLiteral (" camera type ")). The value (). ToInt ();
P. _pCameraName=NowObjMap - & gt; Find (QStringLiteral (" camera name ")). The value (). The toString ();
P. _CameraSN=NowObjMap - & gt; Find (QStringLiteral (SN "camera")). The value (), toString ();

P. _pFocusDis=NowObjMap - & gt; Find (QStringLiteral (" focus ")). The value (). ToDouble ();
P. _pPixelSize=NowObjMap - & gt; Find (QStringLiteral (" size like yuan ")). The value (). ToDouble ();
P. _ImageWidth=NowObjMap - & gt; Find (QStringLiteral (" wide width ")). The value (). ToDouble ();
P. _ImageHeight=NowObjMap - & gt; Find (QStringLiteral (" wide height ")). The value (). ToDouble ();
P. _pColorful=NowObjMap - & gt; Whether find (QStringLiteral (" color "). The value (). ToBool ();
P. _PictureStyle=NowObjMap - & gt; Find (QStringLiteral (" photo type ")). The value (), toInt ();
P. _TrigStyle=NowObjMap - & gt; Find (QStringLiteral (" trigger type ")). The value (). ToInt ();
P. _SampleStyle=NowObjMap - & gt; Find (QStringLiteral (" collection types "). The value (), toInt ();
This - & gt; Objstate_=ObjState: : ALL_NONE;
break;
}
Case ObjState: : Camera_InsideParam_Parser:
{
Auto & amp; P=this - & gt; Vec_CameraParam - & gt; M_pInsideParam;
P.F=NowObjMap - & gt; Find (QStringLiteral (" F ")). The value (). ToDouble ();
Conviction yourself x=NowObjMap - & gt; Find (QStringLiteral (" Dx ")). The value (). ToDouble ();
Conviction yourself y=NowObjMap - & gt; Find (QStringLiteral (" Dy ")). The value (). ToDouble ();
1=NowObjMap - p.K & gt; Find (QStringLiteral (" K1 ")). The value (). ToDouble ();
2=NowObjMap - p.K & gt; Find (QStringLiteral (" K2 ")). The value (). ToDouble ();
3=NowObjMap - p.K & gt; Find (QStringLiteral (" K3 ")). The value (). ToDouble ();
1=NowObjMap p.B - & gt; Find (QStringLiteral (" B1 ")). The value (). ToDouble ();
P.B 2=NowObjMap - & gt; nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  •  Tags:  
  • Qt
  • Related