//----------------------------------------------------------------------------//Copyright(C)2002-2006MarcinKalicinski////DistributedundertheBoostSoftwareLicense,Version1.0.//(SeeaccompanyingfileLICENSE_1_0.txtorcopyat//http://www.boost.org/LICENSE_1_0.txt)////Formoreinformation,seewww.boost.org//----------------------------------------------------------------------------#ifndefBOOST_PROPERTY_TREE_JSON_PARSER_HPP_INCLUDED#defineBOOST_PROPERTY_TREE_JSON_PARSER_HPP_INCLUDED#include<boost/property_tree/ptree.hpp>#include<boost/property_tree/detail/json_parser_read.hpp>//@PATCH!!!Patchedbythe"iCardClient"developingteam.//#include<boost/property_tree/detail/json_parser_write.hpp>//Donotincludetheoriginalversion.#include"etradeclient/boost_patch/property_tree/json_parser_write.hpp"//Includeourpatchversioninstead.//@}#include<boost/property_tree/detail/json_parser_error.hpp>#include<fstream>#include<string>#include<locale>namespaceboost{namespaceproperty_tree{namespacejson_parser{/***ReadJSONfromathegivenstreamandtranslateittoapropertytree.*@noteClearsexistingcontentsofpropertytree.Incaseoferrorthe*propertytreeunmodified.*@noteItemsofJSONarraysaretranslatedintoptreekeyswithempty*names.Membersofobjectsaretranslatedintonamedkeys.*@noteJSONdatacanbeastring,anumericvalue,oroneofliterals*"null","true"and"false".Duringparse,anyoftheaboveis*copiedverbatimintoptreedatastring.*@throwjson_parser_errorIncaseoferrordeserializingtheproperty*tree.*@paramstreamStreamfromwhichtoreadinthepropertytree.*@param[out]ptThepropertytreetopopulate.*/template<classPtree>voidread_json(std::basic_istream<typenamePtree::key_type::value_type>&stream,Ptree&pt){read_json_internal(stream,pt,std::string());}/***ReadJSONfromathegivenfileandtranslateittoapropertytree.*@noteClearsexistingcontentsofpropertytree.Incaseoferrorthe*propertytreeunmodified.*@noteItemsofJSONarraysaretranslatedintoptreekeyswithempty*names.Membersofobjectsaretranslatedintonamedkeys.*@noteJSONdatacanbeastring,anumericvalue,oroneofliterals*"null","true"and"false".Duringparse,anyoftheaboveis*copiedverbatimintoptreedatastring.*@throwjson_parser_errorIncaseoferrordeserializingtheproperty*tree.*@paramfilenameNameoffilefromwhichtoreadinthepropertytree.*@param[out]ptThepropertytreetopopulate.*@paramlocThelocaletousewhenreadinginthefilecontents.*/template<classPtree>voidread_json(conststd::string&filename,Ptree&pt,conststd::locale&loc=std::locale()){std::basic_ifstream<typenamePtree::key_type::value_type>stream(filename.c_str());if(!stream)BOOST_PROPERTY_TREE_THROW(json_parser_error("cannot open file",filename,0));stream.imbue(loc);read_json_internal(stream,pt,filename);}/***TranslatesthepropertytreetoJSONandwritesitthegivenoutput*stream.*@noteAnypropertytreekeycontainingonlyunnamedsubkeyswillbe*renderedasJSONarrays.*@pre@eptcannotcontainkeysthathavebothsubkeysandnon-emptydata.*@throwjson_parser_errorIncaseoferrortranslatingthepropertytree*toJSONorwritingtotheoutputstream.*@paramstreamThestreamtowhichtowritetheJSONrepresentationofthe*propertytree.*@paramptThepropertytreetotranlsatetoJSONandoutput.*@paramprettyWhethertopretty-print.Defaultstotrueforbackward*compatibility.*/template<classPtree>voidwrite_json(std::basic_ostream<typenamePtree::key_type::value_type>&stream,constPtree&pt,boolpretty=true){write_json_internal(stream,pt,std::string(),pretty);}/***TranslatesthepropertytreetoJSONandwritesitthegivenfile.*@noteAnypropertytreekeycontainingonlyunnamedsubkeyswillbe*renderedasJSONarrays.*@pre@eptcannotcontainkeysthathavebothsubkeysandnon-emptydata.*@throwjson_parser_errorIncaseoferrortranslatingthepropertytree*toJSONorwritingtothefile.*@paramfilenameThenameofthefiletowhichtowritetheJSON*representationofthepropertytree.*@paramptThepropertytreetotranslatetoJSONandoutput.*@paramlocThelocaletousewhenwritingouttotheoutputfile.*@paramprettyWhethertopretty-print.Defaultstotrueandlastplace*forbackwardcompatibility.*/template<classPtree>voidwrite_json(conststd::string&filename,constPtree&pt,conststd::locale&loc=std::locale(),boolpretty=true){std::basic_ofstream<typenamePtree::key_type::value_type>stream(filename.c_str());if(!stream)BOOST_PROPERTY_TREE_THROW(json_parser_error("cannot open file",filename,0));stream.imbue(loc);write_json_internal(stream,pt,filename,pretty);}}}}namespaceboost{namespaceproperty_tree{usingjson_parser::read_json;usingjson_parser::write_json;usingjson_parser::json_parser_error;}}#endif