123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757 |
- #ifndef INCLUDE_NLOHMANN_JSON_HPP_
- #define INCLUDE_NLOHMANN_JSON_HPP_
- #define NLOHMANN_JSON_VERSION_MAJOR 3
- #define NLOHMANN_JSON_VERSION_MINOR 10
- #define NLOHMANN_JSON_VERSION_PATCH 4
- #include <algorithm> // all_of, find, for_each
- #include <cstddef> // nullptr_t, ptrdiff_t, size_t
- #include <functional> // hash, less
- #include <initializer_list> // initializer_list
- #ifndef JSON_NO_IO
- #include <iosfwd> // istream, ostream
- #endif
- #include <iterator> // random_access_iterator_tag
- #include <memory> // unique_ptr
- #include <numeric> // accumulate
- #include <string> // string, stoi, to_string
- #include <utility> // declval, forward, move, pair, swap
- #include <vector> // vector
- #include <type_traits>
- #include <utility>
- #include <algorithm> // transform
- #include <array> // array
- #include <forward_list> // forward_list
- #include <iterator> // inserter, front_inserter, end
- #include <map> // map
- #include <string> // string
- #include <tuple> // tuple, make_tuple
- #include <type_traits> // is_arithmetic, is_same, is_enum, underlying_type, is_convertible
- #include <unordered_map> // unordered_map
- #include <utility> // pair, declval
- #include <valarray> // valarray
- #include <exception> // exception
- #include <stdexcept> // runtime_error
- #include <string> // to_string
- #include <vector> // vector
- #include <array> // array
- #include <cstddef> // size_t
- #include <cstdint> // uint8_t
- #include <string> // string
- namespace nlohmann
- {
- namespace detail
- {
- enum class value_t : std::uint8_t
- {
- null,
- object,
- array,
- string,
- boolean,
- number_integer,
- number_unsigned,
- number_float,
- binary,
- discarded
- };
- inline bool operator<(const value_t lhs, const value_t rhs) noexcept
- {
- static constexpr std::array<std::uint8_t, 9> order = {{
- 0 , 3 , 4 , 5 ,
- 1 , 2 , 2 , 2 ,
- 6
- }
- };
- const auto l_index = static_cast<std::size_t>(lhs);
- const auto r_index = static_cast<std::size_t>(rhs);
- return l_index < order.size() && r_index < order.size() && order[l_index] < order[r_index];
- }
- }
- }
- #include <string>
- #include <utility> // declval, pair
- #if !defined(JSON_HEDLEY_VERSION) || (JSON_HEDLEY_VERSION < 15)
- #if defined(JSON_HEDLEY_VERSION)
- #undef JSON_HEDLEY_VERSION
- #endif
- #define JSON_HEDLEY_VERSION 15
- #if defined(JSON_HEDLEY_STRINGIFY_EX)
- #undef JSON_HEDLEY_STRINGIFY_EX
- #endif
- #define JSON_HEDLEY_STRINGIFY_EX(x) #x
- #if defined(JSON_HEDLEY_STRINGIFY)
- #undef JSON_HEDLEY_STRINGIFY
- #endif
- #define JSON_HEDLEY_STRINGIFY(x) JSON_HEDLEY_STRINGIFY_EX(x)
- #if defined(JSON_HEDLEY_CONCAT_EX)
- #undef JSON_HEDLEY_CONCAT_EX
- #endif
- #define JSON_HEDLEY_CONCAT_EX(a,b) a##b
- #if defined(JSON_HEDLEY_CONCAT)
- #undef JSON_HEDLEY_CONCAT
- #endif
- #define JSON_HEDLEY_CONCAT(a,b) JSON_HEDLEY_CONCAT_EX(a,b)
- #if defined(JSON_HEDLEY_CONCAT3_EX)
- #undef JSON_HEDLEY_CONCAT3_EX
- #endif
- #define JSON_HEDLEY_CONCAT3_EX(a,b,c) a##b##c
- #if defined(JSON_HEDLEY_CONCAT3)
- #undef JSON_HEDLEY_CONCAT3
- #endif
- #define JSON_HEDLEY_CONCAT3(a,b,c) JSON_HEDLEY_CONCAT3_EX(a,b,c)
- #if defined(JSON_HEDLEY_VERSION_ENCODE)
- #undef JSON_HEDLEY_VERSION_ENCODE
- #endif
- #define JSON_HEDLEY_VERSION_ENCODE(major,minor,revision) (((major) * 1000000) + ((minor) * 1000) + (revision))
- #if defined(JSON_HEDLEY_VERSION_DECODE_MAJOR)
- #undef JSON_HEDLEY_VERSION_DECODE_MAJOR
- #endif
- #define JSON_HEDLEY_VERSION_DECODE_MAJOR(version) ((version) / 1000000)
- #if defined(JSON_HEDLEY_VERSION_DECODE_MINOR)
- #undef JSON_HEDLEY_VERSION_DECODE_MINOR
- #endif
- #define JSON_HEDLEY_VERSION_DECODE_MINOR(version) (((version) % 1000000) / 1000)
- #if defined(JSON_HEDLEY_VERSION_DECODE_REVISION)
- #undef JSON_HEDLEY_VERSION_DECODE_REVISION
- #endif
- #define JSON_HEDLEY_VERSION_DECODE_REVISION(version) ((version) % 1000)
- #if defined(JSON_HEDLEY_GNUC_VERSION)
- #undef JSON_HEDLEY_GNUC_VERSION
- #endif
- #if defined(__GNUC__) && defined(__GNUC_PATCHLEVEL__)
- #define JSON_HEDLEY_GNUC_VERSION JSON_HEDLEY_VERSION_ENCODE(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__)
- #elif defined(__GNUC__)
- #define JSON_HEDLEY_GNUC_VERSION JSON_HEDLEY_VERSION_ENCODE(__GNUC__, __GNUC_MINOR__, 0)
- #endif
- #if defined(JSON_HEDLEY_GNUC_VERSION_CHECK)
- #undef JSON_HEDLEY_GNUC_VERSION_CHECK
- #endif
- #if defined(JSON_HEDLEY_GNUC_VERSION)
- #define JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_GNUC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
- #else
- #define JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) (0)
- #endif
- #if defined(JSON_HEDLEY_MSVC_VERSION)
- #undef JSON_HEDLEY_MSVC_VERSION
- #endif
- #if defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 140000000) && !defined(__ICL)
- #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 10000000, (_MSC_FULL_VER % 10000000) / 100000, (_MSC_FULL_VER % 100000) / 100)
- #elif defined(_MSC_FULL_VER) && !defined(__ICL)
- #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 1000000, (_MSC_FULL_VER % 1000000) / 10000, (_MSC_FULL_VER % 10000) / 10)
- #elif defined(_MSC_VER) && !defined(__ICL)
- #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_VER / 100, _MSC_VER % 100, 0)
- #endif
- #if defined(JSON_HEDLEY_MSVC_VERSION_CHECK)
- #undef JSON_HEDLEY_MSVC_VERSION_CHECK
- #endif
- #if !defined(JSON_HEDLEY_MSVC_VERSION)
- #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (0)
- #elif defined(_MSC_VER) && (_MSC_VER >= 1400)
- #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_FULL_VER >= ((major * 10000000) + (minor * 100000) + (patch)))
- #elif defined(_MSC_VER) && (_MSC_VER >= 1200)
- #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_FULL_VER >= ((major * 1000000) + (minor * 10000) + (patch)))
- #else
- #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_VER >= ((major * 100) + (minor)))
- #endif
- #if defined(JSON_HEDLEY_INTEL_VERSION)
- #undef JSON_HEDLEY_INTEL_VERSION
- #endif
- #if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE) && !defined(__ICL)
- #define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, __INTEL_COMPILER_UPDATE)
- #elif defined(__INTEL_COMPILER) && !defined(__ICL)
- #define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, 0)
- #endif
- #if defined(JSON_HEDLEY_INTEL_VERSION_CHECK)
- #undef JSON_HEDLEY_INTEL_VERSION_CHECK
- #endif
- #if defined(JSON_HEDLEY_INTEL_VERSION)
- #define JSON_HEDLEY_INTEL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_INTEL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
- #else
- #define JSON_HEDLEY_INTEL_VERSION_CHECK(major,minor,patch) (0)
- #endif
- #if defined(JSON_HEDLEY_INTEL_CL_VERSION)
- #undef JSON_HEDLEY_INTEL_CL_VERSION
- #endif
- #if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE) && defined(__ICL)
- #define JSON_HEDLEY_INTEL_CL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER, __INTEL_COMPILER_UPDATE, 0)
- #endif
- #if defined(JSON_HEDLEY_INTEL_CL_VERSION_CHECK)
- #undef JSON_HEDLEY_INTEL_CL_VERSION_CHECK
- #endif
- #if defined(JSON_HEDLEY_INTEL_CL_VERSION)
- #define JSON_HEDLEY_INTEL_CL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_INTEL_CL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
- #else
- #define JSON_HEDLEY_INTEL_CL_VERSION_CHECK(major,minor,patch) (0)
- #endif
- #if defined(JSON_HEDLEY_PGI_VERSION)
- #undef JSON_HEDLEY_PGI_VERSION
- #endif
- #if defined(__PGI) && defined(__PGIC__) && defined(__PGIC_MINOR__) && defined(__PGIC_PATCHLEVEL__)
- #define JSON_HEDLEY_PGI_VERSION JSON_HEDLEY_VERSION_ENCODE(__PGIC__, __PGIC_MINOR__, __PGIC_PATCHLEVEL__)
- #endif
- #if defined(JSON_HEDLEY_PGI_VERSION_CHECK)
- #undef JSON_HEDLEY_PGI_VERSION_CHECK
- #endif
- #if defined(JSON_HEDLEY_PGI_VERSION)
- #define JSON_HEDLEY_PGI_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_PGI_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
- #else
- #define JSON_HEDLEY_PGI_VERSION_CHECK(major,minor,patch) (0)
- #endif
- #if defined(JSON_HEDLEY_SUNPRO_VERSION)
- #undef JSON_HEDLEY_SUNPRO_VERSION
- #endif
- #if defined(__SUNPRO_C) && (__SUNPRO_C > 0x1000)
- #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((((__SUNPRO_C >> 16) & 0xf) * 10) + ((__SUNPRO_C >> 12) & 0xf), (((__SUNPRO_C >> 8) & 0xf) * 10) + ((__SUNPRO_C >> 4) & 0xf), (__SUNPRO_C & 0xf) * 10)
- #elif defined(__SUNPRO_C)
- #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((__SUNPRO_C >> 8) & 0xf, (__SUNPRO_C >> 4) & 0xf, (__SUNPRO_C) & 0xf)
- #elif defined(__SUNPRO_CC) && (__SUNPRO_CC > 0x1000)
- #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((((__SUNPRO_CC >> 16) & 0xf) * 10) + ((__SUNPRO_CC >> 12) & 0xf), (((__SUNPRO_CC >> 8) & 0xf) * 10) + ((__SUNPRO_CC >> 4) & 0xf), (__SUNPRO_CC & 0xf) * 10)
- #elif defined(__SUNPRO_CC)
- #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((__SUNPRO_CC >> 8) & 0xf, (__SUNPRO_CC >> 4) & 0xf, (__SUNPRO_CC) & 0xf)
- #endif
- #if defined(JSON_HEDLEY_SUNPRO_VERSION_CHECK)
- #undef JSON_HEDLEY_SUNPRO_VERSION_CHECK
- #endif
- #if defined(JSON_HEDLEY_SUNPRO_VERSION)
- #define JSON_HEDLEY_SUNPRO_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_SUNPRO_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
- #else
- #define JSON_HEDLEY_SUNPRO_VERSION_CHECK(major,minor,patch) (0)
- #endif
- #if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION)
- #undef JSON_HEDLEY_EMSCRIPTEN_VERSION
- #endif
- #if defined(__EMSCRIPTEN__)
- #define JSON_HEDLEY_EMSCRIPTEN_VERSION JSON_HEDLEY_VERSION_ENCODE(__EMSCRIPTEN_major__, __EMSCRIPTEN_minor__, __EMSCRIPTEN_tiny__)
- #endif
- #if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK)
- #undef JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK
- #endif
- #if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION)
- #define JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_EMSCRIPTEN_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
- #else
- #define JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK(major,minor,patch) (0)
- #endif
- #if defined(JSON_HEDLEY_ARM_VERSION)
- #undef JSON_HEDLEY_ARM_VERSION
- #endif
- #if defined(__CC_ARM) && defined(__ARMCOMPILER_VERSION)
- #define JSON_HEDLEY_ARM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ARMCOMPILER_VERSION / 1000000, (__ARMCOMPILER_VERSION % 1000000) / 10000, (__ARMCOMPILER_VERSION % 10000) / 100)
- #elif defined(__CC_ARM) && defined(__ARMCC_VERSION)
- #define JSON_HEDLEY_ARM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ARMCC_VERSION / 1000000, (__ARMCC_VERSION % 1000000) / 10000, (__ARMCC_VERSION % 10000) / 100)
- #endif
- #if defined(JSON_HEDLEY_ARM_VERSION_CHECK)
- #undef JSON_HEDLEY_ARM_VERSION_CHECK
- #endif
- #if defined(JSON_HEDLEY_ARM_VERSION)
- #define JSON_HEDLEY_ARM_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_ARM_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
- #else
- #define JSON_HEDLEY_ARM_VERSION_CHECK(major,minor,patch) (0)
- #endif
- #if defined(JSON_HEDLEY_IBM_VERSION)
- #undef JSON_HEDLEY_IBM_VERSION
- #endif
- #if defined(__ibmxl__)
- #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ibmxl_version__, __ibmxl_release__, __ibmxl_modification__)
- #elif defined(__xlC__) && defined(__xlC_ver__)
- #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__xlC__ >> 8, __xlC__ & 0xff, (__xlC_ver__ >> 8) & 0xff)
- #elif defined(__xlC__)
- #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__xlC__ >> 8, __xlC__ & 0xff, 0)
- #endif
- #if defined(JSON_HEDLEY_IBM_VERSION_CHECK)
- #undef JSON_HEDLEY_IBM_VERSION_CHECK
- #endif
- #if defined(JSON_HEDLEY_IBM_VERSION)
- #define JSON_HEDLEY_IBM_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_IBM_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
- #else
- #define JSON_HEDLEY_IBM_VERSION_CHECK(major,minor,patch) (0)
- #endif
- #if defined(JSON_HEDLEY_TI_VERSION)
- #undef JSON_HEDLEY_TI_VERSION
- #endif
- #if \
- defined(__TI_COMPILER_VERSION__) && \
- ( \
- defined(__TMS470__) || defined(__TI_ARM__) || \
- defined(__MSP430__) || \
- defined(__TMS320C2000__) \
- )
- #if (__TI_COMPILER_VERSION__ >= 16000000)
- #define JSON_HEDLEY_TI_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
- #endif
- #endif
- #if defined(JSON_HEDLEY_TI_VERSION_CHECK)
- #undef JSON_HEDLEY_TI_VERSION_CHECK
- #endif
- #if defined(JSON_HEDLEY_TI_VERSION)
- #define JSON_HEDLEY_TI_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
- #else
- #define JSON_HEDLEY_TI_VERSION_CHECK(major,minor,patch) (0)
- #endif
- #if defined(JSON_HEDLEY_TI_CL2000_VERSION)
- #undef JSON_HEDLEY_TI_CL2000_VERSION
- #endif
- #if defined(__TI_COMPILER_VERSION__) && defined(__TMS320C2000__)
- #define JSON_HEDLEY_TI_CL2000_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
- #endif
- #if defined(JSON_HEDLEY_TI_CL2000_VERSION_CHECK)
- #undef JSON_HEDLEY_TI_CL2000_VERSION_CHECK
- #endif
- #if defined(JSON_HEDLEY_TI_CL2000_VERSION)
- #define JSON_HEDLEY_TI_CL2000_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL2000_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
- #else
- #define JSON_HEDLEY_TI_CL2000_VERSION_CHECK(major,minor,patch) (0)
- #endif
- #if defined(JSON_HEDLEY_TI_CL430_VERSION)
- #undef JSON_HEDLEY_TI_CL430_VERSION
- #endif
- #if defined(__TI_COMPILER_VERSION__) && defined(__MSP430__)
- #define JSON_HEDLEY_TI_CL430_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
- #endif
- #if defined(JSON_HEDLEY_TI_CL430_VERSION_CHECK)
- #undef JSON_HEDLEY_TI_CL430_VERSION_CHECK
- #endif
- #if defined(JSON_HEDLEY_TI_CL430_VERSION)
- #define JSON_HEDLEY_TI_CL430_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL430_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
- #else
- #define JSON_HEDLEY_TI_CL430_VERSION_CHECK(major,minor,patch) (0)
- #endif
- #if defined(JSON_HEDLEY_TI_ARMCL_VERSION)
- #undef JSON_HEDLEY_TI_ARMCL_VERSION
- #endif
- #if defined(__TI_COMPILER_VERSION__) && (defined(__TMS470__) || defined(__TI_ARM__))
- #define JSON_HEDLEY_TI_ARMCL_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
- #endif
- #if defined(JSON_HEDLEY_TI_ARMCL_VERSION_CHECK)
- #undef JSON_HEDLEY_TI_ARMCL_VERSION_CHECK
- #endif
- #if defined(JSON_HEDLEY_TI_ARMCL_VERSION)
- #define JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_ARMCL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
- #else
- #define JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(major,minor,patch) (0)
- #endif
- #if defined(JSON_HEDLEY_TI_CL6X_VERSION)
- #undef JSON_HEDLEY_TI_CL6X_VERSION
- #endif
- #if defined(__TI_COMPILER_VERSION__) && defined(__TMS320C6X__)
- #define JSON_HEDLEY_TI_CL6X_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
- #endif
- #if defined(JSON_HEDLEY_TI_CL6X_VERSION_CHECK)
- #undef JSON_HEDLEY_TI_CL6X_VERSION_CHECK
- #endif
- #if defined(JSON_HEDLEY_TI_CL6X_VERSION)
- #define JSON_HEDLEY_TI_CL6X_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL6X_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
- #else
- #define JSON_HEDLEY_TI_CL6X_VERSION_CHECK(major,minor,patch) (0)
- #endif
- #if defined(JSON_HEDLEY_TI_CL7X_VERSION)
- #undef JSON_HEDLEY_TI_CL7X_VERSION
- #endif
- #if defined(__TI_COMPILER_VERSION__) && defined(__C7000__)
- #define JSON_HEDLEY_TI_CL7X_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
- #endif
- #if defined(JSON_HEDLEY_TI_CL7X_VERSION_CHECK)
- #undef JSON_HEDLEY_TI_CL7X_VERSION_CHECK
- #endif
- #if defined(JSON_HEDLEY_TI_CL7X_VERSION)
- #define JSON_HEDLEY_TI_CL7X_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL7X_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
- #else
- #define JSON_HEDLEY_TI_CL7X_VERSION_CHECK(major,minor,patch) (0)
- #endif
- #if defined(JSON_HEDLEY_TI_CLPRU_VERSION)
- #undef JSON_HEDLEY_TI_CLPRU_VERSION
- #endif
- #if defined(__TI_COMPILER_VERSION__) && defined(__PRU__)
- #define JSON_HEDLEY_TI_CLPRU_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
- #endif
- #if defined(JSON_HEDLEY_TI_CLPRU_VERSION_CHECK)
- #undef JSON_HEDLEY_TI_CLPRU_VERSION_CHECK
- #endif
- #if defined(JSON_HEDLEY_TI_CLPRU_VERSION)
- #define JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CLPRU_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
- #else
- #define JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(major,minor,patch) (0)
- #endif
- #if defined(JSON_HEDLEY_CRAY_VERSION)
- #undef JSON_HEDLEY_CRAY_VERSION
- #endif
- #if defined(_CRAYC)
- #if defined(_RELEASE_PATCHLEVEL)
- #define JSON_HEDLEY_CRAY_VERSION JSON_HEDLEY_VERSION_ENCODE(_RELEASE_MAJOR, _RELEASE_MINOR, _RELEASE_PATCHLEVEL)
- #else
- #define JSON_HEDLEY_CRAY_VERSION JSON_HEDLEY_VERSION_ENCODE(_RELEASE_MAJOR, _RELEASE_MINOR, 0)
- #endif
- #endif
- #if defined(JSON_HEDLEY_CRAY_VERSION_CHECK)
- #undef JSON_HEDLEY_CRAY_VERSION_CHECK
- #endif
- #if defined(JSON_HEDLEY_CRAY_VERSION)
- #define JSON_HEDLEY_CRAY_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_CRAY_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
- #else
- #define JSON_HEDLEY_CRAY_VERSION_CHECK(major,minor,patch) (0)
- #endif
- #if defined(JSON_HEDLEY_IAR_VERSION)
- #undef JSON_HEDLEY_IAR_VERSION
- #endif
- #if defined(__IAR_SYSTEMS_ICC__)
- #if __VER__ > 1000
- #define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE((__VER__ / 1000000), ((__VER__ / 1000) % 1000), (__VER__ % 1000))
- #else
- #define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE(__VER__ / 100, __VER__ % 100, 0)
- #endif
- #endif
- #if defined(JSON_HEDLEY_IAR_VERSION_CHECK)
- #undef JSON_HEDLEY_IAR_VERSION_CHECK
- #endif
- #if defined(JSON_HEDLEY_IAR_VERSION)
- #define JSON_HEDLEY_IAR_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_IAR_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
- #else
- #define JSON_HEDLEY_IAR_VERSION_CHECK(major,minor,patch) (0)
- #endif
- #if defined(JSON_HEDLEY_TINYC_VERSION)
- #undef JSON_HEDLEY_TINYC_VERSION
- #endif
- #if defined(__TINYC__)
- #define JSON_HEDLEY_TINYC_VERSION JSON_HEDLEY_VERSION_ENCODE(__TINYC__ / 1000, (__TINYC__ / 100) % 10, __TINYC__ % 100)
- #endif
- #if defined(JSON_HEDLEY_TINYC_VERSION_CHECK)
- #undef JSON_HEDLEY_TINYC_VERSION_CHECK
- #endif
- #if defined(JSON_HEDLEY_TINYC_VERSION)
- #define JSON_HEDLEY_TINYC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TINYC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
- #else
- #define JSON_HEDLEY_TINYC_VERSION_CHECK(major,minor,patch) (0)
- #endif
- #if defined(JSON_HEDLEY_DMC_VERSION)
- #undef JSON_HEDLEY_DMC_VERSION
- #endif
- #if defined(__DMC__)
- #define JSON_HEDLEY_DMC_VERSION JSON_HEDLEY_VERSION_ENCODE(__DMC__ >> 8, (__DMC__ >> 4) & 0xf, __DMC__ & 0xf)
- #endif
- #if defined(JSON_HEDLEY_DMC_VERSION_CHECK)
- #undef JSON_HEDLEY_DMC_VERSION_CHECK
- #endif
- #if defined(JSON_HEDLEY_DMC_VERSION)
- #define JSON_HEDLEY_DMC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_DMC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
- #else
- #define JSON_HEDLEY_DMC_VERSION_CHECK(major,minor,patch) (0)
- #endif
- #if defined(JSON_HEDLEY_COMPCERT_VERSION)
- #undef JSON_HEDLEY_COMPCERT_VERSION
- #endif
- #if defined(__COMPCERT_VERSION__)
- #define JSON_HEDLEY_COMPCERT_VERSION JSON_HEDLEY_VERSION_ENCODE(__COMPCERT_VERSION__ / 10000, (__COMPCERT_VERSION__ / 100) % 100, __COMPCERT_VERSION__ % 100)
- #endif
- #if defined(JSON_HEDLEY_COMPCERT_VERSION_CHECK)
- #undef JSON_HEDLEY_COMPCERT_VERSION_CHECK
- #endif
- #if defined(JSON_HEDLEY_COMPCERT_VERSION)
- #define JSON_HEDLEY_COMPCERT_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_COMPCERT_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
- #else
- #define JSON_HEDLEY_COMPCERT_VERSION_CHECK(major,minor,patch) (0)
- #endif
- #if defined(JSON_HEDLEY_PELLES_VERSION)
- #undef JSON_HEDLEY_PELLES_VERSION
- #endif
- #if defined(__POCC__)
- #define JSON_HEDLEY_PELLES_VERSION JSON_HEDLEY_VERSION_ENCODE(__POCC__ / 100, __POCC__ % 100, 0)
- #endif
- #if defined(JSON_HEDLEY_PELLES_VERSION_CHECK)
- #undef JSON_HEDLEY_PELLES_VERSION_CHECK
- #endif
- #if defined(JSON_HEDLEY_PELLES_VERSION)
- #define JSON_HEDLEY_PELLES_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_PELLES_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
- #else
- #define JSON_HEDLEY_PELLES_VERSION_CHECK(major,minor,patch) (0)
- #endif
- #if defined(JSON_HEDLEY_MCST_LCC_VERSION)
- #undef JSON_HEDLEY_MCST_LCC_VERSION
- #endif
- #if defined(__LCC__) && defined(__LCC_MINOR__)
- #define JSON_HEDLEY_MCST_LCC_VERSION JSON_HEDLEY_VERSION_ENCODE(__LCC__ / 100, __LCC__ % 100, __LCC_MINOR__)
- #endif
- #if defined(JSON_HEDLEY_MCST_LCC_VERSION_CHECK)
- #undef JSON_HEDLEY_MCST_LCC_VERSION_CHECK
- #endif
- #if defined(JSON_HEDLEY_MCST_LCC_VERSION)
- #define JSON_HEDLEY_MCST_LCC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_MCST_LCC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
- #else
- #define JSON_HEDLEY_MCST_LCC_VERSION_CHECK(major,minor,patch) (0)
- #endif
- #if defined(JSON_HEDLEY_GCC_VERSION)
- #undef JSON_HEDLEY_GCC_VERSION
- #endif
- #if \
- defined(JSON_HEDLEY_GNUC_VERSION) && \
- !defined(__clang__) && \
- !defined(JSON_HEDLEY_INTEL_VERSION) && \
- !defined(JSON_HEDLEY_PGI_VERSION) && \
- !defined(JSON_HEDLEY_ARM_VERSION) && \
- !defined(JSON_HEDLEY_CRAY_VERSION) && \
- !defined(JSON_HEDLEY_TI_VERSION) && \
- !defined(JSON_HEDLEY_TI_ARMCL_VERSION) && \
- !defined(JSON_HEDLEY_TI_CL430_VERSION) && \
- !defined(JSON_HEDLEY_TI_CL2000_VERSION) && \
- !defined(JSON_HEDLEY_TI_CL6X_VERSION) && \
- !defined(JSON_HEDLEY_TI_CL7X_VERSION) && \
- !defined(JSON_HEDLEY_TI_CLPRU_VERSION) && \
- !defined(__COMPCERT__) && \
- !defined(JSON_HEDLEY_MCST_LCC_VERSION)
- #define JSON_HEDLEY_GCC_VERSION JSON_HEDLEY_GNUC_VERSION
- #endif
- #if defined(JSON_HEDLEY_GCC_VERSION_CHECK)
- #undef JSON_HEDLEY_GCC_VERSION_CHECK
- #endif
- #if defined(JSON_HEDLEY_GCC_VERSION)
- #define JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_GCC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
- #else
- #define JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) (0)
- #endif
- #if defined(JSON_HEDLEY_HAS_ATTRIBUTE)
- #undef JSON_HEDLEY_HAS_ATTRIBUTE
- #endif
- #if \
- defined(__has_attribute) && \
- ( \
- (!defined(JSON_HEDLEY_IAR_VERSION) || JSON_HEDLEY_IAR_VERSION_CHECK(8,5,9)) \
- )
- # define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) __has_attribute(attribute)
- #else
- # define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) (0)
- #endif
- #if defined(JSON_HEDLEY_GNUC_HAS_ATTRIBUTE)
- #undef JSON_HEDLEY_GNUC_HAS_ATTRIBUTE
- #endif
- #if defined(__has_attribute)
- #define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_HAS_ATTRIBUTE(attribute)
- #else
- #define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
- #endif
- #if defined(JSON_HEDLEY_GCC_HAS_ATTRIBUTE)
- #undef JSON_HEDLEY_GCC_HAS_ATTRIBUTE
- #endif
- #if defined(__has_attribute)
- #define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_HAS_ATTRIBUTE(attribute)
- #else
- #define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
- #endif
- #if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE)
- #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE
- #endif
- #if \
- defined(__has_cpp_attribute) && \
- defined(__cplusplus) && \
- (!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0))
- #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) __has_cpp_attribute(attribute)
- #else
- #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) (0)
- #endif
- #if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS)
- #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS
- #endif
- #if !defined(__cplusplus) || !defined(__has_cpp_attribute)
- #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) (0)
- #elif \
- !defined(JSON_HEDLEY_PGI_VERSION) && \
- !defined(JSON_HEDLEY_IAR_VERSION) && \
- (!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0)) && \
- (!defined(JSON_HEDLEY_MSVC_VERSION) || JSON_HEDLEY_MSVC_VERSION_CHECK(19,20,0))
- #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) JSON_HEDLEY_HAS_CPP_ATTRIBUTE(ns::attribute)
- #else
- #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) (0)
- #endif
- #if defined(JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE)
- #undef JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE
- #endif
- #if defined(__has_cpp_attribute) && defined(__cplusplus)
- #define JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) __has_cpp_attribute(attribute)
- #else
- #define JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
- #endif
- #if defined(JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE)
- #undef JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE
- #endif
- #if defined(__has_cpp_attribute) && defined(__cplusplus)
- #define JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) __has_cpp_attribute(attribute)
- #else
- #define JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
- #endif
- #if defined(JSON_HEDLEY_HAS_BUILTIN)
- #undef JSON_HEDLEY_HAS_BUILTIN
- #endif
- #if defined(__has_builtin)
- #define JSON_HEDLEY_HAS_BUILTIN(builtin) __has_builtin(builtin)
- #else
- #define JSON_HEDLEY_HAS_BUILTIN(builtin) (0)
- #endif
- #if defined(JSON_HEDLEY_GNUC_HAS_BUILTIN)
- #undef JSON_HEDLEY_GNUC_HAS_BUILTIN
- #endif
- #if defined(__has_builtin)
- #define JSON_HEDLEY_GNUC_HAS_BUILTIN(builtin,major,minor,patch) __has_builtin(builtin)
- #else
- #define JSON_HEDLEY_GNUC_HAS_BUILTIN(builtin,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
- #endif
- #if defined(JSON_HEDLEY_GCC_HAS_BUILTIN)
- #undef JSON_HEDLEY_GCC_HAS_BUILTIN
- #endif
- #if defined(__has_builtin)
- #define JSON_HEDLEY_GCC_HAS_BUILTIN(builtin,major,minor,patch) __has_builtin(builtin)
- #else
- #define JSON_HEDLEY_GCC_HAS_BUILTIN(builtin,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
- #endif
- #if defined(JSON_HEDLEY_HAS_FEATURE)
- #undef JSON_HEDLEY_HAS_FEATURE
- #endif
- #if defined(__has_feature)
- #define JSON_HEDLEY_HAS_FEATURE(feature) __has_feature(feature)
- #else
- #define JSON_HEDLEY_HAS_FEATURE(feature) (0)
- #endif
- #if defined(JSON_HEDLEY_GNUC_HAS_FEATURE)
- #undef JSON_HEDLEY_GNUC_HAS_FEATURE
- #endif
- #if defined(__has_feature)
- #define JSON_HEDLEY_GNUC_HAS_FEATURE(feature,major,minor,patch) __has_feature(feature)
- #else
- #define JSON_HEDLEY_GNUC_HAS_FEATURE(feature,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
- #endif
- #if defined(JSON_HEDLEY_GCC_HAS_FEATURE)
- #undef JSON_HEDLEY_GCC_HAS_FEATURE
- #endif
- #if defined(__has_feature)
- #define JSON_HEDLEY_GCC_HAS_FEATURE(feature,major,minor,patch) __has_feature(feature)
- #else
- #define JSON_HEDLEY_GCC_HAS_FEATURE(feature,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
- #endif
- #if defined(JSON_HEDLEY_HAS_EXTENSION)
- #undef JSON_HEDLEY_HAS_EXTENSION
- #endif
- #if defined(__has_extension)
- #define JSON_HEDLEY_HAS_EXTENSION(extension) __has_extension(extension)
- #else
- #define JSON_HEDLEY_HAS_EXTENSION(extension) (0)
- #endif
- #if defined(JSON_HEDLEY_GNUC_HAS_EXTENSION)
- #undef JSON_HEDLEY_GNUC_HAS_EXTENSION
- #endif
- #if defined(__has_extension)
- #define JSON_HEDLEY_GNUC_HAS_EXTENSION(extension,major,minor,patch) __has_extension(extension)
- #else
- #define JSON_HEDLEY_GNUC_HAS_EXTENSION(extension,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
- #endif
- #if defined(JSON_HEDLEY_GCC_HAS_EXTENSION)
- #undef JSON_HEDLEY_GCC_HAS_EXTENSION
- #endif
- #if defined(__has_extension)
- #define JSON_HEDLEY_GCC_HAS_EXTENSION(extension,major,minor,patch) __has_extension(extension)
- #else
- #define JSON_HEDLEY_GCC_HAS_EXTENSION(extension,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
- #endif
- #if defined(JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE)
- #undef JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE
- #endif
- #if defined(__has_declspec_attribute)
- #define JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) __has_declspec_attribute(attribute)
- #else
- #define JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) (0)
- #endif
- #if defined(JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE)
- #undef JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE
- #endif
- #if defined(__has_declspec_attribute)
- #define JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) __has_declspec_attribute(attribute)
- #else
- #define JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
- #endif
- #if defined(JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE)
- #undef JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE
- #endif
- #if defined(__has_declspec_attribute)
- #define JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) __has_declspec_attribute(attribute)
- #else
- #define JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
- #endif
- #if defined(JSON_HEDLEY_HAS_WARNING)
- #undef JSON_HEDLEY_HAS_WARNING
- #endif
- #if defined(__has_warning)
- #define JSON_HEDLEY_HAS_WARNING(warning) __has_warning(warning)
- #else
- #define JSON_HEDLEY_HAS_WARNING(warning) (0)
- #endif
- #if defined(JSON_HEDLEY_GNUC_HAS_WARNING)
- #undef JSON_HEDLEY_GNUC_HAS_WARNING
- #endif
- #if defined(__has_warning)
- #define JSON_HEDLEY_GNUC_HAS_WARNING(warning,major,minor,patch) __has_warning(warning)
- #else
- #define JSON_HEDLEY_GNUC_HAS_WARNING(warning,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
- #endif
- #if defined(JSON_HEDLEY_GCC_HAS_WARNING)
- #undef JSON_HEDLEY_GCC_HAS_WARNING
- #endif
- #if defined(__has_warning)
- #define JSON_HEDLEY_GCC_HAS_WARNING(warning,major,minor,patch) __has_warning(warning)
- #else
- #define JSON_HEDLEY_GCC_HAS_WARNING(warning,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
- #endif
- #if \
- (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \
- defined(__clang__) || \
- JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) || \
- JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
- JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) || \
- JSON_HEDLEY_PGI_VERSION_CHECK(18,4,0) || \
- JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
- JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
- JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,7,0) || \
- JSON_HEDLEY_TI_CL430_VERSION_CHECK(2,0,1) || \
- JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,1,0) || \
- JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,0,0) || \
- JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
- JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
- JSON_HEDLEY_CRAY_VERSION_CHECK(5,0,0) || \
- JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,17) || \
- JSON_HEDLEY_SUNPRO_VERSION_CHECK(8,0,0) || \
- (JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) && defined(__C99_PRAGMA_OPERATOR))
- #define JSON_HEDLEY_PRAGMA(value) _Pragma(#value)
- #elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
- #define JSON_HEDLEY_PRAGMA(value) __pragma(value)
- #else
- #define JSON_HEDLEY_PRAGMA(value)
- #endif
- #if defined(JSON_HEDLEY_DIAGNOSTIC_PUSH)
- #undef JSON_HEDLEY_DIAGNOSTIC_PUSH
- #endif
- #if defined(JSON_HEDLEY_DIAGNOSTIC_POP)
- #undef JSON_HEDLEY_DIAGNOSTIC_POP
- #endif
- #if defined(__clang__)
- #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push")
- #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("clang diagnostic pop")
- #elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
- #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)")
- #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)")
- #elif JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0)
- #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
- #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
- #elif \
- JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) || \
- JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
- #define JSON_HEDLEY_DIAGNOSTIC_PUSH __pragma(warning(push))
- #define JSON_HEDLEY_DIAGNOSTIC_POP __pragma(warning(pop))
- #elif JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0)
- #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("push")
- #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("pop")
- #elif \
- JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
- JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
- JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,4,0) || \
- JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,1,0) || \
- JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
- JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0)
- #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("diag_push")
- #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("diag_pop")
- #elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,90,0)
- #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)")
- #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)")
- #else
- #define JSON_HEDLEY_DIAGNOSTIC_PUSH
- #define JSON_HEDLEY_DIAGNOSTIC_POP
- #endif
- #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_)
- #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_
- #endif
- #if defined(__cplusplus)
- # if JSON_HEDLEY_HAS_WARNING("-Wc++98-compat")
- # if JSON_HEDLEY_HAS_WARNING("-Wc++17-extensions")
- # if JSON_HEDLEY_HAS_WARNING("-Wc++1z-extensions")
- # define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \
- JSON_HEDLEY_DIAGNOSTIC_PUSH \
- _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \
- _Pragma("clang diagnostic ignored \"-Wc++17-extensions\"") \
- _Pragma("clang diagnostic ignored \"-Wc++1z-extensions\"") \
- xpr \
- JSON_HEDLEY_DIAGNOSTIC_POP
- # else
- # define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \
- JSON_HEDLEY_DIAGNOSTIC_PUSH \
- _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \
- _Pragma("clang diagnostic ignored \"-Wc++17-extensions\"") \
- xpr \
- JSON_HEDLEY_DIAGNOSTIC_POP
- # endif
- # else
- # define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \
- JSON_HEDLEY_DIAGNOSTIC_PUSH \
- _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \
- xpr \
- JSON_HEDLEY_DIAGNOSTIC_POP
- # endif
- # endif
- #endif
- #if !defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_)
- #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(x) x
- #endif
- #if defined(JSON_HEDLEY_CONST_CAST)
- #undef JSON_HEDLEY_CONST_CAST
- #endif
- #if defined(__cplusplus)
- # define JSON_HEDLEY_CONST_CAST(T, expr) (const_cast<T>(expr))
- #elif \
- JSON_HEDLEY_HAS_WARNING("-Wcast-qual") || \
- JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0) || \
- JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
- # define JSON_HEDLEY_CONST_CAST(T, expr) (__extension__ ({ \
- JSON_HEDLEY_DIAGNOSTIC_PUSH \
- JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL \
- ((T) (expr)); \
- JSON_HEDLEY_DIAGNOSTIC_POP \
- }))
- #else
- # define JSON_HEDLEY_CONST_CAST(T, expr) ((T) (expr))
- #endif
- #if defined(JSON_HEDLEY_REINTERPRET_CAST)
- #undef JSON_HEDLEY_REINTERPRET_CAST
- #endif
- #if defined(__cplusplus)
- #define JSON_HEDLEY_REINTERPRET_CAST(T, expr) (reinterpret_cast<T>(expr))
- #else
- #define JSON_HEDLEY_REINTERPRET_CAST(T, expr) ((T) (expr))
- #endif
- #if defined(JSON_HEDLEY_STATIC_CAST)
- #undef JSON_HEDLEY_STATIC_CAST
- #endif
- #if defined(__cplusplus)
- #define JSON_HEDLEY_STATIC_CAST(T, expr) (static_cast<T>(expr))
- #else
- #define JSON_HEDLEY_STATIC_CAST(T, expr) ((T) (expr))
- #endif
- #if defined(JSON_HEDLEY_CPP_CAST)
- #undef JSON_HEDLEY_CPP_CAST
- #endif
- #if defined(__cplusplus)
- # if JSON_HEDLEY_HAS_WARNING("-Wold-style-cast")
- # define JSON_HEDLEY_CPP_CAST(T, expr) \
- JSON_HEDLEY_DIAGNOSTIC_PUSH \
- _Pragma("clang diagnostic ignored \"-Wold-style-cast\"") \
- ((T) (expr)) \
- JSON_HEDLEY_DIAGNOSTIC_POP
- # elif JSON_HEDLEY_IAR_VERSION_CHECK(8,3,0)
- # define JSON_HEDLEY_CPP_CAST(T, expr) \
- JSON_HEDLEY_DIAGNOSTIC_PUSH \
- _Pragma("diag_suppress=Pe137") \
- JSON_HEDLEY_DIAGNOSTIC_POP
- # else
- # define JSON_HEDLEY_CPP_CAST(T, expr) ((T) (expr))
- # endif
- #else
- # define JSON_HEDLEY_CPP_CAST(T, expr) (expr)
- #endif
- #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED)
- #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED
- #endif
- #if JSON_HEDLEY_HAS_WARNING("-Wdeprecated-declarations")
- #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")
- #elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
- #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("warning(disable:1478 1786)")
- #elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
- #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED __pragma(warning(disable:1478 1786))
- #elif JSON_HEDLEY_PGI_VERSION_CHECK(20,7,0)
- #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1216,1444,1445")
- #elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
- #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1444")
- #elif JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0)
- #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
- #elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
- #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED __pragma(warning(disable:4996))
- #elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
- #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1444")
- #elif \
- JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
- (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
- JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
- (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
- JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
- (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
- JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
- (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
- JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
- JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
- JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0)
- #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1291,1718")
- #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) && !defined(__cplusplus)
- #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("error_messages(off,E_DEPRECATED_ATT,E_DEPRECATED_ATT_MESS)")
- #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) && defined(__cplusplus)
- #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("error_messages(off,symdeprecated,symdeprecated2)")
- #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
- #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress=Pe1444,Pe1215")
- #elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,90,0)
- #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("warn(disable:2241)")
- #else
- #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED
- #endif
- #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS)
- #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS
- #endif
- #if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas")
- #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("clang diagnostic ignored \"-Wunknown-pragmas\"")
- #elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
- #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("warning(disable:161)")
- #elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
- #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS __pragma(warning(disable:161))
- #elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
- #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 1675")
- #elif JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0)
- #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("GCC diagnostic ignored \"-Wunknown-pragmas\"")
- #elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
- #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS __pragma(warning(disable:4068))
- #elif \
- JSON_HEDLEY_TI_VERSION_CHECK(16,9,0) || \
- JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0) || \
- JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
- JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,3,0)
- #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 163")
- #elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0)
- #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 163")
- #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
- #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress=Pe161")
- #elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
- #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 161")
- #else
- #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS
- #endif
- #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES)
- #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES
- #endif
- #if JSON_HEDLEY_HAS_WARNING("-Wunknown-attributes")
- #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("clang diagnostic ignored \"-Wunknown-attributes\"")
- #elif JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0)
- #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
- #elif JSON_HEDLEY_INTEL_VERSION_CHECK(17,0,0)
- #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("warning(disable:1292)")
- #elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
- #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES __pragma(warning(disable:1292))
- #elif JSON_HEDLEY_MSVC_VERSION_CHECK(19,0,0)
- #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES __pragma(warning(disable:5030))
- #elif JSON_HEDLEY_PGI_VERSION_CHECK(20,7,0)
- #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097,1098")
- #elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
- #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097")
- #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,14,0) && defined(__cplusplus)
- #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("error_messages(off,attrskipunsup)")
- #elif \
- JSON_HEDLEY_TI_VERSION_CHECK(18,1,0) || \
- JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,3,0) || \
- JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0)
- #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1173")
- #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
- #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress=Pe1097")
- #elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
- #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097")
- #else
- #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES
- #endif
- #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL)
- #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL
- #endif
- #if JSON_HEDLEY_HAS_WARNING("-Wcast-qual")
- #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("clang diagnostic ignored \"-Wcast-qual\"")
- #elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
- #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("warning(disable:2203 2331)")
- #elif JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0)
- #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("GCC diagnostic ignored \"-Wcast-qual\"")
- #else
- #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL
- #endif
- #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION)
- #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION
- #endif
- #if JSON_HEDLEY_HAS_WARNING("-Wunused-function")
- #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("clang diagnostic ignored \"-Wunused-function\"")
- #elif JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0)
- #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("GCC diagnostic ignored \"-Wunused-function\"")
- #elif JSON_HEDLEY_MSVC_VERSION_CHECK(1,0,0)
- #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION __pragma(warning(disable:4505))
- #elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
- #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("diag_suppress 3142")
- #else
- #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION
- #endif
- #if defined(JSON_HEDLEY_DEPRECATED)
- #undef JSON_HEDLEY_DEPRECATED
- #endif
- #if defined(JSON_HEDLEY_DEPRECATED_FOR)
- #undef JSON_HEDLEY_DEPRECATED_FOR
- #endif
- #if \
- JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \
- JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
- #define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated("Since " # since))
- #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated("Since " #since "; use " #replacement))
- #elif \
- (JSON_HEDLEY_HAS_EXTENSION(attribute_deprecated_with_message) && !defined(JSON_HEDLEY_IAR_VERSION)) || \
- JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) || \
- JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
- JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) || \
- JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) || \
- JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
- JSON_HEDLEY_TI_VERSION_CHECK(18,1,0) || \
- JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(18,1,0) || \
- JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,3,0) || \
- JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
- JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,3,0) || \
- JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
- #define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__("Since " #since)))
- #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__("Since " #since "; use " #replacement)))
- #elif defined(__cplusplus) && (__cplusplus >= 201402L)
- #define JSON_HEDLEY_DEPRECATED(since) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since)]])
- #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since "; use " #replacement)]])
- #elif \
- JSON_HEDLEY_HAS_ATTRIBUTE(deprecated) || \
- JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
- JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
- JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
- (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
- JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
- (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
- JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
- (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
- JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
- (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
- JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
- JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
- JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
- JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \
- JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0)
- #define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__))
- #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__))
- #elif \
- JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
- JSON_HEDLEY_PELLES_VERSION_CHECK(6,50,0) || \
- JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
- #define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated)
- #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated)
- #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
- #define JSON_HEDLEY_DEPRECATED(since) _Pragma("deprecated")
- #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) _Pragma("deprecated")
- #else
- #define JSON_HEDLEY_DEPRECATED(since)
- #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement)
- #endif
- #if defined(JSON_HEDLEY_UNAVAILABLE)
- #undef JSON_HEDLEY_UNAVAILABLE
- #endif
- #if \
- JSON_HEDLEY_HAS_ATTRIBUTE(warning) || \
- JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0) || \
- JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
- JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
- #define JSON_HEDLEY_UNAVAILABLE(available_since) __attribute__((__warning__("Not available until " #available_since)))
- #else
- #define JSON_HEDLEY_UNAVAILABLE(available_since)
- #endif
- #if defined(JSON_HEDLEY_WARN_UNUSED_RESULT)
- #undef JSON_HEDLEY_WARN_UNUSED_RESULT
- #endif
- #if defined(JSON_HEDLEY_WARN_UNUSED_RESULT_MSG)
- #undef JSON_HEDLEY_WARN_UNUSED_RESULT_MSG
- #endif
- #if \
- JSON_HEDLEY_HAS_ATTRIBUTE(warn_unused_result) || \
- JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \
- JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
- JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
- (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
- JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
- (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
- JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
- (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
- JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
- (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
- JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
- JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
- JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
- (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0) && defined(__cplusplus)) || \
- JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
- JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
- #define JSON_HEDLEY_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__))
- #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) __attribute__((__warn_unused_result__))
- #elif (JSON_HEDLEY_HAS_CPP_ATTRIBUTE(nodiscard) >= 201907L)
- #define JSON_HEDLEY_WARN_UNUSED_RESULT JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]])
- #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard(msg)]])
- #elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE(nodiscard)
- #define JSON_HEDLEY_WARN_UNUSED_RESULT JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]])
- #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]])
- #elif defined(_Check_return_)
- #define JSON_HEDLEY_WARN_UNUSED_RESULT _Check_return_
- #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) _Check_return_
- #else
- #define JSON_HEDLEY_WARN_UNUSED_RESULT
- #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg)
- #endif
- #if defined(JSON_HEDLEY_SENTINEL)
- #undef JSON_HEDLEY_SENTINEL
- #endif
- #if \
- JSON_HEDLEY_HAS_ATTRIBUTE(sentinel) || \
- JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \
- JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
- JSON_HEDLEY_ARM_VERSION_CHECK(5,4,0) || \
- JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
- #define JSON_HEDLEY_SENTINEL(position) __attribute__((__sentinel__(position)))
- #else
- #define JSON_HEDLEY_SENTINEL(position)
- #endif
- #if defined(JSON_HEDLEY_NO_RETURN)
- #undef JSON_HEDLEY_NO_RETURN
- #endif
- #if JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
- #define JSON_HEDLEY_NO_RETURN __noreturn
- #elif \
- JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
- JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
- #define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__))
- #elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
- #define JSON_HEDLEY_NO_RETURN _Noreturn
- #elif defined(__cplusplus) && (__cplusplus >= 201103L)
- #define JSON_HEDLEY_NO_RETURN JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[noreturn]])
- #elif \
- JSON_HEDLEY_HAS_ATTRIBUTE(noreturn) || \
- JSON_HEDLEY_GCC_VERSION_CHECK(3,2,0) || \
- JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
- JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
- JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
- JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
- (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
- JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
- (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
- JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
- (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
- JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
- (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
- JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
- JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
- JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
- JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0)
- #define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__))
- #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
- #define JSON_HEDLEY_NO_RETURN _Pragma("does_not_return")
- #elif \
- JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
- JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
- #define JSON_HEDLEY_NO_RETURN __declspec(noreturn)
- #elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,0,0) && defined(__cplusplus)
- #define JSON_HEDLEY_NO_RETURN _Pragma("FUNC_NEVER_RETURNS;")
- #elif JSON_HEDLEY_COMPCERT_VERSION_CHECK(3,2,0)
- #define JSON_HEDLEY_NO_RETURN __attribute((noreturn))
- #elif JSON_HEDLEY_PELLES_VERSION_CHECK(9,0,0)
- #define JSON_HEDLEY_NO_RETURN __declspec(noreturn)
- #else
- #define JSON_HEDLEY_NO_RETURN
- #endif
- #if defined(JSON_HEDLEY_NO_ESCAPE)
- #undef JSON_HEDLEY_NO_ESCAPE
- #endif
- #if JSON_HEDLEY_HAS_ATTRIBUTE(noescape)
- #define JSON_HEDLEY_NO_ESCAPE __attribute__((__noescape__))
- #else
- #define JSON_HEDLEY_NO_ESCAPE
- #endif
- #if defined(JSON_HEDLEY_UNREACHABLE)
- #undef JSON_HEDLEY_UNREACHABLE
- #endif
- #if defined(JSON_HEDLEY_UNREACHABLE_RETURN)
- #undef JSON_HEDLEY_UNREACHABLE_RETURN
- #endif
- #if defined(JSON_HEDLEY_ASSUME)
- #undef JSON_HEDLEY_ASSUME
- #endif
- #if \
- JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
- JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
- JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
- #define JSON_HEDLEY_ASSUME(expr) __assume(expr)
- #elif JSON_HEDLEY_HAS_BUILTIN(__builtin_assume)
- #define JSON_HEDLEY_ASSUME(expr) __builtin_assume(expr)
- #elif \
- JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \
- JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0)
- #if defined(__cplusplus)
- #define JSON_HEDLEY_ASSUME(expr) std::_nassert(expr)
- #else
- #define JSON_HEDLEY_ASSUME(expr) _nassert(expr)
- #endif
- #endif
- #if \
- (JSON_HEDLEY_HAS_BUILTIN(__builtin_unreachable) && (!defined(JSON_HEDLEY_ARM_VERSION))) || \
- JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) || \
- JSON_HEDLEY_PGI_VERSION_CHECK(18,10,0) || \
- JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
- JSON_HEDLEY_IBM_VERSION_CHECK(13,1,5) || \
- JSON_HEDLEY_CRAY_VERSION_CHECK(10,0,0) || \
- JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
- #define JSON_HEDLEY_UNREACHABLE() __builtin_unreachable()
- #elif defined(JSON_HEDLEY_ASSUME)
- #define JSON_HEDLEY_UNREACHABLE() JSON_HEDLEY_ASSUME(0)
- #endif
- #if !defined(JSON_HEDLEY_ASSUME)
- #if defined(JSON_HEDLEY_UNREACHABLE)
- #define JSON_HEDLEY_ASSUME(expr) JSON_HEDLEY_STATIC_CAST(void, ((expr) ? 1 : (JSON_HEDLEY_UNREACHABLE(), 1)))
- #else
- #define JSON_HEDLEY_ASSUME(expr) JSON_HEDLEY_STATIC_CAST(void, expr)
- #endif
- #endif
- #if defined(JSON_HEDLEY_UNREACHABLE)
- #if \
- JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \
- JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0)
- #define JSON_HEDLEY_UNREACHABLE_RETURN(value) return (JSON_HEDLEY_STATIC_CAST(void, JSON_HEDLEY_ASSUME(0)), (value))
- #else
- #define JSON_HEDLEY_UNREACHABLE_RETURN(value) JSON_HEDLEY_UNREACHABLE()
- #endif
- #else
- #define JSON_HEDLEY_UNREACHABLE_RETURN(value) return (value)
- #endif
- #if !defined(JSON_HEDLEY_UNREACHABLE)
- #define JSON_HEDLEY_UNREACHABLE() JSON_HEDLEY_ASSUME(0)
- #endif
- JSON_HEDLEY_DIAGNOSTIC_PUSH
- #if JSON_HEDLEY_HAS_WARNING("-Wpedantic")
- #pragma clang diagnostic ignored "-Wpedantic"
- #endif
- #if JSON_HEDLEY_HAS_WARNING("-Wc++98-compat-pedantic") && defined(__cplusplus)
- #pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
- #endif
- #if JSON_HEDLEY_GCC_HAS_WARNING("-Wvariadic-macros",4,0,0)
- #if defined(__clang__)
- #pragma clang diagnostic ignored "-Wvariadic-macros"
- #elif defined(JSON_HEDLEY_GCC_VERSION)
- #pragma GCC diagnostic ignored "-Wvariadic-macros"
- #endif
- #endif
- #if defined(JSON_HEDLEY_NON_NULL)
- #undef JSON_HEDLEY_NON_NULL
- #endif
- #if \
- JSON_HEDLEY_HAS_ATTRIBUTE(nonnull) || \
- JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \
- JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
- JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0)
- #define JSON_HEDLEY_NON_NULL(...) __attribute__((__nonnull__(__VA_ARGS__)))
- #else
- #define JSON_HEDLEY_NON_NULL(...)
- #endif
- JSON_HEDLEY_DIAGNOSTIC_POP
- #if defined(JSON_HEDLEY_PRINTF_FORMAT)
- #undef JSON_HEDLEY_PRINTF_FORMAT
- #endif
- #if defined(__MINGW32__) && JSON_HEDLEY_GCC_HAS_ATTRIBUTE(format,4,4,0) && !defined(__USE_MINGW_ANSI_STDIO)
- #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(ms_printf, string_idx, first_to_check)))
- #elif defined(__MINGW32__) && JSON_HEDLEY_GCC_HAS_ATTRIBUTE(format,4,4,0) && defined(__USE_MINGW_ANSI_STDIO)
- #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(gnu_printf, string_idx, first_to_check)))
- #elif \
- JSON_HEDLEY_HAS_ATTRIBUTE(format) || \
- JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
- JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
- JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) || \
- JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
- JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
- (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
- JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
- (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
- JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
- (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
- JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
- (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
- JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
- JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
- JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
- JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
- #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(__printf__, string_idx, first_to_check)))
- #elif JSON_HEDLEY_PELLES_VERSION_CHECK(6,0,0)
- #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __declspec(vaformat(printf,string_idx,first_to_check))
- #else
- #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check)
- #endif
- #if defined(JSON_HEDLEY_CONSTEXPR)
- #undef JSON_HEDLEY_CONSTEXPR
- #endif
- #if defined(__cplusplus)
- #if __cplusplus >= 201103L
- #define JSON_HEDLEY_CONSTEXPR JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(constexpr)
- #endif
- #endif
- #if !defined(JSON_HEDLEY_CONSTEXPR)
- #define JSON_HEDLEY_CONSTEXPR
- #endif
- #if defined(JSON_HEDLEY_PREDICT)
- #undef JSON_HEDLEY_PREDICT
- #endif
- #if defined(JSON_HEDLEY_LIKELY)
- #undef JSON_HEDLEY_LIKELY
- #endif
- #if defined(JSON_HEDLEY_UNLIKELY)
- #undef JSON_HEDLEY_UNLIKELY
- #endif
- #if defined(JSON_HEDLEY_UNPREDICTABLE)
- #undef JSON_HEDLEY_UNPREDICTABLE
- #endif
- #if JSON_HEDLEY_HAS_BUILTIN(__builtin_unpredictable)
- #define JSON_HEDLEY_UNPREDICTABLE(expr) __builtin_unpredictable((expr))
- #endif
- #if \
- (JSON_HEDLEY_HAS_BUILTIN(__builtin_expect_with_probability) && !defined(JSON_HEDLEY_PGI_VERSION)) || \
- JSON_HEDLEY_GCC_VERSION_CHECK(9,0,0) || \
- JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
- # define JSON_HEDLEY_PREDICT(expr, value, probability) __builtin_expect_with_probability( (expr), (value), (probability))
- # define JSON_HEDLEY_PREDICT_TRUE(expr, probability) __builtin_expect_with_probability(!!(expr), 1 , (probability))
- # define JSON_HEDLEY_PREDICT_FALSE(expr, probability) __builtin_expect_with_probability(!!(expr), 0 , (probability))
- # define JSON_HEDLEY_LIKELY(expr) __builtin_expect (!!(expr), 1 )
- # define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect (!!(expr), 0 )
- #elif \
- (JSON_HEDLEY_HAS_BUILTIN(__builtin_expect) && !defined(JSON_HEDLEY_INTEL_CL_VERSION)) || \
- JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) || \
- JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
- (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0) && defined(__cplusplus)) || \
- JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
- JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
- JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
- JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,7,0) || \
- JSON_HEDLEY_TI_CL430_VERSION_CHECK(3,1,0) || \
- JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,1,0) || \
- JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \
- JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
- JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
- JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,27) || \
- JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \
- JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
- # define JSON_HEDLEY_PREDICT(expr, expected, probability) \
- (((probability) >= 0.9) ? __builtin_expect((expr), (expected)) : (JSON_HEDLEY_STATIC_CAST(void, expected), (expr)))
- # define JSON_HEDLEY_PREDICT_TRUE(expr, probability) \
- (__extension__ ({ \
- double hedley_probability_ = (probability); \
- ((hedley_probability_ >= 0.9) ? __builtin_expect(!!(expr), 1) : ((hedley_probability_ <= 0.1) ? __builtin_expect(!!(expr), 0) : !!(expr))); \
- }))
- # define JSON_HEDLEY_PREDICT_FALSE(expr, probability) \
- (__extension__ ({ \
- double hedley_probability_ = (probability); \
- ((hedley_probability_ >= 0.9) ? __builtin_expect(!!(expr), 0) : ((hedley_probability_ <= 0.1) ? __builtin_expect(!!(expr), 1) : !!(expr))); \
- }))
- # define JSON_HEDLEY_LIKELY(expr) __builtin_expect(!!(expr), 1)
- # define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect(!!(expr), 0)
- #else
- # define JSON_HEDLEY_PREDICT(expr, expected, probability) (JSON_HEDLEY_STATIC_CAST(void, expected), (expr))
- # define JSON_HEDLEY_PREDICT_TRUE(expr, probability) (!!(expr))
- # define JSON_HEDLEY_PREDICT_FALSE(expr, probability) (!!(expr))
- # define JSON_HEDLEY_LIKELY(expr) (!!(expr))
- # define JSON_HEDLEY_UNLIKELY(expr) (!!(expr))
- #endif
- #if !defined(JSON_HEDLEY_UNPREDICTABLE)
- #define JSON_HEDLEY_UNPREDICTABLE(expr) JSON_HEDLEY_PREDICT(expr, 1, 0.5)
- #endif
- #if defined(JSON_HEDLEY_MALLOC)
- #undef JSON_HEDLEY_MALLOC
- #endif
- #if \
- JSON_HEDLEY_HAS_ATTRIBUTE(malloc) || \
- JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
- JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
- JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
- JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
- JSON_HEDLEY_IBM_VERSION_CHECK(12,1,0) || \
- JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
- (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
- JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
- (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
- JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
- (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
- JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
- (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
- JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
- JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
- JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
- JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
- #define JSON_HEDLEY_MALLOC __attribute__((__malloc__))
- #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
- #define JSON_HEDLEY_MALLOC _Pragma("returns_new_memory")
- #elif \
- JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \
- JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
- #define JSON_HEDLEY_MALLOC __declspec(restrict)
- #else
- #define JSON_HEDLEY_MALLOC
- #endif
- #if defined(JSON_HEDLEY_PURE)
- #undef JSON_HEDLEY_PURE
- #endif
- #if \
- JSON_HEDLEY_HAS_ATTRIBUTE(pure) || \
- JSON_HEDLEY_GCC_VERSION_CHECK(2,96,0) || \
- JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
- JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
- JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
- JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
- JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
- (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
- JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
- (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
- JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
- (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
- JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
- (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
- JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
- JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
- JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
- JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
- JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
- # define JSON_HEDLEY_PURE __attribute__((__pure__))
- #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
- # define JSON_HEDLEY_PURE _Pragma("does_not_write_global_data")
- #elif defined(__cplusplus) && \
- ( \
- JSON_HEDLEY_TI_CL430_VERSION_CHECK(2,0,1) || \
- JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0) || \
- JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) \
- )
- # define JSON_HEDLEY_PURE _Pragma("FUNC_IS_PURE;")
- #else
- # define JSON_HEDLEY_PURE
- #endif
- #if defined(JSON_HEDLEY_CONST)
- #undef JSON_HEDLEY_CONST
- #endif
- #if \
- JSON_HEDLEY_HAS_ATTRIBUTE(const) || \
- JSON_HEDLEY_GCC_VERSION_CHECK(2,5,0) || \
- JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
- JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
- JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
- JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
- JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
- (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
- JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
- (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
- JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
- (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
- JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
- (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
- JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
- JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
- JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
- JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
- JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
- #define JSON_HEDLEY_CONST __attribute__((__const__))
- #elif \
- JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
- #define JSON_HEDLEY_CONST _Pragma("no_side_effect")
- #else
- #define JSON_HEDLEY_CONST JSON_HEDLEY_PURE
- #endif
- #if defined(JSON_HEDLEY_RESTRICT)
- #undef JSON_HEDLEY_RESTRICT
- #endif
- #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && !defined(__cplusplus)
- #define JSON_HEDLEY_RESTRICT restrict
- #elif \
- JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
- JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \
- JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
- JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \
- JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
- JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
- JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
- JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
- JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,4) || \
- JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,1,0) || \
- JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
- (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,14,0) && defined(__cplusplus)) || \
- JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) || \
- defined(__clang__) || \
- JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
- #define JSON_HEDLEY_RESTRICT __restrict
- #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,3,0) && !defined(__cplusplus)
- #define JSON_HEDLEY_RESTRICT _Restrict
- #else
- #define JSON_HEDLEY_RESTRICT
- #endif
- #if defined(JSON_HEDLEY_INLINE)
- #undef JSON_HEDLEY_INLINE
- #endif
- #if \
- (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \
- (defined(__cplusplus) && (__cplusplus >= 199711L))
- #define JSON_HEDLEY_INLINE inline
- #elif \
- defined(JSON_HEDLEY_GCC_VERSION) || \
- JSON_HEDLEY_ARM_VERSION_CHECK(6,2,0)
- #define JSON_HEDLEY_INLINE __inline__
- #elif \
- JSON_HEDLEY_MSVC_VERSION_CHECK(12,0,0) || \
- JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \
- JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
- JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,1,0) || \
- JSON_HEDLEY_TI_CL430_VERSION_CHECK(3,1,0) || \
- JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \
- JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0) || \
- JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
- JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
- JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
- #define JSON_HEDLEY_INLINE __inline
- #else
- #define JSON_HEDLEY_INLINE
- #endif
- #if defined(JSON_HEDLEY_ALWAYS_INLINE)
- #undef JSON_HEDLEY_ALWAYS_INLINE
- #endif
- #if \
- JSON_HEDLEY_HAS_ATTRIBUTE(always_inline) || \
- JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \
- JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
- JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
- JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
- JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
- JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
- (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
- JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
- (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
- JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
- (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
- JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
- (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
- JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
- JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
- JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
- JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \
- JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0)
- # define JSON_HEDLEY_ALWAYS_INLINE __attribute__((__always_inline__)) JSON_HEDLEY_INLINE
- #elif \
- JSON_HEDLEY_MSVC_VERSION_CHECK(12,0,0) || \
- JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
- # define JSON_HEDLEY_ALWAYS_INLINE __forceinline
- #elif defined(__cplusplus) && \
- ( \
- JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
- JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
- JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
- JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \
- JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
- JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) \
- )
- # define JSON_HEDLEY_ALWAYS_INLINE _Pragma("FUNC_ALWAYS_INLINE;")
- #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
- # define JSON_HEDLEY_ALWAYS_INLINE _Pragma("inline=forced")
- #else
- # define JSON_HEDLEY_ALWAYS_INLINE JSON_HEDLEY_INLINE
- #endif
- #if defined(JSON_HEDLEY_NEVER_INLINE)
- #undef JSON_HEDLEY_NEVER_INLINE
- #endif
- #if \
- JSON_HEDLEY_HAS_ATTRIBUTE(noinline) || \
- JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \
- JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
- JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
- JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
- JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
- JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
- (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
- JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
- (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
- JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
- (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
- JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
- (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
- JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
- JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
- JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
- JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \
- JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0)
- #define JSON_HEDLEY_NEVER_INLINE __attribute__((__noinline__))
- #elif \
- JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
- JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
- #define JSON_HEDLEY_NEVER_INLINE __declspec(noinline)
- #elif JSON_HEDLEY_PGI_VERSION_CHECK(10,2,0)
- #define JSON_HEDLEY_NEVER_INLINE _Pragma("noinline")
- #elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,0,0) && defined(__cplusplus)
- #define JSON_HEDLEY_NEVER_INLINE _Pragma("FUNC_CANNOT_INLINE;")
- #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
- #define JSON_HEDLEY_NEVER_INLINE _Pragma("inline=never")
- #elif JSON_HEDLEY_COMPCERT_VERSION_CHECK(3,2,0)
- #define JSON_HEDLEY_NEVER_INLINE __attribute((noinline))
- #elif JSON_HEDLEY_PELLES_VERSION_CHECK(9,0,0)
- #define JSON_HEDLEY_NEVER_INLINE __declspec(noinline)
- #else
- #define JSON_HEDLEY_NEVER_INLINE
- #endif
- #if defined(JSON_HEDLEY_PRIVATE)
- #undef JSON_HEDLEY_PRIVATE
- #endif
- #if defined(JSON_HEDLEY_PUBLIC)
- #undef JSON_HEDLEY_PUBLIC
- #endif
- #if defined(JSON_HEDLEY_IMPORT)
- #undef JSON_HEDLEY_IMPORT
- #endif
- #if defined(_WIN32) || defined(__CYGWIN__)
- # define JSON_HEDLEY_PRIVATE
- # define JSON_HEDLEY_PUBLIC __declspec(dllexport)
- # define JSON_HEDLEY_IMPORT __declspec(dllimport)
- #else
- # if \
- JSON_HEDLEY_HAS_ATTRIBUTE(visibility) || \
- JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \
- JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
- JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
- JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
- JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \
- ( \
- defined(__TI_EABI__) && \
- ( \
- (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
- JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) \
- ) \
- ) || \
- JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
- # define JSON_HEDLEY_PRIVATE __attribute__((__visibility__("hidden")))
- # define JSON_HEDLEY_PUBLIC __attribute__((__visibility__("default")))
- # else
- # define JSON_HEDLEY_PRIVATE
- # define JSON_HEDLEY_PUBLIC
- # endif
- # define JSON_HEDLEY_IMPORT extern
- #endif
- #if defined(JSON_HEDLEY_NO_THROW)
- #undef JSON_HEDLEY_NO_THROW
- #endif
- #if \
- JSON_HEDLEY_HAS_ATTRIBUTE(nothrow) || \
- JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \
- JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
- JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
- #define JSON_HEDLEY_NO_THROW __attribute__((__nothrow__))
- #elif \
- JSON_HEDLEY_MSVC_VERSION_CHECK(13,1,0) || \
- JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \
- JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0)
- #define JSON_HEDLEY_NO_THROW __declspec(nothrow)
- #else
- #define JSON_HEDLEY_NO_THROW
- #endif
- #if defined(JSON_HEDLEY_FALL_THROUGH)
- #undef JSON_HEDLEY_FALL_THROUGH
- #endif
- #if \
- JSON_HEDLEY_HAS_ATTRIBUTE(fallthrough) || \
- JSON_HEDLEY_GCC_VERSION_CHECK(7,0,0) || \
- JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
- #define JSON_HEDLEY_FALL_THROUGH __attribute__((__fallthrough__))
- #elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(clang,fallthrough)
- #define JSON_HEDLEY_FALL_THROUGH JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[clang::fallthrough]])
- #elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE(fallthrough)
- #define JSON_HEDLEY_FALL_THROUGH JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[fallthrough]])
- #elif defined(__fallthrough)
- #define JSON_HEDLEY_FALL_THROUGH __fallthrough
- #else
- #define JSON_HEDLEY_FALL_THROUGH
- #endif
- #if defined(JSON_HEDLEY_RETURNS_NON_NULL)
- #undef JSON_HEDLEY_RETURNS_NON_NULL
- #endif
- #if \
- JSON_HEDLEY_HAS_ATTRIBUTE(returns_nonnull) || \
- JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) || \
- JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
- #define JSON_HEDLEY_RETURNS_NON_NULL __attribute__((__returns_nonnull__))
- #elif defined(_Ret_notnull_)
- #define JSON_HEDLEY_RETURNS_NON_NULL _Ret_notnull_
- #else
- #define JSON_HEDLEY_RETURNS_NON_NULL
- #endif
- #if defined(JSON_HEDLEY_ARRAY_PARAM)
- #undef JSON_HEDLEY_ARRAY_PARAM
- #endif
- #if \
- defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \
- !defined(__STDC_NO_VLA__) && \
- !defined(__cplusplus) && \
- !defined(JSON_HEDLEY_PGI_VERSION) && \
- !defined(JSON_HEDLEY_TINYC_VERSION)
- #define JSON_HEDLEY_ARRAY_PARAM(name) (name)
- #else
- #define JSON_HEDLEY_ARRAY_PARAM(name)
- #endif
- #if defined(JSON_HEDLEY_IS_CONSTANT)
- #undef JSON_HEDLEY_IS_CONSTANT
- #endif
- #if defined(JSON_HEDLEY_REQUIRE_CONSTEXPR)
- #undef JSON_HEDLEY_REQUIRE_CONSTEXPR
- #endif
- #if defined(JSON_HEDLEY_IS_CONSTEXPR_)
- #undef JSON_HEDLEY_IS_CONSTEXPR_
- #endif
- #if \
- JSON_HEDLEY_HAS_BUILTIN(__builtin_constant_p) || \
- JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \
- JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
- JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,19) || \
- JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
- JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \
- JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \
- (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) && !defined(__cplusplus)) || \
- JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \
- JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
- #define JSON_HEDLEY_IS_CONSTANT(expr) __builtin_constant_p(expr)
- #endif
- #if !defined(__cplusplus)
- # if \
- JSON_HEDLEY_HAS_BUILTIN(__builtin_types_compatible_p) || \
- JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \
- JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
- JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \
- JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \
- JSON_HEDLEY_ARM_VERSION_CHECK(5,4,0) || \
- JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,24)
- #if defined(__INTPTR_TYPE__)
- #define JSON_HEDLEY_IS_CONSTEXPR_(expr) __builtin_types_compatible_p(__typeof__((1 ? (void*) ((__INTPTR_TYPE__) ((expr) * 0)) : (int*) 0)), int*)
- #else
- #include <stdint.h>
- #define JSON_HEDLEY_IS_CONSTEXPR_(expr) __builtin_types_compatible_p(__typeof__((1 ? (void*) ((intptr_t) ((expr) * 0)) : (int*) 0)), int*)
- #endif
- # elif \
- ( \
- defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) && \
- !defined(JSON_HEDLEY_SUNPRO_VERSION) && \
- !defined(JSON_HEDLEY_PGI_VERSION) && \
- !defined(JSON_HEDLEY_IAR_VERSION)) || \
- (JSON_HEDLEY_HAS_EXTENSION(c_generic_selections) && !defined(JSON_HEDLEY_IAR_VERSION)) || \
- JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) || \
- JSON_HEDLEY_INTEL_VERSION_CHECK(17,0,0) || \
- JSON_HEDLEY_IBM_VERSION_CHECK(12,1,0) || \
- JSON_HEDLEY_ARM_VERSION_CHECK(5,3,0)
- #if defined(__INTPTR_TYPE__)
- #define JSON_HEDLEY_IS_CONSTEXPR_(expr) _Generic((1 ? (void*) ((__INTPTR_TYPE__) ((expr) * 0)) : (int*) 0), int*: 1, void*: 0)
- #else
- #include <stdint.h>
- #define JSON_HEDLEY_IS_CONSTEXPR_(expr) _Generic((1 ? (void*) ((intptr_t) * 0) : (int*) 0), int*: 1, void*: 0)
- #endif
- # elif \
- defined(JSON_HEDLEY_GCC_VERSION) || \
- defined(JSON_HEDLEY_INTEL_VERSION) || \
- defined(JSON_HEDLEY_TINYC_VERSION) || \
- defined(JSON_HEDLEY_TI_ARMCL_VERSION) || \
- JSON_HEDLEY_TI_CL430_VERSION_CHECK(18,12,0) || \
- defined(JSON_HEDLEY_TI_CL2000_VERSION) || \
- defined(JSON_HEDLEY_TI_CL6X_VERSION) || \
- defined(JSON_HEDLEY_TI_CL7X_VERSION) || \
- defined(JSON_HEDLEY_TI_CLPRU_VERSION) || \
- defined(__clang__)
- # define JSON_HEDLEY_IS_CONSTEXPR_(expr) ( \
- sizeof(void) != \
- sizeof(*( \
- 1 ? \
- ((void*) ((expr) * 0L) ) : \
- ((struct { char v[sizeof(void) * 2]; } *) 1) \
- ) \
- ) \
- )
- # endif
- #endif
- #if defined(JSON_HEDLEY_IS_CONSTEXPR_)
- #if !defined(JSON_HEDLEY_IS_CONSTANT)
- #define JSON_HEDLEY_IS_CONSTANT(expr) JSON_HEDLEY_IS_CONSTEXPR_(expr)
- #endif
- #define JSON_HEDLEY_REQUIRE_CONSTEXPR(expr) (JSON_HEDLEY_IS_CONSTEXPR_(expr) ? (expr) : (-1))
- #else
- #if !defined(JSON_HEDLEY_IS_CONSTANT)
- #define JSON_HEDLEY_IS_CONSTANT(expr) (0)
- #endif
- #define JSON_HEDLEY_REQUIRE_CONSTEXPR(expr) (expr)
- #endif
- #if defined(JSON_HEDLEY_BEGIN_C_DECLS)
- #undef JSON_HEDLEY_BEGIN_C_DECLS
- #endif
- #if defined(JSON_HEDLEY_END_C_DECLS)
- #undef JSON_HEDLEY_END_C_DECLS
- #endif
- #if defined(JSON_HEDLEY_C_DECL)
- #undef JSON_HEDLEY_C_DECL
- #endif
- #if defined(__cplusplus)
- #define JSON_HEDLEY_BEGIN_C_DECLS extern "C" {
- #define JSON_HEDLEY_END_C_DECLS }
- #define JSON_HEDLEY_C_DECL extern "C"
- #else
- #define JSON_HEDLEY_BEGIN_C_DECLS
- #define JSON_HEDLEY_END_C_DECLS
- #define JSON_HEDLEY_C_DECL
- #endif
- #if defined(JSON_HEDLEY_STATIC_ASSERT)
- #undef JSON_HEDLEY_STATIC_ASSERT
- #endif
- #if \
- !defined(__cplusplus) && ( \
- (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)) || \
- (JSON_HEDLEY_HAS_FEATURE(c_static_assert) && !defined(JSON_HEDLEY_INTEL_CL_VERSION)) || \
- JSON_HEDLEY_GCC_VERSION_CHECK(6,0,0) || \
- JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
- defined(_Static_assert) \
- )
- # define JSON_HEDLEY_STATIC_ASSERT(expr, message) _Static_assert(expr, message)
- #elif \
- (defined(__cplusplus) && (__cplusplus >= 201103L)) || \
- JSON_HEDLEY_MSVC_VERSION_CHECK(16,0,0) || \
- JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
- # define JSON_HEDLEY_STATIC_ASSERT(expr, message) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(static_assert(expr, message))
- #else
- # define JSON_HEDLEY_STATIC_ASSERT(expr, message)
- #endif
- #if defined(JSON_HEDLEY_NULL)
- #undef JSON_HEDLEY_NULL
- #endif
- #if defined(__cplusplus)
- #if __cplusplus >= 201103L
- #define JSON_HEDLEY_NULL JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(nullptr)
- #elif defined(NULL)
- #define JSON_HEDLEY_NULL NULL
- #else
- #define JSON_HEDLEY_NULL JSON_HEDLEY_STATIC_CAST(void*, 0)
- #endif
- #elif defined(NULL)
- #define JSON_HEDLEY_NULL NULL
- #else
- #define JSON_HEDLEY_NULL ((void*) 0)
- #endif
- #if defined(JSON_HEDLEY_MESSAGE)
- #undef JSON_HEDLEY_MESSAGE
- #endif
- #if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas")
- # define JSON_HEDLEY_MESSAGE(msg) \
- JSON_HEDLEY_DIAGNOSTIC_PUSH \
- JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \
- JSON_HEDLEY_PRAGMA(message msg) \
- JSON_HEDLEY_DIAGNOSTIC_POP
- #elif \
- JSON_HEDLEY_GCC_VERSION_CHECK(4,4,0) || \
- JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
- # define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message msg)
- #elif JSON_HEDLEY_CRAY_VERSION_CHECK(5,0,0)
- # define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(_CRI message msg)
- #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
- # define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message(msg))
- #elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,0,0)
- # define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message(msg))
- #else
- # define JSON_HEDLEY_MESSAGE(msg)
- #endif
- #if defined(JSON_HEDLEY_WARNING)
- #undef JSON_HEDLEY_WARNING
- #endif
- #if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas")
- # define JSON_HEDLEY_WARNING(msg) \
- JSON_HEDLEY_DIAGNOSTIC_PUSH \
- JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \
- JSON_HEDLEY_PRAGMA(clang warning msg) \
- JSON_HEDLEY_DIAGNOSTIC_POP
- #elif \
- JSON_HEDLEY_GCC_VERSION_CHECK(4,8,0) || \
- JSON_HEDLEY_PGI_VERSION_CHECK(18,4,0) || \
- JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
- # define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(GCC warning msg)
- #elif \
- JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) || \
- JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
- # define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(message(msg))
- #else
- # define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_MESSAGE(msg)
- #endif
- #if defined(JSON_HEDLEY_REQUIRE)
- #undef JSON_HEDLEY_REQUIRE
- #endif
- #if defined(JSON_HEDLEY_REQUIRE_MSG)
- #undef JSON_HEDLEY_REQUIRE_MSG
- #endif
- #if JSON_HEDLEY_HAS_ATTRIBUTE(diagnose_if)
- # if JSON_HEDLEY_HAS_WARNING("-Wgcc-compat")
- # define JSON_HEDLEY_REQUIRE(expr) \
- JSON_HEDLEY_DIAGNOSTIC_PUSH \
- _Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \
- __attribute__((diagnose_if(!(expr), #expr, "error"))) \
- JSON_HEDLEY_DIAGNOSTIC_POP
- # define JSON_HEDLEY_REQUIRE_MSG(expr,msg) \
- JSON_HEDLEY_DIAGNOSTIC_PUSH \
- _Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \
- __attribute__((diagnose_if(!(expr), msg, "error"))) \
- JSON_HEDLEY_DIAGNOSTIC_POP
- # else
- # define JSON_HEDLEY_REQUIRE(expr) __attribute__((diagnose_if(!(expr), #expr, "error")))
- # define JSON_HEDLEY_REQUIRE_MSG(expr,msg) __attribute__((diagnose_if(!(expr), msg, "error")))
- # endif
- #else
- # define JSON_HEDLEY_REQUIRE(expr)
- # define JSON_HEDLEY_REQUIRE_MSG(expr,msg)
- #endif
- #if defined(JSON_HEDLEY_FLAGS)
- #undef JSON_HEDLEY_FLAGS
- #endif
- #if JSON_HEDLEY_HAS_ATTRIBUTE(flag_enum) && (!defined(__cplusplus) || JSON_HEDLEY_HAS_WARNING("-Wbitfield-enum-conversion"))
- #define JSON_HEDLEY_FLAGS __attribute__((__flag_enum__))
- #else
- #define JSON_HEDLEY_FLAGS
- #endif
- #if defined(JSON_HEDLEY_FLAGS_CAST)
- #undef JSON_HEDLEY_FLAGS_CAST
- #endif
- #if JSON_HEDLEY_INTEL_VERSION_CHECK(19,0,0)
- # define JSON_HEDLEY_FLAGS_CAST(T, expr) (__extension__ ({ \
- JSON_HEDLEY_DIAGNOSTIC_PUSH \
- _Pragma("warning(disable:188)") \
- ((T) (expr)); \
- JSON_HEDLEY_DIAGNOSTIC_POP \
- }))
- #else
- # define JSON_HEDLEY_FLAGS_CAST(T, expr) JSON_HEDLEY_STATIC_CAST(T, expr)
- #endif
- #if defined(JSON_HEDLEY_EMPTY_BASES)
- #undef JSON_HEDLEY_EMPTY_BASES
- #endif
- #if \
- (JSON_HEDLEY_MSVC_VERSION_CHECK(19,0,23918) && !JSON_HEDLEY_MSVC_VERSION_CHECK(20,0,0)) || \
- JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
- #define JSON_HEDLEY_EMPTY_BASES __declspec(empty_bases)
- #else
- #define JSON_HEDLEY_EMPTY_BASES
- #endif
- #if defined(JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK)
- #undef JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK
- #endif
- #if defined(__clang__)
- #define JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK(major,minor,patch) (0)
- #else
- #define JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK(major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
- #endif
- #if defined(JSON_HEDLEY_CLANG_HAS_ATTRIBUTE)
- #undef JSON_HEDLEY_CLANG_HAS_ATTRIBUTE
- #endif
- #define JSON_HEDLEY_CLANG_HAS_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_ATTRIBUTE(attribute)
- #if defined(JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE)
- #undef JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE
- #endif
- #define JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute)
- #if defined(JSON_HEDLEY_CLANG_HAS_BUILTIN)
- #undef JSON_HEDLEY_CLANG_HAS_BUILTIN
- #endif
- #define JSON_HEDLEY_CLANG_HAS_BUILTIN(builtin) JSON_HEDLEY_HAS_BUILTIN(builtin)
- #if defined(JSON_HEDLEY_CLANG_HAS_FEATURE)
- #undef JSON_HEDLEY_CLANG_HAS_FEATURE
- #endif
- #define JSON_HEDLEY_CLANG_HAS_FEATURE(feature) JSON_HEDLEY_HAS_FEATURE(feature)
- #if defined(JSON_HEDLEY_CLANG_HAS_EXTENSION)
- #undef JSON_HEDLEY_CLANG_HAS_EXTENSION
- #endif
- #define JSON_HEDLEY_CLANG_HAS_EXTENSION(extension) JSON_HEDLEY_HAS_EXTENSION(extension)
- #if defined(JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE)
- #undef JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE
- #endif
- #define JSON_HEDLEY_CLANG_HAS_DECLSPEC_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute)
- #if defined(JSON_HEDLEY_CLANG_HAS_WARNING)
- #undef JSON_HEDLEY_CLANG_HAS_WARNING
- #endif
- #define JSON_HEDLEY_CLANG_HAS_WARNING(warning) JSON_HEDLEY_HAS_WARNING(warning)
- #endif
- #include <type_traits>
- namespace nlohmann
- {
- namespace detail
- {
- template<typename ...Ts> struct make_void
- {
- using type = void;
- };
- template<typename ...Ts> using void_t = typename make_void<Ts...>::type;
- }
- }
- namespace nlohmann
- {
- namespace detail
- {
- struct nonesuch
- {
- nonesuch() = delete;
- ~nonesuch() = delete;
- nonesuch(nonesuch const&) = delete;
- nonesuch(nonesuch const&&) = delete;
- void operator=(nonesuch const&) = delete;
- void operator=(nonesuch&&) = delete;
- };
- template<class Default,
- class AlwaysVoid,
- template<class...> class Op,
- class... Args>
- struct detector
- {
- using value_t = std::false_type;
- using type = Default;
- };
- template<class Default, template<class...> class Op, class... Args>
- struct detector<Default, void_t<Op<Args...>>, Op, Args...>
- {
- using value_t = std::true_type;
- using type = Op<Args...>;
- };
- template<template<class...> class Op, class... Args>
- using is_detected = typename detector<nonesuch, void, Op, Args...>::value_t;
- template<template<class...> class Op, class... Args>
- struct is_detected_lazy : is_detected<Op, Args...> { };
- template<template<class...> class Op, class... Args>
- using detected_t = typename detector<nonesuch, void, Op, Args...>::type;
- template<class Default, template<class...> class Op, class... Args>
- using detected_or = detector<Default, void, Op, Args...>;
- template<class Default, template<class...> class Op, class... Args>
- using detected_or_t = typename detected_or<Default, Op, Args...>::type;
- template<class Expected, template<class...> class Op, class... Args>
- using is_detected_exact = std::is_same<Expected, detected_t<Op, Args...>>;
- template<class To, template<class...> class Op, class... Args>
- using is_detected_convertible =
- std::is_convertible<detected_t<Op, Args...>, To>;
- }
- }
- #if !defined(JSON_SKIP_UNSUPPORTED_COMPILER_CHECK)
- #if defined(__clang__)
- #if (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__) < 30400
- #error "unsupported Clang version - see https://github.com/nlohmann/json#supported-compilers"
- #endif
- #elif defined(__GNUC__) && !(defined(__ICC) || defined(__INTEL_COMPILER))
- #if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40800
- #error "unsupported GCC version - see https://github.com/nlohmann/json#supported-compilers"
- #endif
- #endif
- #endif
- #if !defined(JSON_HAS_CPP_20) && !defined(JSON_HAS_CPP_17) && !defined(JSON_HAS_CPP_14) && !defined(JSON_HAS_CPP_11)
- #if (defined(__cplusplus) && __cplusplus >= 202002L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 202002L)
- #define JSON_HAS_CPP_20
- #define JSON_HAS_CPP_17
- #define JSON_HAS_CPP_14
- #elif (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1)
- #define JSON_HAS_CPP_17
- #define JSON_HAS_CPP_14
- #elif (defined(__cplusplus) && __cplusplus >= 201402L) || (defined(_HAS_CXX14) && _HAS_CXX14 == 1)
- #define JSON_HAS_CPP_14
- #endif
-
- #define JSON_HAS_CPP_11
- #endif
- #if defined(__clang__)
- #pragma clang diagnostic push
- #pragma clang diagnostic ignored "-Wdocumentation"
- #pragma clang diagnostic ignored "-Wdocumentation-unknown-command"
- #endif
- #if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(JSON_NOEXCEPTION)
- #define JSON_THROW(exception) throw exception
- #define JSON_TRY try
- #define JSON_CATCH(exception) catch(exception)
- #define JSON_INTERNAL_CATCH(exception) catch(exception)
- #else
- #include <cstdlib>
- #define JSON_THROW(exception) std::abort()
- #define JSON_TRY if(true)
- #define JSON_CATCH(exception) if(false)
- #define JSON_INTERNAL_CATCH(exception) if(false)
- #endif
- #if defined(JSON_THROW_USER)
- #undef JSON_THROW
- #define JSON_THROW JSON_THROW_USER
- #endif
- #if defined(JSON_TRY_USER)
- #undef JSON_TRY
- #define JSON_TRY JSON_TRY_USER
- #endif
- #if defined(JSON_CATCH_USER)
- #undef JSON_CATCH
- #define JSON_CATCH JSON_CATCH_USER
- #undef JSON_INTERNAL_CATCH
- #define JSON_INTERNAL_CATCH JSON_CATCH_USER
- #endif
- #if defined(JSON_INTERNAL_CATCH_USER)
- #undef JSON_INTERNAL_CATCH
- #define JSON_INTERNAL_CATCH JSON_INTERNAL_CATCH_USER
- #endif
- #if !defined(JSON_ASSERT)
- #include <cassert> // assert
- #define JSON_ASSERT(x) assert(x)
- #endif
- #if defined(JSON_TESTS_PRIVATE)
- #define JSON_PRIVATE_UNLESS_TESTED public
- #else
- #define JSON_PRIVATE_UNLESS_TESTED private
- #endif
- #define NLOHMANN_JSON_SERIALIZE_ENUM(ENUM_TYPE, ...) \
- template<typename BasicJsonType> \
- inline void to_json(BasicJsonType& j, const ENUM_TYPE& e) \
- { \
- static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \
- static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \
- auto it = std::find_if(std::begin(m), std::end(m), \
- [e](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \
- { \
- return ej_pair.first == e; \
- }); \
- j = ((it != std::end(m)) ? it : std::begin(m))->second; \
- } \
- template<typename BasicJsonType> \
- inline void from_json(const BasicJsonType& j, ENUM_TYPE& e) \
- { \
- static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \
- static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \
- auto it = std::find_if(std::begin(m), std::end(m), \
- [&j](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \
- { \
- return ej_pair.second == j; \
- }); \
- e = ((it != std::end(m)) ? it : std::begin(m))->first; \
- }
- #define NLOHMANN_BASIC_JSON_TPL_DECLARATION \
- template<template<typename, typename, typename...> class ObjectType, \
- template<typename, typename...> class ArrayType, \
- class StringType, class BooleanType, class NumberIntegerType, \
- class NumberUnsignedType, class NumberFloatType, \
- template<typename> class AllocatorType, \
- template<typename, typename = void> class JSONSerializer, \
- class BinaryType>
- #define NLOHMANN_BASIC_JSON_TPL \
- basic_json<ObjectType, ArrayType, StringType, BooleanType, \
- NumberIntegerType, NumberUnsignedType, NumberFloatType, \
- AllocatorType, JSONSerializer, BinaryType>
- #define NLOHMANN_JSON_EXPAND( x ) x
- #define NLOHMANN_JSON_GET_MACRO(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, _62, _63, _64, NAME,...) NAME
- #define NLOHMANN_JSON_PASTE(...) NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_GET_MACRO(__VA_ARGS__, \
- NLOHMANN_JSON_PASTE64, \
- NLOHMANN_JSON_PASTE63, \
- NLOHMANN_JSON_PASTE62, \
- NLOHMANN_JSON_PASTE61, \
- NLOHMANN_JSON_PASTE60, \
- NLOHMANN_JSON_PASTE59, \
- NLOHMANN_JSON_PASTE58, \
- NLOHMANN_JSON_PASTE57, \
- NLOHMANN_JSON_PASTE56, \
- NLOHMANN_JSON_PASTE55, \
- NLOHMANN_JSON_PASTE54, \
- NLOHMANN_JSON_PASTE53, \
- NLOHMANN_JSON_PASTE52, \
- NLOHMANN_JSON_PASTE51, \
- NLOHMANN_JSON_PASTE50, \
- NLOHMANN_JSON_PASTE49, \
- NLOHMANN_JSON_PASTE48, \
- NLOHMANN_JSON_PASTE47, \
- NLOHMANN_JSON_PASTE46, \
- NLOHMANN_JSON_PASTE45, \
- NLOHMANN_JSON_PASTE44, \
- NLOHMANN_JSON_PASTE43, \
- NLOHMANN_JSON_PASTE42, \
- NLOHMANN_JSON_PASTE41, \
- NLOHMANN_JSON_PASTE40, \
- NLOHMANN_JSON_PASTE39, \
- NLOHMANN_JSON_PASTE38, \
- NLOHMANN_JSON_PASTE37, \
- NLOHMANN_JSON_PASTE36, \
- NLOHMANN_JSON_PASTE35, \
- NLOHMANN_JSON_PASTE34, \
- NLOHMANN_JSON_PASTE33, \
- NLOHMANN_JSON_PASTE32, \
- NLOHMANN_JSON_PASTE31, \
- NLOHMANN_JSON_PASTE30, \
- NLOHMANN_JSON_PASTE29, \
- NLOHMANN_JSON_PASTE28, \
- NLOHMANN_JSON_PASTE27, \
- NLOHMANN_JSON_PASTE26, \
- NLOHMANN_JSON_PASTE25, \
- NLOHMANN_JSON_PASTE24, \
- NLOHMANN_JSON_PASTE23, \
- NLOHMANN_JSON_PASTE22, \
- NLOHMANN_JSON_PASTE21, \
- NLOHMANN_JSON_PASTE20, \
- NLOHMANN_JSON_PASTE19, \
- NLOHMANN_JSON_PASTE18, \
- NLOHMANN_JSON_PASTE17, \
- NLOHMANN_JSON_PASTE16, \
- NLOHMANN_JSON_PASTE15, \
- NLOHMANN_JSON_PASTE14, \
- NLOHMANN_JSON_PASTE13, \
- NLOHMANN_JSON_PASTE12, \
- NLOHMANN_JSON_PASTE11, \
- NLOHMANN_JSON_PASTE10, \
- NLOHMANN_JSON_PASTE9, \
- NLOHMANN_JSON_PASTE8, \
- NLOHMANN_JSON_PASTE7, \
- NLOHMANN_JSON_PASTE6, \
- NLOHMANN_JSON_PASTE5, \
- NLOHMANN_JSON_PASTE4, \
- NLOHMANN_JSON_PASTE3, \
- NLOHMANN_JSON_PASTE2, \
- NLOHMANN_JSON_PASTE1)(__VA_ARGS__))
- #define NLOHMANN_JSON_PASTE2(func, v1) func(v1)
- #define NLOHMANN_JSON_PASTE3(func, v1, v2) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE2(func, v2)
- #define NLOHMANN_JSON_PASTE4(func, v1, v2, v3) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE3(func, v2, v3)
- #define NLOHMANN_JSON_PASTE5(func, v1, v2, v3, v4) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE4(func, v2, v3, v4)
- #define NLOHMANN_JSON_PASTE6(func, v1, v2, v3, v4, v5) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE5(func, v2, v3, v4, v5)
- #define NLOHMANN_JSON_PASTE7(func, v1, v2, v3, v4, v5, v6) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE6(func, v2, v3, v4, v5, v6)
- #define NLOHMANN_JSON_PASTE8(func, v1, v2, v3, v4, v5, v6, v7) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE7(func, v2, v3, v4, v5, v6, v7)
- #define NLOHMANN_JSON_PASTE9(func, v1, v2, v3, v4, v5, v6, v7, v8) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE8(func, v2, v3, v4, v5, v6, v7, v8)
- #define NLOHMANN_JSON_PASTE10(func, v1, v2, v3, v4, v5, v6, v7, v8, v9) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE9(func, v2, v3, v4, v5, v6, v7, v8, v9)
- #define NLOHMANN_JSON_PASTE11(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE10(func, v2, v3, v4, v5, v6, v7, v8, v9, v10)
- #define NLOHMANN_JSON_PASTE12(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE11(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11)
- #define NLOHMANN_JSON_PASTE13(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE12(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12)
- #define NLOHMANN_JSON_PASTE14(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE13(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13)
- #define NLOHMANN_JSON_PASTE15(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE14(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14)
- #define NLOHMANN_JSON_PASTE16(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE15(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15)
- #define NLOHMANN_JSON_PASTE17(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE16(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16)
- #define NLOHMANN_JSON_PASTE18(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE17(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17)
- #define NLOHMANN_JSON_PASTE19(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE18(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18)
- #define NLOHMANN_JSON_PASTE20(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE19(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19)
- #define NLOHMANN_JSON_PASTE21(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE20(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20)
- #define NLOHMANN_JSON_PASTE22(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE21(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21)
- #define NLOHMANN_JSON_PASTE23(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE22(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22)
- #define NLOHMANN_JSON_PASTE24(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE23(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23)
- #define NLOHMANN_JSON_PASTE25(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE24(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24)
- #define NLOHMANN_JSON_PASTE26(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE25(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25)
- #define NLOHMANN_JSON_PASTE27(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE26(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26)
- #define NLOHMANN_JSON_PASTE28(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE27(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27)
- #define NLOHMANN_JSON_PASTE29(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE28(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28)
- #define NLOHMANN_JSON_PASTE30(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE29(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29)
- #define NLOHMANN_JSON_PASTE31(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE30(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30)
- #define NLOHMANN_JSON_PASTE32(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE31(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31)
- #define NLOHMANN_JSON_PASTE33(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE32(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32)
- #define NLOHMANN_JSON_PASTE34(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE33(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33)
- #define NLOHMANN_JSON_PASTE35(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE34(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34)
- #define NLOHMANN_JSON_PASTE36(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE35(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35)
- #define NLOHMANN_JSON_PASTE37(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE36(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36)
- #define NLOHMANN_JSON_PASTE38(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE37(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37)
- #define NLOHMANN_JSON_PASTE39(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE38(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38)
- #define NLOHMANN_JSON_PASTE40(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE39(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39)
- #define NLOHMANN_JSON_PASTE41(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE40(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40)
- #define NLOHMANN_JSON_PASTE42(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE41(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41)
- #define NLOHMANN_JSON_PASTE43(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE42(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42)
- #define NLOHMANN_JSON_PASTE44(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE43(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43)
- #define NLOHMANN_JSON_PASTE45(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE44(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44)
- #define NLOHMANN_JSON_PASTE46(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE45(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45)
- #define NLOHMANN_JSON_PASTE47(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE46(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46)
- #define NLOHMANN_JSON_PASTE48(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE47(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47)
- #define NLOHMANN_JSON_PASTE49(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE48(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48)
- #define NLOHMANN_JSON_PASTE50(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE49(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49)
- #define NLOHMANN_JSON_PASTE51(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE50(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50)
- #define NLOHMANN_JSON_PASTE52(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE51(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51)
- #define NLOHMANN_JSON_PASTE53(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE52(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52)
- #define NLOHMANN_JSON_PASTE54(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE53(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53)
- #define NLOHMANN_JSON_PASTE55(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE54(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54)
- #define NLOHMANN_JSON_PASTE56(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE55(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55)
- #define NLOHMANN_JSON_PASTE57(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE56(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56)
- #define NLOHMANN_JSON_PASTE58(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE57(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57)
- #define NLOHMANN_JSON_PASTE59(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE58(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58)
- #define NLOHMANN_JSON_PASTE60(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE59(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59)
- #define NLOHMANN_JSON_PASTE61(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE60(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60)
- #define NLOHMANN_JSON_PASTE62(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE61(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61)
- #define NLOHMANN_JSON_PASTE63(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61, v62) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE62(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61, v62)
- #define NLOHMANN_JSON_PASTE64(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61, v62, v63) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE63(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61, v62, v63)
- #define NLOHMANN_JSON_TO(v1) nlohmann_json_j[#v1] = nlohmann_json_t.v1;
- #define NLOHMANN_JSON_FROM(v1) nlohmann_json_j.at(#v1).get_to(nlohmann_json_t.v1);
- #define NLOHMANN_DEFINE_TYPE_INTRUSIVE(Type, ...) \
- friend void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \
- friend void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) }
- #define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Type, ...) \
- inline void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \
- inline void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) }
- #define NLOHMANN_CAN_CALL_STD_FUNC_IMPL(std_name) \
- namespace detail { \
- using std::std_name; \
- \
- template<typename... T> \
- using result_of_##std_name = decltype(std_name(std::declval<T>()...)); \
- } \
- \
- namespace detail2 { \
- struct std_name##_tag \
- { \
- }; \
- \
- template<typename... T> \
- std_name##_tag std_name(T&&...); \
- \
- template<typename... T> \
- using result_of_##std_name = decltype(std_name(std::declval<T>()...)); \
- \
- template<typename... T> \
- struct would_call_std_##std_name \
- { \
- static constexpr auto const value = ::nlohmann::detail:: \
- is_detected_exact<std_name##_tag, result_of_##std_name, T...>::value; \
- }; \
- } \
- \
- template<typename... T> \
- struct would_call_std_##std_name : detail2::would_call_std_##std_name<T...> \
- { \
- }
- #ifndef JSON_USE_IMPLICIT_CONVERSIONS
- #define JSON_USE_IMPLICIT_CONVERSIONS 1
- #endif
- #if JSON_USE_IMPLICIT_CONVERSIONS
- #define JSON_EXPLICIT
- #else
- #define JSON_EXPLICIT explicit
- #endif
- #ifndef JSON_DIAGNOSTICS
- #define JSON_DIAGNOSTICS 0
- #endif
- namespace nlohmann
- {
- namespace detail
- {
- inline void replace_substring(std::string& s, const std::string& f,
- const std::string& t)
- {
- JSON_ASSERT(!f.empty());
- for (auto pos = s.find(f);
- pos != std::string::npos;
- s.replace(pos, f.size(), t),
- pos = s.find(f, pos + t.size()))
- {}
- }
- inline std::string escape(std::string s)
- {
- replace_substring(s, "~", "~0");
- replace_substring(s, "/", "~1");
- return s;
- }
- static void unescape(std::string& s)
- {
- replace_substring(s, "~1", "/");
- replace_substring(s, "~0", "~");
- }
- }
- }
- #include <cstddef> // size_t
- namespace nlohmann
- {
- namespace detail
- {
- struct position_t
- {
-
- std::size_t chars_read_total = 0;
-
- std::size_t chars_read_current_line = 0;
-
- std::size_t lines_read = 0;
-
- constexpr operator size_t() const
- {
- return chars_read_total;
- }
- };
- }
- }
- namespace nlohmann
- {
- namespace detail
- {
- class exception : public std::exception
- {
- public:
-
- const char* what() const noexcept override
- {
- return m.what();
- }
-
- const int id;
- protected:
- JSON_HEDLEY_NON_NULL(3)
- exception(int id_, const char* what_arg) : id(id_), m(what_arg) {}
- static std::string name(const std::string& ename, int id_)
- {
- return "[json.exception." + ename + "." + std::to_string(id_) + "] ";
- }
- template<typename BasicJsonType>
- static std::string diagnostics(const BasicJsonType& leaf_element)
- {
- #if JSON_DIAGNOSTICS
- std::vector<std::string> tokens;
- for (const auto* current = &leaf_element; current->m_parent != nullptr; current = current->m_parent)
- {
- switch (current->m_parent->type())
- {
- case value_t::array:
- {
- for (std::size_t i = 0; i < current->m_parent->m_value.array->size(); ++i)
- {
- if (¤t->m_parent->m_value.array->operator[](i) == current)
- {
- tokens.emplace_back(std::to_string(i));
- break;
- }
- }
- break;
- }
- case value_t::object:
- {
- for (const auto& element : *current->m_parent->m_value.object)
- {
- if (&element.second == current)
- {
- tokens.emplace_back(element.first.c_str());
- break;
- }
- }
- break;
- }
- case value_t::null:
- case value_t::string:
- case value_t::boolean:
- case value_t::number_integer:
- case value_t::number_unsigned:
- case value_t::number_float:
- case value_t::binary:
- case value_t::discarded:
- default:
- break;
- }
- }
- if (tokens.empty())
- {
- return "";
- }
- return "(" + std::accumulate(tokens.rbegin(), tokens.rend(), std::string{},
- [](const std::string & a, const std::string & b)
- {
- return a + "/" + detail::escape(b);
- }) + ") ";
- #else
- static_cast<void>(leaf_element);
- return "";
- #endif
- }
- private:
-
- std::runtime_error m;
- };
- class parse_error : public exception
- {
- public:
-
- template<typename BasicJsonType>
- static parse_error create(int id_, const position_t& pos, const std::string& what_arg, const BasicJsonType& context)
- {
- std::string w = exception::name("parse_error", id_) + "parse error" +
- position_string(pos) + ": " + exception::diagnostics(context) + what_arg;
- return parse_error(id_, pos.chars_read_total, w.c_str());
- }
- template<typename BasicJsonType>
- static parse_error create(int id_, std::size_t byte_, const std::string& what_arg, const BasicJsonType& context)
- {
- std::string w = exception::name("parse_error", id_) + "parse error" +
- (byte_ != 0 ? (" at byte " + std::to_string(byte_)) : "") +
- ": " + exception::diagnostics(context) + what_arg;
- return parse_error(id_, byte_, w.c_str());
- }
-
- const std::size_t byte;
- private:
- parse_error(int id_, std::size_t byte_, const char* what_arg)
- : exception(id_, what_arg), byte(byte_) {}
- static std::string position_string(const position_t& pos)
- {
- return " at line " + std::to_string(pos.lines_read + 1) +
- ", column " + std::to_string(pos.chars_read_current_line);
- }
- };
- class invalid_iterator : public exception
- {
- public:
- template<typename BasicJsonType>
- static invalid_iterator create(int id_, const std::string& what_arg, const BasicJsonType& context)
- {
- std::string w = exception::name("invalid_iterator", id_) + exception::diagnostics(context) + what_arg;
- return invalid_iterator(id_, w.c_str());
- }
- private:
- JSON_HEDLEY_NON_NULL(3)
- invalid_iterator(int id_, const char* what_arg)
- : exception(id_, what_arg) {}
- };
- class type_error : public exception
- {
- public:
- template<typename BasicJsonType>
- static type_error create(int id_, const std::string& what_arg, const BasicJsonType& context)
- {
- std::string w = exception::name("type_error", id_) + exception::diagnostics(context) + what_arg;
- return type_error(id_, w.c_str());
- }
- private:
- JSON_HEDLEY_NON_NULL(3)
- type_error(int id_, const char* what_arg) : exception(id_, what_arg) {}
- };
- class out_of_range : public exception
- {
- public:
- template<typename BasicJsonType>
- static out_of_range create(int id_, const std::string& what_arg, const BasicJsonType& context)
- {
- std::string w = exception::name("out_of_range", id_) + exception::diagnostics(context) + what_arg;
- return out_of_range(id_, w.c_str());
- }
- private:
- JSON_HEDLEY_NON_NULL(3)
- out_of_range(int id_, const char* what_arg) : exception(id_, what_arg) {}
- };
- class other_error : public exception
- {
- public:
- template<typename BasicJsonType>
- static other_error create(int id_, const std::string& what_arg, const BasicJsonType& context)
- {
- std::string w = exception::name("other_error", id_) + exception::diagnostics(context) + what_arg;
- return other_error(id_, w.c_str());
- }
- private:
- JSON_HEDLEY_NON_NULL(3)
- other_error(int id_, const char* what_arg) : exception(id_, what_arg) {}
- };
- }
- }
- #include <cstddef> // size_t
- #include <type_traits> // conditional, enable_if, false_type, integral_constant, is_constructible, is_integral, is_same, remove_cv, remove_reference, true_type
- #include <utility> // index_sequence, make_index_sequence, index_sequence_for
- namespace nlohmann
- {
- namespace detail
- {
- template<typename T>
- using uncvref_t = typename std::remove_cv<typename std::remove_reference<T>::type>::type;
- #ifdef JSON_HAS_CPP_14
- using std::enable_if_t;
- using std::index_sequence;
- using std::make_index_sequence;
- using std::index_sequence_for;
- #else
- template<bool B, typename T = void>
- using enable_if_t = typename std::enable_if<B, T>::type;
- template <typename T, T... Ints>
- struct integer_sequence
- {
- using value_type = T;
- static constexpr std::size_t size() noexcept
- {
- return sizeof...(Ints);
- }
- };
- template <size_t... Ints>
- using index_sequence = integer_sequence<size_t, Ints...>;
- namespace utility_internal
- {
- template <typename Seq, size_t SeqSize, size_t Rem>
- struct Extend;
- template <typename T, T... Ints, size_t SeqSize>
- struct Extend<integer_sequence<T, Ints...>, SeqSize, 0>
- {
- using type = integer_sequence < T, Ints..., (Ints + SeqSize)... >;
- };
- template <typename T, T... Ints, size_t SeqSize>
- struct Extend<integer_sequence<T, Ints...>, SeqSize, 1>
- {
- using type = integer_sequence < T, Ints..., (Ints + SeqSize)..., 2 * SeqSize >;
- };
- template <typename T, size_t N>
- struct Gen
- {
- using type =
- typename Extend < typename Gen < T, N / 2 >::type, N / 2, N % 2 >::type;
- };
- template <typename T>
- struct Gen<T, 0>
- {
- using type = integer_sequence<T>;
- };
- }
- template <typename T, T N>
- using make_integer_sequence = typename utility_internal::Gen<T, N>::type;
- template <size_t N>
- using make_index_sequence = make_integer_sequence<size_t, N>;
- template <typename... Ts>
- using index_sequence_for = make_index_sequence<sizeof...(Ts)>;
- #endif
- template<unsigned N> struct priority_tag : priority_tag < N - 1 > {};
- template<> struct priority_tag<0> {};
- template<typename T>
- struct static_const
- {
- static constexpr T value{};
- };
- template<typename T>
- constexpr T static_const<T>::value;
- }
- }
- namespace nlohmann
- {
- namespace detail
- {
- template <class T> struct identity_tag {};
- }
- }
- #include <limits> // numeric_limits
- #include <type_traits> // false_type, is_constructible, is_integral, is_same, true_type
- #include <utility> // declval
- #include <tuple> // tuple
- #include <iterator> // random_access_iterator_tag
- namespace nlohmann
- {
- namespace detail
- {
- template<typename It, typename = void>
- struct iterator_types {};
- template<typename It>
- struct iterator_types <
- It,
- void_t<typename It::difference_type, typename It::value_type, typename It::pointer,
- typename It::reference, typename It::iterator_category >>
- {
- using difference_type = typename It::difference_type;
- using value_type = typename It::value_type;
- using pointer = typename It::pointer;
- using reference = typename It::reference;
- using iterator_category = typename It::iterator_category;
- };
- template<typename T, typename = void>
- struct iterator_traits
- {
- };
- template<typename T>
- struct iterator_traits < T, enable_if_t < !std::is_pointer<T>::value >>
- : iterator_types<T>
- {
- };
- template<typename T>
- struct iterator_traits<T*, enable_if_t<std::is_object<T>::value>>
- {
- using iterator_category = std::random_access_iterator_tag;
- using value_type = T;
- using difference_type = ptrdiff_t;
- using pointer = T*;
- using reference = T&;
- };
- }
- }
- namespace nlohmann
- {
- NLOHMANN_CAN_CALL_STD_FUNC_IMPL(begin);
- }
- namespace nlohmann
- {
- NLOHMANN_CAN_CALL_STD_FUNC_IMPL(end);
- }
- #ifndef INCLUDE_NLOHMANN_JSON_FWD_HPP_
- #define INCLUDE_NLOHMANN_JSON_FWD_HPP_
- #include <cstdint> // int64_t, uint64_t
- #include <map> // map
- #include <memory> // allocator
- #include <string> // string
- #include <vector> // vector
- namespace nlohmann
- {
- template<typename T = void, typename SFINAE = void>
- struct adl_serializer;
- template<template<typename U, typename V, typename... Args> class ObjectType =
- std::map,
- template<typename U, typename... Args> class ArrayType = std::vector,
- class StringType = std::string, class BooleanType = bool,
- class NumberIntegerType = std::int64_t,
- class NumberUnsignedType = std::uint64_t,
- class NumberFloatType = double,
- template<typename U> class AllocatorType = std::allocator,
- template<typename T, typename SFINAE = void> class JSONSerializer =
- adl_serializer,
- class BinaryType = std::vector<std::uint8_t>>
- class basic_json;
- template<typename BasicJsonType>
- class json_pointer;
- using json = basic_json<>;
- template<class Key, class T, class IgnoredLess, class Allocator>
- struct ordered_map;
- using ordered_json = basic_json<nlohmann::ordered_map>;
- }
- #endif
- namespace nlohmann
- {
- namespace detail
- {
- template<typename> struct is_basic_json : std::false_type {};
- NLOHMANN_BASIC_JSON_TPL_DECLARATION
- struct is_basic_json<NLOHMANN_BASIC_JSON_TPL> : std::true_type {};
- template<typename>
- class json_ref;
- template<typename>
- struct is_json_ref : std::false_type {};
- template<typename T>
- struct is_json_ref<json_ref<T>> : std::true_type {};
- template<typename T>
- using mapped_type_t = typename T::mapped_type;
- template<typename T>
- using key_type_t = typename T::key_type;
- template<typename T>
- using value_type_t = typename T::value_type;
- template<typename T>
- using difference_type_t = typename T::difference_type;
- template<typename T>
- using pointer_t = typename T::pointer;
- template<typename T>
- using reference_t = typename T::reference;
- template<typename T>
- using iterator_category_t = typename T::iterator_category;
- template<typename T, typename... Args>
- using to_json_function = decltype(T::to_json(std::declval<Args>()...));
- template<typename T, typename... Args>
- using from_json_function = decltype(T::from_json(std::declval<Args>()...));
- template<typename T, typename U>
- using get_template_function = decltype(std::declval<T>().template get<U>());
- template<typename BasicJsonType, typename T, typename = void>
- struct has_from_json : std::false_type {};
- template <typename BasicJsonType, typename T>
- struct is_getable
- {
- static constexpr bool value = is_detected<get_template_function, const BasicJsonType&, T>::value;
- };
- template<typename BasicJsonType, typename T>
- struct has_from_json < BasicJsonType, T, enable_if_t < !is_basic_json<T>::value >>
- {
- using serializer = typename BasicJsonType::template json_serializer<T, void>;
- static constexpr bool value =
- is_detected_exact<void, from_json_function, serializer,
- const BasicJsonType&, T&>::value;
- };
- template<typename BasicJsonType, typename T, typename = void>
- struct has_non_default_from_json : std::false_type {};
- template<typename BasicJsonType, typename T>
- struct has_non_default_from_json < BasicJsonType, T, enable_if_t < !is_basic_json<T>::value >>
- {
- using serializer = typename BasicJsonType::template json_serializer<T, void>;
- static constexpr bool value =
- is_detected_exact<T, from_json_function, serializer,
- const BasicJsonType&>::value;
- };
- template<typename BasicJsonType, typename T, typename = void>
- struct has_to_json : std::false_type {};
- template<typename BasicJsonType, typename T>
- struct has_to_json < BasicJsonType, T, enable_if_t < !is_basic_json<T>::value >>
- {
- using serializer = typename BasicJsonType::template json_serializer<T, void>;
- static constexpr bool value =
- is_detected_exact<void, to_json_function, serializer, BasicJsonType&,
- T>::value;
- };
- template<class...> struct conjunction : std::true_type { };
- template<class B1> struct conjunction<B1> : B1 { };
- template<class B1, class... Bn>
- struct conjunction<B1, Bn...>
- : std::conditional<bool(B1::value), conjunction<Bn...>, B1>::type {};
- template<class B> struct negation : std::integral_constant < bool, !B::value > { };
- template <typename T>
- struct is_default_constructible : std::is_default_constructible<T> {};
- template <typename T1, typename T2>
- struct is_default_constructible<std::pair<T1, T2>>
- : conjunction<is_default_constructible<T1>, is_default_constructible<T2>> {};
- template <typename T1, typename T2>
- struct is_default_constructible<const std::pair<T1, T2>>
- : conjunction<is_default_constructible<T1>, is_default_constructible<T2>> {};
- template <typename... Ts>
- struct is_default_constructible<std::tuple<Ts...>>
- : conjunction<is_default_constructible<Ts>...> {};
- template <typename... Ts>
- struct is_default_constructible<const std::tuple<Ts...>>
- : conjunction<is_default_constructible<Ts>...> {};
- template <typename T, typename... Args>
- struct is_constructible : std::is_constructible<T, Args...> {};
- template <typename T1, typename T2>
- struct is_constructible<std::pair<T1, T2>> : is_default_constructible<std::pair<T1, T2>> {};
- template <typename T1, typename T2>
- struct is_constructible<const std::pair<T1, T2>> : is_default_constructible<const std::pair<T1, T2>> {};
- template <typename... Ts>
- struct is_constructible<std::tuple<Ts...>> : is_default_constructible<std::tuple<Ts...>> {};
- template <typename... Ts>
- struct is_constructible<const std::tuple<Ts...>> : is_default_constructible<const std::tuple<Ts...>> {};
- template<typename T, typename = void>
- struct is_iterator_traits : std::false_type {};
- template<typename T>
- struct is_iterator_traits<iterator_traits<T>>
- {
- private:
- using traits = iterator_traits<T>;
- public:
- static constexpr auto value =
- is_detected<value_type_t, traits>::value &&
- is_detected<difference_type_t, traits>::value &&
- is_detected<pointer_t, traits>::value &&
- is_detected<iterator_category_t, traits>::value &&
- is_detected<reference_t, traits>::value;
- };
- template<typename T>
- struct is_range
- {
- private:
- using t_ref = typename std::add_lvalue_reference<T>::type;
- using iterator = detected_t<result_of_begin, t_ref>;
- using sentinel = detected_t<result_of_end, t_ref>;
-
-
-
- static constexpr auto is_iterator_begin =
- is_iterator_traits<iterator_traits<iterator>>::value;
- public:
- static constexpr bool value = !std::is_same<iterator, nonesuch>::value && !std::is_same<sentinel, nonesuch>::value && is_iterator_begin;
- };
- template<typename R>
- using iterator_t = enable_if_t<is_range<R>::value, result_of_begin<decltype(std::declval<R&>())>>;
- template<typename T>
- using range_value_t = value_type_t<iterator_traits<iterator_t<T>>>;
- template<typename T, typename = void>
- struct is_complete_type : std::false_type {};
- template<typename T>
- struct is_complete_type<T, decltype(void(sizeof(T)))> : std::true_type {};
- template<typename BasicJsonType, typename CompatibleObjectType,
- typename = void>
- struct is_compatible_object_type_impl : std::false_type {};
- template<typename BasicJsonType, typename CompatibleObjectType>
- struct is_compatible_object_type_impl <
- BasicJsonType, CompatibleObjectType,
- enable_if_t < is_detected<mapped_type_t, CompatibleObjectType>::value&&
- is_detected<key_type_t, CompatibleObjectType>::value >>
- {
- using object_t = typename BasicJsonType::object_t;
-
- static constexpr bool value =
- is_constructible<typename object_t::key_type,
- typename CompatibleObjectType::key_type>::value &&
- is_constructible<typename object_t::mapped_type,
- typename CompatibleObjectType::mapped_type>::value;
- };
- template<typename BasicJsonType, typename CompatibleObjectType>
- struct is_compatible_object_type
- : is_compatible_object_type_impl<BasicJsonType, CompatibleObjectType> {};
- template<typename BasicJsonType, typename ConstructibleObjectType,
- typename = void>
- struct is_constructible_object_type_impl : std::false_type {};
- template<typename BasicJsonType, typename ConstructibleObjectType>
- struct is_constructible_object_type_impl <
- BasicJsonType, ConstructibleObjectType,
- enable_if_t < is_detected<mapped_type_t, ConstructibleObjectType>::value&&
- is_detected<key_type_t, ConstructibleObjectType>::value >>
- {
- using object_t = typename BasicJsonType::object_t;
- static constexpr bool value =
- (is_default_constructible<ConstructibleObjectType>::value &&
- (std::is_move_assignable<ConstructibleObjectType>::value ||
- std::is_copy_assignable<ConstructibleObjectType>::value) &&
- (is_constructible<typename ConstructibleObjectType::key_type,
- typename object_t::key_type>::value &&
- std::is_same <
- typename object_t::mapped_type,
- typename ConstructibleObjectType::mapped_type >::value)) ||
- (has_from_json<BasicJsonType,
- typename ConstructibleObjectType::mapped_type>::value ||
- has_non_default_from_json <
- BasicJsonType,
- typename ConstructibleObjectType::mapped_type >::value);
- };
- template<typename BasicJsonType, typename ConstructibleObjectType>
- struct is_constructible_object_type
- : is_constructible_object_type_impl<BasicJsonType,
- ConstructibleObjectType> {};
- template<typename BasicJsonType, typename CompatibleStringType>
- struct is_compatible_string_type
- {
- static constexpr auto value =
- is_constructible<typename BasicJsonType::string_t, CompatibleStringType>::value;
- };
- template<typename BasicJsonType, typename ConstructibleStringType>
- struct is_constructible_string_type
- {
- static constexpr auto value =
- is_constructible<ConstructibleStringType,
- typename BasicJsonType::string_t>::value;
- };
- template<typename BasicJsonType, typename CompatibleArrayType, typename = void>
- struct is_compatible_array_type_impl : std::false_type {};
- template<typename BasicJsonType, typename CompatibleArrayType>
- struct is_compatible_array_type_impl <
- BasicJsonType, CompatibleArrayType,
- enable_if_t <
- is_detected<iterator_t, CompatibleArrayType>::value&&
- is_iterator_traits<iterator_traits<detected_t<iterator_t, CompatibleArrayType>>>::value&&
- !std::is_same<CompatibleArrayType, detected_t<range_value_t, CompatibleArrayType>>::value >>
- {
- static constexpr bool value =
- is_constructible<BasicJsonType,
- range_value_t<CompatibleArrayType>>::value;
- };
- template<typename BasicJsonType, typename CompatibleArrayType>
- struct is_compatible_array_type
- : is_compatible_array_type_impl<BasicJsonType, CompatibleArrayType> {};
- template<typename BasicJsonType, typename ConstructibleArrayType, typename = void>
- struct is_constructible_array_type_impl : std::false_type {};
- template<typename BasicJsonType, typename ConstructibleArrayType>
- struct is_constructible_array_type_impl <
- BasicJsonType, ConstructibleArrayType,
- enable_if_t<std::is_same<ConstructibleArrayType,
- typename BasicJsonType::value_type>::value >>
- : std::true_type {};
- template<typename BasicJsonType, typename ConstructibleArrayType>
- struct is_constructible_array_type_impl <
- BasicJsonType, ConstructibleArrayType,
- enable_if_t < !std::is_same<ConstructibleArrayType,
- typename BasicJsonType::value_type>::value&&
- !is_compatible_string_type<BasicJsonType, ConstructibleArrayType>::value&&
- is_default_constructible<ConstructibleArrayType>::value&&
- (std::is_move_assignable<ConstructibleArrayType>::value ||
- std::is_copy_assignable<ConstructibleArrayType>::value)&&
- is_detected<iterator_t, ConstructibleArrayType>::value&&
- is_iterator_traits<iterator_traits<detected_t<iterator_t, ConstructibleArrayType>>>::value&&
- is_detected<range_value_t, ConstructibleArrayType>::value&&
- !std::is_same<ConstructibleArrayType, detected_t<range_value_t, ConstructibleArrayType>>::value&&
- is_complete_type <
- detected_t<range_value_t, ConstructibleArrayType >>::value >>
- {
- using value_type = range_value_t<ConstructibleArrayType>;
- static constexpr bool value =
- std::is_same<value_type,
- typename BasicJsonType::array_t::value_type>::value ||
- has_from_json<BasicJsonType,
- value_type>::value ||
- has_non_default_from_json <
- BasicJsonType,
- value_type >::value;
- };
- template<typename BasicJsonType, typename ConstructibleArrayType>
- struct is_constructible_array_type
- : is_constructible_array_type_impl<BasicJsonType, ConstructibleArrayType> {};
- template<typename RealIntegerType, typename CompatibleNumberIntegerType,
- typename = void>
- struct is_compatible_integer_type_impl : std::false_type {};
- template<typename RealIntegerType, typename CompatibleNumberIntegerType>
- struct is_compatible_integer_type_impl <
- RealIntegerType, CompatibleNumberIntegerType,
- enable_if_t < std::is_integral<RealIntegerType>::value&&
- std::is_integral<CompatibleNumberIntegerType>::value&&
- !std::is_same<bool, CompatibleNumberIntegerType>::value >>
- {
-
- using RealLimits = std::numeric_limits<RealIntegerType>;
- using CompatibleLimits = std::numeric_limits<CompatibleNumberIntegerType>;
- static constexpr auto value =
- is_constructible<RealIntegerType,
- CompatibleNumberIntegerType>::value &&
- CompatibleLimits::is_integer &&
- RealLimits::is_signed == CompatibleLimits::is_signed;
- };
- template<typename RealIntegerType, typename CompatibleNumberIntegerType>
- struct is_compatible_integer_type
- : is_compatible_integer_type_impl<RealIntegerType,
- CompatibleNumberIntegerType> {};
- template<typename BasicJsonType, typename CompatibleType, typename = void>
- struct is_compatible_type_impl: std::false_type {};
- template<typename BasicJsonType, typename CompatibleType>
- struct is_compatible_type_impl <
- BasicJsonType, CompatibleType,
- enable_if_t<is_complete_type<CompatibleType>::value >>
- {
- static constexpr bool value =
- has_to_json<BasicJsonType, CompatibleType>::value;
- };
- template<typename BasicJsonType, typename CompatibleType>
- struct is_compatible_type
- : is_compatible_type_impl<BasicJsonType, CompatibleType> {};
- template<typename T1, typename T2>
- struct is_constructible_tuple : std::false_type {};
- template<typename T1, typename... Args>
- struct is_constructible_tuple<T1, std::tuple<Args...>> : conjunction<is_constructible<T1, Args>...> {};
- template <typename T>
- struct is_ordered_map
- {
- using one = char;
- struct two
- {
- char x[2];
- };
- template <typename C> static one test( decltype(&C::capacity) ) ;
- template <typename C> static two test(...);
- enum { value = sizeof(test<T>(nullptr)) == sizeof(char) };
- };
- template < typename T, typename U, enable_if_t < !std::is_same<T, U>::value, int > = 0 >
- T conditional_static_cast(U value)
- {
- return static_cast<T>(value);
- }
- template<typename T, typename U, enable_if_t<std::is_same<T, U>::value, int> = 0>
- T conditional_static_cast(U value)
- {
- return value;
- }
- }
- }
- #ifdef JSON_HAS_CPP_17
-
- #include <boost/filesystem.hpp>
- #endif
- namespace nlohmann
- {
- namespace detail
- {
- template<typename BasicJsonType>
- void from_json(const BasicJsonType& j, typename std::nullptr_t& n)
- {
- if (JSON_HEDLEY_UNLIKELY(!j.is_null()))
- {
- JSON_THROW(type_error::create(302, "type must be null, but is " + std::string(j.type_name()), j));
- }
- n = nullptr;
- }
- template < typename BasicJsonType, typename ArithmeticType,
- enable_if_t < std::is_arithmetic<ArithmeticType>::value&&
- !std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value,
- int > = 0 >
- void get_arithmetic_value(const BasicJsonType& j, ArithmeticType& val)
- {
- switch (static_cast<value_t>(j))
- {
- case value_t::number_unsigned:
- {
- val = static_cast<ArithmeticType>(*j.template get_ptr<const typename BasicJsonType::number_unsigned_t*>());
- break;
- }
- case value_t::number_integer:
- {
- val = static_cast<ArithmeticType>(*j.template get_ptr<const typename BasicJsonType::number_integer_t*>());
- break;
- }
- case value_t::number_float:
- {
- val = static_cast<ArithmeticType>(*j.template get_ptr<const typename BasicJsonType::number_float_t*>());
- break;
- }
- case value_t::null:
- case value_t::object:
- case value_t::array:
- case value_t::string:
- case value_t::boolean:
- case value_t::binary:
- case value_t::discarded:
- default:
- JSON_THROW(type_error::create(302, "type must be number, but is " + std::string(j.type_name()), j));
- }
- }
- template<typename BasicJsonType>
- void from_json(const BasicJsonType& j, typename BasicJsonType::boolean_t& b)
- {
- if (JSON_HEDLEY_UNLIKELY(!j.is_boolean()))
- {
- JSON_THROW(type_error::create(302, "type must be boolean, but is " + std::string(j.type_name()), j));
- }
- b = *j.template get_ptr<const typename BasicJsonType::boolean_t*>();
- }
- template<typename BasicJsonType>
- void from_json(const BasicJsonType& j, typename BasicJsonType::string_t& s)
- {
- if (JSON_HEDLEY_UNLIKELY(!j.is_string()))
- {
- JSON_THROW(type_error::create(302, "type must be string, but is " + std::string(j.type_name()), j));
- }
- s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
- }
- template <
- typename BasicJsonType, typename ConstructibleStringType,
- enable_if_t <
- is_constructible_string_type<BasicJsonType, ConstructibleStringType>::value&&
- !std::is_same<typename BasicJsonType::string_t,
- ConstructibleStringType>::value,
- int > = 0 >
- void from_json(const BasicJsonType& j, ConstructibleStringType& s)
- {
- if (JSON_HEDLEY_UNLIKELY(!j.is_string()))
- {
- JSON_THROW(type_error::create(302, "type must be string, but is " + std::string(j.type_name()), j));
- }
- s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
- }
- template<typename BasicJsonType>
- void from_json(const BasicJsonType& j, typename BasicJsonType::number_float_t& val)
- {
- get_arithmetic_value(j, val);
- }
- template<typename BasicJsonType>
- void from_json(const BasicJsonType& j, typename BasicJsonType::number_unsigned_t& val)
- {
- get_arithmetic_value(j, val);
- }
- template<typename BasicJsonType>
- void from_json(const BasicJsonType& j, typename BasicJsonType::number_integer_t& val)
- {
- get_arithmetic_value(j, val);
- }
- template<typename BasicJsonType, typename EnumType,
- enable_if_t<std::is_enum<EnumType>::value, int> = 0>
- void from_json(const BasicJsonType& j, EnumType& e)
- {
- typename std::underlying_type<EnumType>::type val;
- get_arithmetic_value(j, val);
- e = static_cast<EnumType>(val);
- }
- template<typename BasicJsonType, typename T, typename Allocator,
- enable_if_t<is_getable<BasicJsonType, T>::value, int> = 0>
- void from_json(const BasicJsonType& j, std::forward_list<T, Allocator>& l)
- {
- if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
- {
- JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name()), j));
- }
- l.clear();
- std::transform(j.rbegin(), j.rend(),
- std::front_inserter(l), [](const BasicJsonType & i)
- {
- return i.template get<T>();
- });
- }
- template<typename BasicJsonType, typename T,
- enable_if_t<is_getable<BasicJsonType, T>::value, int> = 0>
- void from_json(const BasicJsonType& j, std::valarray<T>& l)
- {
- if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
- {
- JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name()), j));
- }
- l.resize(j.size());
- std::transform(j.begin(), j.end(), std::begin(l),
- [](const BasicJsonType & elem)
- {
- return elem.template get<T>();
- });
- }
- template<typename BasicJsonType, typename T, std::size_t N>
- auto from_json(const BasicJsonType& j, T (&arr)[N])
- -> decltype(j.template get<T>(), void())
- {
- for (std::size_t i = 0; i < N; ++i)
- {
- arr[i] = j.at(i).template get<T>();
- }
- }
- template<typename BasicJsonType>
- void from_json_array_impl(const BasicJsonType& j, typename BasicJsonType::array_t& arr, priority_tag<3> )
- {
- arr = *j.template get_ptr<const typename BasicJsonType::array_t*>();
- }
- template<typename BasicJsonType, typename T, std::size_t N>
- auto from_json_array_impl(const BasicJsonType& j, std::array<T, N>& arr,
- priority_tag<2> )
- -> decltype(j.template get<T>(), void())
- {
- for (std::size_t i = 0; i < N; ++i)
- {
- arr[i] = j.at(i).template get<T>();
- }
- }
- template<typename BasicJsonType, typename ConstructibleArrayType,
- enable_if_t<
- std::is_assignable<ConstructibleArrayType&, ConstructibleArrayType>::value,
- int> = 0>
- auto from_json_array_impl(const BasicJsonType& j, ConstructibleArrayType& arr, priority_tag<1> )
- -> decltype(
- arr.reserve(std::declval<typename ConstructibleArrayType::size_type>()),
- j.template get<typename ConstructibleArrayType::value_type>(),
- void())
- {
- using std::end;
- ConstructibleArrayType ret;
- ret.reserve(j.size());
- std::transform(j.begin(), j.end(),
- std::inserter(ret, end(ret)), [](const BasicJsonType & i)
- {
-
-
- return i.template get<typename ConstructibleArrayType::value_type>();
- });
- arr = std::move(ret);
- }
- template<typename BasicJsonType, typename ConstructibleArrayType,
- enable_if_t<
- std::is_assignable<ConstructibleArrayType&, ConstructibleArrayType>::value,
- int> = 0>
- void from_json_array_impl(const BasicJsonType& j, ConstructibleArrayType& arr,
- priority_tag<0> )
- {
- using std::end;
- ConstructibleArrayType ret;
- std::transform(
- j.begin(), j.end(), std::inserter(ret, end(ret)),
- [](const BasicJsonType & i)
- {
-
-
- return i.template get<typename ConstructibleArrayType::value_type>();
- });
- arr = std::move(ret);
- }
- template < typename BasicJsonType, typename ConstructibleArrayType,
- enable_if_t <
- is_constructible_array_type<BasicJsonType, ConstructibleArrayType>::value&&
- !is_constructible_object_type<BasicJsonType, ConstructibleArrayType>::value&&
- !is_constructible_string_type<BasicJsonType, ConstructibleArrayType>::value&&
- !std::is_same<ConstructibleArrayType, typename BasicJsonType::binary_t>::value&&
- !is_basic_json<ConstructibleArrayType>::value,
- int > = 0 >
- auto from_json(const BasicJsonType& j, ConstructibleArrayType& arr)
- -> decltype(from_json_array_impl(j, arr, priority_tag<3> {}),
- j.template get<typename ConstructibleArrayType::value_type>(),
- void())
- {
- if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
- {
- JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name()), j));
- }
- from_json_array_impl(j, arr, priority_tag<3> {});
- }
- template < typename BasicJsonType, typename T, std::size_t... Idx >
- std::array<T, sizeof...(Idx)> from_json_inplace_array_impl(BasicJsonType&& j,
- identity_tag<std::array<T, sizeof...(Idx)>> , index_sequence<Idx...> )
- {
- return { { std::forward<BasicJsonType>(j).at(Idx).template get<T>()... } };
- }
- template < typename BasicJsonType, typename T, std::size_t N >
- auto from_json(BasicJsonType&& j, identity_tag<std::array<T, N>> tag)
- -> decltype(from_json_inplace_array_impl(std::forward<BasicJsonType>(j), tag, make_index_sequence<N> {}))
- {
- if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
- {
- JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name()), j));
- }
- return from_json_inplace_array_impl(std::forward<BasicJsonType>(j), tag, make_index_sequence<N> {});
- }
- template<typename BasicJsonType>
- void from_json(const BasicJsonType& j, typename BasicJsonType::binary_t& bin)
- {
- if (JSON_HEDLEY_UNLIKELY(!j.is_binary()))
- {
- JSON_THROW(type_error::create(302, "type must be binary, but is " + std::string(j.type_name()), j));
- }
- bin = *j.template get_ptr<const typename BasicJsonType::binary_t*>();
- }
- template<typename BasicJsonType, typename ConstructibleObjectType,
- enable_if_t<is_constructible_object_type<BasicJsonType, ConstructibleObjectType>::value, int> = 0>
- void from_json(const BasicJsonType& j, ConstructibleObjectType& obj)
- {
- if (JSON_HEDLEY_UNLIKELY(!j.is_object()))
- {
- JSON_THROW(type_error::create(302, "type must be object, but is " + std::string(j.type_name()), j));
- }
- ConstructibleObjectType ret;
- const auto* inner_object = j.template get_ptr<const typename BasicJsonType::object_t*>();
- using value_type = typename ConstructibleObjectType::value_type;
- std::transform(
- inner_object->begin(), inner_object->end(),
- std::inserter(ret, ret.begin()),
- [](typename BasicJsonType::object_t::value_type const & p)
- {
- return value_type(p.first, p.second.template get<typename ConstructibleObjectType::mapped_type>());
- });
- obj = std::move(ret);
- }
- template < typename BasicJsonType, typename ArithmeticType,
- enable_if_t <
- std::is_arithmetic<ArithmeticType>::value&&
- !std::is_same<ArithmeticType, typename BasicJsonType::number_unsigned_t>::value&&
- !std::is_same<ArithmeticType, typename BasicJsonType::number_integer_t>::value&&
- !std::is_same<ArithmeticType, typename BasicJsonType::number_float_t>::value&&
- !std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value,
- int > = 0 >
- void from_json(const BasicJsonType& j, ArithmeticType& val)
- {
- switch (static_cast<value_t>(j))
- {
- case value_t::number_unsigned:
- {
- val = static_cast<ArithmeticType>(*j.template get_ptr<const typename BasicJsonType::number_unsigned_t*>());
- break;
- }
- case value_t::number_integer:
- {
- val = static_cast<ArithmeticType>(*j.template get_ptr<const typename BasicJsonType::number_integer_t*>());
- break;
- }
- case value_t::number_float:
- {
- val = static_cast<ArithmeticType>(*j.template get_ptr<const typename BasicJsonType::number_float_t*>());
- break;
- }
- case value_t::boolean:
- {
- val = static_cast<ArithmeticType>(*j.template get_ptr<const typename BasicJsonType::boolean_t*>());
- break;
- }
- case value_t::null:
- case value_t::object:
- case value_t::array:
- case value_t::string:
- case value_t::binary:
- case value_t::discarded:
- default:
- JSON_THROW(type_error::create(302, "type must be number, but is " + std::string(j.type_name()), j));
- }
- }
- template<typename BasicJsonType, typename... Args, std::size_t... Idx>
- std::tuple<Args...> from_json_tuple_impl_base(BasicJsonType&& j, index_sequence<Idx...> )
- {
- return std::make_tuple(std::forward<BasicJsonType>(j).at(Idx).template get<Args>()...);
- }
- template < typename BasicJsonType, class A1, class A2 >
- std::pair<A1, A2> from_json_tuple_impl(BasicJsonType&& j, identity_tag<std::pair<A1, A2>> , priority_tag<0> )
- {
- return {std::forward<BasicJsonType>(j).at(0).template get<A1>(),
- std::forward<BasicJsonType>(j).at(1).template get<A2>()};
- }
- template<typename BasicJsonType, typename A1, typename A2>
- void from_json_tuple_impl(BasicJsonType&& j, std::pair<A1, A2>& p, priority_tag<1> )
- {
- p = from_json_tuple_impl(std::forward<BasicJsonType>(j), identity_tag<std::pair<A1, A2>> {}, priority_tag<0> {});
- }
- template<typename BasicJsonType, typename... Args>
- std::tuple<Args...> from_json_tuple_impl(BasicJsonType&& j, identity_tag<std::tuple<Args...>> , priority_tag<2> )
- {
- return from_json_tuple_impl_base<BasicJsonType, Args...>(std::forward<BasicJsonType>(j), index_sequence_for<Args...> {});
- }
- template<typename BasicJsonType, typename... Args>
- void from_json_tuple_impl(BasicJsonType&& j, std::tuple<Args...>& t, priority_tag<3> )
- {
- t = from_json_tuple_impl_base<BasicJsonType, Args...>(std::forward<BasicJsonType>(j), index_sequence_for<Args...> {});
- }
- template<typename BasicJsonType, typename TupleRelated>
- auto from_json(BasicJsonType&& j, TupleRelated&& t)
- -> decltype(from_json_tuple_impl(std::forward<BasicJsonType>(j), std::forward<TupleRelated>(t), priority_tag<3> {}))
- {
- if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
- {
- JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name()), j));
- }
- return from_json_tuple_impl(std::forward<BasicJsonType>(j), std::forward<TupleRelated>(t), priority_tag<3> {});
- }
- template < typename BasicJsonType, typename Key, typename Value, typename Compare, typename Allocator,
- typename = enable_if_t < !std::is_constructible <
- typename BasicJsonType::string_t, Key >::value >>
- void from_json(const BasicJsonType& j, std::map<Key, Value, Compare, Allocator>& m)
- {
- if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
- {
- JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name()), j));
- }
- m.clear();
- for (const auto& p : j)
- {
- if (JSON_HEDLEY_UNLIKELY(!p.is_array()))
- {
- JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(p.type_name()), j));
- }
- m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>());
- }
- }
- template < typename BasicJsonType, typename Key, typename Value, typename Hash, typename KeyEqual, typename Allocator,
- typename = enable_if_t < !std::is_constructible <
- typename BasicJsonType::string_t, Key >::value >>
- void from_json(const BasicJsonType& j, std::unordered_map<Key, Value, Hash, KeyEqual, Allocator>& m)
- {
- if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
- {
- JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name()), j));
- }
- m.clear();
- for (const auto& p : j)
- {
- if (JSON_HEDLEY_UNLIKELY(!p.is_array()))
- {
- JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(p.type_name()), j));
- }
- m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>());
- }
- }
- #ifdef JSON_HAS_CPP_17
- template<typename BasicJsonType>
- void from_json(const BasicJsonType& j, boost::filesystem::path& p)
- {
- if (JSON_HEDLEY_UNLIKELY(!j.is_string()))
- {
- JSON_THROW(type_error::create(302, "type must be string, but is " + std::string(j.type_name()), j));
- }
- p = *j.template get_ptr<const typename BasicJsonType::string_t*>();
- }
- #endif
- struct from_json_fn
- {
- template<typename BasicJsonType, typename T>
- auto operator()(const BasicJsonType& j, T&& val) const
- noexcept(noexcept(from_json(j, std::forward<T>(val))))
- -> decltype(from_json(j, std::forward<T>(val)))
- {
- return from_json(j, std::forward<T>(val));
- }
- };
- }
- namespace
- {
- constexpr const auto& from_json = detail::static_const<detail::from_json_fn>::value;
- }
- }
- #include <algorithm> // copy
- #include <iterator> // begin, end
- #include <string> // string
- #include <tuple> // tuple, get
- #include <type_traits> // is_same, is_constructible, is_floating_point, is_enum, underlying_type
- #include <utility> // move, forward, declval, pair
- #include <valarray> // valarray
- #include <vector> // vector
- #include <cstddef> // size_t
- #include <iterator> // input_iterator_tag
- #include <string> // string, to_string
- #include <tuple> // tuple_size, get, tuple_element
- #include <utility> // move
- namespace nlohmann
- {
- namespace detail
- {
- template<typename string_type>
- void int_to_string( string_type& target, std::size_t value )
- {
-
- using std::to_string;
- target = to_string(value);
- }
- template<typename IteratorType> class iteration_proxy_value
- {
- public:
- using difference_type = std::ptrdiff_t;
- using value_type = iteration_proxy_value;
- using pointer = value_type * ;
- using reference = value_type & ;
- using iterator_category = std::input_iterator_tag;
- using string_type = typename std::remove_cv< typename std::remove_reference<decltype( std::declval<IteratorType>().key() ) >::type >::type;
- private:
-
- IteratorType anchor;
-
- std::size_t array_index = 0;
-
- mutable std::size_t array_index_last = 0;
-
- mutable string_type array_index_str = "0";
-
- const string_type empty_str{};
- public:
- explicit iteration_proxy_value(IteratorType it) noexcept
- : anchor(std::move(it))
- {}
-
- iteration_proxy_value& operator*()
- {
- return *this;
- }
-
- iteration_proxy_value& operator++()
- {
- ++anchor;
- ++array_index;
- return *this;
- }
-
- bool operator==(const iteration_proxy_value& o) const
- {
- return anchor == o.anchor;
- }
-
- bool operator!=(const iteration_proxy_value& o) const
- {
- return anchor != o.anchor;
- }
-
- const string_type& key() const
- {
- JSON_ASSERT(anchor.m_object != nullptr);
- switch (anchor.m_object->type())
- {
-
- case value_t::array:
- {
- if (array_index != array_index_last)
- {
- int_to_string( array_index_str, array_index );
- array_index_last = array_index;
- }
- return array_index_str;
- }
-
- case value_t::object:
- return anchor.key();
-
- case value_t::null:
- case value_t::string:
- case value_t::boolean:
- case value_t::number_integer:
- case value_t::number_unsigned:
- case value_t::number_float:
- case value_t::binary:
- case value_t::discarded:
- default:
- return empty_str;
- }
- }
-
- typename IteratorType::reference value() const
- {
- return anchor.value();
- }
- };
- template<typename IteratorType> class iteration_proxy
- {
- private:
-
- typename IteratorType::reference container;
- public:
-
- explicit iteration_proxy(typename IteratorType::reference cont) noexcept
- : container(cont) {}
-
- iteration_proxy_value<IteratorType> begin() noexcept
- {
- return iteration_proxy_value<IteratorType>(container.begin());
- }
-
- iteration_proxy_value<IteratorType> end() noexcept
- {
- return iteration_proxy_value<IteratorType>(container.end());
- }
- };
- template<std::size_t N, typename IteratorType, enable_if_t<N == 0, int> = 0>
- auto get(const nlohmann::detail::iteration_proxy_value<IteratorType>& i) -> decltype(i.key())
- {
- return i.key();
- }
- template<std::size_t N, typename IteratorType, enable_if_t<N == 1, int> = 0>
- auto get(const nlohmann::detail::iteration_proxy_value<IteratorType>& i) -> decltype(i.value())
- {
- return i.value();
- }
- }
- }
- namespace std
- {
- #if defined(__clang__)
-
- #pragma clang diagnostic push
- #pragma clang diagnostic ignored "-Wmismatched-tags"
- #endif
- template<typename IteratorType>
- class tuple_size<::nlohmann::detail::iteration_proxy_value<IteratorType>>
- : public std::integral_constant<std::size_t, 2> {};
- template<std::size_t N, typename IteratorType>
- class tuple_element<N, ::nlohmann::detail::iteration_proxy_value<IteratorType >>
- {
- public:
- using type = decltype(
- get<N>(std::declval <
- ::nlohmann::detail::iteration_proxy_value<IteratorType >> ()));
- };
- #if defined(__clang__)
- #pragma clang diagnostic pop
- #endif
- }
- #ifdef JSON_HAS_CPP_17
-
- #include <boost/filesystem.hpp>
- #endif
- namespace nlohmann
- {
- namespace detail
- {
- template<value_t> struct external_constructor;
- template<>
- struct external_constructor<value_t::boolean>
- {
- template<typename BasicJsonType>
- static void construct(BasicJsonType& j, typename BasicJsonType::boolean_t b) noexcept
- {
- j.m_value.destroy(j.m_type);
- j.m_type = value_t::boolean;
- j.m_value = b;
- j.assert_invariant();
- }
- };
- template<>
- struct external_constructor<value_t::string>
- {
- template<typename BasicJsonType>
- static void construct(BasicJsonType& j, const typename BasicJsonType::string_t& s)
- {
- j.m_value.destroy(j.m_type);
- j.m_type = value_t::string;
- j.m_value = s;
- j.assert_invariant();
- }
- template<typename BasicJsonType>
- static void construct(BasicJsonType& j, typename BasicJsonType::string_t&& s)
- {
- j.m_value.destroy(j.m_type);
- j.m_type = value_t::string;
- j.m_value = std::move(s);
- j.assert_invariant();
- }
- template < typename BasicJsonType, typename CompatibleStringType,
- enable_if_t < !std::is_same<CompatibleStringType, typename BasicJsonType::string_t>::value,
- int > = 0 >
- static void construct(BasicJsonType& j, const CompatibleStringType& str)
- {
- j.m_value.destroy(j.m_type);
- j.m_type = value_t::string;
- j.m_value.string = j.template create<typename BasicJsonType::string_t>(str);
- j.assert_invariant();
- }
- };
- template<>
- struct external_constructor<value_t::binary>
- {
- template<typename BasicJsonType>
- static void construct(BasicJsonType& j, const typename BasicJsonType::binary_t& b)
- {
- j.m_value.destroy(j.m_type);
- j.m_type = value_t::binary;
- j.m_value = typename BasicJsonType::binary_t(b);
- j.assert_invariant();
- }
- template<typename BasicJsonType>
- static void construct(BasicJsonType& j, typename BasicJsonType::binary_t&& b)
- {
- j.m_value.destroy(j.m_type);
- j.m_type = value_t::binary;
- j.m_value = typename BasicJsonType::binary_t(std::move(b));
- j.assert_invariant();
- }
- };
- template<>
- struct external_constructor<value_t::number_float>
- {
- template<typename BasicJsonType>
- static void construct(BasicJsonType& j, typename BasicJsonType::number_float_t val) noexcept
- {
- j.m_value.destroy(j.m_type);
- j.m_type = value_t::number_float;
- j.m_value = val;
- j.assert_invariant();
- }
- };
- template<>
- struct external_constructor<value_t::number_unsigned>
- {
- template<typename BasicJsonType>
- static void construct(BasicJsonType& j, typename BasicJsonType::number_unsigned_t val) noexcept
- {
- j.m_value.destroy(j.m_type);
- j.m_type = value_t::number_unsigned;
- j.m_value = val;
- j.assert_invariant();
- }
- };
- template<>
- struct external_constructor<value_t::number_integer>
- {
- template<typename BasicJsonType>
- static void construct(BasicJsonType& j, typename BasicJsonType::number_integer_t val) noexcept
- {
- j.m_value.destroy(j.m_type);
- j.m_type = value_t::number_integer;
- j.m_value = val;
- j.assert_invariant();
- }
- };
- template<>
- struct external_constructor<value_t::array>
- {
- template<typename BasicJsonType>
- static void construct(BasicJsonType& j, const typename BasicJsonType::array_t& arr)
- {
- j.m_value.destroy(j.m_type);
- j.m_type = value_t::array;
- j.m_value = arr;
- j.set_parents();
- j.assert_invariant();
- }
- template<typename BasicJsonType>
- static void construct(BasicJsonType& j, typename BasicJsonType::array_t&& arr)
- {
- j.m_value.destroy(j.m_type);
- j.m_type = value_t::array;
- j.m_value = std::move(arr);
- j.set_parents();
- j.assert_invariant();
- }
- template < typename BasicJsonType, typename CompatibleArrayType,
- enable_if_t < !std::is_same<CompatibleArrayType, typename BasicJsonType::array_t>::value,
- int > = 0 >
- static void construct(BasicJsonType& j, const CompatibleArrayType& arr)
- {
- using std::begin;
- using std::end;
- j.m_value.destroy(j.m_type);
- j.m_type = value_t::array;
- j.m_value.array = j.template create<typename BasicJsonType::array_t>(begin(arr), end(arr));
- j.set_parents();
- j.assert_invariant();
- }
- template<typename BasicJsonType>
- static void construct(BasicJsonType& j, const std::vector<bool>& arr)
- {
- j.m_value.destroy(j.m_type);
- j.m_type = value_t::array;
- j.m_value = value_t::array;
- j.m_value.array->reserve(arr.size());
- for (const bool x : arr)
- {
- j.m_value.array->push_back(x);
- j.set_parent(j.m_value.array->back());
- }
- j.assert_invariant();
- }
- template<typename BasicJsonType, typename T,
- enable_if_t<std::is_convertible<T, BasicJsonType>::value, int> = 0>
- static void construct(BasicJsonType& j, const std::valarray<T>& arr)
- {
- j.m_value.destroy(j.m_type);
- j.m_type = value_t::array;
- j.m_value = value_t::array;
- j.m_value.array->resize(arr.size());
- if (arr.size() > 0)
- {
- std::copy(std::begin(arr), std::end(arr), j.m_value.array->begin());
- }
- j.set_parents();
- j.assert_invariant();
- }
- };
- template<>
- struct external_constructor<value_t::object>
- {
- template<typename BasicJsonType>
- static void construct(BasicJsonType& j, const typename BasicJsonType::object_t& obj)
- {
- j.m_value.destroy(j.m_type);
- j.m_type = value_t::object;
- j.m_value = obj;
- j.set_parents();
- j.assert_invariant();
- }
- template<typename BasicJsonType>
- static void construct(BasicJsonType& j, typename BasicJsonType::object_t&& obj)
- {
- j.m_value.destroy(j.m_type);
- j.m_type = value_t::object;
- j.m_value = std::move(obj);
- j.set_parents();
- j.assert_invariant();
- }
- template < typename BasicJsonType, typename CompatibleObjectType,
- enable_if_t < !std::is_same<CompatibleObjectType, typename BasicJsonType::object_t>::value, int > = 0 >
- static void construct(BasicJsonType& j, const CompatibleObjectType& obj)
- {
- using std::begin;
- using std::end;
- j.m_value.destroy(j.m_type);
- j.m_type = value_t::object;
- j.m_value.object = j.template create<typename BasicJsonType::object_t>(begin(obj), end(obj));
- j.set_parents();
- j.assert_invariant();
- }
- };
- template<typename BasicJsonType, typename T,
- enable_if_t<std::is_same<T, typename BasicJsonType::boolean_t>::value, int> = 0>
- void to_json(BasicJsonType& j, T b) noexcept
- {
- external_constructor<value_t::boolean>::construct(j, b);
- }
- template<typename BasicJsonType, typename CompatibleString,
- enable_if_t<std::is_constructible<typename BasicJsonType::string_t, CompatibleString>::value, int> = 0>
- void to_json(BasicJsonType& j, const CompatibleString& s)
- {
- external_constructor<value_t::string>::construct(j, s);
- }
- template<typename BasicJsonType>
- void to_json(BasicJsonType& j, typename BasicJsonType::string_t&& s)
- {
- external_constructor<value_t::string>::construct(j, std::move(s));
- }
- template<typename BasicJsonType, typename FloatType,
- enable_if_t<std::is_floating_point<FloatType>::value, int> = 0>
- void to_json(BasicJsonType& j, FloatType val) noexcept
- {
- external_constructor<value_t::number_float>::construct(j, static_cast<typename BasicJsonType::number_float_t>(val));
- }
- template<typename BasicJsonType, typename CompatibleNumberUnsignedType,
- enable_if_t<is_compatible_integer_type<typename BasicJsonType::number_unsigned_t, CompatibleNumberUnsignedType>::value, int> = 0>
- void to_json(BasicJsonType& j, CompatibleNumberUnsignedType val) noexcept
- {
- external_constructor<value_t::number_unsigned>::construct(j, static_cast<typename BasicJsonType::number_unsigned_t>(val));
- }
- template<typename BasicJsonType, typename CompatibleNumberIntegerType,
- enable_if_t<is_compatible_integer_type<typename BasicJsonType::number_integer_t, CompatibleNumberIntegerType>::value, int> = 0>
- void to_json(BasicJsonType& j, CompatibleNumberIntegerType val) noexcept
- {
- external_constructor<value_t::number_integer>::construct(j, static_cast<typename BasicJsonType::number_integer_t>(val));
- }
- template<typename BasicJsonType, typename EnumType,
- enable_if_t<std::is_enum<EnumType>::value, int> = 0>
- void to_json(BasicJsonType& j, EnumType e) noexcept
- {
- using underlying_type = typename std::underlying_type<EnumType>::type;
- external_constructor<value_t::number_integer>::construct(j, static_cast<underlying_type>(e));
- }
- template<typename BasicJsonType>
- void to_json(BasicJsonType& j, const std::vector<bool>& e)
- {
- external_constructor<value_t::array>::construct(j, e);
- }
- template < typename BasicJsonType, typename CompatibleArrayType,
- enable_if_t < is_compatible_array_type<BasicJsonType,
- CompatibleArrayType>::value&&
- !is_compatible_object_type<BasicJsonType, CompatibleArrayType>::value&&
- !is_compatible_string_type<BasicJsonType, CompatibleArrayType>::value&&
- !std::is_same<typename BasicJsonType::binary_t, CompatibleArrayType>::value&&
- !is_basic_json<CompatibleArrayType>::value,
- int > = 0 >
- void to_json(BasicJsonType& j, const CompatibleArrayType& arr)
- {
- external_constructor<value_t::array>::construct(j, arr);
- }
- template<typename BasicJsonType>
- void to_json(BasicJsonType& j, const typename BasicJsonType::binary_t& bin)
- {
- external_constructor<value_t::binary>::construct(j, bin);
- }
- template<typename BasicJsonType, typename T,
- enable_if_t<std::is_convertible<T, BasicJsonType>::value, int> = 0>
- void to_json(BasicJsonType& j, const std::valarray<T>& arr)
- {
- external_constructor<value_t::array>::construct(j, std::move(arr));
- }
- template<typename BasicJsonType>
- void to_json(BasicJsonType& j, typename BasicJsonType::array_t&& arr)
- {
- external_constructor<value_t::array>::construct(j, std::move(arr));
- }
- template < typename BasicJsonType, typename CompatibleObjectType,
- enable_if_t < is_compatible_object_type<BasicJsonType, CompatibleObjectType>::value&& !is_basic_json<CompatibleObjectType>::value, int > = 0 >
- void to_json(BasicJsonType& j, const CompatibleObjectType& obj)
- {
- external_constructor<value_t::object>::construct(j, obj);
- }
- template<typename BasicJsonType>
- void to_json(BasicJsonType& j, typename BasicJsonType::object_t&& obj)
- {
- external_constructor<value_t::object>::construct(j, std::move(obj));
- }
- template <
- typename BasicJsonType, typename T, std::size_t N,
- enable_if_t < !std::is_constructible<typename BasicJsonType::string_t,
- const T(&)[N]>::value,
- int > = 0 >
- void to_json(BasicJsonType& j, const T(&arr)[N])
- {
- external_constructor<value_t::array>::construct(j, arr);
- }
- template < typename BasicJsonType, typename T1, typename T2, enable_if_t < std::is_constructible<BasicJsonType, T1>::value&& std::is_constructible<BasicJsonType, T2>::value, int > = 0 >
- void to_json(BasicJsonType& j, const std::pair<T1, T2>& p)
- {
- j = { p.first, p.second };
- }
- template<typename BasicJsonType, typename T,
- enable_if_t<std::is_same<T, iteration_proxy_value<typename BasicJsonType::iterator>>::value, int> = 0>
- void to_json(BasicJsonType& j, const T& b)
- {
- j = { {b.key(), b.value()} };
- }
- template<typename BasicJsonType, typename Tuple, std::size_t... Idx>
- void to_json_tuple_impl(BasicJsonType& j, const Tuple& t, index_sequence<Idx...> )
- {
- j = { std::get<Idx>(t)... };
- }
- template<typename BasicJsonType, typename T, enable_if_t<is_constructible_tuple<BasicJsonType, T>::value, int > = 0>
- void to_json(BasicJsonType& j, const T& t)
- {
- to_json_tuple_impl(j, t, make_index_sequence<std::tuple_size<T>::value> {});
- }
- #ifdef JSON_HAS_CPP_17
- template<typename BasicJsonType>
- void to_json(BasicJsonType& j, const boost::filesystem::path& p)
- {
- j = p.string();
- }
- #endif
- struct to_json_fn
- {
- template<typename BasicJsonType, typename T>
- auto operator()(BasicJsonType& j, T&& val) const noexcept(noexcept(to_json(j, std::forward<T>(val))))
- -> decltype(to_json(j, std::forward<T>(val)), void())
- {
- return to_json(j, std::forward<T>(val));
- }
- };
- }
- namespace
- {
- constexpr const auto& to_json = detail::static_const<detail::to_json_fn>::value;
- }
- }
- namespace nlohmann
- {
- template<typename ValueType, typename>
- struct adl_serializer
- {
-
- template<typename BasicJsonType, typename TargetType = ValueType>
- static auto from_json(BasicJsonType && j, TargetType& val) noexcept(
- noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), val)))
- -> decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), val), void())
- {
- ::nlohmann::from_json(std::forward<BasicJsonType>(j), val);
- }
-
- template<typename BasicJsonType, typename TargetType = ValueType>
- static auto from_json(BasicJsonType && j) noexcept(
- noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {})))
- -> decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {}))
- {
- return ::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {});
- }
-
- template<typename BasicJsonType, typename TargetType = ValueType>
- static auto to_json(BasicJsonType& j, TargetType && val) noexcept(
- noexcept(::nlohmann::to_json(j, std::forward<TargetType>(val))))
- -> decltype(::nlohmann::to_json(j, std::forward<TargetType>(val)), void())
- {
- ::nlohmann::to_json(j, std::forward<TargetType>(val));
- }
- };
- }
- #include <cstdint> // uint8_t, uint64_t
- #include <tuple> // tie
- #include <utility> // move
- namespace nlohmann
- {
- template<typename BinaryType>
- class byte_container_with_subtype : public BinaryType
- {
- public:
-
- using container_type = BinaryType;
-
- using subtype_type = std::uint64_t;
- byte_container_with_subtype() noexcept(noexcept(container_type()))
- : container_type()
- {}
- byte_container_with_subtype(const container_type& b) noexcept(noexcept(container_type(b)))
- : container_type(b)
- {}
- byte_container_with_subtype(container_type&& b) noexcept(noexcept(container_type(std::move(b))))
- : container_type(std::move(b))
- {}
- byte_container_with_subtype(const container_type& b, subtype_type subtype_) noexcept(noexcept(container_type(b)))
- : container_type(b)
- , m_subtype(subtype_)
- , m_has_subtype(true)
- {}
- byte_container_with_subtype(container_type&& b, subtype_type subtype_) noexcept(noexcept(container_type(std::move(b))))
- : container_type(std::move(b))
- , m_subtype(subtype_)
- , m_has_subtype(true)
- {}
- bool operator==(const byte_container_with_subtype& rhs) const
- {
- return std::tie(static_cast<const BinaryType&>(*this), m_subtype, m_has_subtype) ==
- std::tie(static_cast<const BinaryType&>(rhs), rhs.m_subtype, rhs.m_has_subtype);
- }
- bool operator!=(const byte_container_with_subtype& rhs) const
- {
- return !(rhs == *this);
- }
-
- void set_subtype(subtype_type subtype_) noexcept
- {
- m_subtype = subtype_;
- m_has_subtype = true;
- }
-
- constexpr subtype_type subtype() const noexcept
- {
- return m_has_subtype ? m_subtype : subtype_type(-1);
- }
-
- constexpr bool has_subtype() const noexcept
- {
- return m_has_subtype;
- }
-
- void clear_subtype() noexcept
- {
- m_subtype = 0;
- m_has_subtype = false;
- }
- private:
- subtype_type m_subtype = 0;
- bool m_has_subtype = false;
- };
- }
- #include <cstdint> // uint8_t
- #include <cstddef> // size_t
- #include <functional> // hash
- namespace nlohmann
- {
- namespace detail
- {
- inline std::size_t combine(std::size_t seed, std::size_t h) noexcept
- {
- seed ^= h + 0x9e3779b9 + (seed << 6U) + (seed >> 2U);
- return seed;
- }
- template<typename BasicJsonType>
- std::size_t hash(const BasicJsonType& j)
- {
- using string_t = typename BasicJsonType::string_t;
- using number_integer_t = typename BasicJsonType::number_integer_t;
- using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
- using number_float_t = typename BasicJsonType::number_float_t;
- const auto type = static_cast<std::size_t>(j.type());
- switch (j.type())
- {
- case BasicJsonType::value_t::null:
- case BasicJsonType::value_t::discarded:
- {
- return combine(type, 0);
- }
- case BasicJsonType::value_t::object:
- {
- auto seed = combine(type, j.size());
- for (const auto& element : j.items())
- {
- const auto h = std::hash<string_t> {}(element.key());
- seed = combine(seed, h);
- seed = combine(seed, hash(element.value()));
- }
- return seed;
- }
- case BasicJsonType::value_t::array:
- {
- auto seed = combine(type, j.size());
- for (const auto& element : j)
- {
- seed = combine(seed, hash(element));
- }
- return seed;
- }
- case BasicJsonType::value_t::string:
- {
- const auto h = std::hash<string_t> {}(j.template get_ref<const string_t&>());
- return combine(type, h);
- }
- case BasicJsonType::value_t::boolean:
- {
- const auto h = std::hash<bool> {}(j.template get<bool>());
- return combine(type, h);
- }
- case BasicJsonType::value_t::number_integer:
- {
- const auto h = std::hash<number_integer_t> {}(j.template get<number_integer_t>());
- return combine(type, h);
- }
- case BasicJsonType::value_t::number_unsigned:
- {
- const auto h = std::hash<number_unsigned_t> {}(j.template get<number_unsigned_t>());
- return combine(type, h);
- }
- case BasicJsonType::value_t::number_float:
- {
- const auto h = std::hash<number_float_t> {}(j.template get<number_float_t>());
- return combine(type, h);
- }
- case BasicJsonType::value_t::binary:
- {
- auto seed = combine(type, j.get_binary().size());
- const auto h = std::hash<bool> {}(j.get_binary().has_subtype());
- seed = combine(seed, h);
- seed = combine(seed, static_cast<std::size_t>(j.get_binary().subtype()));
- for (const auto byte : j.get_binary())
- {
- seed = combine(seed, std::hash<std::uint8_t> {}(byte));
- }
- return seed;
- }
- default:
- JSON_ASSERT(false);
- return 0;
- }
- }
- }
- }
- #include <algorithm> // generate_n
- #include <array> // array
- #include <cmath> // ldexp
- #include <cstddef> // size_t
- #include <cstdint> // uint8_t, uint16_t, uint32_t, uint64_t
- #include <cstdio> // snprintf
- #include <cstring> // memcpy
- #include <iterator> // back_inserter
- #include <limits> // numeric_limits
- #include <string> // char_traits, string
- #include <utility> // make_pair, move
- #include <vector> // vector
- #include <array> // array
- #include <cstddef> // size_t
- #include <cstring> // strlen
- #include <iterator> // begin, end, iterator_traits, random_access_iterator_tag, distance, next
- #include <memory> // shared_ptr, make_shared, addressof
- #include <numeric> // accumulate
- #include <string> // string, char_traits
- #include <type_traits> // enable_if, is_base_of, is_pointer, is_integral, remove_pointer
- #include <utility> // pair, declval
- #ifndef JSON_NO_IO
- #include <cstdio> // FILE *
- #include <istream> // istream
- #endif
- namespace nlohmann
- {
- namespace detail
- {
- enum class input_format_t { json, cbor, msgpack, ubjson, bson };
- #ifndef JSON_NO_IO
- class file_input_adapter
- {
- public:
- using char_type = char;
- JSON_HEDLEY_NON_NULL(2)
- explicit file_input_adapter(std::FILE* f) noexcept
- : m_file(f)
- {}
-
- file_input_adapter(const file_input_adapter&) = delete;
- file_input_adapter(file_input_adapter&&) noexcept = default;
- file_input_adapter& operator=(const file_input_adapter&) = delete;
- file_input_adapter& operator=(file_input_adapter&&) = delete;
- ~file_input_adapter() = default;
- std::char_traits<char>::int_type get_character() noexcept
- {
- return std::fgetc(m_file);
- }
- private:
-
- std::FILE* m_file;
- };
- class input_stream_adapter
- {
- public:
- using char_type = char;
- ~input_stream_adapter()
- {
-
-
- if (is != nullptr)
- {
- is->clear(is->rdstate() & std::ios::eofbit);
- }
- }
- explicit input_stream_adapter(std::istream& i)
- : is(&i), sb(i.rdbuf())
- {}
-
- input_stream_adapter(const input_stream_adapter&) = delete;
- input_stream_adapter& operator=(input_stream_adapter&) = delete;
- input_stream_adapter& operator=(input_stream_adapter&&) = delete;
- input_stream_adapter(input_stream_adapter&& rhs) noexcept
- : is(rhs.is), sb(rhs.sb)
- {
- rhs.is = nullptr;
- rhs.sb = nullptr;
- }
-
-
-
- std::char_traits<char>::int_type get_character()
- {
- auto res = sb->sbumpc();
-
- if (JSON_HEDLEY_UNLIKELY(res == std::char_traits<char>::eof()))
- {
- is->clear(is->rdstate() | std::ios::eofbit);
- }
- return res;
- }
- private:
-
- std::istream* is = nullptr;
- std::streambuf* sb = nullptr;
- };
- #endif
- template<typename IteratorType>
- class iterator_input_adapter
- {
- public:
- using char_type = typename std::iterator_traits<IteratorType>::value_type;
- iterator_input_adapter(IteratorType first, IteratorType last)
- : current(std::move(first)), end(std::move(last))
- {}
- typename std::char_traits<char_type>::int_type get_character()
- {
- if (JSON_HEDLEY_LIKELY(current != end))
- {
- auto result = std::char_traits<char_type>::to_int_type(*current);
- std::advance(current, 1);
- return result;
- }
- return std::char_traits<char_type>::eof();
- }
- private:
- IteratorType current;
- IteratorType end;
- template<typename BaseInputAdapter, size_t T>
- friend struct wide_string_input_helper;
- bool empty() const
- {
- return current == end;
- }
- };
- template<typename BaseInputAdapter, size_t T>
- struct wide_string_input_helper;
- template<typename BaseInputAdapter>
- struct wide_string_input_helper<BaseInputAdapter, 4>
- {
-
- static void fill_buffer(BaseInputAdapter& input,
- std::array<std::char_traits<char>::int_type, 4>& utf8_bytes,
- size_t& utf8_bytes_index,
- size_t& utf8_bytes_filled)
- {
- utf8_bytes_index = 0;
- if (JSON_HEDLEY_UNLIKELY(input.empty()))
- {
- utf8_bytes[0] = std::char_traits<char>::eof();
- utf8_bytes_filled = 1;
- }
- else
- {
-
- const auto wc = input.get_character();
-
- if (wc < 0x80)
- {
- utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(wc);
- utf8_bytes_filled = 1;
- }
- else if (wc <= 0x7FF)
- {
- utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(0xC0u | ((static_cast<unsigned int>(wc) >> 6u) & 0x1Fu));
- utf8_bytes[1] = static_cast<std::char_traits<char>::int_type>(0x80u | (static_cast<unsigned int>(wc) & 0x3Fu));
- utf8_bytes_filled = 2;
- }
- else if (wc <= 0xFFFF)
- {
- utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(0xE0u | ((static_cast<unsigned int>(wc) >> 12u) & 0x0Fu));
- utf8_bytes[1] = static_cast<std::char_traits<char>::int_type>(0x80u | ((static_cast<unsigned int>(wc) >> 6u) & 0x3Fu));
- utf8_bytes[2] = static_cast<std::char_traits<char>::int_type>(0x80u | (static_cast<unsigned int>(wc) & 0x3Fu));
- utf8_bytes_filled = 3;
- }
- else if (wc <= 0x10FFFF)
- {
- utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(0xF0u | ((static_cast<unsigned int>(wc) >> 18u) & 0x07u));
- utf8_bytes[1] = static_cast<std::char_traits<char>::int_type>(0x80u | ((static_cast<unsigned int>(wc) >> 12u) & 0x3Fu));
- utf8_bytes[2] = static_cast<std::char_traits<char>::int_type>(0x80u | ((static_cast<unsigned int>(wc) >> 6u) & 0x3Fu));
- utf8_bytes[3] = static_cast<std::char_traits<char>::int_type>(0x80u | (static_cast<unsigned int>(wc) & 0x3Fu));
- utf8_bytes_filled = 4;
- }
- else
- {
-
- utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(wc);
- utf8_bytes_filled = 1;
- }
- }
- }
- };
- template<typename BaseInputAdapter>
- struct wide_string_input_helper<BaseInputAdapter, 2>
- {
-
- static void fill_buffer(BaseInputAdapter& input,
- std::array<std::char_traits<char>::int_type, 4>& utf8_bytes,
- size_t& utf8_bytes_index,
- size_t& utf8_bytes_filled)
- {
- utf8_bytes_index = 0;
- if (JSON_HEDLEY_UNLIKELY(input.empty()))
- {
- utf8_bytes[0] = std::char_traits<char>::eof();
- utf8_bytes_filled = 1;
- }
- else
- {
-
- const auto wc = input.get_character();
-
- if (wc < 0x80)
- {
- utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(wc);
- utf8_bytes_filled = 1;
- }
- else if (wc <= 0x7FF)
- {
- utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(0xC0u | ((static_cast<unsigned int>(wc) >> 6u)));
- utf8_bytes[1] = static_cast<std::char_traits<char>::int_type>(0x80u | (static_cast<unsigned int>(wc) & 0x3Fu));
- utf8_bytes_filled = 2;
- }
- else if (0xD800 > wc || wc >= 0xE000)
- {
- utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(0xE0u | ((static_cast<unsigned int>(wc) >> 12u)));
- utf8_bytes[1] = static_cast<std::char_traits<char>::int_type>(0x80u | ((static_cast<unsigned int>(wc) >> 6u) & 0x3Fu));
- utf8_bytes[2] = static_cast<std::char_traits<char>::int_type>(0x80u | (static_cast<unsigned int>(wc) & 0x3Fu));
- utf8_bytes_filled = 3;
- }
- else
- {
- if (JSON_HEDLEY_UNLIKELY(!input.empty()))
- {
- const auto wc2 = static_cast<unsigned int>(input.get_character());
- const auto charcode = 0x10000u + (((static_cast<unsigned int>(wc) & 0x3FFu) << 10u) | (wc2 & 0x3FFu));
- utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(0xF0u | (charcode >> 18u));
- utf8_bytes[1] = static_cast<std::char_traits<char>::int_type>(0x80u | ((charcode >> 12u) & 0x3Fu));
- utf8_bytes[2] = static_cast<std::char_traits<char>::int_type>(0x80u | ((charcode >> 6u) & 0x3Fu));
- utf8_bytes[3] = static_cast<std::char_traits<char>::int_type>(0x80u | (charcode & 0x3Fu));
- utf8_bytes_filled = 4;
- }
- else
- {
- utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(wc);
- utf8_bytes_filled = 1;
- }
- }
- }
- }
- };
- template<typename BaseInputAdapter, typename WideCharType>
- class wide_string_input_adapter
- {
- public:
- using char_type = char;
- wide_string_input_adapter(BaseInputAdapter base)
- : base_adapter(base) {}
- typename std::char_traits<char>::int_type get_character() noexcept
- {
-
- if (utf8_bytes_index == utf8_bytes_filled)
- {
- fill_buffer<sizeof(WideCharType)>();
- JSON_ASSERT(utf8_bytes_filled > 0);
- JSON_ASSERT(utf8_bytes_index == 0);
- }
-
- JSON_ASSERT(utf8_bytes_filled > 0);
- JSON_ASSERT(utf8_bytes_index < utf8_bytes_filled);
- return utf8_bytes[utf8_bytes_index++];
- }
- private:
- BaseInputAdapter base_adapter;
- template<size_t T>
- void fill_buffer()
- {
- wide_string_input_helper<BaseInputAdapter, T>::fill_buffer(base_adapter, utf8_bytes, utf8_bytes_index, utf8_bytes_filled);
- }
-
- std::array<std::char_traits<char>::int_type, 4> utf8_bytes = {{0, 0, 0, 0}};
-
- std::size_t utf8_bytes_index = 0;
-
- std::size_t utf8_bytes_filled = 0;
- };
- template<typename IteratorType, typename Enable = void>
- struct iterator_input_adapter_factory
- {
- using iterator_type = IteratorType;
- using char_type = typename std::iterator_traits<iterator_type>::value_type;
- using adapter_type = iterator_input_adapter<iterator_type>;
- static adapter_type create(IteratorType first, IteratorType last)
- {
- return adapter_type(std::move(first), std::move(last));
- }
- };
- template<typename T>
- struct is_iterator_of_multibyte
- {
- using value_type = typename std::iterator_traits<T>::value_type;
- enum
- {
- value = sizeof(value_type) > 1
- };
- };
- template<typename IteratorType>
- struct iterator_input_adapter_factory<IteratorType, enable_if_t<is_iterator_of_multibyte<IteratorType>::value>>
- {
- using iterator_type = IteratorType;
- using char_type = typename std::iterator_traits<iterator_type>::value_type;
- using base_adapter_type = iterator_input_adapter<iterator_type>;
- using adapter_type = wide_string_input_adapter<base_adapter_type, char_type>;
- static adapter_type create(IteratorType first, IteratorType last)
- {
- return adapter_type(base_adapter_type(std::move(first), std::move(last)));
- }
- };
- template<typename IteratorType>
- typename iterator_input_adapter_factory<IteratorType>::adapter_type input_adapter(IteratorType first, IteratorType last)
- {
- using factory_type = iterator_input_adapter_factory<IteratorType>;
- return factory_type::create(first, last);
- }
- namespace container_input_adapter_factory_impl
- {
- using std::begin;
- using std::end;
- template<typename ContainerType, typename Enable = void>
- struct container_input_adapter_factory {};
- template<typename ContainerType>
- struct container_input_adapter_factory< ContainerType,
- void_t<decltype(begin(std::declval<ContainerType>()), end(std::declval<ContainerType>()))>>
- {
- using adapter_type = decltype(input_adapter(begin(std::declval<ContainerType>()), end(std::declval<ContainerType>())));
- static adapter_type create(const ContainerType& container)
- {
- return input_adapter(begin(container), end(container));
- }
- };
- }
- template<typename ContainerType>
- typename container_input_adapter_factory_impl::container_input_adapter_factory<ContainerType>::adapter_type input_adapter(const ContainerType& container)
- {
- return container_input_adapter_factory_impl::container_input_adapter_factory<ContainerType>::create(container);
- }
- #ifndef JSON_NO_IO
- inline file_input_adapter input_adapter(std::FILE* file)
- {
- return file_input_adapter(file);
- }
- inline input_stream_adapter input_adapter(std::istream& stream)
- {
- return input_stream_adapter(stream);
- }
- inline input_stream_adapter input_adapter(std::istream&& stream)
- {
- return input_stream_adapter(stream);
- }
- #endif
- using contiguous_bytes_input_adapter = decltype(input_adapter(std::declval<const char*>(), std::declval<const char*>()));
- template < typename CharT,
- typename std::enable_if <
- std::is_pointer<CharT>::value&&
- !std::is_array<CharT>::value&&
- std::is_integral<typename std::remove_pointer<CharT>::type>::value&&
- sizeof(typename std::remove_pointer<CharT>::type) == 1,
- int >::type = 0 >
- contiguous_bytes_input_adapter input_adapter(CharT b)
- {
- auto length = std::strlen(reinterpret_cast<const char*>(b));
- const auto* ptr = reinterpret_cast<const char*>(b);
- return input_adapter(ptr, ptr + length);
- }
- template<typename T, std::size_t N>
- auto input_adapter(T (&array)[N]) -> decltype(input_adapter(array, array + N))
- {
- return input_adapter(array, array + N);
- }
- class span_input_adapter
- {
- public:
- template < typename CharT,
- typename std::enable_if <
- std::is_pointer<CharT>::value&&
- std::is_integral<typename std::remove_pointer<CharT>::type>::value&&
- sizeof(typename std::remove_pointer<CharT>::type) == 1,
- int >::type = 0 >
- span_input_adapter(CharT b, std::size_t l)
- : ia(reinterpret_cast<const char*>(b), reinterpret_cast<const char*>(b) + l) {}
- template<class IteratorType,
- typename std::enable_if<
- std::is_same<typename iterator_traits<IteratorType>::iterator_category, std::random_access_iterator_tag>::value,
- int>::type = 0>
- span_input_adapter(IteratorType first, IteratorType last)
- : ia(input_adapter(first, last)) {}
- contiguous_bytes_input_adapter&& get()
- {
- return std::move(ia);
- }
- private:
- contiguous_bytes_input_adapter ia;
- };
- }
- }
- #include <cstddef>
- #include <string> // string
- #include <utility> // move
- #include <vector> // vector
- namespace nlohmann
- {
- template<typename BasicJsonType>
- struct json_sax
- {
- using number_integer_t = typename BasicJsonType::number_integer_t;
- using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
- using number_float_t = typename BasicJsonType::number_float_t;
- using string_t = typename BasicJsonType::string_t;
- using binary_t = typename BasicJsonType::binary_t;
-
- virtual bool null() = 0;
-
- virtual bool boolean(bool val) = 0;
-
- virtual bool number_integer(number_integer_t val) = 0;
-
- virtual bool number_unsigned(number_unsigned_t val) = 0;
-
- virtual bool number_float(number_float_t val, const string_t& s) = 0;
-
- virtual bool string(string_t& val) = 0;
-
- virtual bool binary(binary_t& val) = 0;
-
- virtual bool start_object(std::size_t elements) = 0;
-
- virtual bool key(string_t& val) = 0;
-
- virtual bool end_object() = 0;
-
- virtual bool start_array(std::size_t elements) = 0;
-
- virtual bool end_array() = 0;
-
- virtual bool parse_error(std::size_t position,
- const std::string& last_token,
- const detail::exception& ex) = 0;
- json_sax() = default;
- json_sax(const json_sax&) = default;
- json_sax(json_sax&&) noexcept = default;
- json_sax& operator=(const json_sax&) = default;
- json_sax& operator=(json_sax&&) noexcept = default;
- virtual ~json_sax() = default;
- };
- namespace detail
- {
- template<typename BasicJsonType>
- class json_sax_dom_parser
- {
- public:
- using number_integer_t = typename BasicJsonType::number_integer_t;
- using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
- using number_float_t = typename BasicJsonType::number_float_t;
- using string_t = typename BasicJsonType::string_t;
- using binary_t = typename BasicJsonType::binary_t;
-
- explicit json_sax_dom_parser(BasicJsonType& r, const bool allow_exceptions_ = true)
- : root(r), allow_exceptions(allow_exceptions_)
- {}
-
- json_sax_dom_parser(const json_sax_dom_parser&) = delete;
- json_sax_dom_parser(json_sax_dom_parser&&) = default;
- json_sax_dom_parser& operator=(const json_sax_dom_parser&) = delete;
- json_sax_dom_parser& operator=(json_sax_dom_parser&&) = default;
- ~json_sax_dom_parser() = default;
- bool null()
- {
- handle_value(nullptr);
- return true;
- }
- bool boolean(bool val)
- {
- handle_value(val);
- return true;
- }
- bool number_integer(number_integer_t val)
- {
- handle_value(val);
- return true;
- }
- bool number_unsigned(number_unsigned_t val)
- {
- handle_value(val);
- return true;
- }
- bool number_float(number_float_t val, const string_t& )
- {
- handle_value(val);
- return true;
- }
- bool string(string_t& val)
- {
- handle_value(val);
- return true;
- }
- bool binary(binary_t& val)
- {
- handle_value(std::move(val));
- return true;
- }
- bool start_object(std::size_t len)
- {
- ref_stack.push_back(handle_value(BasicJsonType::value_t::object));
- if (JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size()))
- {
- JSON_THROW(out_of_range::create(408, "excessive object size: " + std::to_string(len), *ref_stack.back()));
- }
- return true;
- }
- bool key(string_t& val)
- {
-
- object_element = &(ref_stack.back()->m_value.object->operator[](val));
- return true;
- }
- bool end_object()
- {
- ref_stack.back()->set_parents();
- ref_stack.pop_back();
- return true;
- }
- bool start_array(std::size_t len)
- {
- ref_stack.push_back(handle_value(BasicJsonType::value_t::array));
- if (JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size()))
- {
- JSON_THROW(out_of_range::create(408, "excessive array size: " + std::to_string(len), *ref_stack.back()));
- }
- return true;
- }
- bool end_array()
- {
- ref_stack.back()->set_parents();
- ref_stack.pop_back();
- return true;
- }
- template<class Exception>
- bool parse_error(std::size_t , const std::string& ,
- const Exception& ex)
- {
- errored = true;
- static_cast<void>(ex);
- if (allow_exceptions)
- {
- JSON_THROW(ex);
- }
- return false;
- }
- constexpr bool is_errored() const
- {
- return errored;
- }
- private:
-
- template<typename Value>
- JSON_HEDLEY_RETURNS_NON_NULL
- BasicJsonType* handle_value(Value&& v)
- {
- if (ref_stack.empty())
- {
- root = BasicJsonType(std::forward<Value>(v));
- return &root;
- }
- JSON_ASSERT(ref_stack.back()->is_array() || ref_stack.back()->is_object());
- if (ref_stack.back()->is_array())
- {
- ref_stack.back()->m_value.array->emplace_back(std::forward<Value>(v));
- return &(ref_stack.back()->m_value.array->back());
- }
- JSON_ASSERT(ref_stack.back()->is_object());
- JSON_ASSERT(object_element);
- *object_element = BasicJsonType(std::forward<Value>(v));
- return object_element;
- }
-
- BasicJsonType& root;
-
- std::vector<BasicJsonType*> ref_stack {};
-
- BasicJsonType* object_element = nullptr;
-
- bool errored = false;
-
- const bool allow_exceptions = true;
- };
- template<typename BasicJsonType>
- class json_sax_dom_callback_parser
- {
- public:
- using number_integer_t = typename BasicJsonType::number_integer_t;
- using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
- using number_float_t = typename BasicJsonType::number_float_t;
- using string_t = typename BasicJsonType::string_t;
- using binary_t = typename BasicJsonType::binary_t;
- using parser_callback_t = typename BasicJsonType::parser_callback_t;
- using parse_event_t = typename BasicJsonType::parse_event_t;
- json_sax_dom_callback_parser(BasicJsonType& r,
- const parser_callback_t cb,
- const bool allow_exceptions_ = true)
- : root(r), callback(cb), allow_exceptions(allow_exceptions_)
- {
- keep_stack.push_back(true);
- }
-
- json_sax_dom_callback_parser(const json_sax_dom_callback_parser&) = delete;
- json_sax_dom_callback_parser(json_sax_dom_callback_parser&&) = default;
- json_sax_dom_callback_parser& operator=(const json_sax_dom_callback_parser&) = delete;
- json_sax_dom_callback_parser& operator=(json_sax_dom_callback_parser&&) = default;
- ~json_sax_dom_callback_parser() = default;
- bool null()
- {
- handle_value(nullptr);
- return true;
- }
- bool boolean(bool val)
- {
- handle_value(val);
- return true;
- }
- bool number_integer(number_integer_t val)
- {
- handle_value(val);
- return true;
- }
- bool number_unsigned(number_unsigned_t val)
- {
- handle_value(val);
- return true;
- }
- bool number_float(number_float_t val, const string_t& )
- {
- handle_value(val);
- return true;
- }
- bool string(string_t& val)
- {
- handle_value(val);
- return true;
- }
- bool binary(binary_t& val)
- {
- handle_value(std::move(val));
- return true;
- }
- bool start_object(std::size_t len)
- {
-
- const bool keep = callback(static_cast<int>(ref_stack.size()), parse_event_t::object_start, discarded);
- keep_stack.push_back(keep);
- auto val = handle_value(BasicJsonType::value_t::object, true);
- ref_stack.push_back(val.second);
-
- if (ref_stack.back() && JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size()))
- {
- JSON_THROW(out_of_range::create(408, "excessive object size: " + std::to_string(len), *ref_stack.back()));
- }
- return true;
- }
- bool key(string_t& val)
- {
- BasicJsonType k = BasicJsonType(val);
-
- const bool keep = callback(static_cast<int>(ref_stack.size()), parse_event_t::key, k);
- key_keep_stack.push_back(keep);
-
- if (keep && ref_stack.back())
- {
- object_element = &(ref_stack.back()->m_value.object->operator[](val) = discarded);
- }
- return true;
- }
- bool end_object()
- {
- if (ref_stack.back())
- {
- if (!callback(static_cast<int>(ref_stack.size()) - 1, parse_event_t::object_end, *ref_stack.back()))
- {
-
- *ref_stack.back() = discarded;
- }
- else
- {
- ref_stack.back()->set_parents();
- }
- }
- JSON_ASSERT(!ref_stack.empty());
- JSON_ASSERT(!keep_stack.empty());
- ref_stack.pop_back();
- keep_stack.pop_back();
- if (!ref_stack.empty() && ref_stack.back() && ref_stack.back()->is_structured())
- {
-
- for (auto it = ref_stack.back()->begin(); it != ref_stack.back()->end(); ++it)
- {
- if (it->is_discarded())
- {
- ref_stack.back()->erase(it);
- break;
- }
- }
- }
- return true;
- }
- bool start_array(std::size_t len)
- {
- const bool keep = callback(static_cast<int>(ref_stack.size()), parse_event_t::array_start, discarded);
- keep_stack.push_back(keep);
- auto val = handle_value(BasicJsonType::value_t::array, true);
- ref_stack.push_back(val.second);
-
- if (ref_stack.back() && JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size()))
- {
- JSON_THROW(out_of_range::create(408, "excessive array size: " + std::to_string(len), *ref_stack.back()));
- }
- return true;
- }
- bool end_array()
- {
- bool keep = true;
- if (ref_stack.back())
- {
- keep = callback(static_cast<int>(ref_stack.size()) - 1, parse_event_t::array_end, *ref_stack.back());
- if (keep)
- {
- ref_stack.back()->set_parents();
- }
- else
- {
-
- *ref_stack.back() = discarded;
- }
- }
- JSON_ASSERT(!ref_stack.empty());
- JSON_ASSERT(!keep_stack.empty());
- ref_stack.pop_back();
- keep_stack.pop_back();
-
- if (!keep && !ref_stack.empty() && ref_stack.back()->is_array())
- {
- ref_stack.back()->m_value.array->pop_back();
- }
- return true;
- }
- template<class Exception>
- bool parse_error(std::size_t , const std::string& ,
- const Exception& ex)
- {
- errored = true;
- static_cast<void>(ex);
- if (allow_exceptions)
- {
- JSON_THROW(ex);
- }
- return false;
- }
- constexpr bool is_errored() const
- {
- return errored;
- }
- private:
-
- template<typename Value>
- std::pair<bool, BasicJsonType*> handle_value(Value&& v, const bool skip_callback = false)
- {
- JSON_ASSERT(!keep_stack.empty());
-
-
- if (!keep_stack.back())
- {
- return {false, nullptr};
- }
-
- auto value = BasicJsonType(std::forward<Value>(v));
-
- const bool keep = skip_callback || callback(static_cast<int>(ref_stack.size()), parse_event_t::value, value);
-
- if (!keep)
- {
- return {false, nullptr};
- }
- if (ref_stack.empty())
- {
- root = std::move(value);
- return {true, &root};
- }
-
-
- if (!ref_stack.back())
- {
- return {false, nullptr};
- }
-
- JSON_ASSERT(ref_stack.back()->is_array() || ref_stack.back()->is_object());
-
- if (ref_stack.back()->is_array())
- {
- ref_stack.back()->m_value.array->emplace_back(std::move(value));
- return {true, &(ref_stack.back()->m_value.array->back())};
- }
-
- JSON_ASSERT(ref_stack.back()->is_object());
-
- JSON_ASSERT(!key_keep_stack.empty());
- const bool store_element = key_keep_stack.back();
- key_keep_stack.pop_back();
- if (!store_element)
- {
- return {false, nullptr};
- }
- JSON_ASSERT(object_element);
- *object_element = std::move(value);
- return {true, object_element};
- }
-
- BasicJsonType& root;
-
- std::vector<BasicJsonType*> ref_stack {};
-
- std::vector<bool> keep_stack {};
-
- std::vector<bool> key_keep_stack {};
-
- BasicJsonType* object_element = nullptr;
-
- bool errored = false;
-
- const parser_callback_t callback = nullptr;
-
- const bool allow_exceptions = true;
-
- BasicJsonType discarded = BasicJsonType::value_t::discarded;
- };
- template<typename BasicJsonType>
- class json_sax_acceptor
- {
- public:
- using number_integer_t = typename BasicJsonType::number_integer_t;
- using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
- using number_float_t = typename BasicJsonType::number_float_t;
- using string_t = typename BasicJsonType::string_t;
- using binary_t = typename BasicJsonType::binary_t;
- bool null()
- {
- return true;
- }
- bool boolean(bool )
- {
- return true;
- }
- bool number_integer(number_integer_t )
- {
- return true;
- }
- bool number_unsigned(number_unsigned_t )
- {
- return true;
- }
- bool number_float(number_float_t , const string_t& )
- {
- return true;
- }
- bool string(string_t& )
- {
- return true;
- }
- bool binary(binary_t& )
- {
- return true;
- }
- bool start_object(std::size_t = std::size_t(-1))
- {
- return true;
- }
- bool key(string_t& )
- {
- return true;
- }
- bool end_object()
- {
- return true;
- }
- bool start_array(std::size_t = std::size_t(-1))
- {
- return true;
- }
- bool end_array()
- {
- return true;
- }
- bool parse_error(std::size_t , const std::string& , const detail::exception& )
- {
- return false;
- }
- };
- }
- }
- #include <array> // array
- #include <clocale> // localeconv
- #include <cstddef> // size_t
- #include <cstdio> // snprintf
- #include <cstdlib> // strtof, strtod, strtold, strtoll, strtoull
- #include <initializer_list> // initializer_list
- #include <string> // char_traits, string
- #include <utility> // move
- #include <vector> // vector
- namespace nlohmann
- {
- namespace detail
- {
- template<typename BasicJsonType>
- class lexer_base
- {
- public:
-
- enum class token_type
- {
- uninitialized,
- literal_true,
- literal_false,
- literal_null,
- value_string,
- value_unsigned,
- value_integer,
- value_float,
- begin_array,
- begin_object,
- end_array,
- end_object,
- name_separator,
- value_separator,
- parse_error,
- end_of_input,
- literal_or_value
- };
-
- JSON_HEDLEY_RETURNS_NON_NULL
- JSON_HEDLEY_CONST
- static const char* token_type_name(const token_type t) noexcept
- {
- switch (t)
- {
- case token_type::uninitialized:
- return "<uninitialized>";
- case token_type::literal_true:
- return "true literal";
- case token_type::literal_false:
- return "false literal";
- case token_type::literal_null:
- return "null literal";
- case token_type::value_string:
- return "string literal";
- case token_type::value_unsigned:
- case token_type::value_integer:
- case token_type::value_float:
- return "number literal";
- case token_type::begin_array:
- return "'['";
- case token_type::begin_object:
- return "'{'";
- case token_type::end_array:
- return "']'";
- case token_type::end_object:
- return "'}'";
- case token_type::name_separator:
- return "':'";
- case token_type::value_separator:
- return "','";
- case token_type::parse_error:
- return "<parse error>";
- case token_type::end_of_input:
- return "end of input";
- case token_type::literal_or_value:
- return "'[', '{', or a literal";
-
- default:
- return "unknown token";
-
- }
- }
- };
- template<typename BasicJsonType, typename InputAdapterType>
- class lexer : public lexer_base<BasicJsonType>
- {
- using number_integer_t = typename BasicJsonType::number_integer_t;
- using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
- using number_float_t = typename BasicJsonType::number_float_t;
- using string_t = typename BasicJsonType::string_t;
- using char_type = typename InputAdapterType::char_type;
- using char_int_type = typename std::char_traits<char_type>::int_type;
- public:
- using token_type = typename lexer_base<BasicJsonType>::token_type;
- explicit lexer(InputAdapterType&& adapter, bool ignore_comments_ = false) noexcept
- : ia(std::move(adapter))
- , ignore_comments(ignore_comments_)
- , decimal_point_char(static_cast<char_int_type>(get_decimal_point()))
- {}
-
- lexer(const lexer&) = delete;
- lexer(lexer&&) = default;
- lexer& operator=(lexer&) = delete;
- lexer& operator=(lexer&&) = default;
- ~lexer() = default;
- private:
-
-
-
-
- JSON_HEDLEY_PURE
- static char get_decimal_point() noexcept
- {
- const auto* loc = localeconv();
- JSON_ASSERT(loc != nullptr);
- return (loc->decimal_point == nullptr) ? '.' : *(loc->decimal_point);
- }
-
-
-
-
- int get_codepoint()
- {
-
- JSON_ASSERT(current == 'u');
- int codepoint = 0;
- const auto factors = { 12u, 8u, 4u, 0u };
- for (const auto factor : factors)
- {
- get();
- if (current >= '0' && current <= '9')
- {
- codepoint += static_cast<int>((static_cast<unsigned int>(current) - 0x30u) << factor);
- }
- else if (current >= 'A' && current <= 'F')
- {
- codepoint += static_cast<int>((static_cast<unsigned int>(current) - 0x37u) << factor);
- }
- else if (current >= 'a' && current <= 'f')
- {
- codepoint += static_cast<int>((static_cast<unsigned int>(current) - 0x57u) << factor);
- }
- else
- {
- return -1;
- }
- }
- JSON_ASSERT(0x0000 <= codepoint && codepoint <= 0xFFFF);
- return codepoint;
- }
-
- bool next_byte_in_range(std::initializer_list<char_int_type> ranges)
- {
- JSON_ASSERT(ranges.size() == 2 || ranges.size() == 4 || ranges.size() == 6);
- add(current);
- for (auto range = ranges.begin(); range != ranges.end(); ++range)
- {
- get();
- if (JSON_HEDLEY_LIKELY(*range <= current && current <= *(++range)))
- {
- add(current);
- }
- else
- {
- error_message = "invalid string: ill-formed UTF-8 byte";
- return false;
- }
- }
- return true;
- }
-
- token_type scan_string()
- {
-
- reset();
-
- JSON_ASSERT(current == '\"');
- while (true)
- {
-
- switch (get())
- {
-
- case std::char_traits<char_type>::eof():
- {
- error_message = "invalid string: missing closing quote";
- return token_type::parse_error;
- }
-
- case '\"':
- {
- return token_type::value_string;
- }
-
- case '\\':
- {
- switch (get())
- {
-
- case '\"':
- add('\"');
- break;
-
- case '\\':
- add('\\');
- break;
-
- case '/':
- add('/');
- break;
-
- case 'b':
- add('\b');
- break;
-
- case 'f':
- add('\f');
- break;
-
- case 'n':
- add('\n');
- break;
-
- case 'r':
- add('\r');
- break;
-
- case 't':
- add('\t');
- break;
-
- case 'u':
- {
- const int codepoint1 = get_codepoint();
- int codepoint = codepoint1;
- if (JSON_HEDLEY_UNLIKELY(codepoint1 == -1))
- {
- error_message = "invalid string: '\\u' must be followed by 4 hex digits";
- return token_type::parse_error;
- }
-
- if (0xD800 <= codepoint1 && codepoint1 <= 0xDBFF)
- {
-
- if (JSON_HEDLEY_LIKELY(get() == '\\' && get() == 'u'))
- {
- const int codepoint2 = get_codepoint();
- if (JSON_HEDLEY_UNLIKELY(codepoint2 == -1))
- {
- error_message = "invalid string: '\\u' must be followed by 4 hex digits";
- return token_type::parse_error;
- }
-
- if (JSON_HEDLEY_LIKELY(0xDC00 <= codepoint2 && codepoint2 <= 0xDFFF))
- {
-
- codepoint = static_cast<int>(
-
- (static_cast<unsigned int>(codepoint1) << 10u)
-
- + static_cast<unsigned int>(codepoint2)
-
-
-
- - 0x35FDC00u);
- }
- else
- {
- error_message = "invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF";
- return token_type::parse_error;
- }
- }
- else
- {
- error_message = "invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF";
- return token_type::parse_error;
- }
- }
- else
- {
- if (JSON_HEDLEY_UNLIKELY(0xDC00 <= codepoint1 && codepoint1 <= 0xDFFF))
- {
- error_message = "invalid string: surrogate U+DC00..U+DFFF must follow U+D800..U+DBFF";
- return token_type::parse_error;
- }
- }
-
- JSON_ASSERT(0x00 <= codepoint && codepoint <= 0x10FFFF);
-
- if (codepoint < 0x80)
- {
-
- add(static_cast<char_int_type>(codepoint));
- }
- else if (codepoint <= 0x7FF)
- {
-
- add(static_cast<char_int_type>(0xC0u | (static_cast<unsigned int>(codepoint) >> 6u)));
- add(static_cast<char_int_type>(0x80u | (static_cast<unsigned int>(codepoint) & 0x3Fu)));
- }
- else if (codepoint <= 0xFFFF)
- {
-
- add(static_cast<char_int_type>(0xE0u | (static_cast<unsigned int>(codepoint) >> 12u)));
- add(static_cast<char_int_type>(0x80u | ((static_cast<unsigned int>(codepoint) >> 6u) & 0x3Fu)));
- add(static_cast<char_int_type>(0x80u | (static_cast<unsigned int>(codepoint) & 0x3Fu)));
- }
- else
- {
-
- add(static_cast<char_int_type>(0xF0u | (static_cast<unsigned int>(codepoint) >> 18u)));
- add(static_cast<char_int_type>(0x80u | ((static_cast<unsigned int>(codepoint) >> 12u) & 0x3Fu)));
- add(static_cast<char_int_type>(0x80u | ((static_cast<unsigned int>(codepoint) >> 6u) & 0x3Fu)));
- add(static_cast<char_int_type>(0x80u | (static_cast<unsigned int>(codepoint) & 0x3Fu)));
- }
- break;
- }
-
- default:
- error_message = "invalid string: forbidden character after backslash";
- return token_type::parse_error;
- }
- break;
- }
-
- case 0x00:
- {
- error_message = "invalid string: control character U+0000 (NUL) must be escaped to \\u0000";
- return token_type::parse_error;
- }
- case 0x01:
- {
- error_message = "invalid string: control character U+0001 (SOH) must be escaped to \\u0001";
- return token_type::parse_error;
- }
- case 0x02:
- {
- error_message = "invalid string: control character U+0002 (STX) must be escaped to \\u0002";
- return token_type::parse_error;
- }
- case 0x03:
- {
- error_message = "invalid string: control character U+0003 (ETX) must be escaped to \\u0003";
- return token_type::parse_error;
- }
- case 0x04:
- {
- error_message = "invalid string: control character U+0004 (EOT) must be escaped to \\u0004";
- return token_type::parse_error;
- }
- case 0x05:
- {
- error_message = "invalid string: control character U+0005 (ENQ) must be escaped to \\u0005";
- return token_type::parse_error;
- }
- case 0x06:
- {
- error_message = "invalid string: control character U+0006 (ACK) must be escaped to \\u0006";
- return token_type::parse_error;
- }
- case 0x07:
- {
- error_message = "invalid string: control character U+0007 (BEL) must be escaped to \\u0007";
- return token_type::parse_error;
- }
- case 0x08:
- {
- error_message = "invalid string: control character U+0008 (BS) must be escaped to \\u0008 or \\b";
- return token_type::parse_error;
- }
- case 0x09:
- {
- error_message = "invalid string: control character U+0009 (HT) must be escaped to \\u0009 or \\t";
- return token_type::parse_error;
- }
- case 0x0A:
- {
- error_message = "invalid string: control character U+000A (LF) must be escaped to \\u000A or \\n";
- return token_type::parse_error;
- }
- case 0x0B:
- {
- error_message = "invalid string: control character U+000B (VT) must be escaped to \\u000B";
- return token_type::parse_error;
- }
- case 0x0C:
- {
- error_message = "invalid string: control character U+000C (FF) must be escaped to \\u000C or \\f";
- return token_type::parse_error;
- }
- case 0x0D:
- {
- error_message = "invalid string: control character U+000D (CR) must be escaped to \\u000D or \\r";
- return token_type::parse_error;
- }
- case 0x0E:
- {
- error_message = "invalid string: control character U+000E (SO) must be escaped to \\u000E";
- return token_type::parse_error;
- }
- case 0x0F:
- {
- error_message = "invalid string: control character U+000F (SI) must be escaped to \\u000F";
- return token_type::parse_error;
- }
- case 0x10:
- {
- error_message = "invalid string: control character U+0010 (DLE) must be escaped to \\u0010";
- return token_type::parse_error;
- }
- case 0x11:
- {
- error_message = "invalid string: control character U+0011 (DC1) must be escaped to \\u0011";
- return token_type::parse_error;
- }
- case 0x12:
- {
- error_message = "invalid string: control character U+0012 (DC2) must be escaped to \\u0012";
- return token_type::parse_error;
- }
- case 0x13:
- {
- error_message = "invalid string: control character U+0013 (DC3) must be escaped to \\u0013";
- return token_type::parse_error;
- }
- case 0x14:
- {
- error_message = "invalid string: control character U+0014 (DC4) must be escaped to \\u0014";
- return token_type::parse_error;
- }
- case 0x15:
- {
- error_message = "invalid string: control character U+0015 (NAK) must be escaped to \\u0015";
- return token_type::parse_error;
- }
- case 0x16:
- {
- error_message = "invalid string: control character U+0016 (SYN) must be escaped to \\u0016";
- return token_type::parse_error;
- }
- case 0x17:
- {
- error_message = "invalid string: control character U+0017 (ETB) must be escaped to \\u0017";
- return token_type::parse_error;
- }
- case 0x18:
- {
- error_message = "invalid string: control character U+0018 (CAN) must be escaped to \\u0018";
- return token_type::parse_error;
- }
- case 0x19:
- {
- error_message = "invalid string: control character U+0019 (EM) must be escaped to \\u0019";
- return token_type::parse_error;
- }
- case 0x1A:
- {
- error_message = "invalid string: control character U+001A (SUB) must be escaped to \\u001A";
- return token_type::parse_error;
- }
- case 0x1B:
- {
- error_message = "invalid string: control character U+001B (ESC) must be escaped to \\u001B";
- return token_type::parse_error;
- }
- case 0x1C:
- {
- error_message = "invalid string: control character U+001C (FS) must be escaped to \\u001C";
- return token_type::parse_error;
- }
- case 0x1D:
- {
- error_message = "invalid string: control character U+001D (GS) must be escaped to \\u001D";
- return token_type::parse_error;
- }
- case 0x1E:
- {
- error_message = "invalid string: control character U+001E (RS) must be escaped to \\u001E";
- return token_type::parse_error;
- }
- case 0x1F:
- {
- error_message = "invalid string: control character U+001F (US) must be escaped to \\u001F";
- return token_type::parse_error;
- }
-
- case 0x20:
- case 0x21:
- case 0x23:
- case 0x24:
- case 0x25:
- case 0x26:
- case 0x27:
- case 0x28:
- case 0x29:
- case 0x2A:
- case 0x2B:
- case 0x2C:
- case 0x2D:
- case 0x2E:
- case 0x2F:
- case 0x30:
- case 0x31:
- case 0x32:
- case 0x33:
- case 0x34:
- case 0x35:
- case 0x36:
- case 0x37:
- case 0x38:
- case 0x39:
- case 0x3A:
- case 0x3B:
- case 0x3C:
- case 0x3D:
- case 0x3E:
- case 0x3F:
- case 0x40:
- case 0x41:
- case 0x42:
- case 0x43:
- case 0x44:
- case 0x45:
- case 0x46:
- case 0x47:
- case 0x48:
- case 0x49:
- case 0x4A:
- case 0x4B:
- case 0x4C:
- case 0x4D:
- case 0x4E:
- case 0x4F:
- case 0x50:
- case 0x51:
- case 0x52:
- case 0x53:
- case 0x54:
- case 0x55:
- case 0x56:
- case 0x57:
- case 0x58:
- case 0x59:
- case 0x5A:
- case 0x5B:
- case 0x5D:
- case 0x5E:
- case 0x5F:
- case 0x60:
- case 0x61:
- case 0x62:
- case 0x63:
- case 0x64:
- case 0x65:
- case 0x66:
- case 0x67:
- case 0x68:
- case 0x69:
- case 0x6A:
- case 0x6B:
- case 0x6C:
- case 0x6D:
- case 0x6E:
- case 0x6F:
- case 0x70:
- case 0x71:
- case 0x72:
- case 0x73:
- case 0x74:
- case 0x75:
- case 0x76:
- case 0x77:
- case 0x78:
- case 0x79:
- case 0x7A:
- case 0x7B:
- case 0x7C:
- case 0x7D:
- case 0x7E:
- case 0x7F:
- {
- add(current);
- break;
- }
-
- case 0xC2:
- case 0xC3:
- case 0xC4:
- case 0xC5:
- case 0xC6:
- case 0xC7:
- case 0xC8:
- case 0xC9:
- case 0xCA:
- case 0xCB:
- case 0xCC:
- case 0xCD:
- case 0xCE:
- case 0xCF:
- case 0xD0:
- case 0xD1:
- case 0xD2:
- case 0xD3:
- case 0xD4:
- case 0xD5:
- case 0xD6:
- case 0xD7:
- case 0xD8:
- case 0xD9:
- case 0xDA:
- case 0xDB:
- case 0xDC:
- case 0xDD:
- case 0xDE:
- case 0xDF:
- {
- if (JSON_HEDLEY_UNLIKELY(!next_byte_in_range({0x80, 0xBF})))
- {
- return token_type::parse_error;
- }
- break;
- }
-
- case 0xE0:
- {
- if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0xA0, 0xBF, 0x80, 0xBF}))))
- {
- return token_type::parse_error;
- }
- break;
- }
-
-
- case 0xE1:
- case 0xE2:
- case 0xE3:
- case 0xE4:
- case 0xE5:
- case 0xE6:
- case 0xE7:
- case 0xE8:
- case 0xE9:
- case 0xEA:
- case 0xEB:
- case 0xEC:
- case 0xEE:
- case 0xEF:
- {
- if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0xBF, 0x80, 0xBF}))))
- {
- return token_type::parse_error;
- }
- break;
- }
-
- case 0xED:
- {
- if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0x9F, 0x80, 0xBF}))))
- {
- return token_type::parse_error;
- }
- break;
- }
-
- case 0xF0:
- {
- if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x90, 0xBF, 0x80, 0xBF, 0x80, 0xBF}))))
- {
- return token_type::parse_error;
- }
- break;
- }
-
- case 0xF1:
- case 0xF2:
- case 0xF3:
- {
- if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0xBF, 0x80, 0xBF, 0x80, 0xBF}))))
- {
- return token_type::parse_error;
- }
- break;
- }
-
- case 0xF4:
- {
- if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0x8F, 0x80, 0xBF, 0x80, 0xBF}))))
- {
- return token_type::parse_error;
- }
- break;
- }
-
- default:
- {
- error_message = "invalid string: ill-formed UTF-8 byte";
- return token_type::parse_error;
- }
- }
- }
- }
-
- bool scan_comment()
- {
- switch (get())
- {
-
- case '/':
- {
- while (true)
- {
- switch (get())
- {
- case '\n':
- case '\r':
- case std::char_traits<char_type>::eof():
- case '\0':
- return true;
- default:
- break;
- }
- }
- }
-
- case '*':
- {
- while (true)
- {
- switch (get())
- {
- case std::char_traits<char_type>::eof():
- case '\0':
- {
- error_message = "invalid comment; missing closing '*/'";
- return false;
- }
- case '*':
- {
- switch (get())
- {
- case '/':
- return true;
- default:
- {
- unget();
- continue;
- }
- }
- }
- default:
- continue;
- }
- }
- }
-
- default:
- {
- error_message = "invalid comment; expecting '/' or '*' after '/'";
- return false;
- }
- }
- }
- JSON_HEDLEY_NON_NULL(2)
- static void strtof(float& f, const char* str, char** endptr) noexcept
- {
- f = std::strtof(str, endptr);
- }
- JSON_HEDLEY_NON_NULL(2)
- static void strtof(double& f, const char* str, char** endptr) noexcept
- {
- f = std::strtod(str, endptr);
- }
- JSON_HEDLEY_NON_NULL(2)
- static void strtof(long double& f, const char* str, char** endptr) noexcept
- {
- f = std::strtold(str, endptr);
- }
-
- token_type scan_number()
- {
-
- reset();
-
-
- token_type number_type = token_type::value_unsigned;
-
- switch (current)
- {
- case '-':
- {
- add(current);
- goto scan_number_minus;
- }
- case '0':
- {
- add(current);
- goto scan_number_zero;
- }
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- {
- add(current);
- goto scan_number_any1;
- }
-
- default:
- JSON_ASSERT(false);
- }
- scan_number_minus:
-
- number_type = token_type::value_integer;
- switch (get())
- {
- case '0':
- {
- add(current);
- goto scan_number_zero;
- }
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- {
- add(current);
- goto scan_number_any1;
- }
- default:
- {
- error_message = "invalid number; expected digit after '-'";
- return token_type::parse_error;
- }
- }
- scan_number_zero:
-
- switch (get())
- {
- case '.':
- {
- add(decimal_point_char);
- goto scan_number_decimal1;
- }
- case 'e':
- case 'E':
- {
- add(current);
- goto scan_number_exponent;
- }
- default:
- goto scan_number_done;
- }
- scan_number_any1:
-
- switch (get())
- {
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- {
- add(current);
- goto scan_number_any1;
- }
- case '.':
- {
- add(decimal_point_char);
- goto scan_number_decimal1;
- }
- case 'e':
- case 'E':
- {
- add(current);
- goto scan_number_exponent;
- }
- default:
- goto scan_number_done;
- }
- scan_number_decimal1:
-
- number_type = token_type::value_float;
- switch (get())
- {
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- {
- add(current);
- goto scan_number_decimal2;
- }
- default:
- {
- error_message = "invalid number; expected digit after '.'";
- return token_type::parse_error;
- }
- }
- scan_number_decimal2:
-
- switch (get())
- {
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- {
- add(current);
- goto scan_number_decimal2;
- }
- case 'e':
- case 'E':
- {
- add(current);
- goto scan_number_exponent;
- }
- default:
- goto scan_number_done;
- }
- scan_number_exponent:
-
- number_type = token_type::value_float;
- switch (get())
- {
- case '+':
- case '-':
- {
- add(current);
- goto scan_number_sign;
- }
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- {
- add(current);
- goto scan_number_any2;
- }
- default:
- {
- error_message =
- "invalid number; expected '+', '-', or digit after exponent";
- return token_type::parse_error;
- }
- }
- scan_number_sign:
-
- switch (get())
- {
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- {
- add(current);
- goto scan_number_any2;
- }
- default:
- {
- error_message = "invalid number; expected digit after exponent sign";
- return token_type::parse_error;
- }
- }
- scan_number_any2:
-
- switch (get())
- {
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- {
- add(current);
- goto scan_number_any2;
- }
- default:
- goto scan_number_done;
- }
- scan_number_done:
-
-
- unget();
- char* endptr = nullptr;
- errno = 0;
-
- if (number_type == token_type::value_unsigned)
- {
- const auto x = std::strtoull(token_buffer.data(), &endptr, 10);
-
- JSON_ASSERT(endptr == token_buffer.data() + token_buffer.size());
- if (errno == 0)
- {
- value_unsigned = static_cast<number_unsigned_t>(x);
- if (value_unsigned == x)
- {
- return token_type::value_unsigned;
- }
- }
- }
- else if (number_type == token_type::value_integer)
- {
- const auto x = std::strtoll(token_buffer.data(), &endptr, 10);
-
- JSON_ASSERT(endptr == token_buffer.data() + token_buffer.size());
- if (errno == 0)
- {
- value_integer = static_cast<number_integer_t>(x);
- if (value_integer == x)
- {
- return token_type::value_integer;
- }
- }
- }
-
-
- strtof(value_float, token_buffer.data(), &endptr);
-
- JSON_ASSERT(endptr == token_buffer.data() + token_buffer.size());
- return token_type::value_float;
- }
-
- JSON_HEDLEY_NON_NULL(2)
- token_type scan_literal(const char_type* literal_text, const std::size_t length,
- token_type return_type)
- {
- JSON_ASSERT(std::char_traits<char_type>::to_char_type(current) == literal_text[0]);
- for (std::size_t i = 1; i < length; ++i)
- {
- if (JSON_HEDLEY_UNLIKELY(std::char_traits<char_type>::to_char_type(get()) != literal_text[i]))
- {
- error_message = "invalid literal";
- return token_type::parse_error;
- }
- }
- return return_type;
- }
-
-
-
-
- void reset() noexcept
- {
- token_buffer.clear();
- token_string.clear();
- token_string.push_back(std::char_traits<char_type>::to_char_type(current));
- }
-
- char_int_type get()
- {
- ++position.chars_read_total;
- ++position.chars_read_current_line;
- if (next_unget)
- {
-
- next_unget = false;
- }
- else
- {
- current = ia.get_character();
- }
- if (JSON_HEDLEY_LIKELY(current != std::char_traits<char_type>::eof()))
- {
- token_string.push_back(std::char_traits<char_type>::to_char_type(current));
- }
- if (current == '\n')
- {
- ++position.lines_read;
- position.chars_read_current_line = 0;
- }
- return current;
- }
-
- void unget()
- {
- next_unget = true;
- --position.chars_read_total;
-
- if (position.chars_read_current_line == 0)
- {
- if (position.lines_read > 0)
- {
- --position.lines_read;
- }
- }
- else
- {
- --position.chars_read_current_line;
- }
- if (JSON_HEDLEY_LIKELY(current != std::char_traits<char_type>::eof()))
- {
- JSON_ASSERT(!token_string.empty());
- token_string.pop_back();
- }
- }
-
- void add(char_int_type c)
- {
- token_buffer.push_back(static_cast<typename string_t::value_type>(c));
- }
- public:
-
-
-
-
- constexpr number_integer_t get_number_integer() const noexcept
- {
- return value_integer;
- }
-
- constexpr number_unsigned_t get_number_unsigned() const noexcept
- {
- return value_unsigned;
- }
-
- constexpr number_float_t get_number_float() const noexcept
- {
- return value_float;
- }
-
- string_t& get_string()
- {
- return token_buffer;
- }
-
-
-
-
- constexpr position_t get_position() const noexcept
- {
- return position;
- }
-
-
-
- std::string get_token_string() const
- {
-
- std::string result;
- for (const auto c : token_string)
- {
- if (static_cast<unsigned char>(c) <= '\x1F')
- {
-
- std::array<char, 9> cs{{}};
- (std::snprintf)(cs.data(), cs.size(), "<U+%.4X>", static_cast<unsigned char>(c));
- result += cs.data();
- }
- else
- {
-
- result.push_back(static_cast<std::string::value_type>(c));
- }
- }
- return result;
- }
-
- JSON_HEDLEY_RETURNS_NON_NULL
- constexpr const char* get_error_message() const noexcept
- {
- return error_message;
- }
-
-
-
-
- bool skip_bom()
- {
- if (get() == 0xEF)
- {
-
- return get() == 0xBB && get() == 0xBF;
- }
-
-
- unget();
- return true;
- }
- void skip_whitespace()
- {
- do
- {
- get();
- }
- while (current == ' ' || current == '\t' || current == '\n' || current == '\r');
- }
- token_type scan()
- {
-
- if (position.chars_read_total == 0 && !skip_bom())
- {
- error_message = "invalid BOM; must be 0xEF 0xBB 0xBF if given";
- return token_type::parse_error;
- }
-
- skip_whitespace();
-
- while (ignore_comments && current == '/')
- {
- if (!scan_comment())
- {
- return token_type::parse_error;
- }
-
- skip_whitespace();
- }
- switch (current)
- {
-
- case '[':
- return token_type::begin_array;
- case ']':
- return token_type::end_array;
- case '{':
- return token_type::begin_object;
- case '}':
- return token_type::end_object;
- case ':':
- return token_type::name_separator;
- case ',':
- return token_type::value_separator;
-
- case 't':
- {
- std::array<char_type, 4> true_literal = {{char_type('t'), char_type('r'), char_type('u'), char_type('e')}};
- return scan_literal(true_literal.data(), true_literal.size(), token_type::literal_true);
- }
- case 'f':
- {
- std::array<char_type, 5> false_literal = {{char_type('f'), char_type('a'), char_type('l'), char_type('s'), char_type('e')}};
- return scan_literal(false_literal.data(), false_literal.size(), token_type::literal_false);
- }
- case 'n':
- {
- std::array<char_type, 4> null_literal = {{char_type('n'), char_type('u'), char_type('l'), char_type('l')}};
- return scan_literal(null_literal.data(), null_literal.size(), token_type::literal_null);
- }
-
- case '\"':
- return scan_string();
-
- case '-':
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- return scan_number();
-
-
- case '\0':
- case std::char_traits<char_type>::eof():
- return token_type::end_of_input;
-
- default:
- error_message = "invalid literal";
- return token_type::parse_error;
- }
- }
- private:
-
- InputAdapterType ia;
-
- const bool ignore_comments = false;
-
- char_int_type current = std::char_traits<char_type>::eof();
-
- bool next_unget = false;
-
- position_t position {};
-
- std::vector<char_type> token_string {};
-
- string_t token_buffer {};
-
- const char* error_message = "";
-
- number_integer_t value_integer = 0;
- number_unsigned_t value_unsigned = 0;
- number_float_t value_float = 0;
-
- const char_int_type decimal_point_char = '.';
- };
- }
- }
- #include <cstdint> // size_t
- #include <utility> // declval
- #include <string> // string
- namespace nlohmann
- {
- namespace detail
- {
- template<typename T>
- using null_function_t = decltype(std::declval<T&>().null());
- template<typename T>
- using boolean_function_t =
- decltype(std::declval<T&>().boolean(std::declval<bool>()));
- template<typename T, typename Integer>
- using number_integer_function_t =
- decltype(std::declval<T&>().number_integer(std::declval<Integer>()));
- template<typename T, typename Unsigned>
- using number_unsigned_function_t =
- decltype(std::declval<T&>().number_unsigned(std::declval<Unsigned>()));
- template<typename T, typename Float, typename String>
- using number_float_function_t = decltype(std::declval<T&>().number_float(
- std::declval<Float>(), std::declval<const String&>()));
- template<typename T, typename String>
- using string_function_t =
- decltype(std::declval<T&>().string(std::declval<String&>()));
- template<typename T, typename Binary>
- using binary_function_t =
- decltype(std::declval<T&>().binary(std::declval<Binary&>()));
- template<typename T>
- using start_object_function_t =
- decltype(std::declval<T&>().start_object(std::declval<std::size_t>()));
- template<typename T, typename String>
- using key_function_t =
- decltype(std::declval<T&>().key(std::declval<String&>()));
- template<typename T>
- using end_object_function_t = decltype(std::declval<T&>().end_object());
- template<typename T>
- using start_array_function_t =
- decltype(std::declval<T&>().start_array(std::declval<std::size_t>()));
- template<typename T>
- using end_array_function_t = decltype(std::declval<T&>().end_array());
- template<typename T, typename Exception>
- using parse_error_function_t = decltype(std::declval<T&>().parse_error(
- std::declval<std::size_t>(), std::declval<const std::string&>(),
- std::declval<const Exception&>()));
- template<typename SAX, typename BasicJsonType>
- struct is_sax
- {
- private:
- static_assert(is_basic_json<BasicJsonType>::value,
- "BasicJsonType must be of type basic_json<...>");
- using number_integer_t = typename BasicJsonType::number_integer_t;
- using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
- using number_float_t = typename BasicJsonType::number_float_t;
- using string_t = typename BasicJsonType::string_t;
- using binary_t = typename BasicJsonType::binary_t;
- using exception_t = typename BasicJsonType::exception;
- public:
- static constexpr bool value =
- is_detected_exact<bool, null_function_t, SAX>::value &&
- is_detected_exact<bool, boolean_function_t, SAX>::value &&
- is_detected_exact<bool, number_integer_function_t, SAX, number_integer_t>::value &&
- is_detected_exact<bool, number_unsigned_function_t, SAX, number_unsigned_t>::value &&
- is_detected_exact<bool, number_float_function_t, SAX, number_float_t, string_t>::value &&
- is_detected_exact<bool, string_function_t, SAX, string_t>::value &&
- is_detected_exact<bool, binary_function_t, SAX, binary_t>::value &&
- is_detected_exact<bool, start_object_function_t, SAX>::value &&
- is_detected_exact<bool, key_function_t, SAX, string_t>::value &&
- is_detected_exact<bool, end_object_function_t, SAX>::value &&
- is_detected_exact<bool, start_array_function_t, SAX>::value &&
- is_detected_exact<bool, end_array_function_t, SAX>::value &&
- is_detected_exact<bool, parse_error_function_t, SAX, exception_t>::value;
- };
- template<typename SAX, typename BasicJsonType>
- struct is_sax_static_asserts
- {
- private:
- static_assert(is_basic_json<BasicJsonType>::value,
- "BasicJsonType must be of type basic_json<...>");
- using number_integer_t = typename BasicJsonType::number_integer_t;
- using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
- using number_float_t = typename BasicJsonType::number_float_t;
- using string_t = typename BasicJsonType::string_t;
- using binary_t = typename BasicJsonType::binary_t;
- using exception_t = typename BasicJsonType::exception;
- public:
- static_assert(is_detected_exact<bool, null_function_t, SAX>::value,
- "Missing/invalid function: bool null()");
- static_assert(is_detected_exact<bool, boolean_function_t, SAX>::value,
- "Missing/invalid function: bool boolean(bool)");
- static_assert(is_detected_exact<bool, boolean_function_t, SAX>::value,
- "Missing/invalid function: bool boolean(bool)");
- static_assert(
- is_detected_exact<bool, number_integer_function_t, SAX,
- number_integer_t>::value,
- "Missing/invalid function: bool number_integer(number_integer_t)");
- static_assert(
- is_detected_exact<bool, number_unsigned_function_t, SAX,
- number_unsigned_t>::value,
- "Missing/invalid function: bool number_unsigned(number_unsigned_t)");
- static_assert(is_detected_exact<bool, number_float_function_t, SAX,
- number_float_t, string_t>::value,
- "Missing/invalid function: bool number_float(number_float_t, const string_t&)");
- static_assert(
- is_detected_exact<bool, string_function_t, SAX, string_t>::value,
- "Missing/invalid function: bool string(string_t&)");
- static_assert(
- is_detected_exact<bool, binary_function_t, SAX, binary_t>::value,
- "Missing/invalid function: bool binary(binary_t&)");
- static_assert(is_detected_exact<bool, start_object_function_t, SAX>::value,
- "Missing/invalid function: bool start_object(std::size_t)");
- static_assert(is_detected_exact<bool, key_function_t, SAX, string_t>::value,
- "Missing/invalid function: bool key(string_t&)");
- static_assert(is_detected_exact<bool, end_object_function_t, SAX>::value,
- "Missing/invalid function: bool end_object()");
- static_assert(is_detected_exact<bool, start_array_function_t, SAX>::value,
- "Missing/invalid function: bool start_array(std::size_t)");
- static_assert(is_detected_exact<bool, end_array_function_t, SAX>::value,
- "Missing/invalid function: bool end_array()");
- static_assert(
- is_detected_exact<bool, parse_error_function_t, SAX, exception_t>::value,
- "Missing/invalid function: bool parse_error(std::size_t, const "
- "std::string&, const exception&)");
- };
- }
- }
- namespace nlohmann
- {
- namespace detail
- {
- enum class cbor_tag_handler_t
- {
- error,
- ignore,
- store
- };
- static inline bool little_endianess(int num = 1) noexcept
- {
- return *reinterpret_cast<char*>(&num) == 1;
- }
- template<typename BasicJsonType, typename InputAdapterType, typename SAX = json_sax_dom_parser<BasicJsonType>>
- class binary_reader
- {
- using number_integer_t = typename BasicJsonType::number_integer_t;
- using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
- using number_float_t = typename BasicJsonType::number_float_t;
- using string_t = typename BasicJsonType::string_t;
- using binary_t = typename BasicJsonType::binary_t;
- using json_sax_t = SAX;
- using char_type = typename InputAdapterType::char_type;
- using char_int_type = typename std::char_traits<char_type>::int_type;
- public:
-
- explicit binary_reader(InputAdapterType&& adapter) noexcept : ia(std::move(adapter))
- {
- (void)detail::is_sax_static_asserts<SAX, BasicJsonType> {};
- }
-
- binary_reader(const binary_reader&) = delete;
- binary_reader(binary_reader&&) = default;
- binary_reader& operator=(const binary_reader&) = delete;
- binary_reader& operator=(binary_reader&&) = default;
- ~binary_reader() = default;
-
- JSON_HEDLEY_NON_NULL(3)
- bool sax_parse(const input_format_t format,
- json_sax_t* sax_,
- const bool strict = true,
- const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error)
- {
- sax = sax_;
- bool result = false;
- switch (format)
- {
- case input_format_t::bson:
- result = parse_bson_internal();
- break;
- case input_format_t::cbor:
- result = parse_cbor_internal(true, tag_handler);
- break;
- case input_format_t::msgpack:
- result = parse_msgpack_internal();
- break;
- case input_format_t::ubjson:
- result = parse_ubjson_internal();
- break;
- case input_format_t::json:
- default:
- JSON_ASSERT(false);
- }
-
- if (result && strict)
- {
- if (format == input_format_t::ubjson)
- {
- get_ignore_noop();
- }
- else
- {
- get();
- }
- if (JSON_HEDLEY_UNLIKELY(current != std::char_traits<char_type>::eof()))
- {
- return sax->parse_error(chars_read, get_token_string(),
- parse_error::create(110, chars_read, exception_message(format, "expected end of input; last byte: 0x" + get_token_string(), "value"), BasicJsonType()));
- }
- }
- return result;
- }
- private:
-
-
-
-
- bool parse_bson_internal()
- {
- std::int32_t document_size{};
- get_number<std::int32_t, true>(input_format_t::bson, document_size);
- if (JSON_HEDLEY_UNLIKELY(!sax->start_object(std::size_t(-1))))
- {
- return false;
- }
- if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_list(false)))
- {
- return false;
- }
- return sax->end_object();
- }
-
- bool get_bson_cstr(string_t& result)
- {
- auto out = std::back_inserter(result);
- while (true)
- {
- get();
- if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::bson, "cstring")))
- {
- return false;
- }
- if (current == 0x00)
- {
- return true;
- }
- *out++ = static_cast<typename string_t::value_type>(current);
- }
- }
-
- template<typename NumberType>
- bool get_bson_string(const NumberType len, string_t& result)
- {
- if (JSON_HEDLEY_UNLIKELY(len < 1))
- {
- auto last_token = get_token_string();
- return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::bson, "string length must be at least 1, is " + std::to_string(len), "string"), BasicJsonType()));
- }
- return get_string(input_format_t::bson, len - static_cast<NumberType>(1), result) && get() != std::char_traits<char_type>::eof();
- }
-
- template<typename NumberType>
- bool get_bson_binary(const NumberType len, binary_t& result)
- {
- if (JSON_HEDLEY_UNLIKELY(len < 0))
- {
- auto last_token = get_token_string();
- return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::bson, "byte array length cannot be negative, is " + std::to_string(len), "binary"), BasicJsonType()));
- }
-
- std::uint8_t subtype{};
- get_number<std::uint8_t>(input_format_t::bson, subtype);
- result.set_subtype(subtype);
- return get_binary(input_format_t::bson, len, result);
- }
-
- bool parse_bson_element_internal(const char_int_type element_type,
- const std::size_t element_type_parse_position)
- {
- switch (element_type)
- {
- case 0x01:
- {
- double number{};
- return get_number<double, true>(input_format_t::bson, number) && sax->number_float(static_cast<number_float_t>(number), "");
- }
- case 0x02:
- {
- std::int32_t len{};
- string_t value;
- return get_number<std::int32_t, true>(input_format_t::bson, len) && get_bson_string(len, value) && sax->string(value);
- }
- case 0x03:
- {
- return parse_bson_internal();
- }
- case 0x04:
- {
- return parse_bson_array();
- }
- case 0x05:
- {
- std::int32_t len{};
- binary_t value;
- return get_number<std::int32_t, true>(input_format_t::bson, len) && get_bson_binary(len, value) && sax->binary(value);
- }
- case 0x08:
- {
- return sax->boolean(get() != 0);
- }
- case 0x0A:
- {
- return sax->null();
- }
- case 0x10:
- {
- std::int32_t value{};
- return get_number<std::int32_t, true>(input_format_t::bson, value) && sax->number_integer(value);
- }
- case 0x12:
- {
- std::int64_t value{};
- return get_number<std::int64_t, true>(input_format_t::bson, value) && sax->number_integer(value);
- }
- default:
- {
- std::array<char, 3> cr{{}};
- (std::snprintf)(cr.data(), cr.size(), "%.2hhX", static_cast<unsigned char>(element_type));
- return sax->parse_error(element_type_parse_position, std::string(cr.data()), parse_error::create(114, element_type_parse_position, "Unsupported BSON record type 0x" + std::string(cr.data()), BasicJsonType()));
- }
- }
- }
-
- bool parse_bson_element_list(const bool is_array)
- {
- string_t key;
- while (auto element_type = get())
- {
- if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::bson, "element list")))
- {
- return false;
- }
- const std::size_t element_type_parse_position = chars_read;
- if (JSON_HEDLEY_UNLIKELY(!get_bson_cstr(key)))
- {
- return false;
- }
- if (!is_array && !sax->key(key))
- {
- return false;
- }
- if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_internal(element_type, element_type_parse_position)))
- {
- return false;
- }
-
- key.clear();
- }
- return true;
- }
-
- bool parse_bson_array()
- {
- std::int32_t document_size{};
- get_number<std::int32_t, true>(input_format_t::bson, document_size);
- if (JSON_HEDLEY_UNLIKELY(!sax->start_array(std::size_t(-1))))
- {
- return false;
- }
- if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_list(true)))
- {
- return false;
- }
- return sax->end_array();
- }
-
-
-
-
- bool parse_cbor_internal(const bool get_char,
- const cbor_tag_handler_t tag_handler)
- {
- switch (get_char ? get() : current)
- {
-
- case std::char_traits<char_type>::eof():
- return unexpect_eof(input_format_t::cbor, "value");
-
- case 0x00:
- case 0x01:
- case 0x02:
- case 0x03:
- case 0x04:
- case 0x05:
- case 0x06:
- case 0x07:
- case 0x08:
- case 0x09:
- case 0x0A:
- case 0x0B:
- case 0x0C:
- case 0x0D:
- case 0x0E:
- case 0x0F:
- case 0x10:
- case 0x11:
- case 0x12:
- case 0x13:
- case 0x14:
- case 0x15:
- case 0x16:
- case 0x17:
- return sax->number_unsigned(static_cast<number_unsigned_t>(current));
- case 0x18:
- {
- std::uint8_t number{};
- return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
- }
- case 0x19:
- {
- std::uint16_t number{};
- return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
- }
- case 0x1A:
- {
- std::uint32_t number{};
- return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
- }
- case 0x1B:
- {
- std::uint64_t number{};
- return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
- }
-
- case 0x20:
- case 0x21:
- case 0x22:
- case 0x23:
- case 0x24:
- case 0x25:
- case 0x26:
- case 0x27:
- case 0x28:
- case 0x29:
- case 0x2A:
- case 0x2B:
- case 0x2C:
- case 0x2D:
- case 0x2E:
- case 0x2F:
- case 0x30:
- case 0x31:
- case 0x32:
- case 0x33:
- case 0x34:
- case 0x35:
- case 0x36:
- case 0x37:
- return sax->number_integer(static_cast<std::int8_t>(0x20 - 1 - current));
- case 0x38:
- {
- std::uint8_t number{};
- return get_number(input_format_t::cbor, number) && sax->number_integer(static_cast<number_integer_t>(-1) - number);
- }
- case 0x39:
- {
- std::uint16_t number{};
- return get_number(input_format_t::cbor, number) && sax->number_integer(static_cast<number_integer_t>(-1) - number);
- }
- case 0x3A:
- {
- std::uint32_t number{};
- return get_number(input_format_t::cbor, number) && sax->number_integer(static_cast<number_integer_t>(-1) - number);
- }
- case 0x3B:
- {
- std::uint64_t number{};
- return get_number(input_format_t::cbor, number) && sax->number_integer(static_cast<number_integer_t>(-1)
- - static_cast<number_integer_t>(number));
- }
-
- case 0x40:
- case 0x41:
- case 0x42:
- case 0x43:
- case 0x44:
- case 0x45:
- case 0x46:
- case 0x47:
- case 0x48:
- case 0x49:
- case 0x4A:
- case 0x4B:
- case 0x4C:
- case 0x4D:
- case 0x4E:
- case 0x4F:
- case 0x50:
- case 0x51:
- case 0x52:
- case 0x53:
- case 0x54:
- case 0x55:
- case 0x56:
- case 0x57:
- case 0x58:
- case 0x59:
- case 0x5A:
- case 0x5B:
- case 0x5F:
- {
- binary_t b;
- return get_cbor_binary(b) && sax->binary(b);
- }
-
- case 0x60:
- case 0x61:
- case 0x62:
- case 0x63:
- case 0x64:
- case 0x65:
- case 0x66:
- case 0x67:
- case 0x68:
- case 0x69:
- case 0x6A:
- case 0x6B:
- case 0x6C:
- case 0x6D:
- case 0x6E:
- case 0x6F:
- case 0x70:
- case 0x71:
- case 0x72:
- case 0x73:
- case 0x74:
- case 0x75:
- case 0x76:
- case 0x77:
- case 0x78:
- case 0x79:
- case 0x7A:
- case 0x7B:
- case 0x7F:
- {
- string_t s;
- return get_cbor_string(s) && sax->string(s);
- }
-
- case 0x80:
- case 0x81:
- case 0x82:
- case 0x83:
- case 0x84:
- case 0x85:
- case 0x86:
- case 0x87:
- case 0x88:
- case 0x89:
- case 0x8A:
- case 0x8B:
- case 0x8C:
- case 0x8D:
- case 0x8E:
- case 0x8F:
- case 0x90:
- case 0x91:
- case 0x92:
- case 0x93:
- case 0x94:
- case 0x95:
- case 0x96:
- case 0x97:
- return get_cbor_array(static_cast<std::size_t>(static_cast<unsigned int>(current) & 0x1Fu), tag_handler);
- case 0x98:
- {
- std::uint8_t len{};
- return get_number(input_format_t::cbor, len) && get_cbor_array(static_cast<std::size_t>(len), tag_handler);
- }
- case 0x99:
- {
- std::uint16_t len{};
- return get_number(input_format_t::cbor, len) && get_cbor_array(static_cast<std::size_t>(len), tag_handler);
- }
- case 0x9A:
- {
- std::uint32_t len{};
- return get_number(input_format_t::cbor, len) && get_cbor_array(static_cast<std::size_t>(len), tag_handler);
- }
- case 0x9B:
- {
- std::uint64_t len{};
- return get_number(input_format_t::cbor, len) && get_cbor_array(detail::conditional_static_cast<std::size_t>(len), tag_handler);
- }
- case 0x9F:
- return get_cbor_array(std::size_t(-1), tag_handler);
-
- case 0xA0:
- case 0xA1:
- case 0xA2:
- case 0xA3:
- case 0xA4:
- case 0xA5:
- case 0xA6:
- case 0xA7:
- case 0xA8:
- case 0xA9:
- case 0xAA:
- case 0xAB:
- case 0xAC:
- case 0xAD:
- case 0xAE:
- case 0xAF:
- case 0xB0:
- case 0xB1:
- case 0xB2:
- case 0xB3:
- case 0xB4:
- case 0xB5:
- case 0xB6:
- case 0xB7:
- return get_cbor_object(static_cast<std::size_t>(static_cast<unsigned int>(current) & 0x1Fu), tag_handler);
- case 0xB8:
- {
- std::uint8_t len{};
- return get_number(input_format_t::cbor, len) && get_cbor_object(static_cast<std::size_t>(len), tag_handler);
- }
- case 0xB9:
- {
- std::uint16_t len{};
- return get_number(input_format_t::cbor, len) && get_cbor_object(static_cast<std::size_t>(len), tag_handler);
- }
- case 0xBA:
- {
- std::uint32_t len{};
- return get_number(input_format_t::cbor, len) && get_cbor_object(static_cast<std::size_t>(len), tag_handler);
- }
- case 0xBB:
- {
- std::uint64_t len{};
- return get_number(input_format_t::cbor, len) && get_cbor_object(detail::conditional_static_cast<std::size_t>(len), tag_handler);
- }
- case 0xBF:
- return get_cbor_object(std::size_t(-1), tag_handler);
- case 0xC6:
- case 0xC7:
- case 0xC8:
- case 0xC9:
- case 0xCA:
- case 0xCB:
- case 0xCC:
- case 0xCD:
- case 0xCE:
- case 0xCF:
- case 0xD0:
- case 0xD1:
- case 0xD2:
- case 0xD3:
- case 0xD4:
- case 0xD8:
- case 0xD9:
- case 0xDA:
- case 0xDB:
- {
- switch (tag_handler)
- {
- case cbor_tag_handler_t::error:
- {
- auto last_token = get_token_string();
- return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::cbor, "invalid byte: 0x" + last_token, "value"), BasicJsonType()));
- }
- case cbor_tag_handler_t::ignore:
- {
-
- switch (current)
- {
- case 0xD8:
- {
- std::uint8_t subtype_to_ignore{};
- get_number(input_format_t::cbor, subtype_to_ignore);
- break;
- }
- case 0xD9:
- {
- std::uint16_t subtype_to_ignore{};
- get_number(input_format_t::cbor, subtype_to_ignore);
- break;
- }
- case 0xDA:
- {
- std::uint32_t subtype_to_ignore{};
- get_number(input_format_t::cbor, subtype_to_ignore);
- break;
- }
- case 0xDB:
- {
- std::uint64_t subtype_to_ignore{};
- get_number(input_format_t::cbor, subtype_to_ignore);
- break;
- }
- default:
- break;
- }
- return parse_cbor_internal(true, tag_handler);
- }
- case cbor_tag_handler_t::store:
- {
- binary_t b;
-
- switch (current)
- {
- case 0xD8:
- {
- std::uint8_t subtype{};
- get_number(input_format_t::cbor, subtype);
- b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype));
- break;
- }
- case 0xD9:
- {
- std::uint16_t subtype{};
- get_number(input_format_t::cbor, subtype);
- b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype));
- break;
- }
- case 0xDA:
- {
- std::uint32_t subtype{};
- get_number(input_format_t::cbor, subtype);
- b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype));
- break;
- }
- case 0xDB:
- {
- std::uint64_t subtype{};
- get_number(input_format_t::cbor, subtype);
- b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype));
- break;
- }
- default:
- return parse_cbor_internal(true, tag_handler);
- }
- get();
- return get_cbor_binary(b) && sax->binary(b);
- }
- default:
- JSON_ASSERT(false);
- return false;
- }
- }
- case 0xF4:
- return sax->boolean(false);
- case 0xF5:
- return sax->boolean(true);
- case 0xF6:
- return sax->null();
- case 0xF9:
- {
- const auto byte1_raw = get();
- if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor, "number")))
- {
- return false;
- }
- const auto byte2_raw = get();
- if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor, "number")))
- {
- return false;
- }
- const auto byte1 = static_cast<unsigned char>(byte1_raw);
- const auto byte2 = static_cast<unsigned char>(byte2_raw);
-
-
-
-
-
-
-
-
- const auto half = static_cast<unsigned int>((byte1 << 8u) + byte2);
- const double val = [&half]
- {
- const int exp = (half >> 10u) & 0x1Fu;
- const unsigned int mant = half & 0x3FFu;
- JSON_ASSERT(0 <= exp&& exp <= 32);
- JSON_ASSERT(mant <= 1024);
- switch (exp)
- {
- case 0:
- return std::ldexp(mant, -24);
- case 31:
- return (mant == 0)
- ? std::numeric_limits<double>::infinity()
- : std::numeric_limits<double>::quiet_NaN();
- default:
- return std::ldexp(mant + 1024, exp - 25);
- }
- }();
- return sax->number_float((half & 0x8000u) != 0
- ? static_cast<number_float_t>(-val)
- : static_cast<number_float_t>(val), "");
- }
- case 0xFA:
- {
- float number{};
- return get_number(input_format_t::cbor, number) && sax->number_float(static_cast<number_float_t>(number), "");
- }
- case 0xFB:
- {
- double number{};
- return get_number(input_format_t::cbor, number) && sax->number_float(static_cast<number_float_t>(number), "");
- }
- default:
- {
- auto last_token = get_token_string();
- return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::cbor, "invalid byte: 0x" + last_token, "value"), BasicJsonType()));
- }
- }
- }
-
- bool get_cbor_string(string_t& result)
- {
- if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor, "string")))
- {
- return false;
- }
- switch (current)
- {
-
- case 0x60:
- case 0x61:
- case 0x62:
- case 0x63:
- case 0x64:
- case 0x65:
- case 0x66:
- case 0x67:
- case 0x68:
- case 0x69:
- case 0x6A:
- case 0x6B:
- case 0x6C:
- case 0x6D:
- case 0x6E:
- case 0x6F:
- case 0x70:
- case 0x71:
- case 0x72:
- case 0x73:
- case 0x74:
- case 0x75:
- case 0x76:
- case 0x77:
- {
- return get_string(input_format_t::cbor, static_cast<unsigned int>(current) & 0x1Fu, result);
- }
- case 0x78:
- {
- std::uint8_t len{};
- return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
- }
- case 0x79:
- {
- std::uint16_t len{};
- return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
- }
- case 0x7A:
- {
- std::uint32_t len{};
- return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
- }
- case 0x7B:
- {
- std::uint64_t len{};
- return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
- }
- case 0x7F:
- {
- while (get() != 0xFF)
- {
- string_t chunk;
- if (!get_cbor_string(chunk))
- {
- return false;
- }
- result.append(chunk);
- }
- return true;
- }
- default:
- {
- auto last_token = get_token_string();
- return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format_t::cbor, "expected length specification (0x60-0x7B) or indefinite string type (0x7F); last byte: 0x" + last_token, "string"), BasicJsonType()));
- }
- }
- }
-
- bool get_cbor_binary(binary_t& result)
- {
- if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor, "binary")))
- {
- return false;
- }
- switch (current)
- {
-
- case 0x40:
- case 0x41:
- case 0x42:
- case 0x43:
- case 0x44:
- case 0x45:
- case 0x46:
- case 0x47:
- case 0x48:
- case 0x49:
- case 0x4A:
- case 0x4B:
- case 0x4C:
- case 0x4D:
- case 0x4E:
- case 0x4F:
- case 0x50:
- case 0x51:
- case 0x52:
- case 0x53:
- case 0x54:
- case 0x55:
- case 0x56:
- case 0x57:
- {
- return get_binary(input_format_t::cbor, static_cast<unsigned int>(current) & 0x1Fu, result);
- }
- case 0x58:
- {
- std::uint8_t len{};
- return get_number(input_format_t::cbor, len) &&
- get_binary(input_format_t::cbor, len, result);
- }
- case 0x59:
- {
- std::uint16_t len{};
- return get_number(input_format_t::cbor, len) &&
- get_binary(input_format_t::cbor, len, result);
- }
- case 0x5A:
- {
- std::uint32_t len{};
- return get_number(input_format_t::cbor, len) &&
- get_binary(input_format_t::cbor, len, result);
- }
- case 0x5B:
- {
- std::uint64_t len{};
- return get_number(input_format_t::cbor, len) &&
- get_binary(input_format_t::cbor, len, result);
- }
- case 0x5F:
- {
- while (get() != 0xFF)
- {
- binary_t chunk;
- if (!get_cbor_binary(chunk))
- {
- return false;
- }
- result.insert(result.end(), chunk.begin(), chunk.end());
- }
- return true;
- }
- default:
- {
- auto last_token = get_token_string();
- return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format_t::cbor, "expected length specification (0x40-0x5B) or indefinite binary array type (0x5F); last byte: 0x" + last_token, "binary"), BasicJsonType()));
- }
- }
- }
-
- bool get_cbor_array(const std::size_t len,
- const cbor_tag_handler_t tag_handler)
- {
- if (JSON_HEDLEY_UNLIKELY(!sax->start_array(len)))
- {
- return false;
- }
- if (len != std::size_t(-1))
- {
- for (std::size_t i = 0; i < len; ++i)
- {
- if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(true, tag_handler)))
- {
- return false;
- }
- }
- }
- else
- {
- while (get() != 0xFF)
- {
- if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(false, tag_handler)))
- {
- return false;
- }
- }
- }
- return sax->end_array();
- }
-
- bool get_cbor_object(const std::size_t len,
- const cbor_tag_handler_t tag_handler)
- {
- if (JSON_HEDLEY_UNLIKELY(!sax->start_object(len)))
- {
- return false;
- }
- if (len != 0)
- {
- string_t key;
- if (len != std::size_t(-1))
- {
- for (std::size_t i = 0; i < len; ++i)
- {
- get();
- if (JSON_HEDLEY_UNLIKELY(!get_cbor_string(key) || !sax->key(key)))
- {
- return false;
- }
- if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(true, tag_handler)))
- {
- return false;
- }
- key.clear();
- }
- }
- else
- {
- while (get() != 0xFF)
- {
- if (JSON_HEDLEY_UNLIKELY(!get_cbor_string(key) || !sax->key(key)))
- {
- return false;
- }
- if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(true, tag_handler)))
- {
- return false;
- }
- key.clear();
- }
- }
- }
- return sax->end_object();
- }
-
-
-
-
- bool parse_msgpack_internal()
- {
- switch (get())
- {
-
- case std::char_traits<char_type>::eof():
- return unexpect_eof(input_format_t::msgpack, "value");
-
- case 0x00:
- case 0x01:
- case 0x02:
- case 0x03:
- case 0x04:
- case 0x05:
- case 0x06:
- case 0x07:
- case 0x08:
- case 0x09:
- case 0x0A:
- case 0x0B:
- case 0x0C:
- case 0x0D:
- case 0x0E:
- case 0x0F:
- case 0x10:
- case 0x11:
- case 0x12:
- case 0x13:
- case 0x14:
- case 0x15:
- case 0x16:
- case 0x17:
- case 0x18:
- case 0x19:
- case 0x1A:
- case 0x1B:
- case 0x1C:
- case 0x1D:
- case 0x1E:
- case 0x1F:
- case 0x20:
- case 0x21:
- case 0x22:
- case 0x23:
- case 0x24:
- case 0x25:
- case 0x26:
- case 0x27:
- case 0x28:
- case 0x29:
- case 0x2A:
- case 0x2B:
- case 0x2C:
- case 0x2D:
- case 0x2E:
- case 0x2F:
- case 0x30:
- case 0x31:
- case 0x32:
- case 0x33:
- case 0x34:
- case 0x35:
- case 0x36:
- case 0x37:
- case 0x38:
- case 0x39:
- case 0x3A:
- case 0x3B:
- case 0x3C:
- case 0x3D:
- case 0x3E:
- case 0x3F:
- case 0x40:
- case 0x41:
- case 0x42:
- case 0x43:
- case 0x44:
- case 0x45:
- case 0x46:
- case 0x47:
- case 0x48:
- case 0x49:
- case 0x4A:
- case 0x4B:
- case 0x4C:
- case 0x4D:
- case 0x4E:
- case 0x4F:
- case 0x50:
- case 0x51:
- case 0x52:
- case 0x53:
- case 0x54:
- case 0x55:
- case 0x56:
- case 0x57:
- case 0x58:
- case 0x59:
- case 0x5A:
- case 0x5B:
- case 0x5C:
- case 0x5D:
- case 0x5E:
- case 0x5F:
- case 0x60:
- case 0x61:
- case 0x62:
- case 0x63:
- case 0x64:
- case 0x65:
- case 0x66:
- case 0x67:
- case 0x68:
- case 0x69:
- case 0x6A:
- case 0x6B:
- case 0x6C:
- case 0x6D:
- case 0x6E:
- case 0x6F:
- case 0x70:
- case 0x71:
- case 0x72:
- case 0x73:
- case 0x74:
- case 0x75:
- case 0x76:
- case 0x77:
- case 0x78:
- case 0x79:
- case 0x7A:
- case 0x7B:
- case 0x7C:
- case 0x7D:
- case 0x7E:
- case 0x7F:
- return sax->number_unsigned(static_cast<number_unsigned_t>(current));
-
- case 0x80:
- case 0x81:
- case 0x82:
- case 0x83:
- case 0x84:
- case 0x85:
- case 0x86:
- case 0x87:
- case 0x88:
- case 0x89:
- case 0x8A:
- case 0x8B:
- case 0x8C:
- case 0x8D:
- case 0x8E:
- case 0x8F:
- return get_msgpack_object(static_cast<std::size_t>(static_cast<unsigned int>(current) & 0x0Fu));
-
- case 0x90:
- case 0x91:
- case 0x92:
- case 0x93:
- case 0x94:
- case 0x95:
- case 0x96:
- case 0x97:
- case 0x98:
- case 0x99:
- case 0x9A:
- case 0x9B:
- case 0x9C:
- case 0x9D:
- case 0x9E:
- case 0x9F:
- return get_msgpack_array(static_cast<std::size_t>(static_cast<unsigned int>(current) & 0x0Fu));
-
- case 0xA0:
- case 0xA1:
- case 0xA2:
- case 0xA3:
- case 0xA4:
- case 0xA5:
- case 0xA6:
- case 0xA7:
- case 0xA8:
- case 0xA9:
- case 0xAA:
- case 0xAB:
- case 0xAC:
- case 0xAD:
- case 0xAE:
- case 0xAF:
- case 0xB0:
- case 0xB1:
- case 0xB2:
- case 0xB3:
- case 0xB4:
- case 0xB5:
- case 0xB6:
- case 0xB7:
- case 0xB8:
- case 0xB9:
- case 0xBA:
- case 0xBB:
- case 0xBC:
- case 0xBD:
- case 0xBE:
- case 0xBF:
- case 0xD9:
- case 0xDA:
- case 0xDB:
- {
- string_t s;
- return get_msgpack_string(s) && sax->string(s);
- }
- case 0xC0:
- return sax->null();
- case 0xC2:
- return sax->boolean(false);
- case 0xC3:
- return sax->boolean(true);
- case 0xC4:
- case 0xC5:
- case 0xC6:
- case 0xC7:
- case 0xC8:
- case 0xC9:
- case 0xD4:
- case 0xD5:
- case 0xD6:
- case 0xD7:
- case 0xD8:
- {
- binary_t b;
- return get_msgpack_binary(b) && sax->binary(b);
- }
- case 0xCA:
- {
- float number{};
- return get_number(input_format_t::msgpack, number) && sax->number_float(static_cast<number_float_t>(number), "");
- }
- case 0xCB:
- {
- double number{};
- return get_number(input_format_t::msgpack, number) && sax->number_float(static_cast<number_float_t>(number), "");
- }
- case 0xCC:
- {
- std::uint8_t number{};
- return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
- }
- case 0xCD:
- {
- std::uint16_t number{};
- return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
- }
- case 0xCE:
- {
- std::uint32_t number{};
- return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
- }
- case 0xCF:
- {
- std::uint64_t number{};
- return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
- }
- case 0xD0:
- {
- std::int8_t number{};
- return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
- }
- case 0xD1:
- {
- std::int16_t number{};
- return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
- }
- case 0xD2:
- {
- std::int32_t number{};
- return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
- }
- case 0xD3:
- {
- std::int64_t number{};
- return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
- }
- case 0xDC:
- {
- std::uint16_t len{};
- return get_number(input_format_t::msgpack, len) && get_msgpack_array(static_cast<std::size_t>(len));
- }
- case 0xDD:
- {
- std::uint32_t len{};
- return get_number(input_format_t::msgpack, len) && get_msgpack_array(static_cast<std::size_t>(len));
- }
- case 0xDE:
- {
- std::uint16_t len{};
- return get_number(input_format_t::msgpack, len) && get_msgpack_object(static_cast<std::size_t>(len));
- }
- case 0xDF:
- {
- std::uint32_t len{};
- return get_number(input_format_t::msgpack, len) && get_msgpack_object(static_cast<std::size_t>(len));
- }
-
- case 0xE0:
- case 0xE1:
- case 0xE2:
- case 0xE3:
- case 0xE4:
- case 0xE5:
- case 0xE6:
- case 0xE7:
- case 0xE8:
- case 0xE9:
- case 0xEA:
- case 0xEB:
- case 0xEC:
- case 0xED:
- case 0xEE:
- case 0xEF:
- case 0xF0:
- case 0xF1:
- case 0xF2:
- case 0xF3:
- case 0xF4:
- case 0xF5:
- case 0xF6:
- case 0xF7:
- case 0xF8:
- case 0xF9:
- case 0xFA:
- case 0xFB:
- case 0xFC:
- case 0xFD:
- case 0xFE:
- case 0xFF:
- return sax->number_integer(static_cast<std::int8_t>(current));
- default:
- {
- auto last_token = get_token_string();
- return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::msgpack, "invalid byte: 0x" + last_token, "value"), BasicJsonType()));
- }
- }
- }
-
- bool get_msgpack_string(string_t& result)
- {
- if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::msgpack, "string")))
- {
- return false;
- }
- switch (current)
- {
-
- case 0xA0:
- case 0xA1:
- case 0xA2:
- case 0xA3:
- case 0xA4:
- case 0xA5:
- case 0xA6:
- case 0xA7:
- case 0xA8:
- case 0xA9:
- case 0xAA:
- case 0xAB:
- case 0xAC:
- case 0xAD:
- case 0xAE:
- case 0xAF:
- case 0xB0:
- case 0xB1:
- case 0xB2:
- case 0xB3:
- case 0xB4:
- case 0xB5:
- case 0xB6:
- case 0xB7:
- case 0xB8:
- case 0xB9:
- case 0xBA:
- case 0xBB:
- case 0xBC:
- case 0xBD:
- case 0xBE:
- case 0xBF:
- {
- return get_string(input_format_t::msgpack, static_cast<unsigned int>(current) & 0x1Fu, result);
- }
- case 0xD9:
- {
- std::uint8_t len{};
- return get_number(input_format_t::msgpack, len) && get_string(input_format_t::msgpack, len, result);
- }
- case 0xDA:
- {
- std::uint16_t len{};
- return get_number(input_format_t::msgpack, len) && get_string(input_format_t::msgpack, len, result);
- }
- case 0xDB:
- {
- std::uint32_t len{};
- return get_number(input_format_t::msgpack, len) && get_string(input_format_t::msgpack, len, result);
- }
- default:
- {
- auto last_token = get_token_string();
- return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format_t::msgpack, "expected length specification (0xA0-0xBF, 0xD9-0xDB); last byte: 0x" + last_token, "string"), BasicJsonType()));
- }
- }
- }
-
- bool get_msgpack_binary(binary_t& result)
- {
-
- auto assign_and_return_true = [&result](std::int8_t subtype)
- {
- result.set_subtype(static_cast<std::uint8_t>(subtype));
- return true;
- };
- switch (current)
- {
- case 0xC4:
- {
- std::uint8_t len{};
- return get_number(input_format_t::msgpack, len) &&
- get_binary(input_format_t::msgpack, len, result);
- }
- case 0xC5:
- {
- std::uint16_t len{};
- return get_number(input_format_t::msgpack, len) &&
- get_binary(input_format_t::msgpack, len, result);
- }
- case 0xC6:
- {
- std::uint32_t len{};
- return get_number(input_format_t::msgpack, len) &&
- get_binary(input_format_t::msgpack, len, result);
- }
- case 0xC7:
- {
- std::uint8_t len{};
- std::int8_t subtype{};
- return get_number(input_format_t::msgpack, len) &&
- get_number(input_format_t::msgpack, subtype) &&
- get_binary(input_format_t::msgpack, len, result) &&
- assign_and_return_true(subtype);
- }
- case 0xC8:
- {
- std::uint16_t len{};
- std::int8_t subtype{};
- return get_number(input_format_t::msgpack, len) &&
- get_number(input_format_t::msgpack, subtype) &&
- get_binary(input_format_t::msgpack, len, result) &&
- assign_and_return_true(subtype);
- }
- case 0xC9:
- {
- std::uint32_t len{};
- std::int8_t subtype{};
- return get_number(input_format_t::msgpack, len) &&
- get_number(input_format_t::msgpack, subtype) &&
- get_binary(input_format_t::msgpack, len, result) &&
- assign_and_return_true(subtype);
- }
- case 0xD4:
- {
- std::int8_t subtype{};
- return get_number(input_format_t::msgpack, subtype) &&
- get_binary(input_format_t::msgpack, 1, result) &&
- assign_and_return_true(subtype);
- }
- case 0xD5:
- {
- std::int8_t subtype{};
- return get_number(input_format_t::msgpack, subtype) &&
- get_binary(input_format_t::msgpack, 2, result) &&
- assign_and_return_true(subtype);
- }
- case 0xD6:
- {
- std::int8_t subtype{};
- return get_number(input_format_t::msgpack, subtype) &&
- get_binary(input_format_t::msgpack, 4, result) &&
- assign_and_return_true(subtype);
- }
- case 0xD7:
- {
- std::int8_t subtype{};
- return get_number(input_format_t::msgpack, subtype) &&
- get_binary(input_format_t::msgpack, 8, result) &&
- assign_and_return_true(subtype);
- }
- case 0xD8:
- {
- std::int8_t subtype{};
- return get_number(input_format_t::msgpack, subtype) &&
- get_binary(input_format_t::msgpack, 16, result) &&
- assign_and_return_true(subtype);
- }
- default:
- return false;
- }
- }
-
- bool get_msgpack_array(const std::size_t len)
- {
- if (JSON_HEDLEY_UNLIKELY(!sax->start_array(len)))
- {
- return false;
- }
- for (std::size_t i = 0; i < len; ++i)
- {
- if (JSON_HEDLEY_UNLIKELY(!parse_msgpack_internal()))
- {
- return false;
- }
- }
- return sax->end_array();
- }
-
- bool get_msgpack_object(const std::size_t len)
- {
- if (JSON_HEDLEY_UNLIKELY(!sax->start_object(len)))
- {
- return false;
- }
- string_t key;
- for (std::size_t i = 0; i < len; ++i)
- {
- get();
- if (JSON_HEDLEY_UNLIKELY(!get_msgpack_string(key) || !sax->key(key)))
- {
- return false;
- }
- if (JSON_HEDLEY_UNLIKELY(!parse_msgpack_internal()))
- {
- return false;
- }
- key.clear();
- }
- return sax->end_object();
- }
-
-
-
-
- bool parse_ubjson_internal(const bool get_char = true)
- {
- return get_ubjson_value(get_char ? get_ignore_noop() : current);
- }
-
- bool get_ubjson_string(string_t& result, const bool get_char = true)
- {
- if (get_char)
- {
- get();
- }
- if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::ubjson, "value")))
- {
- return false;
- }
- switch (current)
- {
- case 'U':
- {
- std::uint8_t len{};
- return get_number(input_format_t::ubjson, len) && get_string(input_format_t::ubjson, len, result);
- }
- case 'i':
- {
- std::int8_t len{};
- return get_number(input_format_t::ubjson, len) && get_string(input_format_t::ubjson, len, result);
- }
- case 'I':
- {
- std::int16_t len{};
- return get_number(input_format_t::ubjson, len) && get_string(input_format_t::ubjson, len, result);
- }
- case 'l':
- {
- std::int32_t len{};
- return get_number(input_format_t::ubjson, len) && get_string(input_format_t::ubjson, len, result);
- }
- case 'L':
- {
- std::int64_t len{};
- return get_number(input_format_t::ubjson, len) && get_string(input_format_t::ubjson, len, result);
- }
- default:
- auto last_token = get_token_string();
- return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format_t::ubjson, "expected length type specification (U, i, I, l, L); last byte: 0x" + last_token, "string"), BasicJsonType()));
- }
- }
-
- bool get_ubjson_size_value(std::size_t& result)
- {
- switch (get_ignore_noop())
- {
- case 'U':
- {
- std::uint8_t number{};
- if (JSON_HEDLEY_UNLIKELY(!get_number(input_format_t::ubjson, number)))
- {
- return false;
- }
- result = static_cast<std::size_t>(number);
- return true;
- }
- case 'i':
- {
- std::int8_t number{};
- if (JSON_HEDLEY_UNLIKELY(!get_number(input_format_t::ubjson, number)))
- {
- return false;
- }
- result = static_cast<std::size_t>(number);
- return true;
- }
- case 'I':
- {
- std::int16_t number{};
- if (JSON_HEDLEY_UNLIKELY(!get_number(input_format_t::ubjson, number)))
- {
- return false;
- }
- result = static_cast<std::size_t>(number);
- return true;
- }
- case 'l':
- {
- std::int32_t number{};
- if (JSON_HEDLEY_UNLIKELY(!get_number(input_format_t::ubjson, number)))
- {
- return false;
- }
- result = static_cast<std::size_t>(number);
- return true;
- }
- case 'L':
- {
- std::int64_t number{};
- if (JSON_HEDLEY_UNLIKELY(!get_number(input_format_t::ubjson, number)))
- {
- return false;
- }
- result = static_cast<std::size_t>(number);
- return true;
- }
- default:
- {
- auto last_token = get_token_string();
- return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format_t::ubjson, "expected length type specification (U, i, I, l, L) after '#'; last byte: 0x" + last_token, "size"), BasicJsonType()));
- }
- }
- }
-
- bool get_ubjson_size_type(std::pair<std::size_t, char_int_type>& result)
- {
- result.first = string_t::npos;
- result.second = 0;
- get_ignore_noop();
- if (current == '$')
- {
- result.second = get();
- if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::ubjson, "type")))
- {
- return false;
- }
- get_ignore_noop();
- if (JSON_HEDLEY_UNLIKELY(current != '#'))
- {
- if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::ubjson, "value")))
- {
- return false;
- }
- auto last_token = get_token_string();
- return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::ubjson, "expected '#' after type information; last byte: 0x" + last_token, "size"), BasicJsonType()));
- }
- return get_ubjson_size_value(result.first);
- }
- if (current == '#')
- {
- return get_ubjson_size_value(result.first);
- }
- return true;
- }
-
- bool get_ubjson_value(const char_int_type prefix)
- {
- switch (prefix)
- {
- case std::char_traits<char_type>::eof():
- return unexpect_eof(input_format_t::ubjson, "value");
- case 'T':
- return sax->boolean(true);
- case 'F':
- return sax->boolean(false);
- case 'Z':
- return sax->null();
- case 'U':
- {
- std::uint8_t number{};
- return get_number(input_format_t::ubjson, number) && sax->number_unsigned(number);
- }
- case 'i':
- {
- std::int8_t number{};
- return get_number(input_format_t::ubjson, number) && sax->number_integer(number);
- }
- case 'I':
- {
- std::int16_t number{};
- return get_number(input_format_t::ubjson, number) && sax->number_integer(number);
- }
- case 'l':
- {
- std::int32_t number{};
- return get_number(input_format_t::ubjson, number) && sax->number_integer(number);
- }
- case 'L':
- {
- std::int64_t number{};
- return get_number(input_format_t::ubjson, number) && sax->number_integer(number);
- }
- case 'd':
- {
- float number{};
- return get_number(input_format_t::ubjson, number) && sax->number_float(static_cast<number_float_t>(number), "");
- }
- case 'D':
- {
- double number{};
- return get_number(input_format_t::ubjson, number) && sax->number_float(static_cast<number_float_t>(number), "");
- }
- case 'H':
- {
- return get_ubjson_high_precision_number();
- }
- case 'C':
- {
- get();
- if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::ubjson, "char")))
- {
- return false;
- }
- if (JSON_HEDLEY_UNLIKELY(current > 127))
- {
- auto last_token = get_token_string();
- return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format_t::ubjson, "byte after 'C' must be in range 0x00..0x7F; last byte: 0x" + last_token, "char"), BasicJsonType()));
- }
- string_t s(1, static_cast<typename string_t::value_type>(current));
- return sax->string(s);
- }
- case 'S':
- {
- string_t s;
- return get_ubjson_string(s) && sax->string(s);
- }
- case '[':
- return get_ubjson_array();
- case '{':
- return get_ubjson_object();
- default:
- {
- auto last_token = get_token_string();
- return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::ubjson, "invalid byte: 0x" + last_token, "value"), BasicJsonType()));
- }
- }
- }
-
- bool get_ubjson_array()
- {
- std::pair<std::size_t, char_int_type> size_and_type;
- if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_type(size_and_type)))
- {
- return false;
- }
- if (size_and_type.first != string_t::npos)
- {
- if (JSON_HEDLEY_UNLIKELY(!sax->start_array(size_and_type.first)))
- {
- return false;
- }
- if (size_and_type.second != 0)
- {
- if (size_and_type.second != 'N')
- {
- for (std::size_t i = 0; i < size_and_type.first; ++i)
- {
- if (JSON_HEDLEY_UNLIKELY(!get_ubjson_value(size_and_type.second)))
- {
- return false;
- }
- }
- }
- }
- else
- {
- for (std::size_t i = 0; i < size_and_type.first; ++i)
- {
- if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal()))
- {
- return false;
- }
- }
- }
- }
- else
- {
- if (JSON_HEDLEY_UNLIKELY(!sax->start_array(std::size_t(-1))))
- {
- return false;
- }
- while (current != ']')
- {
- if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal(false)))
- {
- return false;
- }
- get_ignore_noop();
- }
- }
- return sax->end_array();
- }
-
- bool get_ubjson_object()
- {
- std::pair<std::size_t, char_int_type> size_and_type;
- if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_type(size_and_type)))
- {
- return false;
- }
- string_t key;
- if (size_and_type.first != string_t::npos)
- {
- if (JSON_HEDLEY_UNLIKELY(!sax->start_object(size_and_type.first)))
- {
- return false;
- }
- if (size_and_type.second != 0)
- {
- for (std::size_t i = 0; i < size_and_type.first; ++i)
- {
- if (JSON_HEDLEY_UNLIKELY(!get_ubjson_string(key) || !sax->key(key)))
- {
- return false;
- }
- if (JSON_HEDLEY_UNLIKELY(!get_ubjson_value(size_and_type.second)))
- {
- return false;
- }
- key.clear();
- }
- }
- else
- {
- for (std::size_t i = 0; i < size_and_type.first; ++i)
- {
- if (JSON_HEDLEY_UNLIKELY(!get_ubjson_string(key) || !sax->key(key)))
- {
- return false;
- }
- if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal()))
- {
- return false;
- }
- key.clear();
- }
- }
- }
- else
- {
- if (JSON_HEDLEY_UNLIKELY(!sax->start_object(std::size_t(-1))))
- {
- return false;
- }
- while (current != '}')
- {
- if (JSON_HEDLEY_UNLIKELY(!get_ubjson_string(key, false) || !sax->key(key)))
- {
- return false;
- }
- if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal()))
- {
- return false;
- }
- get_ignore_noop();
- key.clear();
- }
- }
- return sax->end_object();
- }
-
-
- bool get_ubjson_high_precision_number()
- {
-
- std::size_t size{};
- auto res = get_ubjson_size_value(size);
- if (JSON_HEDLEY_UNLIKELY(!res))
- {
- return res;
- }
-
- std::vector<char> number_vector;
- for (std::size_t i = 0; i < size; ++i)
- {
- get();
- if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::ubjson, "number")))
- {
- return false;
- }
- number_vector.push_back(static_cast<char>(current));
- }
-
- using ia_type = decltype(detail::input_adapter(number_vector));
- auto number_lexer = detail::lexer<BasicJsonType, ia_type>(detail::input_adapter(number_vector), false);
- const auto result_number = number_lexer.scan();
- const auto number_string = number_lexer.get_token_string();
- const auto result_remainder = number_lexer.scan();
- using token_type = typename detail::lexer_base<BasicJsonType>::token_type;
- if (JSON_HEDLEY_UNLIKELY(result_remainder != token_type::end_of_input))
- {
- return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read, exception_message(input_format_t::ubjson, "invalid number text: " + number_lexer.get_token_string(), "high-precision number"), BasicJsonType()));
- }
- switch (result_number)
- {
- case token_type::value_integer:
- return sax->number_integer(number_lexer.get_number_integer());
- case token_type::value_unsigned:
- return sax->number_unsigned(number_lexer.get_number_unsigned());
- case token_type::value_float:
- return sax->number_float(number_lexer.get_number_float(), std::move(number_string));
- case token_type::uninitialized:
- case token_type::literal_true:
- case token_type::literal_false:
- case token_type::literal_null:
- case token_type::value_string:
- case token_type::begin_array:
- case token_type::begin_object:
- case token_type::end_array:
- case token_type::end_object:
- case token_type::name_separator:
- case token_type::value_separator:
- case token_type::parse_error:
- case token_type::end_of_input:
- case token_type::literal_or_value:
- default:
- return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read, exception_message(input_format_t::ubjson, "invalid number text: " + number_lexer.get_token_string(), "high-precision number"), BasicJsonType()));
- }
- }
-
-
-
-
- char_int_type get()
- {
- ++chars_read;
- return current = ia.get_character();
- }
-
- char_int_type get_ignore_noop()
- {
- do
- {
- get();
- }
- while (current == 'N');
- return current;
- }
-
- template<typename NumberType, bool InputIsLittleEndian = false>
- bool get_number(const input_format_t format, NumberType& result)
- {
-
- std::array<std::uint8_t, sizeof(NumberType)> vec{};
- for (std::size_t i = 0; i < sizeof(NumberType); ++i)
- {
- get();
- if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format, "number")))
- {
- return false;
- }
-
- if (is_little_endian != InputIsLittleEndian)
- {
- vec[sizeof(NumberType) - i - 1] = static_cast<std::uint8_t>(current);
- }
- else
- {
- vec[i] = static_cast<std::uint8_t>(current);
- }
- }
-
- std::memcpy(&result, vec.data(), sizeof(NumberType));
- return true;
- }
-
- template<typename NumberType>
- bool get_string(const input_format_t format,
- const NumberType len,
- string_t& result)
- {
- bool success = true;
- for (NumberType i = 0; i < len; i++)
- {
- get();
- if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format, "string")))
- {
- success = false;
- break;
- }
- result.push_back(static_cast<typename string_t::value_type>(current));
- }
- return success;
- }
-
- template<typename NumberType>
- bool get_binary(const input_format_t format,
- const NumberType len,
- binary_t& result)
- {
- bool success = true;
- for (NumberType i = 0; i < len; i++)
- {
- get();
- if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format, "binary")))
- {
- success = false;
- break;
- }
- result.push_back(static_cast<std::uint8_t>(current));
- }
- return success;
- }
-
- JSON_HEDLEY_NON_NULL(3)
- bool unexpect_eof(const input_format_t format, const char* context) const
- {
- if (JSON_HEDLEY_UNLIKELY(current == std::char_traits<char_type>::eof()))
- {
- return sax->parse_error(chars_read, "<end of file>",
- parse_error::create(110, chars_read, exception_message(format, "unexpected end of input", context), BasicJsonType()));
- }
- return true;
- }
-
- std::string get_token_string() const
- {
- std::array<char, 3> cr{{}};
- (std::snprintf)(cr.data(), cr.size(), "%.2hhX", static_cast<unsigned char>(current));
- return std::string{cr.data()};
- }
-
- std::string exception_message(const input_format_t format,
- const std::string& detail,
- const std::string& context) const
- {
- std::string error_msg = "syntax error while parsing ";
- switch (format)
- {
- case input_format_t::cbor:
- error_msg += "CBOR";
- break;
- case input_format_t::msgpack:
- error_msg += "MessagePack";
- break;
- case input_format_t::ubjson:
- error_msg += "UBJSON";
- break;
- case input_format_t::bson:
- error_msg += "BSON";
- break;
- case input_format_t::json:
- default:
- JSON_ASSERT(false);
- }
- return error_msg + " " + context + ": " + detail;
- }
- private:
-
- InputAdapterType ia;
-
- char_int_type current = std::char_traits<char_type>::eof();
-
- std::size_t chars_read = 0;
-
- const bool is_little_endian = little_endianess();
-
- json_sax_t* sax = nullptr;
- };
- }
- }
- #include <cmath> // isfinite
- #include <cstdint> // uint8_t
- #include <functional> // function
- #include <string> // string
- #include <utility> // move
- #include <vector> // vector
- namespace nlohmann
- {
- namespace detail
- {
- enum class parse_event_t : std::uint8_t
- {
-
- object_start,
-
- object_end,
-
- array_start,
-
- array_end,
-
- key,
-
- value
- };
- template<typename BasicJsonType>
- using parser_callback_t =
- std::function<bool(int , parse_event_t , BasicJsonType& )>;
- template<typename BasicJsonType, typename InputAdapterType>
- class parser
- {
- using number_integer_t = typename BasicJsonType::number_integer_t;
- using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
- using number_float_t = typename BasicJsonType::number_float_t;
- using string_t = typename BasicJsonType::string_t;
- using lexer_t = lexer<BasicJsonType, InputAdapterType>;
- using token_type = typename lexer_t::token_type;
- public:
-
- explicit parser(InputAdapterType&& adapter,
- const parser_callback_t<BasicJsonType> cb = nullptr,
- const bool allow_exceptions_ = true,
- const bool skip_comments = false)
- : callback(cb)
- , m_lexer(std::move(adapter), skip_comments)
- , allow_exceptions(allow_exceptions_)
- {
-
- get_token();
- }
-
- void parse(const bool strict, BasicJsonType& result)
- {
- if (callback)
- {
- json_sax_dom_callback_parser<BasicJsonType> sdp(result, callback, allow_exceptions);
- sax_parse_internal(&sdp);
-
- if (strict && (get_token() != token_type::end_of_input))
- {
- sdp.parse_error(m_lexer.get_position(),
- m_lexer.get_token_string(),
- parse_error::create(101, m_lexer.get_position(),
- exception_message(token_type::end_of_input, "value"), BasicJsonType()));
- }
-
- if (sdp.is_errored())
- {
- result = value_t::discarded;
- return;
- }
-
-
- if (result.is_discarded())
- {
- result = nullptr;
- }
- }
- else
- {
- json_sax_dom_parser<BasicJsonType> sdp(result, allow_exceptions);
- sax_parse_internal(&sdp);
-
- if (strict && (get_token() != token_type::end_of_input))
- {
- sdp.parse_error(m_lexer.get_position(),
- m_lexer.get_token_string(),
- parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_of_input, "value"), BasicJsonType()));
- }
-
- if (sdp.is_errored())
- {
- result = value_t::discarded;
- return;
- }
- }
- result.assert_invariant();
- }
-
- bool accept(const bool strict = true)
- {
- json_sax_acceptor<BasicJsonType> sax_acceptor;
- return sax_parse(&sax_acceptor, strict);
- }
- template<typename SAX>
- JSON_HEDLEY_NON_NULL(2)
- bool sax_parse(SAX* sax, const bool strict = true)
- {
- (void)detail::is_sax_static_asserts<SAX, BasicJsonType> {};
- const bool result = sax_parse_internal(sax);
-
- if (result && strict && (get_token() != token_type::end_of_input))
- {
- return sax->parse_error(m_lexer.get_position(),
- m_lexer.get_token_string(),
- parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_of_input, "value"), BasicJsonType()));
- }
- return result;
- }
- private:
- template<typename SAX>
- JSON_HEDLEY_NON_NULL(2)
- bool sax_parse_internal(SAX* sax)
- {
-
-
- std::vector<bool> states;
-
- bool skip_to_state_evaluation = false;
- while (true)
- {
- if (!skip_to_state_evaluation)
- {
-
- switch (last_token)
- {
- case token_type::begin_object:
- {
- if (JSON_HEDLEY_UNLIKELY(!sax->start_object(std::size_t(-1))))
- {
- return false;
- }
-
- if (get_token() == token_type::end_object)
- {
- if (JSON_HEDLEY_UNLIKELY(!sax->end_object()))
- {
- return false;
- }
- break;
- }
-
- if (JSON_HEDLEY_UNLIKELY(last_token != token_type::value_string))
- {
- return sax->parse_error(m_lexer.get_position(),
- m_lexer.get_token_string(),
- parse_error::create(101, m_lexer.get_position(), exception_message(token_type::value_string, "object key"), BasicJsonType()));
- }
- if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string())))
- {
- return false;
- }
-
- if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator))
- {
- return sax->parse_error(m_lexer.get_position(),
- m_lexer.get_token_string(),
- parse_error::create(101, m_lexer.get_position(), exception_message(token_type::name_separator, "object separator"), BasicJsonType()));
- }
-
- states.push_back(false);
-
- get_token();
- continue;
- }
- case token_type::begin_array:
- {
- if (JSON_HEDLEY_UNLIKELY(!sax->start_array(std::size_t(-1))))
- {
- return false;
- }
-
- if (get_token() == token_type::end_array)
- {
- if (JSON_HEDLEY_UNLIKELY(!sax->end_array()))
- {
- return false;
- }
- break;
- }
-
- states.push_back(true);
-
- continue;
- }
- case token_type::value_float:
- {
- const auto res = m_lexer.get_number_float();
- if (JSON_HEDLEY_UNLIKELY(!std::isfinite(res)))
- {
- return sax->parse_error(m_lexer.get_position(),
- m_lexer.get_token_string(),
- out_of_range::create(406, "number overflow parsing '" + m_lexer.get_token_string() + "'", BasicJsonType()));
- }
- if (JSON_HEDLEY_UNLIKELY(!sax->number_float(res, m_lexer.get_string())))
- {
- return false;
- }
- break;
- }
- case token_type::literal_false:
- {
- if (JSON_HEDLEY_UNLIKELY(!sax->boolean(false)))
- {
- return false;
- }
- break;
- }
- case token_type::literal_null:
- {
- if (JSON_HEDLEY_UNLIKELY(!sax->null()))
- {
- return false;
- }
- break;
- }
- case token_type::literal_true:
- {
- if (JSON_HEDLEY_UNLIKELY(!sax->boolean(true)))
- {
- return false;
- }
- break;
- }
- case token_type::value_integer:
- {
- if (JSON_HEDLEY_UNLIKELY(!sax->number_integer(m_lexer.get_number_integer())))
- {
- return false;
- }
- break;
- }
- case token_type::value_string:
- {
- if (JSON_HEDLEY_UNLIKELY(!sax->string(m_lexer.get_string())))
- {
- return false;
- }
- break;
- }
- case token_type::value_unsigned:
- {
- if (JSON_HEDLEY_UNLIKELY(!sax->number_unsigned(m_lexer.get_number_unsigned())))
- {
- return false;
- }
- break;
- }
- case token_type::parse_error:
- {
-
- return sax->parse_error(m_lexer.get_position(),
- m_lexer.get_token_string(),
- parse_error::create(101, m_lexer.get_position(), exception_message(token_type::uninitialized, "value"), BasicJsonType()));
- }
- case token_type::uninitialized:
- case token_type::end_array:
- case token_type::end_object:
- case token_type::name_separator:
- case token_type::value_separator:
- case token_type::end_of_input:
- case token_type::literal_or_value:
- default:
- {
- return sax->parse_error(m_lexer.get_position(),
- m_lexer.get_token_string(),
- parse_error::create(101, m_lexer.get_position(), exception_message(token_type::literal_or_value, "value"), BasicJsonType()));
- }
- }
- }
- else
- {
- skip_to_state_evaluation = false;
- }
-
- if (states.empty())
- {
-
- return true;
- }
- if (states.back())
- {
-
- if (get_token() == token_type::value_separator)
- {
-
- get_token();
- continue;
- }
-
- if (JSON_HEDLEY_LIKELY(last_token == token_type::end_array))
- {
- if (JSON_HEDLEY_UNLIKELY(!sax->end_array()))
- {
- return false;
- }
-
-
-
-
- JSON_ASSERT(!states.empty());
- states.pop_back();
- skip_to_state_evaluation = true;
- continue;
- }
- return sax->parse_error(m_lexer.get_position(),
- m_lexer.get_token_string(),
- parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_array, "array"), BasicJsonType()));
- }
-
-
- if (get_token() == token_type::value_separator)
- {
-
- if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::value_string))
- {
- return sax->parse_error(m_lexer.get_position(),
- m_lexer.get_token_string(),
- parse_error::create(101, m_lexer.get_position(), exception_message(token_type::value_string, "object key"), BasicJsonType()));
- }
- if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string())))
- {
- return false;
- }
-
- if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator))
- {
- return sax->parse_error(m_lexer.get_position(),
- m_lexer.get_token_string(),
- parse_error::create(101, m_lexer.get_position(), exception_message(token_type::name_separator, "object separator"), BasicJsonType()));
- }
-
- get_token();
- continue;
- }
-
- if (JSON_HEDLEY_LIKELY(last_token == token_type::end_object))
- {
- if (JSON_HEDLEY_UNLIKELY(!sax->end_object()))
- {
- return false;
- }
-
-
-
-
- JSON_ASSERT(!states.empty());
- states.pop_back();
- skip_to_state_evaluation = true;
- continue;
- }
- return sax->parse_error(m_lexer.get_position(),
- m_lexer.get_token_string(),
- parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_object, "object"), BasicJsonType()));
- }
- }
-
- token_type get_token()
- {
- return last_token = m_lexer.scan();
- }
- std::string exception_message(const token_type expected, const std::string& context)
- {
- std::string error_msg = "syntax error ";
- if (!context.empty())
- {
- error_msg += "while parsing " + context + " ";
- }
- error_msg += "- ";
- if (last_token == token_type::parse_error)
- {
- error_msg += std::string(m_lexer.get_error_message()) + "; last read: '" +
- m_lexer.get_token_string() + "'";
- }
- else
- {
- error_msg += "unexpected " + std::string(lexer_t::token_type_name(last_token));
- }
- if (expected != token_type::uninitialized)
- {
- error_msg += "; expected " + std::string(lexer_t::token_type_name(expected));
- }
- return error_msg;
- }
- private:
-
- const parser_callback_t<BasicJsonType> callback = nullptr;
-
- token_type last_token = token_type::uninitialized;
-
- lexer_t m_lexer;
-
- const bool allow_exceptions = true;
- };
- }
- }
- #include <cstddef> // ptrdiff_t
- #include <limits> // numeric_limits
- namespace nlohmann
- {
- namespace detail
- {
- class primitive_iterator_t
- {
- private:
- using difference_type = std::ptrdiff_t;
- static constexpr difference_type begin_value = 0;
- static constexpr difference_type end_value = begin_value + 1;
- JSON_PRIVATE_UNLESS_TESTED:
-
- difference_type m_it = (std::numeric_limits<std::ptrdiff_t>::min)();
- public:
- constexpr difference_type get_value() const noexcept
- {
- return m_it;
- }
-
- void set_begin() noexcept
- {
- m_it = begin_value;
- }
-
- void set_end() noexcept
- {
- m_it = end_value;
- }
-
- constexpr bool is_begin() const noexcept
- {
- return m_it == begin_value;
- }
-
- constexpr bool is_end() const noexcept
- {
- return m_it == end_value;
- }
- friend constexpr bool operator==(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept
- {
- return lhs.m_it == rhs.m_it;
- }
- friend constexpr bool operator<(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept
- {
- return lhs.m_it < rhs.m_it;
- }
- primitive_iterator_t operator+(difference_type n) noexcept
- {
- auto result = *this;
- result += n;
- return result;
- }
- friend constexpr difference_type operator-(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept
- {
- return lhs.m_it - rhs.m_it;
- }
- primitive_iterator_t& operator++() noexcept
- {
- ++m_it;
- return *this;
- }
- primitive_iterator_t const operator++(int) noexcept
- {
- auto result = *this;
- ++m_it;
- return result;
- }
- primitive_iterator_t& operator--() noexcept
- {
- --m_it;
- return *this;
- }
- primitive_iterator_t const operator--(int) noexcept
- {
- auto result = *this;
- --m_it;
- return result;
- }
- primitive_iterator_t& operator+=(difference_type n) noexcept
- {
- m_it += n;
- return *this;
- }
- primitive_iterator_t& operator-=(difference_type n) noexcept
- {
- m_it -= n;
- return *this;
- }
- };
- }
- }
- namespace nlohmann
- {
- namespace detail
- {
- template<typename BasicJsonType> struct internal_iterator
- {
-
- typename BasicJsonType::object_t::iterator object_iterator {};
-
- typename BasicJsonType::array_t::iterator array_iterator {};
-
- primitive_iterator_t primitive_iterator {};
- };
- }
- }
- #include <iterator> // iterator, random_access_iterator_tag, bidirectional_iterator_tag, advance, next
- #include <type_traits> // conditional, is_const, remove_const
- namespace nlohmann
- {
- namespace detail
- {
- template<typename IteratorType> class iteration_proxy;
- template<typename IteratorType> class iteration_proxy_value;
- template<typename BasicJsonType>
- class iter_impl
- {
-
- using other_iter_impl = iter_impl<typename std::conditional<std::is_const<BasicJsonType>::value, typename std::remove_const<BasicJsonType>::type, const BasicJsonType>::type>;
-
- friend other_iter_impl;
- friend BasicJsonType;
- friend iteration_proxy<iter_impl>;
- friend iteration_proxy_value<iter_impl>;
- using object_t = typename BasicJsonType::object_t;
- using array_t = typename BasicJsonType::array_t;
-
- static_assert(is_basic_json<typename std::remove_const<BasicJsonType>::type>::value,
- "iter_impl only accepts (const) basic_json");
- public:
-
-
-
-
-
- using iterator_category = std::bidirectional_iterator_tag;
-
- using value_type = typename BasicJsonType::value_type;
-
- using difference_type = typename BasicJsonType::difference_type;
-
- using pointer = typename std::conditional<std::is_const<BasicJsonType>::value,
- typename BasicJsonType::const_pointer,
- typename BasicJsonType::pointer>::type;
-
- using reference =
- typename std::conditional<std::is_const<BasicJsonType>::value,
- typename BasicJsonType::const_reference,
- typename BasicJsonType::reference>::type;
- iter_impl() = default;
- ~iter_impl() = default;
- iter_impl(iter_impl&&) noexcept = default;
- iter_impl& operator=(iter_impl&&) noexcept = default;
-
- explicit iter_impl(pointer object) noexcept : m_object(object)
- {
- JSON_ASSERT(m_object != nullptr);
- switch (m_object->m_type)
- {
- case value_t::object:
- {
- m_it.object_iterator = typename object_t::iterator();
- break;
- }
- case value_t::array:
- {
- m_it.array_iterator = typename array_t::iterator();
- break;
- }
- case value_t::null:
- case value_t::string:
- case value_t::boolean:
- case value_t::number_integer:
- case value_t::number_unsigned:
- case value_t::number_float:
- case value_t::binary:
- case value_t::discarded:
- default:
- {
- m_it.primitive_iterator = primitive_iterator_t();
- break;
- }
- }
- }
-
-
- iter_impl(const iter_impl<const BasicJsonType>& other) noexcept
- : m_object(other.m_object), m_it(other.m_it)
- {}
-
- iter_impl& operator=(const iter_impl<const BasicJsonType>& other) noexcept
- {
- if (&other != this)
- {
- m_object = other.m_object;
- m_it = other.m_it;
- }
- return *this;
- }
-
- iter_impl(const iter_impl<typename std::remove_const<BasicJsonType>::type>& other) noexcept
- : m_object(other.m_object), m_it(other.m_it)
- {}
-
- iter_impl& operator=(const iter_impl<typename std::remove_const<BasicJsonType>::type>& other) noexcept
- {
- m_object = other.m_object;
- m_it = other.m_it;
- return *this;
- }
- JSON_PRIVATE_UNLESS_TESTED:
-
- void set_begin() noexcept
- {
- JSON_ASSERT(m_object != nullptr);
- switch (m_object->m_type)
- {
- case value_t::object:
- {
- m_it.object_iterator = m_object->m_value.object->begin();
- break;
- }
- case value_t::array:
- {
- m_it.array_iterator = m_object->m_value.array->begin();
- break;
- }
- case value_t::null:
- {
-
- m_it.primitive_iterator.set_end();
- break;
- }
- case value_t::string:
- case value_t::boolean:
- case value_t::number_integer:
- case value_t::number_unsigned:
- case value_t::number_float:
- case value_t::binary:
- case value_t::discarded:
- default:
- {
- m_it.primitive_iterator.set_begin();
- break;
- }
- }
- }
-
- void set_end() noexcept
- {
- JSON_ASSERT(m_object != nullptr);
- switch (m_object->m_type)
- {
- case value_t::object:
- {
- m_it.object_iterator = m_object->m_value.object->end();
- break;
- }
- case value_t::array:
- {
- m_it.array_iterator = m_object->m_value.array->end();
- break;
- }
- case value_t::null:
- case value_t::string:
- case value_t::boolean:
- case value_t::number_integer:
- case value_t::number_unsigned:
- case value_t::number_float:
- case value_t::binary:
- case value_t::discarded:
- default:
- {
- m_it.primitive_iterator.set_end();
- break;
- }
- }
- }
- public:
-
- reference operator*() const
- {
- JSON_ASSERT(m_object != nullptr);
- switch (m_object->m_type)
- {
- case value_t::object:
- {
- JSON_ASSERT(m_it.object_iterator != m_object->m_value.object->end());
- return m_it.object_iterator->second;
- }
- case value_t::array:
- {
- JSON_ASSERT(m_it.array_iterator != m_object->m_value.array->end());
- return *m_it.array_iterator;
- }
- case value_t::null:
- JSON_THROW(invalid_iterator::create(214, "cannot get value", *m_object));
- case value_t::string:
- case value_t::boolean:
- case value_t::number_integer:
- case value_t::number_unsigned:
- case value_t::number_float:
- case value_t::binary:
- case value_t::discarded:
- default:
- {
- if (JSON_HEDLEY_LIKELY(m_it.primitive_iterator.is_begin()))
- {
- return *m_object;
- }
- JSON_THROW(invalid_iterator::create(214, "cannot get value", *m_object));
- }
- }
- }
-
- pointer operator->() const
- {
- JSON_ASSERT(m_object != nullptr);
- switch (m_object->m_type)
- {
- case value_t::object:
- {
- JSON_ASSERT(m_it.object_iterator != m_object->m_value.object->end());
- return &(m_it.object_iterator->second);
- }
- case value_t::array:
- {
- JSON_ASSERT(m_it.array_iterator != m_object->m_value.array->end());
- return &*m_it.array_iterator;
- }
- case value_t::null:
- case value_t::string:
- case value_t::boolean:
- case value_t::number_integer:
- case value_t::number_unsigned:
- case value_t::number_float:
- case value_t::binary:
- case value_t::discarded:
- default:
- {
- if (JSON_HEDLEY_LIKELY(m_it.primitive_iterator.is_begin()))
- {
- return m_object;
- }
- JSON_THROW(invalid_iterator::create(214, "cannot get value", *m_object));
- }
- }
- }
-
- iter_impl const operator++(int)
- {
- auto result = *this;
- ++(*this);
- return result;
- }
-
- iter_impl& operator++()
- {
- JSON_ASSERT(m_object != nullptr);
- switch (m_object->m_type)
- {
- case value_t::object:
- {
- std::advance(m_it.object_iterator, 1);
- break;
- }
- case value_t::array:
- {
- std::advance(m_it.array_iterator, 1);
- break;
- }
- case value_t::null:
- case value_t::string:
- case value_t::boolean:
- case value_t::number_integer:
- case value_t::number_unsigned:
- case value_t::number_float:
- case value_t::binary:
- case value_t::discarded:
- default:
- {
- ++m_it.primitive_iterator;
- break;
- }
- }
- return *this;
- }
-
- iter_impl const operator--(int)
- {
- auto result = *this;
- --(*this);
- return result;
- }
-
- iter_impl& operator--()
- {
- JSON_ASSERT(m_object != nullptr);
- switch (m_object->m_type)
- {
- case value_t::object:
- {
- std::advance(m_it.object_iterator, -1);
- break;
- }
- case value_t::array:
- {
- std::advance(m_it.array_iterator, -1);
- break;
- }
- case value_t::null:
- case value_t::string:
- case value_t::boolean:
- case value_t::number_integer:
- case value_t::number_unsigned:
- case value_t::number_float:
- case value_t::binary:
- case value_t::discarded:
- default:
- {
- --m_it.primitive_iterator;
- break;
- }
- }
- return *this;
- }
-
- template < typename IterImpl, detail::enable_if_t < (std::is_same<IterImpl, iter_impl>::value || std::is_same<IterImpl, other_iter_impl>::value), std::nullptr_t > = nullptr >
- bool operator==(const IterImpl& other) const
- {
-
- if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object))
- {
- JSON_THROW(invalid_iterator::create(212, "cannot compare iterators of different containers", *m_object));
- }
- JSON_ASSERT(m_object != nullptr);
- switch (m_object->m_type)
- {
- case value_t::object:
- return (m_it.object_iterator == other.m_it.object_iterator);
- case value_t::array:
- return (m_it.array_iterator == other.m_it.array_iterator);
- case value_t::null:
- case value_t::string:
- case value_t::boolean:
- case value_t::number_integer:
- case value_t::number_unsigned:
- case value_t::number_float:
- case value_t::binary:
- case value_t::discarded:
- default:
- return (m_it.primitive_iterator == other.m_it.primitive_iterator);
- }
- }
-
- template < typename IterImpl, detail::enable_if_t < (std::is_same<IterImpl, iter_impl>::value || std::is_same<IterImpl, other_iter_impl>::value), std::nullptr_t > = nullptr >
- bool operator!=(const IterImpl& other) const
- {
- return !operator==(other);
- }
-
- bool operator<(const iter_impl& other) const
- {
-
- if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object))
- {
- JSON_THROW(invalid_iterator::create(212, "cannot compare iterators of different containers", *m_object));
- }
- JSON_ASSERT(m_object != nullptr);
- switch (m_object->m_type)
- {
- case value_t::object:
- JSON_THROW(invalid_iterator::create(213, "cannot compare order of object iterators", *m_object));
- case value_t::array:
- return (m_it.array_iterator < other.m_it.array_iterator);
- case value_t::null:
- case value_t::string:
- case value_t::boolean:
- case value_t::number_integer:
- case value_t::number_unsigned:
- case value_t::number_float:
- case value_t::binary:
- case value_t::discarded:
- default:
- return (m_it.primitive_iterator < other.m_it.primitive_iterator);
- }
- }
-
- bool operator<=(const iter_impl& other) const
- {
- return !other.operator < (*this);
- }
-
- bool operator>(const iter_impl& other) const
- {
- return !operator<=(other);
- }
-
- bool operator>=(const iter_impl& other) const
- {
- return !operator<(other);
- }
-
- iter_impl& operator+=(difference_type i)
- {
- JSON_ASSERT(m_object != nullptr);
- switch (m_object->m_type)
- {
- case value_t::object:
- JSON_THROW(invalid_iterator::create(209, "cannot use offsets with object iterators", *m_object));
- case value_t::array:
- {
- std::advance(m_it.array_iterator, i);
- break;
- }
- case value_t::null:
- case value_t::string:
- case value_t::boolean:
- case value_t::number_integer:
- case value_t::number_unsigned:
- case value_t::number_float:
- case value_t::binary:
- case value_t::discarded:
- default:
- {
- m_it.primitive_iterator += i;
- break;
- }
- }
- return *this;
- }
-
- iter_impl& operator-=(difference_type i)
- {
- return operator+=(-i);
- }
-
- iter_impl operator+(difference_type i) const
- {
- auto result = *this;
- result += i;
- return result;
- }
-
- friend iter_impl operator+(difference_type i, const iter_impl& it)
- {
- auto result = it;
- result += i;
- return result;
- }
-
- iter_impl operator-(difference_type i) const
- {
- auto result = *this;
- result -= i;
- return result;
- }
-
- difference_type operator-(const iter_impl& other) const
- {
- JSON_ASSERT(m_object != nullptr);
- switch (m_object->m_type)
- {
- case value_t::object:
- JSON_THROW(invalid_iterator::create(209, "cannot use offsets with object iterators", *m_object));
- case value_t::array:
- return m_it.array_iterator - other.m_it.array_iterator;
- case value_t::null:
- case value_t::string:
- case value_t::boolean:
- case value_t::number_integer:
- case value_t::number_unsigned:
- case value_t::number_float:
- case value_t::binary:
- case value_t::discarded:
- default:
- return m_it.primitive_iterator - other.m_it.primitive_iterator;
- }
- }
-
- reference operator[](difference_type n) const
- {
- JSON_ASSERT(m_object != nullptr);
- switch (m_object->m_type)
- {
- case value_t::object:
- JSON_THROW(invalid_iterator::create(208, "cannot use operator[] for object iterators", *m_object));
- case value_t::array:
- return *std::next(m_it.array_iterator, n);
- case value_t::null:
- JSON_THROW(invalid_iterator::create(214, "cannot get value", *m_object));
- case value_t::string:
- case value_t::boolean:
- case value_t::number_integer:
- case value_t::number_unsigned:
- case value_t::number_float:
- case value_t::binary:
- case value_t::discarded:
- default:
- {
- if (JSON_HEDLEY_LIKELY(m_it.primitive_iterator.get_value() == -n))
- {
- return *m_object;
- }
- JSON_THROW(invalid_iterator::create(214, "cannot get value", *m_object));
- }
- }
- }
-
- const typename object_t::key_type& key() const
- {
- JSON_ASSERT(m_object != nullptr);
- if (JSON_HEDLEY_LIKELY(m_object->is_object()))
- {
- return m_it.object_iterator->first;
- }
- JSON_THROW(invalid_iterator::create(207, "cannot use key() for non-object iterators", *m_object));
- }
-
- reference value() const
- {
- return operator*();
- }
- JSON_PRIVATE_UNLESS_TESTED:
-
- pointer m_object = nullptr;
-
- internal_iterator<typename std::remove_const<BasicJsonType>::type> m_it {};
- };
- }
- }
- #include <cstddef> // ptrdiff_t
- #include <iterator> // reverse_iterator
- #include <utility> // declval
- namespace nlohmann
- {
- namespace detail
- {
- template<typename Base>
- class json_reverse_iterator : public std::reverse_iterator<Base>
- {
- public:
- using difference_type = std::ptrdiff_t;
-
- using base_iterator = std::reverse_iterator<Base>;
-
- using reference = typename Base::reference;
-
- explicit json_reverse_iterator(const typename base_iterator::iterator_type& it) noexcept
- : base_iterator(it) {}
-
- explicit json_reverse_iterator(const base_iterator& it) noexcept : base_iterator(it) {}
-
- json_reverse_iterator const operator++(int)
- {
- return static_cast<json_reverse_iterator>(base_iterator::operator++(1));
- }
-
- json_reverse_iterator& operator++()
- {
- return static_cast<json_reverse_iterator&>(base_iterator::operator++());
- }
-
- json_reverse_iterator const operator--(int)
- {
- return static_cast<json_reverse_iterator>(base_iterator::operator--(1));
- }
-
- json_reverse_iterator& operator--()
- {
- return static_cast<json_reverse_iterator&>(base_iterator::operator--());
- }
-
- json_reverse_iterator& operator+=(difference_type i)
- {
- return static_cast<json_reverse_iterator&>(base_iterator::operator+=(i));
- }
-
- json_reverse_iterator operator+(difference_type i) const
- {
- return static_cast<json_reverse_iterator>(base_iterator::operator+(i));
- }
-
- json_reverse_iterator operator-(difference_type i) const
- {
- return static_cast<json_reverse_iterator>(base_iterator::operator-(i));
- }
-
- difference_type operator-(const json_reverse_iterator& other) const
- {
- return base_iterator(*this) - base_iterator(other);
- }
-
- reference operator[](difference_type n) const
- {
- return *(this->operator+(n));
- }
-
- auto key() const -> decltype(std::declval<Base>().key())
- {
- auto it = --this->base();
- return it.key();
- }
-
- reference value() const
- {
- auto it = --this->base();
- return it.operator * ();
- }
- };
- }
- }
- #include <algorithm> // all_of
- #include <cctype> // isdigit
- #include <limits> // max
- #include <numeric> // accumulate
- #include <string> // string
- #include <utility> // move
- #include <vector> // vector
- namespace nlohmann
- {
- template<typename BasicJsonType>
- class json_pointer
- {
-
- NLOHMANN_BASIC_JSON_TPL_DECLARATION
- friend class basic_json;
- public:
-
- explicit json_pointer(const std::string& s = "")
- : reference_tokens(split(s))
- {}
-
- std::string to_string() const
- {
- return std::accumulate(reference_tokens.begin(), reference_tokens.end(),
- std::string{},
- [](const std::string & a, const std::string & b)
- {
- return a + "/" + detail::escape(b);
- });
- }
-
- operator std::string() const
- {
- return to_string();
- }
-
- json_pointer& operator/=(const json_pointer& ptr)
- {
- reference_tokens.insert(reference_tokens.end(),
- ptr.reference_tokens.begin(),
- ptr.reference_tokens.end());
- return *this;
- }
-
- json_pointer& operator/=(std::string token)
- {
- push_back(std::move(token));
- return *this;
- }
-
- json_pointer& operator/=(std::size_t array_idx)
- {
- return *this /= std::to_string(array_idx);
- }
-
- friend json_pointer operator/(const json_pointer& lhs,
- const json_pointer& rhs)
- {
- return json_pointer(lhs) /= rhs;
- }
-
- friend json_pointer operator/(const json_pointer& ptr, std::string token)
- {
- return json_pointer(ptr) /= std::move(token);
- }
-
- friend json_pointer operator/(const json_pointer& ptr, std::size_t array_idx)
- {
- return json_pointer(ptr) /= array_idx;
- }
-
- json_pointer parent_pointer() const
- {
- if (empty())
- {
- return *this;
- }
- json_pointer res = *this;
- res.pop_back();
- return res;
- }
-
- void pop_back()
- {
- if (JSON_HEDLEY_UNLIKELY(empty()))
- {
- JSON_THROW(detail::out_of_range::create(405, "JSON pointer has no parent", BasicJsonType()));
- }
- reference_tokens.pop_back();
- }
-
- const std::string& back() const
- {
- if (JSON_HEDLEY_UNLIKELY(empty()))
- {
- JSON_THROW(detail::out_of_range::create(405, "JSON pointer has no parent", BasicJsonType()));
- }
- return reference_tokens.back();
- }
-
- void push_back(const std::string& token)
- {
- reference_tokens.push_back(token);
- }
-
- void push_back(std::string&& token)
- {
- reference_tokens.push_back(std::move(token));
- }
-
- bool empty() const noexcept
- {
- return reference_tokens.empty();
- }
- private:
-
- static typename BasicJsonType::size_type array_index(const std::string& s)
- {
- using size_type = typename BasicJsonType::size_type;
-
- if (JSON_HEDLEY_UNLIKELY(s.size() > 1 && s[0] == '0'))
- {
- JSON_THROW(detail::parse_error::create(106, 0, "array index '" + s + "' must not begin with '0'", BasicJsonType()));
- }
-
- if (JSON_HEDLEY_UNLIKELY(s.size() > 1 && !(s[0] >= '1' && s[0] <= '9')))
- {
- JSON_THROW(detail::parse_error::create(109, 0, "array index '" + s + "' is not a number", BasicJsonType()));
- }
- std::size_t processed_chars = 0;
- unsigned long long res = 0;
- JSON_TRY
- {
- res = std::stoull(s, &processed_chars);
- }
- JSON_CATCH(std::out_of_range&)
- {
- JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + s + "'", BasicJsonType()));
- }
-
- if (JSON_HEDLEY_UNLIKELY(processed_chars != s.size()))
- {
- JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + s + "'", BasicJsonType()));
- }
-
-
- if (res >= static_cast<unsigned long long>((std::numeric_limits<size_type>::max)()))
- {
- JSON_THROW(detail::out_of_range::create(410, "array index " + s + " exceeds size_type", BasicJsonType()));
- }
- return static_cast<size_type>(res);
- }
- JSON_PRIVATE_UNLESS_TESTED:
- json_pointer top() const
- {
- if (JSON_HEDLEY_UNLIKELY(empty()))
- {
- JSON_THROW(detail::out_of_range::create(405, "JSON pointer has no parent", BasicJsonType()));
- }
- json_pointer result = *this;
- result.reference_tokens = {reference_tokens[0]};
- return result;
- }
- private:
-
- BasicJsonType& get_and_create(BasicJsonType& j) const
- {
- auto* result = &j;
-
-
- for (const auto& reference_token : reference_tokens)
- {
- switch (result->type())
- {
- case detail::value_t::null:
- {
- if (reference_token == "0")
- {
-
- result = &result->operator[](0);
- }
- else
- {
-
- result = &result->operator[](reference_token);
- }
- break;
- }
- case detail::value_t::object:
- {
-
- result = &result->operator[](reference_token);
- break;
- }
- case detail::value_t::array:
- {
-
- result = &result->operator[](array_index(reference_token));
- break;
- }
-
- case detail::value_t::string:
- case detail::value_t::boolean:
- case detail::value_t::number_integer:
- case detail::value_t::number_unsigned:
- case detail::value_t::number_float:
- case detail::value_t::binary:
- case detail::value_t::discarded:
- default:
- JSON_THROW(detail::type_error::create(313, "invalid value to unflatten", j));
- }
- }
- return *result;
- }
-
- BasicJsonType& get_unchecked(BasicJsonType* ptr) const
- {
- for (const auto& reference_token : reference_tokens)
- {
-
- if (ptr->is_null())
- {
-
- const bool nums =
- std::all_of(reference_token.begin(), reference_token.end(),
- [](const unsigned char x)
- {
- return std::isdigit(x);
- });
-
- *ptr = (nums || reference_token == "-")
- ? detail::value_t::array
- : detail::value_t::object;
- }
- switch (ptr->type())
- {
- case detail::value_t::object:
- {
-
- ptr = &ptr->operator[](reference_token);
- break;
- }
- case detail::value_t::array:
- {
- if (reference_token == "-")
- {
-
- ptr = &ptr->operator[](ptr->m_value.array->size());
- }
- else
- {
-
- ptr = &ptr->operator[](array_index(reference_token));
- }
- break;
- }
- case detail::value_t::null:
- case detail::value_t::string:
- case detail::value_t::boolean:
- case detail::value_t::number_integer:
- case detail::value_t::number_unsigned:
- case detail::value_t::number_float:
- case detail::value_t::binary:
- case detail::value_t::discarded:
- default:
- JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + reference_token + "'", *ptr));
- }
- }
- return *ptr;
- }
-
- BasicJsonType& get_checked(BasicJsonType* ptr) const
- {
- for (const auto& reference_token : reference_tokens)
- {
- switch (ptr->type())
- {
- case detail::value_t::object:
- {
-
- ptr = &ptr->at(reference_token);
- break;
- }
- case detail::value_t::array:
- {
- if (JSON_HEDLEY_UNLIKELY(reference_token == "-"))
- {
-
- JSON_THROW(detail::out_of_range::create(402,
- "array index '-' (" + std::to_string(ptr->m_value.array->size()) +
- ") is out of range", *ptr));
- }
-
- ptr = &ptr->at(array_index(reference_token));
- break;
- }
- case detail::value_t::null:
- case detail::value_t::string:
- case detail::value_t::boolean:
- case detail::value_t::number_integer:
- case detail::value_t::number_unsigned:
- case detail::value_t::number_float:
- case detail::value_t::binary:
- case detail::value_t::discarded:
- default:
- JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + reference_token + "'", *ptr));
- }
- }
- return *ptr;
- }
-
- const BasicJsonType& get_unchecked(const BasicJsonType* ptr) const
- {
- for (const auto& reference_token : reference_tokens)
- {
- switch (ptr->type())
- {
- case detail::value_t::object:
- {
-
- ptr = &ptr->operator[](reference_token);
- break;
- }
- case detail::value_t::array:
- {
- if (JSON_HEDLEY_UNLIKELY(reference_token == "-"))
- {
-
- JSON_THROW(detail::out_of_range::create(402, "array index '-' (" + std::to_string(ptr->m_value.array->size()) + ") is out of range", *ptr));
- }
-
- ptr = &ptr->operator[](array_index(reference_token));
- break;
- }
- case detail::value_t::null:
- case detail::value_t::string:
- case detail::value_t::boolean:
- case detail::value_t::number_integer:
- case detail::value_t::number_unsigned:
- case detail::value_t::number_float:
- case detail::value_t::binary:
- case detail::value_t::discarded:
- default:
- JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + reference_token + "'", *ptr));
- }
- }
- return *ptr;
- }
-
- const BasicJsonType& get_checked(const BasicJsonType* ptr) const
- {
- for (const auto& reference_token : reference_tokens)
- {
- switch (ptr->type())
- {
- case detail::value_t::object:
- {
-
- ptr = &ptr->at(reference_token);
- break;
- }
- case detail::value_t::array:
- {
- if (JSON_HEDLEY_UNLIKELY(reference_token == "-"))
- {
-
- JSON_THROW(detail::out_of_range::create(402,
- "array index '-' (" + std::to_string(ptr->m_value.array->size()) +
- ") is out of range", *ptr));
- }
-
- ptr = &ptr->at(array_index(reference_token));
- break;
- }
- case detail::value_t::null:
- case detail::value_t::string:
- case detail::value_t::boolean:
- case detail::value_t::number_integer:
- case detail::value_t::number_unsigned:
- case detail::value_t::number_float:
- case detail::value_t::binary:
- case detail::value_t::discarded:
- default:
- JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + reference_token + "'", *ptr));
- }
- }
- return *ptr;
- }
-
- bool contains(const BasicJsonType* ptr) const
- {
- for (const auto& reference_token : reference_tokens)
- {
- switch (ptr->type())
- {
- case detail::value_t::object:
- {
- if (!ptr->contains(reference_token))
- {
-
- return false;
- }
- ptr = &ptr->operator[](reference_token);
- break;
- }
- case detail::value_t::array:
- {
- if (JSON_HEDLEY_UNLIKELY(reference_token == "-"))
- {
-
- return false;
- }
- if (JSON_HEDLEY_UNLIKELY(reference_token.size() == 1 && !("0" <= reference_token && reference_token <= "9")))
- {
-
- return false;
- }
- if (JSON_HEDLEY_UNLIKELY(reference_token.size() > 1))
- {
- if (JSON_HEDLEY_UNLIKELY(!('1' <= reference_token[0] && reference_token[0] <= '9')))
- {
-
- return false;
- }
- for (std::size_t i = 1; i < reference_token.size(); i++)
- {
- if (JSON_HEDLEY_UNLIKELY(!('0' <= reference_token[i] && reference_token[i] <= '9')))
- {
-
- return false;
- }
- }
- }
- const auto idx = array_index(reference_token);
- if (idx >= ptr->size())
- {
-
- return false;
- }
- ptr = &ptr->operator[](idx);
- break;
- }
- case detail::value_t::null:
- case detail::value_t::string:
- case detail::value_t::boolean:
- case detail::value_t::number_integer:
- case detail::value_t::number_unsigned:
- case detail::value_t::number_float:
- case detail::value_t::binary:
- case detail::value_t::discarded:
- default:
- {
-
-
- return false;
- }
- }
- }
-
- return true;
- }
-
- static std::vector<std::string> split(const std::string& reference_string)
- {
- std::vector<std::string> result;
-
- if (reference_string.empty())
- {
- return result;
- }
-
- if (JSON_HEDLEY_UNLIKELY(reference_string[0] != '/'))
- {
- JSON_THROW(detail::parse_error::create(107, 1, "JSON pointer must be empty or begin with '/' - was: '" + reference_string + "'", BasicJsonType()));
- }
-
-
-
- for (
-
- std::size_t slash = reference_string.find_first_of('/', 1),
-
- start = 1;
-
- start != 0;
-
-
- start = (slash == std::string::npos) ? 0 : slash + 1,
-
- slash = reference_string.find_first_of('/', start))
- {
-
-
- auto reference_token = reference_string.substr(start, slash - start);
-
- for (std::size_t pos = reference_token.find_first_of('~');
- pos != std::string::npos;
- pos = reference_token.find_first_of('~', pos + 1))
- {
- JSON_ASSERT(reference_token[pos] == '~');
-
- if (JSON_HEDLEY_UNLIKELY(pos == reference_token.size() - 1 ||
- (reference_token[pos + 1] != '0' &&
- reference_token[pos + 1] != '1')))
- {
- JSON_THROW(detail::parse_error::create(108, 0, "escape character '~' must be followed with '0' or '1'", BasicJsonType()));
- }
- }
-
- detail::unescape(reference_token);
- result.push_back(reference_token);
- }
- return result;
- }
- private:
-
- static void flatten(const std::string& reference_string,
- const BasicJsonType& value,
- BasicJsonType& result)
- {
- switch (value.type())
- {
- case detail::value_t::array:
- {
- if (value.m_value.array->empty())
- {
-
- result[reference_string] = nullptr;
- }
- else
- {
-
- for (std::size_t i = 0; i < value.m_value.array->size(); ++i)
- {
- flatten(reference_string + "/" + std::to_string(i),
- value.m_value.array->operator[](i), result);
- }
- }
- break;
- }
- case detail::value_t::object:
- {
- if (value.m_value.object->empty())
- {
-
- result[reference_string] = nullptr;
- }
- else
- {
-
- for (const auto& element : *value.m_value.object)
- {
- flatten(reference_string + "/" + detail::escape(element.first), element.second, result);
- }
- }
- break;
- }
- case detail::value_t::null:
- case detail::value_t::string:
- case detail::value_t::boolean:
- case detail::value_t::number_integer:
- case detail::value_t::number_unsigned:
- case detail::value_t::number_float:
- case detail::value_t::binary:
- case detail::value_t::discarded:
- default:
- {
-
- result[reference_string] = value;
- break;
- }
- }
- }
-
- static BasicJsonType
- unflatten(const BasicJsonType& value)
- {
- if (JSON_HEDLEY_UNLIKELY(!value.is_object()))
- {
- JSON_THROW(detail::type_error::create(314, "only objects can be unflattened", value));
- }
- BasicJsonType result;
-
- for (const auto& element : *value.m_value.object)
- {
- if (JSON_HEDLEY_UNLIKELY(!element.second.is_primitive()))
- {
- JSON_THROW(detail::type_error::create(315, "values in object must be primitive", element.second));
- }
-
-
-
-
- json_pointer(element.first).get_and_create(result) = element.second;
- }
- return result;
- }
-
- friend bool operator==(json_pointer const& lhs,
- json_pointer const& rhs) noexcept
- {
- return lhs.reference_tokens == rhs.reference_tokens;
- }
-
- friend bool operator!=(json_pointer const& lhs,
- json_pointer const& rhs) noexcept
- {
- return !(lhs == rhs);
- }
-
- std::vector<std::string> reference_tokens;
- };
- }
- #include <initializer_list>
- #include <utility>
- namespace nlohmann
- {
- namespace detail
- {
- template<typename BasicJsonType>
- class json_ref
- {
- public:
- using value_type = BasicJsonType;
- json_ref(value_type&& value)
- : owned_value(std::move(value))
- {}
- json_ref(const value_type& value)
- : value_ref(&value)
- {}
- json_ref(std::initializer_list<json_ref> init)
- : owned_value(init)
- {}
- template <
- class... Args,
- enable_if_t<std::is_constructible<value_type, Args...>::value, int> = 0 >
- json_ref(Args && ... args)
- : owned_value(std::forward<Args>(args)...)
- {}
-
- json_ref(json_ref&&) noexcept = default;
- json_ref(const json_ref&) = delete;
- json_ref& operator=(const json_ref&) = delete;
- json_ref& operator=(json_ref&&) = delete;
- ~json_ref() = default;
- value_type moved_or_copied() const
- {
- if (value_ref == nullptr)
- {
- return std::move(owned_value);
- }
- return *value_ref;
- }
- value_type const& operator*() const
- {
- return value_ref ? *value_ref : owned_value;
- }
- value_type const* operator->() const
- {
- return &** this;
- }
- private:
- mutable value_type owned_value = nullptr;
- value_type const* value_ref = nullptr;
- };
- }
- }
- #include <algorithm> // reverse
- #include <array> // array
- #include <cmath> // isnan, isinf
- #include <cstdint> // uint8_t, uint16_t, uint32_t, uint64_t
- #include <cstring> // memcpy
- #include <limits> // numeric_limits
- #include <string> // string
- #include <utility> // move
- #include <algorithm> // copy
- #include <cstddef> // size_t
- #include <iterator> // back_inserter
- #include <memory> // shared_ptr, make_shared
- #include <string> // basic_string
- #include <vector> // vector
- #ifndef JSON_NO_IO
- #include <ios> // streamsize
- #include <ostream> // basic_ostream
- #endif
- namespace nlohmann
- {
- namespace detail
- {
- template<typename CharType> struct output_adapter_protocol
- {
- virtual void write_character(CharType c) = 0;
- virtual void write_characters(const CharType* s, std::size_t length) = 0;
- virtual ~output_adapter_protocol() = default;
- output_adapter_protocol() = default;
- output_adapter_protocol(const output_adapter_protocol&) = default;
- output_adapter_protocol(output_adapter_protocol&&) noexcept = default;
- output_adapter_protocol& operator=(const output_adapter_protocol&) = default;
- output_adapter_protocol& operator=(output_adapter_protocol&&) noexcept = default;
- };
- template<typename CharType>
- using output_adapter_t = std::shared_ptr<output_adapter_protocol<CharType>>;
- template<typename CharType, typename AllocatorType = std::allocator<CharType>>
- class output_vector_adapter : public output_adapter_protocol<CharType>
- {
- public:
- explicit output_vector_adapter(std::vector<CharType, AllocatorType>& vec) noexcept
- : v(vec)
- {}
- void write_character(CharType c) override
- {
- v.push_back(c);
- }
- JSON_HEDLEY_NON_NULL(2)
- void write_characters(const CharType* s, std::size_t length) override
- {
- std::copy(s, s + length, std::back_inserter(v));
- }
- private:
- std::vector<CharType, AllocatorType>& v;
- };
- #ifndef JSON_NO_IO
- template<typename CharType>
- class output_stream_adapter : public output_adapter_protocol<CharType>
- {
- public:
- explicit output_stream_adapter(std::basic_ostream<CharType>& s) noexcept
- : stream(s)
- {}
- void write_character(CharType c) override
- {
- stream.put(c);
- }
- JSON_HEDLEY_NON_NULL(2)
- void write_characters(const CharType* s, std::size_t length) override
- {
- stream.write(s, static_cast<std::streamsize>(length));
- }
- private:
- std::basic_ostream<CharType>& stream;
- };
- #endif
- template<typename CharType, typename StringType = std::basic_string<CharType>>
- class output_string_adapter : public output_adapter_protocol<CharType>
- {
- public:
- explicit output_string_adapter(StringType& s) noexcept
- : str(s)
- {}
- void write_character(CharType c) override
- {
- str.push_back(c);
- }
- JSON_HEDLEY_NON_NULL(2)
- void write_characters(const CharType* s, std::size_t length) override
- {
- str.append(s, length);
- }
- private:
- StringType& str;
- };
- template<typename CharType, typename StringType = std::basic_string<CharType>>
- class output_adapter
- {
- public:
- template<typename AllocatorType = std::allocator<CharType>>
- output_adapter(std::vector<CharType, AllocatorType>& vec)
- : oa(std::make_shared<output_vector_adapter<CharType, AllocatorType>>(vec)) {}
- #ifndef JSON_NO_IO
- output_adapter(std::basic_ostream<CharType>& s)
- : oa(std::make_shared<output_stream_adapter<CharType>>(s)) {}
- #endif
- output_adapter(StringType& s)
- : oa(std::make_shared<output_string_adapter<CharType, StringType>>(s)) {}
- operator output_adapter_t<CharType>()
- {
- return oa;
- }
- private:
- output_adapter_t<CharType> oa = nullptr;
- };
- }
- }
- namespace nlohmann
- {
- namespace detail
- {
- template<typename BasicJsonType, typename CharType>
- class binary_writer
- {
- using string_t = typename BasicJsonType::string_t;
- using binary_t = typename BasicJsonType::binary_t;
- using number_float_t = typename BasicJsonType::number_float_t;
- public:
-
- explicit binary_writer(output_adapter_t<CharType> adapter) : oa(std::move(adapter))
- {
- JSON_ASSERT(oa);
- }
-
- void write_bson(const BasicJsonType& j)
- {
- switch (j.type())
- {
- case value_t::object:
- {
- write_bson_object(*j.m_value.object);
- break;
- }
- case value_t::null:
- case value_t::array:
- case value_t::string:
- case value_t::boolean:
- case value_t::number_integer:
- case value_t::number_unsigned:
- case value_t::number_float:
- case value_t::binary:
- case value_t::discarded:
- default:
- {
- JSON_THROW(type_error::create(317, "to serialize to BSON, top-level type must be object, but is " + std::string(j.type_name()), j));
- }
- }
- }
-
- void write_cbor(const BasicJsonType& j)
- {
- switch (j.type())
- {
- case value_t::null:
- {
- oa->write_character(to_char_type(0xF6));
- break;
- }
- case value_t::boolean:
- {
- oa->write_character(j.m_value.boolean
- ? to_char_type(0xF5)
- : to_char_type(0xF4));
- break;
- }
- case value_t::number_integer:
- {
- if (j.m_value.number_integer >= 0)
- {
-
-
-
- if (j.m_value.number_integer <= 0x17)
- {
- write_number(static_cast<std::uint8_t>(j.m_value.number_integer));
- }
- else if (j.m_value.number_integer <= (std::numeric_limits<std::uint8_t>::max)())
- {
- oa->write_character(to_char_type(0x18));
- write_number(static_cast<std::uint8_t>(j.m_value.number_integer));
- }
- else if (j.m_value.number_integer <= (std::numeric_limits<std::uint16_t>::max)())
- {
- oa->write_character(to_char_type(0x19));
- write_number(static_cast<std::uint16_t>(j.m_value.number_integer));
- }
- else if (j.m_value.number_integer <= (std::numeric_limits<std::uint32_t>::max)())
- {
- oa->write_character(to_char_type(0x1A));
- write_number(static_cast<std::uint32_t>(j.m_value.number_integer));
- }
- else
- {
- oa->write_character(to_char_type(0x1B));
- write_number(static_cast<std::uint64_t>(j.m_value.number_integer));
- }
- }
- else
- {
-
-
- const auto positive_number = -1 - j.m_value.number_integer;
- if (j.m_value.number_integer >= -24)
- {
- write_number(static_cast<std::uint8_t>(0x20 + positive_number));
- }
- else if (positive_number <= (std::numeric_limits<std::uint8_t>::max)())
- {
- oa->write_character(to_char_type(0x38));
- write_number(static_cast<std::uint8_t>(positive_number));
- }
- else if (positive_number <= (std::numeric_limits<std::uint16_t>::max)())
- {
- oa->write_character(to_char_type(0x39));
- write_number(static_cast<std::uint16_t>(positive_number));
- }
- else if (positive_number <= (std::numeric_limits<std::uint32_t>::max)())
- {
- oa->write_character(to_char_type(0x3A));
- write_number(static_cast<std::uint32_t>(positive_number));
- }
- else
- {
- oa->write_character(to_char_type(0x3B));
- write_number(static_cast<std::uint64_t>(positive_number));
- }
- }
- break;
- }
- case value_t::number_unsigned:
- {
- if (j.m_value.number_unsigned <= 0x17)
- {
- write_number(static_cast<std::uint8_t>(j.m_value.number_unsigned));
- }
- else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint8_t>::max)())
- {
- oa->write_character(to_char_type(0x18));
- write_number(static_cast<std::uint8_t>(j.m_value.number_unsigned));
- }
- else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)())
- {
- oa->write_character(to_char_type(0x19));
- write_number(static_cast<std::uint16_t>(j.m_value.number_unsigned));
- }
- else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)())
- {
- oa->write_character(to_char_type(0x1A));
- write_number(static_cast<std::uint32_t>(j.m_value.number_unsigned));
- }
- else
- {
- oa->write_character(to_char_type(0x1B));
- write_number(static_cast<std::uint64_t>(j.m_value.number_unsigned));
- }
- break;
- }
- case value_t::number_float:
- {
- if (std::isnan(j.m_value.number_float))
- {
-
- oa->write_character(to_char_type(0xF9));
- oa->write_character(to_char_type(0x7E));
- oa->write_character(to_char_type(0x00));
- }
- else if (std::isinf(j.m_value.number_float))
- {
-
- oa->write_character(to_char_type(0xf9));
- oa->write_character(j.m_value.number_float > 0 ? to_char_type(0x7C) : to_char_type(0xFC));
- oa->write_character(to_char_type(0x00));
- }
- else
- {
- write_compact_float(j.m_value.number_float, detail::input_format_t::cbor);
- }
- break;
- }
- case value_t::string:
- {
-
- const auto N = j.m_value.string->size();
- if (N <= 0x17)
- {
- write_number(static_cast<std::uint8_t>(0x60 + N));
- }
- else if (N <= (std::numeric_limits<std::uint8_t>::max)())
- {
- oa->write_character(to_char_type(0x78));
- write_number(static_cast<std::uint8_t>(N));
- }
- else if (N <= (std::numeric_limits<std::uint16_t>::max)())
- {
- oa->write_character(to_char_type(0x79));
- write_number(static_cast<std::uint16_t>(N));
- }
- else if (N <= (std::numeric_limits<std::uint32_t>::max)())
- {
- oa->write_character(to_char_type(0x7A));
- write_number(static_cast<std::uint32_t>(N));
- }
-
- else if (N <= (std::numeric_limits<std::uint64_t>::max)())
- {
- oa->write_character(to_char_type(0x7B));
- write_number(static_cast<std::uint64_t>(N));
- }
-
-
- oa->write_characters(
- reinterpret_cast<const CharType*>(j.m_value.string->c_str()),
- j.m_value.string->size());
- break;
- }
- case value_t::array:
- {
-
- const auto N = j.m_value.array->size();
- if (N <= 0x17)
- {
- write_number(static_cast<std::uint8_t>(0x80 + N));
- }
- else if (N <= (std::numeric_limits<std::uint8_t>::max)())
- {
- oa->write_character(to_char_type(0x98));
- write_number(static_cast<std::uint8_t>(N));
- }
- else if (N <= (std::numeric_limits<std::uint16_t>::max)())
- {
- oa->write_character(to_char_type(0x99));
- write_number(static_cast<std::uint16_t>(N));
- }
- else if (N <= (std::numeric_limits<std::uint32_t>::max)())
- {
- oa->write_character(to_char_type(0x9A));
- write_number(static_cast<std::uint32_t>(N));
- }
-
- else if (N <= (std::numeric_limits<std::uint64_t>::max)())
- {
- oa->write_character(to_char_type(0x9B));
- write_number(static_cast<std::uint64_t>(N));
- }
-
-
- for (const auto& el : *j.m_value.array)
- {
- write_cbor(el);
- }
- break;
- }
- case value_t::binary:
- {
- if (j.m_value.binary->has_subtype())
- {
- if (j.m_value.binary->subtype() <= (std::numeric_limits<std::uint8_t>::max)())
- {
- write_number(static_cast<std::uint8_t>(0xd8));
- write_number(static_cast<std::uint8_t>(j.m_value.binary->subtype()));
- }
- else if (j.m_value.binary->subtype() <= (std::numeric_limits<std::uint16_t>::max)())
- {
- write_number(static_cast<std::uint8_t>(0xd9));
- write_number(static_cast<std::uint16_t>(j.m_value.binary->subtype()));
- }
- else if (j.m_value.binary->subtype() <= (std::numeric_limits<std::uint32_t>::max)())
- {
- write_number(static_cast<std::uint8_t>(0xda));
- write_number(static_cast<std::uint32_t>(j.m_value.binary->subtype()));
- }
- else if (j.m_value.binary->subtype() <= (std::numeric_limits<std::uint64_t>::max)())
- {
- write_number(static_cast<std::uint8_t>(0xdb));
- write_number(static_cast<std::uint64_t>(j.m_value.binary->subtype()));
- }
- }
-
- const auto N = j.m_value.binary->size();
- if (N <= 0x17)
- {
- write_number(static_cast<std::uint8_t>(0x40 + N));
- }
- else if (N <= (std::numeric_limits<std::uint8_t>::max)())
- {
- oa->write_character(to_char_type(0x58));
- write_number(static_cast<std::uint8_t>(N));
- }
- else if (N <= (std::numeric_limits<std::uint16_t>::max)())
- {
- oa->write_character(to_char_type(0x59));
- write_number(static_cast<std::uint16_t>(N));
- }
- else if (N <= (std::numeric_limits<std::uint32_t>::max)())
- {
- oa->write_character(to_char_type(0x5A));
- write_number(static_cast<std::uint32_t>(N));
- }
-
- else if (N <= (std::numeric_limits<std::uint64_t>::max)())
- {
- oa->write_character(to_char_type(0x5B));
- write_number(static_cast<std::uint64_t>(N));
- }
-
-
- oa->write_characters(
- reinterpret_cast<const CharType*>(j.m_value.binary->data()),
- N);
- break;
- }
- case value_t::object:
- {
-
- const auto N = j.m_value.object->size();
- if (N <= 0x17)
- {
- write_number(static_cast<std::uint8_t>(0xA0 + N));
- }
- else if (N <= (std::numeric_limits<std::uint8_t>::max)())
- {
- oa->write_character(to_char_type(0xB8));
- write_number(static_cast<std::uint8_t>(N));
- }
- else if (N <= (std::numeric_limits<std::uint16_t>::max)())
- {
- oa->write_character(to_char_type(0xB9));
- write_number(static_cast<std::uint16_t>(N));
- }
- else if (N <= (std::numeric_limits<std::uint32_t>::max)())
- {
- oa->write_character(to_char_type(0xBA));
- write_number(static_cast<std::uint32_t>(N));
- }
-
- else if (N <= (std::numeric_limits<std::uint64_t>::max)())
- {
- oa->write_character(to_char_type(0xBB));
- write_number(static_cast<std::uint64_t>(N));
- }
-
-
- for (const auto& el : *j.m_value.object)
- {
- write_cbor(el.first);
- write_cbor(el.second);
- }
- break;
- }
- case value_t::discarded:
- default:
- break;
- }
- }
-
- void write_msgpack(const BasicJsonType& j)
- {
- switch (j.type())
- {
- case value_t::null:
- {
- oa->write_character(to_char_type(0xC0));
- break;
- }
- case value_t::boolean:
- {
- oa->write_character(j.m_value.boolean
- ? to_char_type(0xC3)
- : to_char_type(0xC2));
- break;
- }
- case value_t::number_integer:
- {
- if (j.m_value.number_integer >= 0)
- {
-
-
-
- if (j.m_value.number_unsigned < 128)
- {
-
- write_number(static_cast<std::uint8_t>(j.m_value.number_integer));
- }
- else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint8_t>::max)())
- {
-
- oa->write_character(to_char_type(0xCC));
- write_number(static_cast<std::uint8_t>(j.m_value.number_integer));
- }
- else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)())
- {
-
- oa->write_character(to_char_type(0xCD));
- write_number(static_cast<std::uint16_t>(j.m_value.number_integer));
- }
- else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)())
- {
-
- oa->write_character(to_char_type(0xCE));
- write_number(static_cast<std::uint32_t>(j.m_value.number_integer));
- }
- else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint64_t>::max)())
- {
-
- oa->write_character(to_char_type(0xCF));
- write_number(static_cast<std::uint64_t>(j.m_value.number_integer));
- }
- }
- else
- {
- if (j.m_value.number_integer >= -32)
- {
-
- write_number(static_cast<std::int8_t>(j.m_value.number_integer));
- }
- else if (j.m_value.number_integer >= (std::numeric_limits<std::int8_t>::min)() &&
- j.m_value.number_integer <= (std::numeric_limits<std::int8_t>::max)())
- {
-
- oa->write_character(to_char_type(0xD0));
- write_number(static_cast<std::int8_t>(j.m_value.number_integer));
- }
- else if (j.m_value.number_integer >= (std::numeric_limits<std::int16_t>::min)() &&
- j.m_value.number_integer <= (std::numeric_limits<std::int16_t>::max)())
- {
-
- oa->write_character(to_char_type(0xD1));
- write_number(static_cast<std::int16_t>(j.m_value.number_integer));
- }
- else if (j.m_value.number_integer >= (std::numeric_limits<std::int32_t>::min)() &&
- j.m_value.number_integer <= (std::numeric_limits<std::int32_t>::max)())
- {
-
- oa->write_character(to_char_type(0xD2));
- write_number(static_cast<std::int32_t>(j.m_value.number_integer));
- }
- else if (j.m_value.number_integer >= (std::numeric_limits<std::int64_t>::min)() &&
- j.m_value.number_integer <= (std::numeric_limits<std::int64_t>::max)())
- {
-
- oa->write_character(to_char_type(0xD3));
- write_number(static_cast<std::int64_t>(j.m_value.number_integer));
- }
- }
- break;
- }
- case value_t::number_unsigned:
- {
- if (j.m_value.number_unsigned < 128)
- {
-
- write_number(static_cast<std::uint8_t>(j.m_value.number_integer));
- }
- else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint8_t>::max)())
- {
-
- oa->write_character(to_char_type(0xCC));
- write_number(static_cast<std::uint8_t>(j.m_value.number_integer));
- }
- else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)())
- {
-
- oa->write_character(to_char_type(0xCD));
- write_number(static_cast<std::uint16_t>(j.m_value.number_integer));
- }
- else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)())
- {
-
- oa->write_character(to_char_type(0xCE));
- write_number(static_cast<std::uint32_t>(j.m_value.number_integer));
- }
- else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint64_t>::max)())
- {
-
- oa->write_character(to_char_type(0xCF));
- write_number(static_cast<std::uint64_t>(j.m_value.number_integer));
- }
- break;
- }
- case value_t::number_float:
- {
- write_compact_float(j.m_value.number_float, detail::input_format_t::msgpack);
- break;
- }
- case value_t::string:
- {
-
- const auto N = j.m_value.string->size();
- if (N <= 31)
- {
-
- write_number(static_cast<std::uint8_t>(0xA0 | N));
- }
- else if (N <= (std::numeric_limits<std::uint8_t>::max)())
- {
-
- oa->write_character(to_char_type(0xD9));
- write_number(static_cast<std::uint8_t>(N));
- }
- else if (N <= (std::numeric_limits<std::uint16_t>::max)())
- {
-
- oa->write_character(to_char_type(0xDA));
- write_number(static_cast<std::uint16_t>(N));
- }
- else if (N <= (std::numeric_limits<std::uint32_t>::max)())
- {
-
- oa->write_character(to_char_type(0xDB));
- write_number(static_cast<std::uint32_t>(N));
- }
-
- oa->write_characters(
- reinterpret_cast<const CharType*>(j.m_value.string->c_str()),
- j.m_value.string->size());
- break;
- }
- case value_t::array:
- {
-
- const auto N = j.m_value.array->size();
- if (N <= 15)
- {
-
- write_number(static_cast<std::uint8_t>(0x90 | N));
- }
- else if (N <= (std::numeric_limits<std::uint16_t>::max)())
- {
-
- oa->write_character(to_char_type(0xDC));
- write_number(static_cast<std::uint16_t>(N));
- }
- else if (N <= (std::numeric_limits<std::uint32_t>::max)())
- {
-
- oa->write_character(to_char_type(0xDD));
- write_number(static_cast<std::uint32_t>(N));
- }
-
- for (const auto& el : *j.m_value.array)
- {
- write_msgpack(el);
- }
- break;
- }
- case value_t::binary:
- {
-
-
- const bool use_ext = j.m_value.binary->has_subtype();
-
- const auto N = j.m_value.binary->size();
- if (N <= (std::numeric_limits<std::uint8_t>::max)())
- {
- std::uint8_t output_type{};
- bool fixed = true;
- if (use_ext)
- {
- switch (N)
- {
- case 1:
- output_type = 0xD4;
- break;
- case 2:
- output_type = 0xD5;
- break;
- case 4:
- output_type = 0xD6;
- break;
- case 8:
- output_type = 0xD7;
- break;
- case 16:
- output_type = 0xD8;
- break;
- default:
- output_type = 0xC7;
- fixed = false;
- break;
- }
- }
- else
- {
- output_type = 0xC4;
- fixed = false;
- }
- oa->write_character(to_char_type(output_type));
- if (!fixed)
- {
- write_number(static_cast<std::uint8_t>(N));
- }
- }
- else if (N <= (std::numeric_limits<std::uint16_t>::max)())
- {
- std::uint8_t output_type = use_ext
- ? 0xC8
- : 0xC5;
- oa->write_character(to_char_type(output_type));
- write_number(static_cast<std::uint16_t>(N));
- }
- else if (N <= (std::numeric_limits<std::uint32_t>::max)())
- {
- std::uint8_t output_type = use_ext
- ? 0xC9
- : 0xC6;
- oa->write_character(to_char_type(output_type));
- write_number(static_cast<std::uint32_t>(N));
- }
-
- if (use_ext)
- {
- write_number(static_cast<std::int8_t>(j.m_value.binary->subtype()));
- }
-
- oa->write_characters(
- reinterpret_cast<const CharType*>(j.m_value.binary->data()),
- N);
- break;
- }
- case value_t::object:
- {
-
- const auto N = j.m_value.object->size();
- if (N <= 15)
- {
-
- write_number(static_cast<std::uint8_t>(0x80 | (N & 0xF)));
- }
- else if (N <= (std::numeric_limits<std::uint16_t>::max)())
- {
-
- oa->write_character(to_char_type(0xDE));
- write_number(static_cast<std::uint16_t>(N));
- }
- else if (N <= (std::numeric_limits<std::uint32_t>::max)())
- {
-
- oa->write_character(to_char_type(0xDF));
- write_number(static_cast<std::uint32_t>(N));
- }
-
- for (const auto& el : *j.m_value.object)
- {
- write_msgpack(el.first);
- write_msgpack(el.second);
- }
- break;
- }
- case value_t::discarded:
- default:
- break;
- }
- }
-
- void write_ubjson(const BasicJsonType& j, const bool use_count,
- const bool use_type, const bool add_prefix = true)
- {
- switch (j.type())
- {
- case value_t::null:
- {
- if (add_prefix)
- {
- oa->write_character(to_char_type('Z'));
- }
- break;
- }
- case value_t::boolean:
- {
- if (add_prefix)
- {
- oa->write_character(j.m_value.boolean
- ? to_char_type('T')
- : to_char_type('F'));
- }
- break;
- }
- case value_t::number_integer:
- {
- write_number_with_ubjson_prefix(j.m_value.number_integer, add_prefix);
- break;
- }
- case value_t::number_unsigned:
- {
- write_number_with_ubjson_prefix(j.m_value.number_unsigned, add_prefix);
- break;
- }
- case value_t::number_float:
- {
- write_number_with_ubjson_prefix(j.m_value.number_float, add_prefix);
- break;
- }
- case value_t::string:
- {
- if (add_prefix)
- {
- oa->write_character(to_char_type('S'));
- }
- write_number_with_ubjson_prefix(j.m_value.string->size(), true);
- oa->write_characters(
- reinterpret_cast<const CharType*>(j.m_value.string->c_str()),
- j.m_value.string->size());
- break;
- }
- case value_t::array:
- {
- if (add_prefix)
- {
- oa->write_character(to_char_type('['));
- }
- bool prefix_required = true;
- if (use_type && !j.m_value.array->empty())
- {
- JSON_ASSERT(use_count);
- const CharType first_prefix = ubjson_prefix(j.front());
- const bool same_prefix = std::all_of(j.begin() + 1, j.end(),
- [this, first_prefix](const BasicJsonType & v)
- {
- return ubjson_prefix(v) == first_prefix;
- });
- if (same_prefix)
- {
- prefix_required = false;
- oa->write_character(to_char_type('$'));
- oa->write_character(first_prefix);
- }
- }
- if (use_count)
- {
- oa->write_character(to_char_type('#'));
- write_number_with_ubjson_prefix(j.m_value.array->size(), true);
- }
- for (const auto& el : *j.m_value.array)
- {
- write_ubjson(el, use_count, use_type, prefix_required);
- }
- if (!use_count)
- {
- oa->write_character(to_char_type(']'));
- }
- break;
- }
- case value_t::binary:
- {
- if (add_prefix)
- {
- oa->write_character(to_char_type('['));
- }
- if (use_type && !j.m_value.binary->empty())
- {
- JSON_ASSERT(use_count);
- oa->write_character(to_char_type('$'));
- oa->write_character('U');
- }
- if (use_count)
- {
- oa->write_character(to_char_type('#'));
- write_number_with_ubjson_prefix(j.m_value.binary->size(), true);
- }
- if (use_type)
- {
- oa->write_characters(
- reinterpret_cast<const CharType*>(j.m_value.binary->data()),
- j.m_value.binary->size());
- }
- else
- {
- for (size_t i = 0; i < j.m_value.binary->size(); ++i)
- {
- oa->write_character(to_char_type('U'));
- oa->write_character(j.m_value.binary->data()[i]);
- }
- }
- if (!use_count)
- {
- oa->write_character(to_char_type(']'));
- }
- break;
- }
- case value_t::object:
- {
- if (add_prefix)
- {
- oa->write_character(to_char_type('{'));
- }
- bool prefix_required = true;
- if (use_type && !j.m_value.object->empty())
- {
- JSON_ASSERT(use_count);
- const CharType first_prefix = ubjson_prefix(j.front());
- const bool same_prefix = std::all_of(j.begin(), j.end(),
- [this, first_prefix](const BasicJsonType & v)
- {
- return ubjson_prefix(v) == first_prefix;
- });
- if (same_prefix)
- {
- prefix_required = false;
- oa->write_character(to_char_type('$'));
- oa->write_character(first_prefix);
- }
- }
- if (use_count)
- {
- oa->write_character(to_char_type('#'));
- write_number_with_ubjson_prefix(j.m_value.object->size(), true);
- }
- for (const auto& el : *j.m_value.object)
- {
- write_number_with_ubjson_prefix(el.first.size(), true);
- oa->write_characters(
- reinterpret_cast<const CharType*>(el.first.c_str()),
- el.first.size());
- write_ubjson(el.second, use_count, use_type, prefix_required);
- }
- if (!use_count)
- {
- oa->write_character(to_char_type('}'));
- }
- break;
- }
- case value_t::discarded:
- default:
- break;
- }
- }
- private:
-
-
-
-
- static std::size_t calc_bson_entry_header_size(const string_t& name, const BasicJsonType& j)
- {
- const auto it = name.find(static_cast<typename string_t::value_type>(0));
- if (JSON_HEDLEY_UNLIKELY(it != BasicJsonType::string_t::npos))
- {
- JSON_THROW(out_of_range::create(409, "BSON key cannot contain code point U+0000 (at byte " + std::to_string(it) + ")", j));
- static_cast<void>(j);
- }
- return 1ul + name.size() + 1u;
- }
-
- void write_bson_entry_header(const string_t& name,
- const std::uint8_t element_type)
- {
- oa->write_character(to_char_type(element_type));
- oa->write_characters(
- reinterpret_cast<const CharType*>(name.c_str()),
- name.size() + 1u);
- }
-
- void write_bson_boolean(const string_t& name,
- const bool value)
- {
- write_bson_entry_header(name, 0x08);
- oa->write_character(value ? to_char_type(0x01) : to_char_type(0x00));
- }
-
- void write_bson_double(const string_t& name,
- const double value)
- {
- write_bson_entry_header(name, 0x01);
- write_number<double, true>(value);
- }
-
- static std::size_t calc_bson_string_size(const string_t& value)
- {
- return sizeof(std::int32_t) + value.size() + 1ul;
- }
-
- void write_bson_string(const string_t& name,
- const string_t& value)
- {
- write_bson_entry_header(name, 0x02);
- write_number<std::int32_t, true>(static_cast<std::int32_t>(value.size() + 1ul));
- oa->write_characters(
- reinterpret_cast<const CharType*>(value.c_str()),
- value.size() + 1);
- }
-
- void write_bson_null(const string_t& name)
- {
- write_bson_entry_header(name, 0x0A);
- }
-
- static std::size_t calc_bson_integer_size(const std::int64_t value)
- {
- return (std::numeric_limits<std::int32_t>::min)() <= value && value <= (std::numeric_limits<std::int32_t>::max)()
- ? sizeof(std::int32_t)
- : sizeof(std::int64_t);
- }
-
- void write_bson_integer(const string_t& name,
- const std::int64_t value)
- {
- if ((std::numeric_limits<std::int32_t>::min)() <= value && value <= (std::numeric_limits<std::int32_t>::max)())
- {
- write_bson_entry_header(name, 0x10);
- write_number<std::int32_t, true>(static_cast<std::int32_t>(value));
- }
- else
- {
- write_bson_entry_header(name, 0x12);
- write_number<std::int64_t, true>(static_cast<std::int64_t>(value));
- }
- }
-
- static constexpr std::size_t calc_bson_unsigned_size(const std::uint64_t value) noexcept
- {
- return (value <= static_cast<std::uint64_t>((std::numeric_limits<std::int32_t>::max)()))
- ? sizeof(std::int32_t)
- : sizeof(std::int64_t);
- }
-
- void write_bson_unsigned(const string_t& name,
- const BasicJsonType& j)
- {
- if (j.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::int32_t>::max)()))
- {
- write_bson_entry_header(name, 0x10 );
- write_number<std::int32_t, true>(static_cast<std::int32_t>(j.m_value.number_unsigned));
- }
- else if (j.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::int64_t>::max)()))
- {
- write_bson_entry_header(name, 0x12 );
- write_number<std::int64_t, true>(static_cast<std::int64_t>(j.m_value.number_unsigned));
- }
- else
- {
- JSON_THROW(out_of_range::create(407, "integer number " + std::to_string(j.m_value.number_unsigned) + " cannot be represented by BSON as it does not fit int64", j));
- }
- }
-
- void write_bson_object_entry(const string_t& name,
- const typename BasicJsonType::object_t& value)
- {
- write_bson_entry_header(name, 0x03);
- write_bson_object(value);
- }
-
- static std::size_t calc_bson_array_size(const typename BasicJsonType::array_t& value)
- {
- std::size_t array_index = 0ul;
- const std::size_t embedded_document_size = std::accumulate(std::begin(value), std::end(value), std::size_t(0), [&array_index](std::size_t result, const typename BasicJsonType::array_t::value_type & el)
- {
- return result + calc_bson_element_size(std::to_string(array_index++), el);
- });
- return sizeof(std::int32_t) + embedded_document_size + 1ul;
- }
-
- static std::size_t calc_bson_binary_size(const typename BasicJsonType::binary_t& value)
- {
- return sizeof(std::int32_t) + value.size() + 1ul;
- }
-
- void write_bson_array(const string_t& name,
- const typename BasicJsonType::array_t& value)
- {
- write_bson_entry_header(name, 0x04);
- write_number<std::int32_t, true>(static_cast<std::int32_t>(calc_bson_array_size(value)));
- std::size_t array_index = 0ul;
- for (const auto& el : value)
- {
- write_bson_element(std::to_string(array_index++), el);
- }
- oa->write_character(to_char_type(0x00));
- }
-
- void write_bson_binary(const string_t& name,
- const binary_t& value)
- {
- write_bson_entry_header(name, 0x05);
- write_number<std::int32_t, true>(static_cast<std::int32_t>(value.size()));
- write_number(value.has_subtype() ? static_cast<std::uint8_t>(value.subtype()) : std::uint8_t(0x00));
- oa->write_characters(reinterpret_cast<const CharType*>(value.data()), value.size());
- }
-
- static std::size_t calc_bson_element_size(const string_t& name,
- const BasicJsonType& j)
- {
- const auto header_size = calc_bson_entry_header_size(name, j);
- switch (j.type())
- {
- case value_t::object:
- return header_size + calc_bson_object_size(*j.m_value.object);
- case value_t::array:
- return header_size + calc_bson_array_size(*j.m_value.array);
- case value_t::binary:
- return header_size + calc_bson_binary_size(*j.m_value.binary);
- case value_t::boolean:
- return header_size + 1ul;
- case value_t::number_float:
- return header_size + 8ul;
- case value_t::number_integer:
- return header_size + calc_bson_integer_size(j.m_value.number_integer);
- case value_t::number_unsigned:
- return header_size + calc_bson_unsigned_size(j.m_value.number_unsigned);
- case value_t::string:
- return header_size + calc_bson_string_size(*j.m_value.string);
- case value_t::null:
- return header_size + 0ul;
-
- case value_t::discarded:
- default:
- JSON_ASSERT(false);
- return 0ul;
-
- }
- }
-
- void write_bson_element(const string_t& name,
- const BasicJsonType& j)
- {
- switch (j.type())
- {
- case value_t::object:
- return write_bson_object_entry(name, *j.m_value.object);
- case value_t::array:
- return write_bson_array(name, *j.m_value.array);
- case value_t::binary:
- return write_bson_binary(name, *j.m_value.binary);
- case value_t::boolean:
- return write_bson_boolean(name, j.m_value.boolean);
- case value_t::number_float:
- return write_bson_double(name, j.m_value.number_float);
- case value_t::number_integer:
- return write_bson_integer(name, j.m_value.number_integer);
- case value_t::number_unsigned:
- return write_bson_unsigned(name, j);
- case value_t::string:
- return write_bson_string(name, *j.m_value.string);
- case value_t::null:
- return write_bson_null(name);
-
- case value_t::discarded:
- default:
- JSON_ASSERT(false);
- return;
-
- }
- }
-
- static std::size_t calc_bson_object_size(const typename BasicJsonType::object_t& value)
- {
- std::size_t document_size = std::accumulate(value.begin(), value.end(), std::size_t(0),
- [](size_t result, const typename BasicJsonType::object_t::value_type & el)
- {
- return result += calc_bson_element_size(el.first, el.second);
- });
- return sizeof(std::int32_t) + document_size + 1ul;
- }
-
- void write_bson_object(const typename BasicJsonType::object_t& value)
- {
- write_number<std::int32_t, true>(static_cast<std::int32_t>(calc_bson_object_size(value)));
- for (const auto& el : value)
- {
- write_bson_element(el.first, el.second);
- }
- oa->write_character(to_char_type(0x00));
- }
-
-
-
- static constexpr CharType get_cbor_float_prefix(float )
- {
- return to_char_type(0xFA);
- }
- static constexpr CharType get_cbor_float_prefix(double )
- {
- return to_char_type(0xFB);
- }
-
-
-
- static constexpr CharType get_msgpack_float_prefix(float )
- {
- return to_char_type(0xCA);
- }
- static constexpr CharType get_msgpack_float_prefix(double )
- {
- return to_char_type(0xCB);
- }
-
-
-
-
- template<typename NumberType, typename std::enable_if<
- std::is_floating_point<NumberType>::value, int>::type = 0>
- void write_number_with_ubjson_prefix(const NumberType n,
- const bool add_prefix)
- {
- if (add_prefix)
- {
- oa->write_character(get_ubjson_float_prefix(n));
- }
- write_number(n);
- }
-
- template<typename NumberType, typename std::enable_if<
- std::is_unsigned<NumberType>::value, int>::type = 0>
- void write_number_with_ubjson_prefix(const NumberType n,
- const bool add_prefix)
- {
- if (n <= static_cast<std::uint64_t>((std::numeric_limits<std::int8_t>::max)()))
- {
- if (add_prefix)
- {
- oa->write_character(to_char_type('i'));
- }
- write_number(static_cast<std::uint8_t>(n));
- }
- else if (n <= (std::numeric_limits<std::uint8_t>::max)())
- {
- if (add_prefix)
- {
- oa->write_character(to_char_type('U'));
- }
- write_number(static_cast<std::uint8_t>(n));
- }
- else if (n <= static_cast<std::uint64_t>((std::numeric_limits<std::int16_t>::max)()))
- {
- if (add_prefix)
- {
- oa->write_character(to_char_type('I'));
- }
- write_number(static_cast<std::int16_t>(n));
- }
- else if (n <= static_cast<std::uint64_t>((std::numeric_limits<std::int32_t>::max)()))
- {
- if (add_prefix)
- {
- oa->write_character(to_char_type('l'));
- }
- write_number(static_cast<std::int32_t>(n));
- }
- else if (n <= static_cast<std::uint64_t>((std::numeric_limits<std::int64_t>::max)()))
- {
- if (add_prefix)
- {
- oa->write_character(to_char_type('L'));
- }
- write_number(static_cast<std::int64_t>(n));
- }
- else
- {
- if (add_prefix)
- {
- oa->write_character(to_char_type('H'));
- }
- const auto number = BasicJsonType(n).dump();
- write_number_with_ubjson_prefix(number.size(), true);
- for (std::size_t i = 0; i < number.size(); ++i)
- {
- oa->write_character(to_char_type(static_cast<std::uint8_t>(number[i])));
- }
- }
- }
-
- template < typename NumberType, typename std::enable_if <
- std::is_signed<NumberType>::value&&
- !std::is_floating_point<NumberType>::value, int >::type = 0 >
- void write_number_with_ubjson_prefix(const NumberType n,
- const bool add_prefix)
- {
- if ((std::numeric_limits<std::int8_t>::min)() <= n && n <= (std::numeric_limits<std::int8_t>::max)())
- {
- if (add_prefix)
- {
- oa->write_character(to_char_type('i'));
- }
- write_number(static_cast<std::int8_t>(n));
- }
- else if (static_cast<std::int64_t>((std::numeric_limits<std::uint8_t>::min)()) <= n && n <= static_cast<std::int64_t>((std::numeric_limits<std::uint8_t>::max)()))
- {
- if (add_prefix)
- {
- oa->write_character(to_char_type('U'));
- }
- write_number(static_cast<std::uint8_t>(n));
- }
- else if ((std::numeric_limits<std::int16_t>::min)() <= n && n <= (std::numeric_limits<std::int16_t>::max)())
- {
- if (add_prefix)
- {
- oa->write_character(to_char_type('I'));
- }
- write_number(static_cast<std::int16_t>(n));
- }
- else if ((std::numeric_limits<std::int32_t>::min)() <= n && n <= (std::numeric_limits<std::int32_t>::max)())
- {
- if (add_prefix)
- {
- oa->write_character(to_char_type('l'));
- }
- write_number(static_cast<std::int32_t>(n));
- }
- else if ((std::numeric_limits<std::int64_t>::min)() <= n && n <= (std::numeric_limits<std::int64_t>::max)())
- {
- if (add_prefix)
- {
- oa->write_character(to_char_type('L'));
- }
- write_number(static_cast<std::int64_t>(n));
- }
-
- else
- {
- if (add_prefix)
- {
- oa->write_character(to_char_type('H'));
- }
- const auto number = BasicJsonType(n).dump();
- write_number_with_ubjson_prefix(number.size(), true);
- for (std::size_t i = 0; i < number.size(); ++i)
- {
- oa->write_character(to_char_type(static_cast<std::uint8_t>(number[i])));
- }
- }
-
- }
-
- CharType ubjson_prefix(const BasicJsonType& j) const noexcept
- {
- switch (j.type())
- {
- case value_t::null:
- return 'Z';
- case value_t::boolean:
- return j.m_value.boolean ? 'T' : 'F';
- case value_t::number_integer:
- {
- if ((std::numeric_limits<std::int8_t>::min)() <= j.m_value.number_integer && j.m_value.number_integer <= (std::numeric_limits<std::int8_t>::max)())
- {
- return 'i';
- }
- if ((std::numeric_limits<std::uint8_t>::min)() <= j.m_value.number_integer && j.m_value.number_integer <= (std::numeric_limits<std::uint8_t>::max)())
- {
- return 'U';
- }
- if ((std::numeric_limits<std::int16_t>::min)() <= j.m_value.number_integer && j.m_value.number_integer <= (std::numeric_limits<std::int16_t>::max)())
- {
- return 'I';
- }
- if ((std::numeric_limits<std::int32_t>::min)() <= j.m_value.number_integer && j.m_value.number_integer <= (std::numeric_limits<std::int32_t>::max)())
- {
- return 'l';
- }
- if ((std::numeric_limits<std::int64_t>::min)() <= j.m_value.number_integer && j.m_value.number_integer <= (std::numeric_limits<std::int64_t>::max)())
- {
- return 'L';
- }
-
- return 'H';
- }
- case value_t::number_unsigned:
- {
- if (j.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::int8_t>::max)()))
- {
- return 'i';
- }
- if (j.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::uint8_t>::max)()))
- {
- return 'U';
- }
- if (j.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::int16_t>::max)()))
- {
- return 'I';
- }
- if (j.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::int32_t>::max)()))
- {
- return 'l';
- }
- if (j.m_value.number_unsigned <= static_cast<std::uint64_t>((std::numeric_limits<std::int64_t>::max)()))
- {
- return 'L';
- }
-
- return 'H';
- }
- case value_t::number_float:
- return get_ubjson_float_prefix(j.m_value.number_float);
- case value_t::string:
- return 'S';
- case value_t::array:
- case value_t::binary:
- return '[';
- case value_t::object:
- return '{';
- case value_t::discarded:
- default:
- return 'N';
- }
- }
- static constexpr CharType get_ubjson_float_prefix(float )
- {
- return 'd';
- }
- static constexpr CharType get_ubjson_float_prefix(double )
- {
- return 'D';
- }
-
-
-
-
- template<typename NumberType, bool OutputIsLittleEndian = false>
- void write_number(const NumberType n)
- {
-
- std::array<CharType, sizeof(NumberType)> vec{};
- std::memcpy(vec.data(), &n, sizeof(NumberType));
-
- if (is_little_endian != OutputIsLittleEndian)
- {
-
- std::reverse(vec.begin(), vec.end());
- }
- oa->write_characters(vec.data(), sizeof(NumberType));
- }
- void write_compact_float(const number_float_t n, detail::input_format_t format)
- {
- #ifdef __GNUC__
- #pragma GCC diagnostic push
- #pragma GCC diagnostic ignored "-Wfloat-equal"
- #endif
- if (static_cast<double>(n) >= static_cast<double>(std::numeric_limits<float>::lowest()) &&
- static_cast<double>(n) <= static_cast<double>((std::numeric_limits<float>::max)()) &&
- static_cast<double>(static_cast<float>(n)) == static_cast<double>(n))
- {
- oa->write_character(format == detail::input_format_t::cbor
- ? get_cbor_float_prefix(static_cast<float>(n))
- : get_msgpack_float_prefix(static_cast<float>(n)));
- write_number(static_cast<float>(n));
- }
- else
- {
- oa->write_character(format == detail::input_format_t::cbor
- ? get_cbor_float_prefix(n)
- : get_msgpack_float_prefix(n));
- write_number(n);
- }
- #ifdef __GNUC__
- #pragma GCC diagnostic pop
- #endif
- }
- public:
-
-
-
-
- template < typename C = CharType,
- enable_if_t < std::is_signed<C>::value && std::is_signed<char>::value > * = nullptr >
- static constexpr CharType to_char_type(std::uint8_t x) noexcept
- {
- return *reinterpret_cast<char*>(&x);
- }
- template < typename C = CharType,
- enable_if_t < std::is_signed<C>::value && std::is_unsigned<char>::value > * = nullptr >
- static CharType to_char_type(std::uint8_t x) noexcept
- {
- static_assert(sizeof(std::uint8_t) == sizeof(CharType), "size of CharType must be equal to std::uint8_t");
- static_assert(std::is_trivial<CharType>::value, "CharType must be trivial");
- CharType result;
- std::memcpy(&result, &x, sizeof(x));
- return result;
- }
- template<typename C = CharType,
- enable_if_t<std::is_unsigned<C>::value>* = nullptr>
- static constexpr CharType to_char_type(std::uint8_t x) noexcept
- {
- return x;
- }
- template < typename InputCharType, typename C = CharType,
- enable_if_t <
- std::is_signed<C>::value &&
- std::is_signed<char>::value &&
- std::is_same<char, typename std::remove_cv<InputCharType>::type>::value
- > * = nullptr >
- static constexpr CharType to_char_type(InputCharType x) noexcept
- {
- return x;
- }
- private:
-
- const bool is_little_endian = little_endianess();
-
- output_adapter_t<CharType> oa = nullptr;
- };
- }
- }
- #include <algorithm> // reverse, remove, fill, find, none_of
- #include <array> // array
- #include <clocale> // localeconv, lconv
- #include <cmath> // labs, isfinite, isnan, signbit
- #include <cstddef> // size_t, ptrdiff_t
- #include <cstdint> // uint8_t
- #include <cstdio> // snprintf
- #include <limits> // numeric_limits
- #include <string> // string, char_traits
- #include <type_traits> // is_same
- #include <utility> // move
- #include <array> // array
- #include <cmath> // signbit, isfinite
- #include <cstdint> // intN_t, uintN_t
- #include <cstring> // memcpy, memmove
- #include <limits> // numeric_limits
- #include <type_traits> // conditional
- namespace nlohmann
- {
- namespace detail
- {
- namespace dtoa_impl
- {
- template<typename Target, typename Source>
- Target reinterpret_bits(const Source source)
- {
- static_assert(sizeof(Target) == sizeof(Source), "size mismatch");
- Target target;
- std::memcpy(&target, &source, sizeof(Source));
- return target;
- }
- struct diyfp
- {
- static constexpr int kPrecision = 64;
- std::uint64_t f = 0;
- int e = 0;
- constexpr diyfp(std::uint64_t f_, int e_) noexcept : f(f_), e(e_) {}
-
- static diyfp sub(const diyfp& x, const diyfp& y) noexcept
- {
- JSON_ASSERT(x.e == y.e);
- JSON_ASSERT(x.f >= y.f);
- return {x.f - y.f, x.e};
- }
-
- static diyfp mul(const diyfp& x, const diyfp& y) noexcept
- {
- static_assert(kPrecision == 64, "internal error");
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- const std::uint64_t u_lo = x.f & 0xFFFFFFFFu;
- const std::uint64_t u_hi = x.f >> 32u;
- const std::uint64_t v_lo = y.f & 0xFFFFFFFFu;
- const std::uint64_t v_hi = y.f >> 32u;
- const std::uint64_t p0 = u_lo * v_lo;
- const std::uint64_t p1 = u_lo * v_hi;
- const std::uint64_t p2 = u_hi * v_lo;
- const std::uint64_t p3 = u_hi * v_hi;
- const std::uint64_t p0_hi = p0 >> 32u;
- const std::uint64_t p1_lo = p1 & 0xFFFFFFFFu;
- const std::uint64_t p1_hi = p1 >> 32u;
- const std::uint64_t p2_lo = p2 & 0xFFFFFFFFu;
- const std::uint64_t p2_hi = p2 >> 32u;
- std::uint64_t Q = p0_hi + p1_lo + p2_lo;
-
-
-
-
-
-
-
-
- Q += std::uint64_t{1} << (64u - 32u - 1u);
- const std::uint64_t h = p3 + p2_hi + p1_hi + (Q >> 32u);
- return {h, x.e + y.e + 64};
- }
-
- static diyfp normalize(diyfp x) noexcept
- {
- JSON_ASSERT(x.f != 0);
- while ((x.f >> 63u) == 0)
- {
- x.f <<= 1u;
- x.e--;
- }
- return x;
- }
-
- static diyfp normalize_to(const diyfp& x, const int target_exponent) noexcept
- {
- const int delta = x.e - target_exponent;
- JSON_ASSERT(delta >= 0);
- JSON_ASSERT(((x.f << delta) >> delta) == x.f);
- return {x.f << delta, target_exponent};
- }
- };
- struct boundaries
- {
- diyfp w;
- diyfp minus;
- diyfp plus;
- };
- template<typename FloatType>
- boundaries compute_boundaries(FloatType value)
- {
- JSON_ASSERT(std::isfinite(value));
- JSON_ASSERT(value > 0);
-
-
-
-
-
-
- static_assert(std::numeric_limits<FloatType>::is_iec559,
- "internal error: dtoa_short requires an IEEE-754 floating-point implementation");
- constexpr int kPrecision = std::numeric_limits<FloatType>::digits;
- constexpr int kBias = std::numeric_limits<FloatType>::max_exponent - 1 + (kPrecision - 1);
- constexpr int kMinExp = 1 - kBias;
- constexpr std::uint64_t kHiddenBit = std::uint64_t{1} << (kPrecision - 1);
- using bits_type = typename std::conditional<kPrecision == 24, std::uint32_t, std::uint64_t >::type;
- const auto bits = static_cast<std::uint64_t>(reinterpret_bits<bits_type>(value));
- const std::uint64_t E = bits >> (kPrecision - 1);
- const std::uint64_t F = bits & (kHiddenBit - 1);
- const bool is_denormal = E == 0;
- const diyfp v = is_denormal
- ? diyfp(F, kMinExp)
- : diyfp(F + kHiddenBit, static_cast<int>(E) - kBias);
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- const bool lower_boundary_is_closer = F == 0 && E > 1;
- const diyfp m_plus = diyfp(2 * v.f + 1, v.e - 1);
- const diyfp m_minus = lower_boundary_is_closer
- ? diyfp(4 * v.f - 1, v.e - 2)
- : diyfp(2 * v.f - 1, v.e - 1);
-
- const diyfp w_plus = diyfp::normalize(m_plus);
-
- const diyfp w_minus = diyfp::normalize_to(m_minus, w_plus.e);
- return {diyfp::normalize(v), w_minus, w_plus};
- }
- constexpr int kAlpha = -60;
- constexpr int kGamma = -32;
- struct cached_power
- {
- std::uint64_t f;
- int e;
- int k;
- };
- inline cached_power get_cached_power_for_binary_exponent(int e)
- {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- constexpr int kCachedPowersMinDecExp = -300;
- constexpr int kCachedPowersDecStep = 8;
- static constexpr std::array<cached_power, 79> kCachedPowers =
- {
- {
- { 0xAB70FE17C79AC6CA, -1060, -300 },
- { 0xFF77B1FCBEBCDC4F, -1034, -292 },
- { 0xBE5691EF416BD60C, -1007, -284 },
- { 0x8DD01FAD907FFC3C, -980, -276 },
- { 0xD3515C2831559A83, -954, -268 },
- { 0x9D71AC8FADA6C9B5, -927, -260 },
- { 0xEA9C227723EE8BCB, -901, -252 },
- { 0xAECC49914078536D, -874, -244 },
- { 0x823C12795DB6CE57, -847, -236 },
- { 0xC21094364DFB5637, -821, -228 },
- { 0x9096EA6F3848984F, -794, -220 },
- { 0xD77485CB25823AC7, -768, -212 },
- { 0xA086CFCD97BF97F4, -741, -204 },
- { 0xEF340A98172AACE5, -715, -196 },
- { 0xB23867FB2A35B28E, -688, -188 },
- { 0x84C8D4DFD2C63F3B, -661, -180 },
- { 0xC5DD44271AD3CDBA, -635, -172 },
- { 0x936B9FCEBB25C996, -608, -164 },
- { 0xDBAC6C247D62A584, -582, -156 },
- { 0xA3AB66580D5FDAF6, -555, -148 },
- { 0xF3E2F893DEC3F126, -529, -140 },
- { 0xB5B5ADA8AAFF80B8, -502, -132 },
- { 0x87625F056C7C4A8B, -475, -124 },
- { 0xC9BCFF6034C13053, -449, -116 },
- { 0x964E858C91BA2655, -422, -108 },
- { 0xDFF9772470297EBD, -396, -100 },
- { 0xA6DFBD9FB8E5B88F, -369, -92 },
- { 0xF8A95FCF88747D94, -343, -84 },
- { 0xB94470938FA89BCF, -316, -76 },
- { 0x8A08F0F8BF0F156B, -289, -68 },
- { 0xCDB02555653131B6, -263, -60 },
- { 0x993FE2C6D07B7FAC, -236, -52 },
- { 0xE45C10C42A2B3B06, -210, -44 },
- { 0xAA242499697392D3, -183, -36 },
- { 0xFD87B5F28300CA0E, -157, -28 },
- { 0xBCE5086492111AEB, -130, -20 },
- { 0x8CBCCC096F5088CC, -103, -12 },
- { 0xD1B71758E219652C, -77, -4 },
- { 0x9C40000000000000, -50, 4 },
- { 0xE8D4A51000000000, -24, 12 },
- { 0xAD78EBC5AC620000, 3, 20 },
- { 0x813F3978F8940984, 30, 28 },
- { 0xC097CE7BC90715B3, 56, 36 },
- { 0x8F7E32CE7BEA5C70, 83, 44 },
- { 0xD5D238A4ABE98068, 109, 52 },
- { 0x9F4F2726179A2245, 136, 60 },
- { 0xED63A231D4C4FB27, 162, 68 },
- { 0xB0DE65388CC8ADA8, 189, 76 },
- { 0x83C7088E1AAB65DB, 216, 84 },
- { 0xC45D1DF942711D9A, 242, 92 },
- { 0x924D692CA61BE758, 269, 100 },
- { 0xDA01EE641A708DEA, 295, 108 },
- { 0xA26DA3999AEF774A, 322, 116 },
- { 0xF209787BB47D6B85, 348, 124 },
- { 0xB454E4A179DD1877, 375, 132 },
- { 0x865B86925B9BC5C2, 402, 140 },
- { 0xC83553C5C8965D3D, 428, 148 },
- { 0x952AB45CFA97A0B3, 455, 156 },
- { 0xDE469FBD99A05FE3, 481, 164 },
- { 0xA59BC234DB398C25, 508, 172 },
- { 0xF6C69A72A3989F5C, 534, 180 },
- { 0xB7DCBF5354E9BECE, 561, 188 },
- { 0x88FCF317F22241E2, 588, 196 },
- { 0xCC20CE9BD35C78A5, 614, 204 },
- { 0x98165AF37B2153DF, 641, 212 },
- { 0xE2A0B5DC971F303A, 667, 220 },
- { 0xA8D9D1535CE3B396, 694, 228 },
- { 0xFB9B7CD9A4A7443C, 720, 236 },
- { 0xBB764C4CA7A44410, 747, 244 },
- { 0x8BAB8EEFB6409C1A, 774, 252 },
- { 0xD01FEF10A657842C, 800, 260 },
- { 0x9B10A4E5E9913129, 827, 268 },
- { 0xE7109BFBA19C0C9D, 853, 276 },
- { 0xAC2820D9623BF429, 880, 284 },
- { 0x80444B5E7AA7CF85, 907, 292 },
- { 0xBF21E44003ACDD2D, 933, 300 },
- { 0x8E679C2F5E44FF8F, 960, 308 },
- { 0xD433179D9C8CB841, 986, 316 },
- { 0x9E19DB92B4E31BA9, 1013, 324 },
- }
- };
-
-
-
-
- JSON_ASSERT(e >= -1500);
- JSON_ASSERT(e <= 1500);
- const int f = kAlpha - e - 1;
- const int k = (f * 78913) / (1 << 18) + static_cast<int>(f > 0);
- const int index = (-kCachedPowersMinDecExp + k + (kCachedPowersDecStep - 1)) / kCachedPowersDecStep;
- JSON_ASSERT(index >= 0);
- JSON_ASSERT(static_cast<std::size_t>(index) < kCachedPowers.size());
- const cached_power cached = kCachedPowers[static_cast<std::size_t>(index)];
- JSON_ASSERT(kAlpha <= cached.e + e + 64);
- JSON_ASSERT(kGamma >= cached.e + e + 64);
- return cached;
- }
- inline int find_largest_pow10(const std::uint32_t n, std::uint32_t& pow10)
- {
-
- if (n >= 1000000000)
- {
- pow10 = 1000000000;
- return 10;
- }
-
- if (n >= 100000000)
- {
- pow10 = 100000000;
- return 9;
- }
- if (n >= 10000000)
- {
- pow10 = 10000000;
- return 8;
- }
- if (n >= 1000000)
- {
- pow10 = 1000000;
- return 7;
- }
- if (n >= 100000)
- {
- pow10 = 100000;
- return 6;
- }
- if (n >= 10000)
- {
- pow10 = 10000;
- return 5;
- }
- if (n >= 1000)
- {
- pow10 = 1000;
- return 4;
- }
- if (n >= 100)
- {
- pow10 = 100;
- return 3;
- }
- if (n >= 10)
- {
- pow10 = 10;
- return 2;
- }
- pow10 = 1;
- return 1;
- }
- inline void grisu2_round(char* buf, int len, std::uint64_t dist, std::uint64_t delta,
- std::uint64_t rest, std::uint64_t ten_k)
- {
- JSON_ASSERT(len >= 1);
- JSON_ASSERT(dist <= delta);
- JSON_ASSERT(rest <= delta);
- JSON_ASSERT(ten_k > 0);
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- while (rest < dist
- && delta - rest >= ten_k
- && (rest + ten_k < dist || dist - rest > rest + ten_k - dist))
- {
- JSON_ASSERT(buf[len - 1] != '0');
- buf[len - 1]--;
- rest += ten_k;
- }
- }
- inline void grisu2_digit_gen(char* buffer, int& length, int& decimal_exponent,
- diyfp M_minus, diyfp w, diyfp M_plus)
- {
- static_assert(kAlpha >= -60, "internal error");
- static_assert(kGamma <= -32, "internal error");
-
-
-
-
-
-
-
-
-
-
-
- JSON_ASSERT(M_plus.e >= kAlpha);
- JSON_ASSERT(M_plus.e <= kGamma);
- std::uint64_t delta = diyfp::sub(M_plus, M_minus).f;
- std::uint64_t dist = diyfp::sub(M_plus, w ).f;
-
-
-
-
-
-
- const diyfp one(std::uint64_t{1} << -M_plus.e, M_plus.e);
- auto p1 = static_cast<std::uint32_t>(M_plus.f >> -one.e);
- std::uint64_t p2 = M_plus.f & (one.f - 1);
-
-
-
- JSON_ASSERT(p1 > 0);
- std::uint32_t pow10{};
- const int k = find_largest_pow10(p1, pow10);
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- int n = k;
- while (n > 0)
- {
-
-
-
-
- const std::uint32_t d = p1 / pow10;
- const std::uint32_t r = p1 % pow10;
-
-
-
-
- JSON_ASSERT(d <= 9);
- buffer[length++] = static_cast<char>('0' + d);
-
-
-
- p1 = r;
- n--;
-
-
-
-
-
-
-
-
-
-
-
-
- const std::uint64_t rest = (std::uint64_t{p1} << -one.e) + p2;
- if (rest <= delta)
- {
-
- decimal_exponent += n;
-
-
-
-
-
-
-
-
-
- const std::uint64_t ten_n = std::uint64_t{pow10} << -one.e;
- grisu2_round(buffer, length, dist, delta, rest, ten_n);
- return;
- }
- pow10 /= 10;
-
-
-
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- JSON_ASSERT(p2 > delta);
- int m = 0;
- for (;;)
- {
-
-
-
-
-
-
- JSON_ASSERT(p2 <= (std::numeric_limits<std::uint64_t>::max)() / 10);
- p2 *= 10;
- const std::uint64_t d = p2 >> -one.e;
- const std::uint64_t r = p2 & (one.f - 1);
-
-
-
-
-
- JSON_ASSERT(d <= 9);
- buffer[length++] = static_cast<char>('0' + d);
-
-
-
- p2 = r;
- m++;
-
-
-
-
-
-
-
-
- delta *= 10;
- dist *= 10;
- if (p2 <= delta)
- {
- break;
- }
- }
-
- decimal_exponent -= m;
-
-
-
-
-
-
- const std::uint64_t ten_m = one.f;
- grisu2_round(buffer, length, dist, delta, p2, ten_m);
-
-
-
-
-
-
-
-
-
-
-
-
-
- }
- JSON_HEDLEY_NON_NULL(1)
- inline void grisu2(char* buf, int& len, int& decimal_exponent,
- diyfp m_minus, diyfp v, diyfp m_plus)
- {
- JSON_ASSERT(m_plus.e == m_minus.e);
- JSON_ASSERT(m_plus.e == v.e);
-
-
-
-
-
-
-
-
- const cached_power cached = get_cached_power_for_binary_exponent(m_plus.e);
- const diyfp c_minus_k(cached.f, cached.e);
-
- const diyfp w = diyfp::mul(v, c_minus_k);
- const diyfp w_minus = diyfp::mul(m_minus, c_minus_k);
- const diyfp w_plus = diyfp::mul(m_plus, c_minus_k);
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- const diyfp M_minus(w_minus.f + 1, w_minus.e);
- const diyfp M_plus (w_plus.f - 1, w_plus.e );
- decimal_exponent = -cached.k;
- grisu2_digit_gen(buf, len, decimal_exponent, M_minus, w, M_plus);
- }
- template<typename FloatType>
- JSON_HEDLEY_NON_NULL(1)
- void grisu2(char* buf, int& len, int& decimal_exponent, FloatType value)
- {
- static_assert(diyfp::kPrecision >= std::numeric_limits<FloatType>::digits + 3,
- "internal error: not enough precision");
- JSON_ASSERT(std::isfinite(value));
- JSON_ASSERT(value > 0);
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- #if 0
- const boundaries w = compute_boundaries(static_cast<double>(value));
- #else
- const boundaries w = compute_boundaries(value);
- #endif
- grisu2(buf, len, decimal_exponent, w.minus, w.w, w.plus);
- }
- JSON_HEDLEY_NON_NULL(1)
- JSON_HEDLEY_RETURNS_NON_NULL
- inline char* append_exponent(char* buf, int e)
- {
- JSON_ASSERT(e > -1000);
- JSON_ASSERT(e < 1000);
- if (e < 0)
- {
- e = -e;
- *buf++ = '-';
- }
- else
- {
- *buf++ = '+';
- }
- auto k = static_cast<std::uint32_t>(e);
- if (k < 10)
- {
-
-
- *buf++ = '0';
- *buf++ = static_cast<char>('0' + k);
- }
- else if (k < 100)
- {
- *buf++ = static_cast<char>('0' + k / 10);
- k %= 10;
- *buf++ = static_cast<char>('0' + k);
- }
- else
- {
- *buf++ = static_cast<char>('0' + k / 100);
- k %= 100;
- *buf++ = static_cast<char>('0' + k / 10);
- k %= 10;
- *buf++ = static_cast<char>('0' + k);
- }
- return buf;
- }
- JSON_HEDLEY_NON_NULL(1)
- JSON_HEDLEY_RETURNS_NON_NULL
- inline char* format_buffer(char* buf, int len, int decimal_exponent,
- int min_exp, int max_exp)
- {
- JSON_ASSERT(min_exp < 0);
- JSON_ASSERT(max_exp > 0);
- const int k = len;
- const int n = len + decimal_exponent;
-
-
-
- if (k <= n && n <= max_exp)
- {
-
-
- std::memset(buf + k, '0', static_cast<size_t>(n) - static_cast<size_t>(k));
-
- buf[n + 0] = '.';
- buf[n + 1] = '0';
- return buf + (static_cast<size_t>(n) + 2);
- }
- if (0 < n && n <= max_exp)
- {
-
-
- JSON_ASSERT(k > n);
- std::memmove(buf + (static_cast<size_t>(n) + 1), buf + n, static_cast<size_t>(k) - static_cast<size_t>(n));
- buf[n] = '.';
- return buf + (static_cast<size_t>(k) + 1U);
- }
- if (min_exp < n && n <= 0)
- {
-
-
- std::memmove(buf + (2 + static_cast<size_t>(-n)), buf, static_cast<size_t>(k));
- buf[0] = '0';
- buf[1] = '.';
- std::memset(buf + 2, '0', static_cast<size_t>(-n));
- return buf + (2U + static_cast<size_t>(-n) + static_cast<size_t>(k));
- }
- if (k == 1)
- {
-
-
- buf += 1;
- }
- else
- {
-
-
- std::memmove(buf + 2, buf + 1, static_cast<size_t>(k) - 1);
- buf[1] = '.';
- buf += 1 + static_cast<size_t>(k);
- }
- *buf++ = 'e';
- return append_exponent(buf, n - 1);
- }
- }
- template<typename FloatType>
- JSON_HEDLEY_NON_NULL(1, 2)
- JSON_HEDLEY_RETURNS_NON_NULL
- char* to_chars(char* first, const char* last, FloatType value)
- {
- static_cast<void>(last);
- JSON_ASSERT(std::isfinite(value));
-
- if (std::signbit(value))
- {
- value = -value;
- *first++ = '-';
- }
- #ifdef __GNUC__
- #pragma GCC diagnostic push
- #pragma GCC diagnostic ignored "-Wfloat-equal"
- #endif
- if (value == 0)
- {
- *first++ = '0';
-
- *first++ = '.';
- *first++ = '0';
- return first;
- }
- #ifdef __GNUC__
- #pragma GCC diagnostic pop
- #endif
- JSON_ASSERT(last - first >= std::numeric_limits<FloatType>::max_digits10);
-
-
-
-
- int len = 0;
- int decimal_exponent = 0;
- dtoa_impl::grisu2(first, len, decimal_exponent, value);
- JSON_ASSERT(len <= std::numeric_limits<FloatType>::max_digits10);
-
- constexpr int kMinExp = -4;
-
- constexpr int kMaxExp = std::numeric_limits<FloatType>::digits10;
- JSON_ASSERT(last - first >= kMaxExp + 2);
- JSON_ASSERT(last - first >= 2 + (-kMinExp - 1) + std::numeric_limits<FloatType>::max_digits10);
- JSON_ASSERT(last - first >= std::numeric_limits<FloatType>::max_digits10 + 6);
- return dtoa_impl::format_buffer(first, len, decimal_exponent, kMinExp, kMaxExp);
- }
- }
- }
- namespace nlohmann
- {
- namespace detail
- {
- enum class error_handler_t
- {
- strict,
- replace,
- ignore
- };
- template<typename BasicJsonType>
- class serializer
- {
- using string_t = typename BasicJsonType::string_t;
- using number_float_t = typename BasicJsonType::number_float_t;
- using number_integer_t = typename BasicJsonType::number_integer_t;
- using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
- using binary_char_t = typename BasicJsonType::binary_t::value_type;
- static constexpr std::uint8_t UTF8_ACCEPT = 0;
- static constexpr std::uint8_t UTF8_REJECT = 1;
- public:
-
- serializer(output_adapter_t<char> s, const char ichar,
- error_handler_t error_handler_ = error_handler_t::strict)
- : o(std::move(s))
- , loc(std::localeconv())
- , thousands_sep(loc->thousands_sep == nullptr ? '\0' : std::char_traits<char>::to_char_type(* (loc->thousands_sep)))
- , decimal_point(loc->decimal_point == nullptr ? '\0' : std::char_traits<char>::to_char_type(* (loc->decimal_point)))
- , indent_char(ichar)
- , indent_string(512, indent_char)
- , error_handler(error_handler_)
- {}
-
- serializer(const serializer&) = delete;
- serializer& operator=(const serializer&) = delete;
- serializer(serializer&&) = delete;
- serializer& operator=(serializer&&) = delete;
- ~serializer() = default;
-
- void dump(const BasicJsonType& val,
- const bool pretty_print,
- const bool ensure_ascii,
- const unsigned int indent_step,
- const unsigned int current_indent = 0)
- {
- switch (val.m_type)
- {
- case value_t::object:
- {
- if (val.m_value.object->empty())
- {
- o->write_characters("{}", 2);
- return;
- }
- if (pretty_print)
- {
- o->write_characters("{\n", 2);
-
- const auto new_indent = current_indent + indent_step;
- if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
- {
- indent_string.resize(indent_string.size() * 2, ' ');
- }
-
- auto i = val.m_value.object->cbegin();
- for (std::size_t cnt = 0; cnt < val.m_value.object->size() - 1; ++cnt, ++i)
- {
- o->write_characters(indent_string.c_str(), new_indent);
- o->write_character('\"');
- dump_escaped(i->first, ensure_ascii);
- o->write_characters("\": ", 3);
- dump(i->second, true, ensure_ascii, indent_step, new_indent);
- o->write_characters(",\n", 2);
- }
-
- JSON_ASSERT(i != val.m_value.object->cend());
- JSON_ASSERT(std::next(i) == val.m_value.object->cend());
- o->write_characters(indent_string.c_str(), new_indent);
- o->write_character('\"');
- dump_escaped(i->first, ensure_ascii);
- o->write_characters("\": ", 3);
- dump(i->second, true, ensure_ascii, indent_step, new_indent);
- o->write_character('\n');
- o->write_characters(indent_string.c_str(), current_indent);
- o->write_character('}');
- }
- else
- {
- o->write_character('{');
-
- auto i = val.m_value.object->cbegin();
- for (std::size_t cnt = 0; cnt < val.m_value.object->size() - 1; ++cnt, ++i)
- {
- o->write_character('\"');
- dump_escaped(i->first, ensure_ascii);
- o->write_characters("\":", 2);
- dump(i->second, false, ensure_ascii, indent_step, current_indent);
- o->write_character(',');
- }
-
- JSON_ASSERT(i != val.m_value.object->cend());
- JSON_ASSERT(std::next(i) == val.m_value.object->cend());
- o->write_character('\"');
- dump_escaped(i->first, ensure_ascii);
- o->write_characters("\":", 2);
- dump(i->second, false, ensure_ascii, indent_step, current_indent);
- o->write_character('}');
- }
- return;
- }
- case value_t::array:
- {
- if (val.m_value.array->empty())
- {
- o->write_characters("[]", 2);
- return;
- }
- if (pretty_print)
- {
- o->write_characters("[\n", 2);
-
- const auto new_indent = current_indent + indent_step;
- if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
- {
- indent_string.resize(indent_string.size() * 2, ' ');
- }
-
- for (auto i = val.m_value.array->cbegin();
- i != val.m_value.array->cend() - 1; ++i)
- {
- o->write_characters(indent_string.c_str(), new_indent);
- dump(*i, true, ensure_ascii, indent_step, new_indent);
- o->write_characters(",\n", 2);
- }
-
- JSON_ASSERT(!val.m_value.array->empty());
- o->write_characters(indent_string.c_str(), new_indent);
- dump(val.m_value.array->back(), true, ensure_ascii, indent_step, new_indent);
- o->write_character('\n');
- o->write_characters(indent_string.c_str(), current_indent);
- o->write_character(']');
- }
- else
- {
- o->write_character('[');
-
- for (auto i = val.m_value.array->cbegin();
- i != val.m_value.array->cend() - 1; ++i)
- {
- dump(*i, false, ensure_ascii, indent_step, current_indent);
- o->write_character(',');
- }
-
- JSON_ASSERT(!val.m_value.array->empty());
- dump(val.m_value.array->back(), false, ensure_ascii, indent_step, current_indent);
- o->write_character(']');
- }
- return;
- }
- case value_t::string:
- {
- o->write_character('\"');
- dump_escaped(*val.m_value.string, ensure_ascii);
- o->write_character('\"');
- return;
- }
- case value_t::binary:
- {
- if (pretty_print)
- {
- o->write_characters("{\n", 2);
-
- const auto new_indent = current_indent + indent_step;
- if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
- {
- indent_string.resize(indent_string.size() * 2, ' ');
- }
- o->write_characters(indent_string.c_str(), new_indent);
- o->write_characters("\"bytes\": [", 10);
- if (!val.m_value.binary->empty())
- {
- for (auto i = val.m_value.binary->cbegin();
- i != val.m_value.binary->cend() - 1; ++i)
- {
- dump_integer(*i);
- o->write_characters(", ", 2);
- }
- dump_integer(val.m_value.binary->back());
- }
- o->write_characters("],\n", 3);
- o->write_characters(indent_string.c_str(), new_indent);
- o->write_characters("\"subtype\": ", 11);
- if (val.m_value.binary->has_subtype())
- {
- dump_integer(val.m_value.binary->subtype());
- }
- else
- {
- o->write_characters("null", 4);
- }
- o->write_character('\n');
- o->write_characters(indent_string.c_str(), current_indent);
- o->write_character('}');
- }
- else
- {
- o->write_characters("{\"bytes\":[", 10);
- if (!val.m_value.binary->empty())
- {
- for (auto i = val.m_value.binary->cbegin();
- i != val.m_value.binary->cend() - 1; ++i)
- {
- dump_integer(*i);
- o->write_character(',');
- }
- dump_integer(val.m_value.binary->back());
- }
- o->write_characters("],\"subtype\":", 12);
- if (val.m_value.binary->has_subtype())
- {
- dump_integer(val.m_value.binary->subtype());
- o->write_character('}');
- }
- else
- {
- o->write_characters("null}", 5);
- }
- }
- return;
- }
- case value_t::boolean:
- {
- if (val.m_value.boolean)
- {
- o->write_characters("true", 4);
- }
- else
- {
- o->write_characters("false", 5);
- }
- return;
- }
- case value_t::number_integer:
- {
- dump_integer(val.m_value.number_integer);
- return;
- }
- case value_t::number_unsigned:
- {
- dump_integer(val.m_value.number_unsigned);
- return;
- }
- case value_t::number_float:
- {
- dump_float(val.m_value.number_float);
- return;
- }
- case value_t::discarded:
- {
- o->write_characters("<discarded>", 11);
- return;
- }
- case value_t::null:
- {
- o->write_characters("null", 4);
- return;
- }
- default:
- JSON_ASSERT(false);
- }
- }
- JSON_PRIVATE_UNLESS_TESTED:
-
- void dump_escaped(const string_t& s, const bool ensure_ascii)
- {
- std::uint32_t codepoint{};
- std::uint8_t state = UTF8_ACCEPT;
- std::size_t bytes = 0;
-
- std::size_t bytes_after_last_accept = 0;
- std::size_t undumped_chars = 0;
- for (std::size_t i = 0; i < s.size(); ++i)
- {
- const auto byte = static_cast<std::uint8_t>(s[i]);
- switch (decode(state, codepoint, byte))
- {
- case UTF8_ACCEPT:
- {
- switch (codepoint)
- {
- case 0x08:
- {
- string_buffer[bytes++] = '\\';
- string_buffer[bytes++] = 'b';
- break;
- }
- case 0x09:
- {
- string_buffer[bytes++] = '\\';
- string_buffer[bytes++] = 't';
- break;
- }
- case 0x0A:
- {
- string_buffer[bytes++] = '\\';
- string_buffer[bytes++] = 'n';
- break;
- }
- case 0x0C:
- {
- string_buffer[bytes++] = '\\';
- string_buffer[bytes++] = 'f';
- break;
- }
- case 0x0D:
- {
- string_buffer[bytes++] = '\\';
- string_buffer[bytes++] = 'r';
- break;
- }
- case 0x22:
- {
- string_buffer[bytes++] = '\\';
- string_buffer[bytes++] = '\"';
- break;
- }
- case 0x5C:
- {
- string_buffer[bytes++] = '\\';
- string_buffer[bytes++] = '\\';
- break;
- }
- default:
- {
-
-
- if ((codepoint <= 0x1F) || (ensure_ascii && (codepoint >= 0x7F)))
- {
- if (codepoint <= 0xFFFF)
- {
-
- (std::snprintf)(string_buffer.data() + bytes, 7, "\\u%04x",
- static_cast<std::uint16_t>(codepoint));
- bytes += 6;
- }
- else
- {
-
- (std::snprintf)(string_buffer.data() + bytes, 13, "\\u%04x\\u%04x",
- static_cast<std::uint16_t>(0xD7C0u + (codepoint >> 10u)),
- static_cast<std::uint16_t>(0xDC00u + (codepoint & 0x3FFu)));
- bytes += 12;
- }
- }
- else
- {
-
-
- string_buffer[bytes++] = s[i];
- }
- break;
- }
- }
-
-
-
- if (string_buffer.size() - bytes < 13)
- {
- o->write_characters(string_buffer.data(), bytes);
- bytes = 0;
- }
-
- bytes_after_last_accept = bytes;
- undumped_chars = 0;
- break;
- }
- case UTF8_REJECT:
- {
- switch (error_handler)
- {
- case error_handler_t::strict:
- {
- std::string sn(9, '\0');
-
- (std::snprintf)(&sn[0], sn.size(), "%.2X", byte);
- JSON_THROW(type_error::create(316, "invalid UTF-8 byte at index " + std::to_string(i) + ": 0x" + sn, BasicJsonType()));
- }
- case error_handler_t::ignore:
- case error_handler_t::replace:
- {
-
-
-
-
- if (undumped_chars > 0)
- {
- --i;
- }
-
-
- bytes = bytes_after_last_accept;
- if (error_handler == error_handler_t::replace)
- {
-
- if (ensure_ascii)
- {
- string_buffer[bytes++] = '\\';
- string_buffer[bytes++] = 'u';
- string_buffer[bytes++] = 'f';
- string_buffer[bytes++] = 'f';
- string_buffer[bytes++] = 'f';
- string_buffer[bytes++] = 'd';
- }
- else
- {
- string_buffer[bytes++] = detail::binary_writer<BasicJsonType, char>::to_char_type('\xEF');
- string_buffer[bytes++] = detail::binary_writer<BasicJsonType, char>::to_char_type('\xBF');
- string_buffer[bytes++] = detail::binary_writer<BasicJsonType, char>::to_char_type('\xBD');
- }
-
-
-
- if (string_buffer.size() - bytes < 13)
- {
- o->write_characters(string_buffer.data(), bytes);
- bytes = 0;
- }
- bytes_after_last_accept = bytes;
- }
- undumped_chars = 0;
-
- state = UTF8_ACCEPT;
- break;
- }
- default:
- JSON_ASSERT(false);
- }
- break;
- }
- default:
- {
- if (!ensure_ascii)
- {
-
- string_buffer[bytes++] = s[i];
- }
- ++undumped_chars;
- break;
- }
- }
- }
-
- if (JSON_HEDLEY_LIKELY(state == UTF8_ACCEPT))
- {
-
- if (bytes > 0)
- {
- o->write_characters(string_buffer.data(), bytes);
- }
- }
- else
- {
-
- switch (error_handler)
- {
- case error_handler_t::strict:
- {
- std::string sn(9, '\0');
-
- (std::snprintf)(&sn[0], sn.size(), "%.2X", static_cast<std::uint8_t>(s.back()));
- JSON_THROW(type_error::create(316, "incomplete UTF-8 string; last byte: 0x" + sn, BasicJsonType()));
- }
- case error_handler_t::ignore:
- {
-
- o->write_characters(string_buffer.data(), bytes_after_last_accept);
- break;
- }
- case error_handler_t::replace:
- {
-
- o->write_characters(string_buffer.data(), bytes_after_last_accept);
-
- if (ensure_ascii)
- {
- o->write_characters("\\ufffd", 6);
- }
- else
- {
- o->write_characters("\xEF\xBF\xBD", 3);
- }
- break;
- }
- default:
- JSON_ASSERT(false);
- }
- }
- }
- private:
-
- inline unsigned int count_digits(number_unsigned_t x) noexcept
- {
- unsigned int n_digits = 1;
- for (;;)
- {
- if (x < 10)
- {
- return n_digits;
- }
- if (x < 100)
- {
- return n_digits + 1;
- }
- if (x < 1000)
- {
- return n_digits + 2;
- }
- if (x < 10000)
- {
- return n_digits + 3;
- }
- x = x / 10000u;
- n_digits += 4;
- }
- }
-
- template < typename NumberType, detail::enable_if_t <
- std::is_integral<NumberType>::value ||
- std::is_same<NumberType, number_unsigned_t>::value ||
- std::is_same<NumberType, number_integer_t>::value ||
- std::is_same<NumberType, binary_char_t>::value,
- int > = 0 >
- void dump_integer(NumberType x)
- {
- static constexpr std::array<std::array<char, 2>, 100> digits_to_99
- {
- {
- {{'0', '0'}}, {{'0', '1'}}, {{'0', '2'}}, {{'0', '3'}}, {{'0', '4'}}, {{'0', '5'}}, {{'0', '6'}}, {{'0', '7'}}, {{'0', '8'}}, {{'0', '9'}},
- {{'1', '0'}}, {{'1', '1'}}, {{'1', '2'}}, {{'1', '3'}}, {{'1', '4'}}, {{'1', '5'}}, {{'1', '6'}}, {{'1', '7'}}, {{'1', '8'}}, {{'1', '9'}},
- {{'2', '0'}}, {{'2', '1'}}, {{'2', '2'}}, {{'2', '3'}}, {{'2', '4'}}, {{'2', '5'}}, {{'2', '6'}}, {{'2', '7'}}, {{'2', '8'}}, {{'2', '9'}},
- {{'3', '0'}}, {{'3', '1'}}, {{'3', '2'}}, {{'3', '3'}}, {{'3', '4'}}, {{'3', '5'}}, {{'3', '6'}}, {{'3', '7'}}, {{'3', '8'}}, {{'3', '9'}},
- {{'4', '0'}}, {{'4', '1'}}, {{'4', '2'}}, {{'4', '3'}}, {{'4', '4'}}, {{'4', '5'}}, {{'4', '6'}}, {{'4', '7'}}, {{'4', '8'}}, {{'4', '9'}},
- {{'5', '0'}}, {{'5', '1'}}, {{'5', '2'}}, {{'5', '3'}}, {{'5', '4'}}, {{'5', '5'}}, {{'5', '6'}}, {{'5', '7'}}, {{'5', '8'}}, {{'5', '9'}},
- {{'6', '0'}}, {{'6', '1'}}, {{'6', '2'}}, {{'6', '3'}}, {{'6', '4'}}, {{'6', '5'}}, {{'6', '6'}}, {{'6', '7'}}, {{'6', '8'}}, {{'6', '9'}},
- {{'7', '0'}}, {{'7', '1'}}, {{'7', '2'}}, {{'7', '3'}}, {{'7', '4'}}, {{'7', '5'}}, {{'7', '6'}}, {{'7', '7'}}, {{'7', '8'}}, {{'7', '9'}},
- {{'8', '0'}}, {{'8', '1'}}, {{'8', '2'}}, {{'8', '3'}}, {{'8', '4'}}, {{'8', '5'}}, {{'8', '6'}}, {{'8', '7'}}, {{'8', '8'}}, {{'8', '9'}},
- {{'9', '0'}}, {{'9', '1'}}, {{'9', '2'}}, {{'9', '3'}}, {{'9', '4'}}, {{'9', '5'}}, {{'9', '6'}}, {{'9', '7'}}, {{'9', '8'}}, {{'9', '9'}},
- }
- };
-
- if (x == 0)
- {
- o->write_character('0');
- return;
- }
-
- auto buffer_ptr = number_buffer.begin();
- const bool is_negative = std::is_signed<NumberType>::value && !(x >= 0);
- number_unsigned_t abs_value;
- unsigned int n_chars{};
- if (is_negative)
- {
- *buffer_ptr = '-';
- abs_value = remove_sign(static_cast<number_integer_t>(x));
-
- n_chars = 1 + count_digits(abs_value);
- }
- else
- {
- abs_value = static_cast<number_unsigned_t>(x);
- n_chars = count_digits(abs_value);
- }
-
- JSON_ASSERT(n_chars < number_buffer.size() - 1);
-
-
- buffer_ptr += n_chars;
-
-
- while (abs_value >= 100)
- {
- const auto digits_index = static_cast<unsigned>((abs_value % 100));
- abs_value /= 100;
- *(--buffer_ptr) = digits_to_99[digits_index][1];
- *(--buffer_ptr) = digits_to_99[digits_index][0];
- }
- if (abs_value >= 10)
- {
- const auto digits_index = static_cast<unsigned>(abs_value);
- *(--buffer_ptr) = digits_to_99[digits_index][1];
- *(--buffer_ptr) = digits_to_99[digits_index][0];
- }
- else
- {
- *(--buffer_ptr) = static_cast<char>('0' + abs_value);
- }
- o->write_characters(number_buffer.data(), n_chars);
- }
-
- void dump_float(number_float_t x)
- {
-
- if (!std::isfinite(x))
- {
- o->write_characters("null", 4);
- return;
- }
-
-
-
-
-
- static constexpr bool is_ieee_single_or_double
- = (std::numeric_limits<number_float_t>::is_iec559 && std::numeric_limits<number_float_t>::digits == 24 && std::numeric_limits<number_float_t>::max_exponent == 128) ||
- (std::numeric_limits<number_float_t>::is_iec559 && std::numeric_limits<number_float_t>::digits == 53 && std::numeric_limits<number_float_t>::max_exponent == 1024);
- dump_float(x, std::integral_constant<bool, is_ieee_single_or_double>());
- }
- void dump_float(number_float_t x, std::true_type )
- {
- auto* begin = number_buffer.data();
- auto* end = ::nlohmann::detail::to_chars(begin, begin + number_buffer.size(), x);
- o->write_characters(begin, static_cast<size_t>(end - begin));
- }
- void dump_float(number_float_t x, std::false_type )
- {
-
- static constexpr auto d = std::numeric_limits<number_float_t>::max_digits10;
-
-
- std::ptrdiff_t len = (std::snprintf)(number_buffer.data(), number_buffer.size(), "%.*g", d, x);
-
- JSON_ASSERT(len > 0);
-
- JSON_ASSERT(static_cast<std::size_t>(len) < number_buffer.size());
-
- if (thousands_sep != '\0')
- {
-
- const auto end = std::remove(number_buffer.begin(), number_buffer.begin() + len, thousands_sep);
- std::fill(end, number_buffer.end(), '\0');
- JSON_ASSERT((end - number_buffer.begin()) <= len);
- len = (end - number_buffer.begin());
- }
-
- if (decimal_point != '\0' && decimal_point != '.')
- {
-
- const auto dec_pos = std::find(number_buffer.begin(), number_buffer.end(), decimal_point);
- if (dec_pos != number_buffer.end())
- {
- *dec_pos = '.';
- }
- }
- o->write_characters(number_buffer.data(), static_cast<std::size_t>(len));
-
- const bool value_is_int_like =
- std::none_of(number_buffer.begin(), number_buffer.begin() + len + 1,
- [](char c)
- {
- return c == '.' || c == 'e';
- });
- if (value_is_int_like)
- {
- o->write_characters(".0", 2);
- }
- }
-
- static std::uint8_t decode(std::uint8_t& state, std::uint32_t& codep, const std::uint8_t byte) noexcept
- {
- static const std::array<std::uint8_t, 400> utf8d =
- {
- {
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
- 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
- 8, 8, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 0xA, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x4, 0x3, 0x3,
- 0xB, 0x6, 0x6, 0x6, 0x5, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8,
- 0x0, 0x1, 0x2, 0x3, 0x5, 0x8, 0x7, 0x1, 0x1, 0x1, 0x4, 0x6, 0x1, 0x1, 0x1, 0x1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1,
- 1, 2, 1, 1, 1, 1, 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 3, 1, 1, 1, 1, 1, 1,
- 1, 3, 1, 1, 1, 1, 1, 3, 1, 3, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
- }
- };
- JSON_ASSERT(byte < utf8d.size());
- const std::uint8_t type = utf8d[byte];
- codep = (state != UTF8_ACCEPT)
- ? (byte & 0x3fu) | (codep << 6u)
- : (0xFFu >> type) & (byte);
- std::size_t index = 256u + static_cast<size_t>(state) * 16u + static_cast<size_t>(type);
- JSON_ASSERT(index < 400);
- state = utf8d[index];
- return state;
- }
-
- number_unsigned_t remove_sign(number_unsigned_t x)
- {
- JSON_ASSERT(false);
- return x;
- }
-
- inline number_unsigned_t remove_sign(number_integer_t x) noexcept
- {
- JSON_ASSERT(x < 0 && x < (std::numeric_limits<number_integer_t>::max)());
- return static_cast<number_unsigned_t>(-(x + 1)) + 1;
- }
- private:
-
- output_adapter_t<char> o = nullptr;
-
- std::array<char, 64> number_buffer{{}};
-
- const std::lconv* loc = nullptr;
-
- const char thousands_sep = '\0';
-
- const char decimal_point = '\0';
-
- std::array<char, 512> string_buffer{{}};
-
- const char indent_char;
-
- string_t indent_string;
-
- const error_handler_t error_handler;
- };
- }
- }
- #include <functional> // less
- #include <initializer_list> // initializer_list
- #include <iterator> // input_iterator_tag, iterator_traits
- #include <memory> // allocator
- #include <stdexcept> // for out_of_range
- #include <type_traits> // enable_if, is_convertible
- #include <utility> // pair
- #include <vector> // vector
- namespace nlohmann
- {
- template <class Key, class T, class IgnoredLess = std::less<Key>,
- class Allocator = std::allocator<std::pair<const Key, T>>>
- struct ordered_map : std::vector<std::pair<const Key, T>, Allocator>
- {
- using key_type = Key;
- using mapped_type = T;
- using Container = std::vector<std::pair<const Key, T>, Allocator>;
- using typename Container::iterator;
- using typename Container::const_iterator;
- using typename Container::size_type;
- using typename Container::value_type;
-
-
- ordered_map(const Allocator& alloc = Allocator()) : Container{alloc} {}
- template <class It>
- ordered_map(It first, It last, const Allocator& alloc = Allocator())
- : Container{first, last, alloc} {}
- ordered_map(std::initializer_list<T> init, const Allocator& alloc = Allocator() )
- : Container{init, alloc} {}
- std::pair<iterator, bool> emplace(const key_type& key, T&& t)
- {
- for (auto it = this->begin(); it != this->end(); ++it)
- {
- if (it->first == key)
- {
- return {it, false};
- }
- }
- Container::emplace_back(key, t);
- return {--this->end(), true};
- }
- T& operator[](const Key& key)
- {
- return emplace(key, T{}).first->second;
- }
- const T& operator[](const Key& key) const
- {
- return at(key);
- }
- T& at(const Key& key)
- {
- for (auto it = this->begin(); it != this->end(); ++it)
- {
- if (it->first == key)
- {
- return it->second;
- }
- }
- JSON_THROW(std::out_of_range("key not found"));
- }
- const T& at(const Key& key) const
- {
- for (auto it = this->begin(); it != this->end(); ++it)
- {
- if (it->first == key)
- {
- return it->second;
- }
- }
- JSON_THROW(std::out_of_range("key not found"));
- }
- size_type erase(const Key& key)
- {
- for (auto it = this->begin(); it != this->end(); ++it)
- {
- if (it->first == key)
- {
-
- for (auto next = it; ++next != this->end(); ++it)
- {
- it->~value_type();
- new (&*it) value_type{std::move(*next)};
- }
- Container::pop_back();
- return 1;
- }
- }
- return 0;
- }
- iterator erase(iterator pos)
- {
- auto it = pos;
-
- for (auto next = it; ++next != this->end(); ++it)
- {
- it->~value_type();
- new (&*it) value_type{std::move(*next)};
- }
- Container::pop_back();
- return pos;
- }
- size_type count(const Key& key) const
- {
- for (auto it = this->begin(); it != this->end(); ++it)
- {
- if (it->first == key)
- {
- return 1;
- }
- }
- return 0;
- }
- iterator find(const Key& key)
- {
- for (auto it = this->begin(); it != this->end(); ++it)
- {
- if (it->first == key)
- {
- return it;
- }
- }
- return Container::end();
- }
- const_iterator find(const Key& key) const
- {
- for (auto it = this->begin(); it != this->end(); ++it)
- {
- if (it->first == key)
- {
- return it;
- }
- }
- return Container::end();
- }
- std::pair<iterator, bool> insert( value_type&& value )
- {
- return emplace(value.first, std::move(value.second));
- }
- std::pair<iterator, bool> insert( const value_type& value )
- {
- for (auto it = this->begin(); it != this->end(); ++it)
- {
- if (it->first == value.first)
- {
- return {it, false};
- }
- }
- Container::push_back(value);
- return {--this->end(), true};
- }
- template<typename InputIt>
- using require_input_iter = typename std::enable_if<std::is_convertible<typename std::iterator_traits<InputIt>::iterator_category,
- std::input_iterator_tag>::value>::type;
- template<typename InputIt, typename = require_input_iter<InputIt>>
- void insert(InputIt first, InputIt last)
- {
- for (auto it = first; it != last; ++it)
- {
- insert(*it);
- }
- }
- };
- }
- #if defined(JSON_HAS_CPP_17)
- #include <string_view>
- #endif
- namespace nlohmann
- {
- NLOHMANN_BASIC_JSON_TPL_DECLARATION
- class basic_json
- {
- private:
- template<detail::value_t> friend struct detail::external_constructor;
- friend ::nlohmann::json_pointer<basic_json>;
- template<typename BasicJsonType, typename InputType>
- friend class ::nlohmann::detail::parser;
- friend ::nlohmann::detail::serializer<basic_json>;
- template<typename BasicJsonType>
- friend class ::nlohmann::detail::iter_impl;
- template<typename BasicJsonType, typename CharType>
- friend class ::nlohmann::detail::binary_writer;
- template<typename BasicJsonType, typename InputType, typename SAX>
- friend class ::nlohmann::detail::binary_reader;
- template<typename BasicJsonType>
- friend class ::nlohmann::detail::json_sax_dom_parser;
- template<typename BasicJsonType>
- friend class ::nlohmann::detail::json_sax_dom_callback_parser;
- friend class ::nlohmann::detail::exception;
-
- using basic_json_t = NLOHMANN_BASIC_JSON_TPL;
- JSON_PRIVATE_UNLESS_TESTED:
-
- using lexer = ::nlohmann::detail::lexer_base<basic_json>;
- template<typename InputAdapterType>
- static ::nlohmann::detail::parser<basic_json, InputAdapterType> parser(
- InputAdapterType adapter,
- detail::parser_callback_t<basic_json>cb = nullptr,
- const bool allow_exceptions = true,
- const bool ignore_comments = false
- )
- {
- return ::nlohmann::detail::parser<basic_json, InputAdapterType>(std::move(adapter),
- std::move(cb), allow_exceptions, ignore_comments);
- }
- private:
- using primitive_iterator_t = ::nlohmann::detail::primitive_iterator_t;
- template<typename BasicJsonType>
- using internal_iterator = ::nlohmann::detail::internal_iterator<BasicJsonType>;
- template<typename BasicJsonType>
- using iter_impl = ::nlohmann::detail::iter_impl<BasicJsonType>;
- template<typename Iterator>
- using iteration_proxy = ::nlohmann::detail::iteration_proxy<Iterator>;
- template<typename Base> using json_reverse_iterator = ::nlohmann::detail::json_reverse_iterator<Base>;
- template<typename CharType>
- using output_adapter_t = ::nlohmann::detail::output_adapter_t<CharType>;
- template<typename InputType>
- using binary_reader = ::nlohmann::detail::binary_reader<basic_json, InputType>;
- template<typename CharType> using binary_writer = ::nlohmann::detail::binary_writer<basic_json, CharType>;
- JSON_PRIVATE_UNLESS_TESTED:
- using serializer = ::nlohmann::detail::serializer<basic_json>;
- public:
- using value_t = detail::value_t;
-
- using json_pointer = ::nlohmann::json_pointer<basic_json>;
- template<typename T, typename SFINAE>
- using json_serializer = JSONSerializer<T, SFINAE>;
-
- using error_handler_t = detail::error_handler_t;
-
- using cbor_tag_handler_t = detail::cbor_tag_handler_t;
-
- using initializer_list_t = std::initializer_list<detail::json_ref<basic_json>>;
- using input_format_t = detail::input_format_t;
-
- using json_sax_t = json_sax<basic_json>;
-
-
-
-
-
-
-
- using exception = detail::exception;
-
- using parse_error = detail::parse_error;
-
- using invalid_iterator = detail::invalid_iterator;
-
- using type_error = detail::type_error;
-
- using out_of_range = detail::out_of_range;
-
- using other_error = detail::other_error;
-
-
-
-
-
-
-
-
-
- using value_type = basic_json;
-
- using reference = value_type&;
-
- using const_reference = const value_type&;
-
- using difference_type = std::ptrdiff_t;
-
- using size_type = std::size_t;
-
- using allocator_type = AllocatorType<basic_json>;
-
- using pointer = typename std::allocator_traits<allocator_type>::pointer;
-
- using const_pointer = typename std::allocator_traits<allocator_type>::const_pointer;
-
- using iterator = iter_impl<basic_json>;
-
- using const_iterator = iter_impl<const basic_json>;
-
- using reverse_iterator = json_reverse_iterator<typename basic_json::iterator>;
-
- using const_reverse_iterator = json_reverse_iterator<typename basic_json::const_iterator>;
-
-
- static allocator_type get_allocator()
- {
- return allocator_type();
- }
-
- JSON_HEDLEY_WARN_UNUSED_RESULT
- static basic_json meta()
- {
- basic_json result;
- result["copyright"] = "(C) 2013-2021 Niels Lohmann";
- result["name"] = "JSON for Modern C++";
- result["url"] = "https://github.com/nlohmann/json";
- result["version"]["string"] =
- std::to_string(NLOHMANN_JSON_VERSION_MAJOR) + "." +
- std::to_string(NLOHMANN_JSON_VERSION_MINOR) + "." +
- std::to_string(NLOHMANN_JSON_VERSION_PATCH);
- result["version"]["major"] = NLOHMANN_JSON_VERSION_MAJOR;
- result["version"]["minor"] = NLOHMANN_JSON_VERSION_MINOR;
- result["version"]["patch"] = NLOHMANN_JSON_VERSION_PATCH;
- #ifdef _WIN32
- result["platform"] = "win32";
- #elif defined __linux__
- result["platform"] = "linux";
- #elif defined __APPLE__
- result["platform"] = "apple";
- #elif defined __unix__
- result["platform"] = "unix";
- #else
- result["platform"] = "unknown";
- #endif
- #if defined(__ICC) || defined(__INTEL_COMPILER)
- result["compiler"] = {{"family", "icc"}, {"version", __INTEL_COMPILER}};
- #elif defined(__clang__)
- result["compiler"] = {{"family", "clang"}, {"version", __clang_version__}};
- #elif defined(__GNUC__) || defined(__GNUG__)
- result["compiler"] = {{"family", "gcc"}, {"version", std::to_string(__GNUC__) + "." + std::to_string(__GNUC_MINOR__) + "." + std::to_string(__GNUC_PATCHLEVEL__)}};
- #elif defined(__HP_cc) || defined(__HP_aCC)
- result["compiler"] = "hp"
- #elif defined(__IBMCPP__)
- result["compiler"] = {{"family", "ilecpp"}, {"version", __IBMCPP__}};
- #elif defined(_MSC_VER)
- result["compiler"] = {{"family", "msvc"}, {"version", _MSC_VER}};
- #elif defined(__PGI)
- result["compiler"] = {{"family", "pgcpp"}, {"version", __PGI}};
- #elif defined(__SUNPRO_CC)
- result["compiler"] = {{"family", "sunpro"}, {"version", __SUNPRO_CC}};
- #else
- result["compiler"] = {{"family", "unknown"}, {"version", "unknown"}};
- #endif
- #ifdef __cplusplus
- result["compiler"]["c++"] = std::to_string(__cplusplus);
- #else
- result["compiler"]["c++"] = "unknown";
- #endif
- return result;
- }
-
-
-
-
-
-
-
- #if defined(JSON_HAS_CPP_14)
-
-
- using object_comparator_t = std::less<>;
- #else
- using object_comparator_t = std::less<StringType>;
- #endif
-
- using object_t = ObjectType<StringType,
- basic_json,
- object_comparator_t,
- AllocatorType<std::pair<const StringType,
- basic_json>>>;
-
- using array_t = ArrayType<basic_json, AllocatorType<basic_json>>;
-
- using string_t = StringType;
-
- using boolean_t = BooleanType;
-
- using number_integer_t = NumberIntegerType;
-
- using number_unsigned_t = NumberUnsignedType;
-
- using number_float_t = NumberFloatType;
-
- using binary_t = nlohmann::byte_container_with_subtype<BinaryType>;
-
- private:
-
- template<typename T, typename... Args>
- JSON_HEDLEY_RETURNS_NON_NULL
- static T* create(Args&& ... args)
- {
- AllocatorType<T> alloc;
- using AllocatorTraits = std::allocator_traits<AllocatorType<T>>;
- auto deleter = [&](T * obj)
- {
- AllocatorTraits::deallocate(alloc, obj, 1);
- };
- std::unique_ptr<T, decltype(deleter)> obj(AllocatorTraits::allocate(alloc, 1), deleter);
- AllocatorTraits::construct(alloc, obj.get(), std::forward<Args>(args)...);
- JSON_ASSERT(obj != nullptr);
- return obj.release();
- }
-
-
-
- JSON_PRIVATE_UNLESS_TESTED:
-
- union json_value
- {
-
- object_t* object;
-
- array_t* array;
-
- string_t* string;
-
- binary_t* binary;
-
- boolean_t boolean;
-
- number_integer_t number_integer;
-
- number_unsigned_t number_unsigned;
-
- number_float_t number_float;
-
- json_value() = default;
-
- json_value(boolean_t v) noexcept : boolean(v) {}
-
- json_value(number_integer_t v) noexcept : number_integer(v) {}
-
- json_value(number_unsigned_t v) noexcept : number_unsigned(v) {}
-
- json_value(number_float_t v) noexcept : number_float(v) {}
-
- json_value(value_t t)
- {
- switch (t)
- {
- case value_t::object:
- {
- object = create<object_t>();
- break;
- }
- case value_t::array:
- {
- array = create<array_t>();
- break;
- }
- case value_t::string:
- {
- string = create<string_t>("");
- break;
- }
- case value_t::binary:
- {
- binary = create<binary_t>();
- break;
- }
- case value_t::boolean:
- {
- boolean = boolean_t(false);
- break;
- }
- case value_t::number_integer:
- {
- number_integer = number_integer_t(0);
- break;
- }
- case value_t::number_unsigned:
- {
- number_unsigned = number_unsigned_t(0);
- break;
- }
- case value_t::number_float:
- {
- number_float = number_float_t(0.0);
- break;
- }
- case value_t::null:
- {
- object = nullptr;
- break;
- }
- case value_t::discarded:
- default:
- {
- object = nullptr;
- if (JSON_HEDLEY_UNLIKELY(t == value_t::null))
- {
- JSON_THROW(other_error::create(500, "961c151d2e87f2686a955a9be24d316f1362bf21 3.10.4", basic_json()));
- }
- break;
- }
- }
- }
-
- json_value(const string_t& value)
- {
- string = create<string_t>(value);
- }
-
- json_value(string_t&& value)
- {
- string = create<string_t>(std::move(value));
- }
-
- json_value(const object_t& value)
- {
- object = create<object_t>(value);
- }
-
- json_value(object_t&& value)
- {
- object = create<object_t>(std::move(value));
- }
-
- json_value(const array_t& value)
- {
- array = create<array_t>(value);
- }
-
- json_value(array_t&& value)
- {
- array = create<array_t>(std::move(value));
- }
-
- json_value(const typename binary_t::container_type& value)
- {
- binary = create<binary_t>(value);
- }
-
- json_value(typename binary_t::container_type&& value)
- {
- binary = create<binary_t>(std::move(value));
- }
-
- json_value(const binary_t& value)
- {
- binary = create<binary_t>(value);
- }
-
- json_value(binary_t&& value)
- {
- binary = create<binary_t>(std::move(value));
- }
- void destroy(value_t t)
- {
- if (t == value_t::array || t == value_t::object)
- {
-
- std::vector<basic_json> stack;
-
- if (t == value_t::array)
- {
- stack.reserve(array->size());
- std::move(array->begin(), array->end(), std::back_inserter(stack));
- }
- else
- {
- stack.reserve(object->size());
- for (auto&& it : *object)
- {
- stack.push_back(std::move(it.second));
- }
- }
- while (!stack.empty())
- {
-
- basic_json current_item(std::move(stack.back()));
- stack.pop_back();
-
-
- if (current_item.is_array())
- {
- std::move(current_item.m_value.array->begin(), current_item.m_value.array->end(), std::back_inserter(stack));
- current_item.m_value.array->clear();
- }
- else if (current_item.is_object())
- {
- for (auto&& it : *current_item.m_value.object)
- {
- stack.push_back(std::move(it.second));
- }
- current_item.m_value.object->clear();
- }
-
-
- }
- }
- switch (t)
- {
- case value_t::object:
- {
- AllocatorType<object_t> alloc;
- std::allocator_traits<decltype(alloc)>::destroy(alloc, object);
- std::allocator_traits<decltype(alloc)>::deallocate(alloc, object, 1);
- break;
- }
- case value_t::array:
- {
- AllocatorType<array_t> alloc;
- std::allocator_traits<decltype(alloc)>::destroy(alloc, array);
- std::allocator_traits<decltype(alloc)>::deallocate(alloc, array, 1);
- break;
- }
- case value_t::string:
- {
- AllocatorType<string_t> alloc;
- std::allocator_traits<decltype(alloc)>::destroy(alloc, string);
- std::allocator_traits<decltype(alloc)>::deallocate(alloc, string, 1);
- break;
- }
- case value_t::binary:
- {
- AllocatorType<binary_t> alloc;
- std::allocator_traits<decltype(alloc)>::destroy(alloc, binary);
- std::allocator_traits<decltype(alloc)>::deallocate(alloc, binary, 1);
- break;
- }
- case value_t::null:
- case value_t::boolean:
- case value_t::number_integer:
- case value_t::number_unsigned:
- case value_t::number_float:
- case value_t::discarded:
- default:
- {
- break;
- }
- }
- }
- };
- private:
-
- void assert_invariant(bool check_parents = true) const noexcept
- {
- JSON_ASSERT(m_type != value_t::object || m_value.object != nullptr);
- JSON_ASSERT(m_type != value_t::array || m_value.array != nullptr);
- JSON_ASSERT(m_type != value_t::string || m_value.string != nullptr);
- JSON_ASSERT(m_type != value_t::binary || m_value.binary != nullptr);
- #if JSON_DIAGNOSTICS
- JSON_TRY
- {
-
- JSON_ASSERT(!check_parents || !is_structured() || std::all_of(begin(), end(), [this](const basic_json & j)
- {
- return j.m_parent == this;
- }));
- }
- JSON_CATCH(...) {}
- #endif
- static_cast<void>(check_parents);
- }
- void set_parents()
- {
- #if JSON_DIAGNOSTICS
- switch (m_type)
- {
- case value_t::array:
- {
- for (auto& element : *m_value.array)
- {
- element.m_parent = this;
- }
- break;
- }
- case value_t::object:
- {
- for (auto& element : *m_value.object)
- {
- element.second.m_parent = this;
- }
- break;
- }
- case value_t::null:
- case value_t::string:
- case value_t::boolean:
- case value_t::number_integer:
- case value_t::number_unsigned:
- case value_t::number_float:
- case value_t::binary:
- case value_t::discarded:
- default:
- break;
- }
- #endif
- }
- iterator set_parents(iterator it, typename iterator::difference_type count)
- {
- #if JSON_DIAGNOSTICS
- for (typename iterator::difference_type i = 0; i < count; ++i)
- {
- (it + i)->m_parent = this;
- }
- #else
- static_cast<void>(count);
- #endif
- return it;
- }
- reference set_parent(reference j, std::size_t old_capacity = std::size_t(-1))
- {
- #if JSON_DIAGNOSTICS
- if (old_capacity != std::size_t(-1))
- {
-
- JSON_ASSERT(type() == value_t::array);
- if (JSON_HEDLEY_UNLIKELY(m_value.array->capacity() != old_capacity))
- {
-
- set_parents();
- return j;
- }
- }
-
-
- #ifdef JSON_HEDLEY_MSVC_VERSION
- #pragma warning(push )
- #pragma warning(disable : 4127)
- #endif
- if (detail::is_ordered_map<object_t>::value)
- {
- set_parents();
- return j;
- }
- #ifdef JSON_HEDLEY_MSVC_VERSION
- #pragma warning( pop )
- #endif
- j.m_parent = this;
- #else
- static_cast<void>(j);
- static_cast<void>(old_capacity);
- #endif
- return j;
- }
- public:
-
-
-
-
- using parse_event_t = detail::parse_event_t;
-
- using parser_callback_t = detail::parser_callback_t<basic_json>;
-
-
-
-
-
-
-
-
- basic_json(const value_t v)
- : m_type(v), m_value(v)
- {
- assert_invariant();
- }
-
- basic_json(std::nullptr_t = nullptr) noexcept
- : basic_json(value_t::null)
- {
- assert_invariant();
- }
-
- template < typename CompatibleType,
- typename U = detail::uncvref_t<CompatibleType>,
- detail::enable_if_t <
- !detail::is_basic_json<U>::value && detail::is_compatible_type<basic_json_t, U>::value, int > = 0 >
- basic_json(CompatibleType && val) noexcept(noexcept(
- JSONSerializer<U>::to_json(std::declval<basic_json_t&>(),
- std::forward<CompatibleType>(val))))
- {
- JSONSerializer<U>::to_json(*this, std::forward<CompatibleType>(val));
- set_parents();
- assert_invariant();
- }
-
- template < typename BasicJsonType,
- detail::enable_if_t <
- detail::is_basic_json<BasicJsonType>::value&& !std::is_same<basic_json, BasicJsonType>::value, int > = 0 >
- basic_json(const BasicJsonType& val)
- {
- using other_boolean_t = typename BasicJsonType::boolean_t;
- using other_number_float_t = typename BasicJsonType::number_float_t;
- using other_number_integer_t = typename BasicJsonType::number_integer_t;
- using other_number_unsigned_t = typename BasicJsonType::number_unsigned_t;
- using other_string_t = typename BasicJsonType::string_t;
- using other_object_t = typename BasicJsonType::object_t;
- using other_array_t = typename BasicJsonType::array_t;
- using other_binary_t = typename BasicJsonType::binary_t;
- switch (val.type())
- {
- case value_t::boolean:
- JSONSerializer<other_boolean_t>::to_json(*this, val.template get<other_boolean_t>());
- break;
- case value_t::number_float:
- JSONSerializer<other_number_float_t>::to_json(*this, val.template get<other_number_float_t>());
- break;
- case value_t::number_integer:
- JSONSerializer<other_number_integer_t>::to_json(*this, val.template get<other_number_integer_t>());
- break;
- case value_t::number_unsigned:
- JSONSerializer<other_number_unsigned_t>::to_json(*this, val.template get<other_number_unsigned_t>());
- break;
- case value_t::string:
- JSONSerializer<other_string_t>::to_json(*this, val.template get_ref<const other_string_t&>());
- break;
- case value_t::object:
- JSONSerializer<other_object_t>::to_json(*this, val.template get_ref<const other_object_t&>());
- break;
- case value_t::array:
- JSONSerializer<other_array_t>::to_json(*this, val.template get_ref<const other_array_t&>());
- break;
- case value_t::binary:
- JSONSerializer<other_binary_t>::to_json(*this, val.template get_ref<const other_binary_t&>());
- break;
- case value_t::null:
- *this = nullptr;
- break;
- case value_t::discarded:
- m_type = value_t::discarded;
- break;
- default:
- JSON_ASSERT(false);
- }
- set_parents();
- assert_invariant();
- }
-
- basic_json(initializer_list_t init,
- bool type_deduction = true,
- value_t manual_type = value_t::array)
- {
-
-
- bool is_an_object = std::all_of(init.begin(), init.end(),
- [](const detail::json_ref<basic_json>& element_ref)
- {
- return element_ref->is_array() && element_ref->size() == 2 && (*element_ref)[0].is_string();
- });
-
- if (!type_deduction)
- {
-
- if (manual_type == value_t::array)
- {
- is_an_object = false;
- }
-
- if (JSON_HEDLEY_UNLIKELY(manual_type == value_t::object && !is_an_object))
- {
- JSON_THROW(type_error::create(301, "cannot create object from initializer list", basic_json()));
- }
- }
- if (is_an_object)
- {
-
- m_type = value_t::object;
- m_value = value_t::object;
- for (auto& element_ref : init)
- {
- auto element = element_ref.moved_or_copied();
- m_value.object->emplace(
- std::move(*((*element.m_value.array)[0].m_value.string)),
- std::move((*element.m_value.array)[1]));
- }
- }
- else
- {
-
- m_type = value_t::array;
- m_value.array = create<array_t>(init.begin(), init.end());
- }
- set_parents();
- assert_invariant();
- }
-
- JSON_HEDLEY_WARN_UNUSED_RESULT
- static basic_json binary(const typename binary_t::container_type& init)
- {
- auto res = basic_json();
- res.m_type = value_t::binary;
- res.m_value = init;
- return res;
- }
-
- JSON_HEDLEY_WARN_UNUSED_RESULT
- static basic_json binary(const typename binary_t::container_type& init, typename binary_t::subtype_type subtype)
- {
- auto res = basic_json();
- res.m_type = value_t::binary;
- res.m_value = binary_t(init, subtype);
- return res;
- }
-
- JSON_HEDLEY_WARN_UNUSED_RESULT
- static basic_json binary(typename binary_t::container_type&& init)
- {
- auto res = basic_json();
- res.m_type = value_t::binary;
- res.m_value = std::move(init);
- return res;
- }
-
- JSON_HEDLEY_WARN_UNUSED_RESULT
- static basic_json binary(typename binary_t::container_type&& init, typename binary_t::subtype_type subtype)
- {
- auto res = basic_json();
- res.m_type = value_t::binary;
- res.m_value = binary_t(std::move(init), subtype);
- return res;
- }
-
- JSON_HEDLEY_WARN_UNUSED_RESULT
- static basic_json array(initializer_list_t init = {})
- {
- return basic_json(init, false, value_t::array);
- }
-
- JSON_HEDLEY_WARN_UNUSED_RESULT
- static basic_json object(initializer_list_t init = {})
- {
- return basic_json(init, false, value_t::object);
- }
-
- basic_json(size_type cnt, const basic_json& val)
- : m_type(value_t::array)
- {
- m_value.array = create<array_t>(cnt, val);
- set_parents();
- assert_invariant();
- }
-
- template < class InputIT, typename std::enable_if <
- std::is_same<InputIT, typename basic_json_t::iterator>::value ||
- std::is_same<InputIT, typename basic_json_t::const_iterator>::value, int >::type = 0 >
- basic_json(InputIT first, InputIT last)
- {
- JSON_ASSERT(first.m_object != nullptr);
- JSON_ASSERT(last.m_object != nullptr);
-
- if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
- {
- JSON_THROW(invalid_iterator::create(201, "iterators are not compatible", basic_json()));
- }
-
- m_type = first.m_object->m_type;
-
- switch (m_type)
- {
- case value_t::boolean:
- case value_t::number_float:
- case value_t::number_integer:
- case value_t::number_unsigned:
- case value_t::string:
- {
- if (JSON_HEDLEY_UNLIKELY(!first.m_it.primitive_iterator.is_begin()
- || !last.m_it.primitive_iterator.is_end()))
- {
- JSON_THROW(invalid_iterator::create(204, "iterators out of range", *first.m_object));
- }
- break;
- }
- case value_t::null:
- case value_t::object:
- case value_t::array:
- case value_t::binary:
- case value_t::discarded:
- default:
- break;
- }
- switch (m_type)
- {
- case value_t::number_integer:
- {
- m_value.number_integer = first.m_object->m_value.number_integer;
- break;
- }
- case value_t::number_unsigned:
- {
- m_value.number_unsigned = first.m_object->m_value.number_unsigned;
- break;
- }
- case value_t::number_float:
- {
- m_value.number_float = first.m_object->m_value.number_float;
- break;
- }
- case value_t::boolean:
- {
- m_value.boolean = first.m_object->m_value.boolean;
- break;
- }
- case value_t::string:
- {
- m_value = *first.m_object->m_value.string;
- break;
- }
- case value_t::object:
- {
- m_value.object = create<object_t>(first.m_it.object_iterator,
- last.m_it.object_iterator);
- break;
- }
- case value_t::array:
- {
- m_value.array = create<array_t>(first.m_it.array_iterator,
- last.m_it.array_iterator);
- break;
- }
- case value_t::binary:
- {
- m_value = *first.m_object->m_value.binary;
- break;
- }
- case value_t::null:
- case value_t::discarded:
- default:
- JSON_THROW(invalid_iterator::create(206, "cannot construct with iterators from " + std::string(first.m_object->type_name()), *first.m_object));
- }
- set_parents();
- assert_invariant();
- }
-
-
-
- template<typename JsonRef,
- detail::enable_if_t<detail::conjunction<detail::is_json_ref<JsonRef>,
- std::is_same<typename JsonRef::value_type, basic_json>>::value, int> = 0 >
- basic_json(const JsonRef& ref) : basic_json(ref.moved_or_copied()) {}
-
- basic_json(const basic_json& other)
- : m_type(other.m_type)
- {
-
- other.assert_invariant();
- switch (m_type)
- {
- case value_t::object:
- {
- m_value = *other.m_value.object;
- break;
- }
- case value_t::array:
- {
- m_value = *other.m_value.array;
- break;
- }
- case value_t::string:
- {
- m_value = *other.m_value.string;
- break;
- }
- case value_t::boolean:
- {
- m_value = other.m_value.boolean;
- break;
- }
- case value_t::number_integer:
- {
- m_value = other.m_value.number_integer;
- break;
- }
- case value_t::number_unsigned:
- {
- m_value = other.m_value.number_unsigned;
- break;
- }
- case value_t::number_float:
- {
- m_value = other.m_value.number_float;
- break;
- }
- case value_t::binary:
- {
- m_value = *other.m_value.binary;
- break;
- }
- case value_t::null:
- case value_t::discarded:
- default:
- break;
- }
- set_parents();
- assert_invariant();
- }
-
- basic_json(basic_json&& other) noexcept
- : m_type(std::move(other.m_type)),
- m_value(std::move(other.m_value))
- {
-
- other.assert_invariant(false);
-
- other.m_type = value_t::null;
- other.m_value = {};
- set_parents();
- assert_invariant();
- }
-
- basic_json& operator=(basic_json other) noexcept (
- std::is_nothrow_move_constructible<value_t>::value&&
- std::is_nothrow_move_assignable<value_t>::value&&
- std::is_nothrow_move_constructible<json_value>::value&&
- std::is_nothrow_move_assignable<json_value>::value
- )
- {
-
- other.assert_invariant();
- using std::swap;
- swap(m_type, other.m_type);
- swap(m_value, other.m_value);
- set_parents();
- assert_invariant();
- return *this;
- }
-
- ~basic_json() noexcept
- {
- assert_invariant(false);
- m_value.destroy(m_type);
- }
-
- public:
-
-
-
-
-
-
-
- string_t dump(const int indent = -1,
- const char indent_char = ' ',
- const bool ensure_ascii = false,
- const error_handler_t error_handler = error_handler_t::strict) const
- {
- string_t result;
- serializer s(detail::output_adapter<char, string_t>(result), indent_char, error_handler);
- if (indent >= 0)
- {
- s.dump(*this, true, ensure_ascii, static_cast<unsigned int>(indent));
- }
- else
- {
- s.dump(*this, false, ensure_ascii, 0);
- }
- return result;
- }
-
- constexpr value_t type() const noexcept
- {
- return m_type;
- }
-
- constexpr bool is_primitive() const noexcept
- {
- return is_null() || is_string() || is_boolean() || is_number() || is_binary();
- }
-
- constexpr bool is_structured() const noexcept
- {
- return is_array() || is_object();
- }
-
- constexpr bool is_null() const noexcept
- {
- return m_type == value_t::null;
- }
-
- constexpr bool is_boolean() const noexcept
- {
- return m_type == value_t::boolean;
- }
-
- constexpr bool is_number() const noexcept
- {
- return is_number_integer() || is_number_float();
- }
-
- constexpr bool is_number_integer() const noexcept
- {
- return m_type == value_t::number_integer || m_type == value_t::number_unsigned;
- }
-
- constexpr bool is_number_unsigned() const noexcept
- {
- return m_type == value_t::number_unsigned;
- }
-
- constexpr bool is_number_float() const noexcept
- {
- return m_type == value_t::number_float;
- }
-
- constexpr bool is_object() const noexcept
- {
- return m_type == value_t::object;
- }
-
- constexpr bool is_array() const noexcept
- {
- return m_type == value_t::array;
- }
-
- constexpr bool is_string() const noexcept
- {
- return m_type == value_t::string;
- }
-
- constexpr bool is_binary() const noexcept
- {
- return m_type == value_t::binary;
- }
-
- constexpr bool is_discarded() const noexcept
- {
- return m_type == value_t::discarded;
- }
-
- constexpr operator value_t() const noexcept
- {
- return m_type;
- }
-
- private:
-
-
-
-
- boolean_t get_impl(boolean_t* ) const
- {
- if (JSON_HEDLEY_LIKELY(is_boolean()))
- {
- return m_value.boolean;
- }
- JSON_THROW(type_error::create(302, "type must be boolean, but is " + std::string(type_name()), *this));
- }
-
- object_t* get_impl_ptr(object_t* ) noexcept
- {
- return is_object() ? m_value.object : nullptr;
- }
-
- constexpr const object_t* get_impl_ptr(const object_t* ) const noexcept
- {
- return is_object() ? m_value.object : nullptr;
- }
-
- array_t* get_impl_ptr(array_t* ) noexcept
- {
- return is_array() ? m_value.array : nullptr;
- }
-
- constexpr const array_t* get_impl_ptr(const array_t* ) const noexcept
- {
- return is_array() ? m_value.array : nullptr;
- }
-
- string_t* get_impl_ptr(string_t* ) noexcept
- {
- return is_string() ? m_value.string : nullptr;
- }
-
- constexpr const string_t* get_impl_ptr(const string_t* ) const noexcept
- {
- return is_string() ? m_value.string : nullptr;
- }
-
- boolean_t* get_impl_ptr(boolean_t* ) noexcept
- {
- return is_boolean() ? &m_value.boolean : nullptr;
- }
-
- constexpr const boolean_t* get_impl_ptr(const boolean_t* ) const noexcept
- {
- return is_boolean() ? &m_value.boolean : nullptr;
- }
-
- number_integer_t* get_impl_ptr(number_integer_t* ) noexcept
- {
- return is_number_integer() ? &m_value.number_integer : nullptr;
- }
-
- constexpr const number_integer_t* get_impl_ptr(const number_integer_t* ) const noexcept
- {
- return is_number_integer() ? &m_value.number_integer : nullptr;
- }
-
- number_unsigned_t* get_impl_ptr(number_unsigned_t* ) noexcept
- {
- return is_number_unsigned() ? &m_value.number_unsigned : nullptr;
- }
-
- constexpr const number_unsigned_t* get_impl_ptr(const number_unsigned_t* ) const noexcept
- {
- return is_number_unsigned() ? &m_value.number_unsigned : nullptr;
- }
-
- number_float_t* get_impl_ptr(number_float_t* ) noexcept
- {
- return is_number_float() ? &m_value.number_float : nullptr;
- }
-
- constexpr const number_float_t* get_impl_ptr(const number_float_t* ) const noexcept
- {
- return is_number_float() ? &m_value.number_float : nullptr;
- }
-
- binary_t* get_impl_ptr(binary_t* ) noexcept
- {
- return is_binary() ? m_value.binary : nullptr;
- }
-
- constexpr const binary_t* get_impl_ptr(const binary_t* ) const noexcept
- {
- return is_binary() ? m_value.binary : nullptr;
- }
-
- template<typename ReferenceType, typename ThisType>
- static ReferenceType get_ref_impl(ThisType& obj)
- {
-
- auto* ptr = obj.template get_ptr<typename std::add_pointer<ReferenceType>::type>();
- if (JSON_HEDLEY_LIKELY(ptr != nullptr))
- {
- return *ptr;
- }
- JSON_THROW(type_error::create(303, "incompatible ReferenceType for get_ref, actual type is " + std::string(obj.type_name()), obj));
- }
- public:
-
-
-
-
- template<typename PointerType, typename std::enable_if<
- std::is_pointer<PointerType>::value, int>::type = 0>
- auto get_ptr() noexcept -> decltype(std::declval<basic_json_t&>().get_impl_ptr(std::declval<PointerType>()))
- {
-
- return get_impl_ptr(static_cast<PointerType>(nullptr));
- }
-
- template < typename PointerType, typename std::enable_if <
- std::is_pointer<PointerType>::value&&
- std::is_const<typename std::remove_pointer<PointerType>::type>::value, int >::type = 0 >
- constexpr auto get_ptr() const noexcept -> decltype(std::declval<const basic_json_t&>().get_impl_ptr(std::declval<PointerType>()))
- {
-
- return get_impl_ptr(static_cast<PointerType>(nullptr));
- }
- private:
-
- template < typename ValueType,
- detail::enable_if_t <
- detail::is_default_constructible<ValueType>::value&&
- detail::has_from_json<basic_json_t, ValueType>::value,
- int > = 0 >
- ValueType get_impl(detail::priority_tag<0> ) const noexcept(noexcept(
- JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>(), std::declval<ValueType&>())))
- {
- auto ret = ValueType();
- JSONSerializer<ValueType>::from_json(*this, ret);
- return ret;
- }
-
- template < typename ValueType,
- detail::enable_if_t <
- detail::has_non_default_from_json<basic_json_t, ValueType>::value,
- int > = 0 >
- ValueType get_impl(detail::priority_tag<1> ) const noexcept(noexcept(
- JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>())))
- {
- return JSONSerializer<ValueType>::from_json(*this);
- }
-
- template < typename BasicJsonType,
- detail::enable_if_t <
- detail::is_basic_json<BasicJsonType>::value,
- int > = 0 >
- BasicJsonType get_impl(detail::priority_tag<2> ) const
- {
- return *this;
- }
-
- template<typename BasicJsonType,
- detail::enable_if_t<
- std::is_same<BasicJsonType, basic_json_t>::value,
- int> = 0>
- basic_json get_impl(detail::priority_tag<3> ) const
- {
- return *this;
- }
-
- template<typename PointerType,
- detail::enable_if_t<
- std::is_pointer<PointerType>::value,
- int> = 0>
- constexpr auto get_impl(detail::priority_tag<4> ) const noexcept
- -> decltype(std::declval<const basic_json_t&>().template get_ptr<PointerType>())
- {
-
- return get_ptr<PointerType>();
- }
- public:
-
- template < typename ValueTypeCV, typename ValueType = detail::uncvref_t<ValueTypeCV>>
- #if defined(JSON_HAS_CPP_14)
- constexpr
- #endif
- auto get() const noexcept(
- noexcept(std::declval<const basic_json_t&>().template get_impl<ValueType>(detail::priority_tag<4> {})))
- -> decltype(std::declval<const basic_json_t&>().template get_impl<ValueType>(detail::priority_tag<4> {}))
- {
-
-
-
- static_assert(!std::is_reference<ValueTypeCV>::value,
- "get() cannot be used with reference types, you might want to use get_ref()");
- return get_impl<ValueType>(detail::priority_tag<4> {});
- }
-
- template<typename PointerType, typename std::enable_if<
- std::is_pointer<PointerType>::value, int>::type = 0>
- auto get() noexcept -> decltype(std::declval<basic_json_t&>().template get_ptr<PointerType>())
- {
-
- return get_ptr<PointerType>();
- }
-
- template < typename ValueType,
- detail::enable_if_t <
- !detail::is_basic_json<ValueType>::value&&
- detail::has_from_json<basic_json_t, ValueType>::value,
- int > = 0 >
- ValueType & get_to(ValueType& v) const noexcept(noexcept(
- JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>(), v)))
- {
- JSONSerializer<ValueType>::from_json(*this, v);
- return v;
- }
-
-
- template<typename ValueType,
- detail::enable_if_t <
- detail::is_basic_json<ValueType>::value,
- int> = 0>
- ValueType & get_to(ValueType& v) const
- {
- v = *this;
- return v;
- }
- template <
- typename T, std::size_t N,
- typename Array = T (&)[N],
- detail::enable_if_t <
- detail::has_from_json<basic_json_t, Array>::value, int > = 0 >
- Array get_to(T (&v)[N]) const
- noexcept(noexcept(JSONSerializer<Array>::from_json(
- std::declval<const basic_json_t&>(), v)))
- {
- JSONSerializer<Array>::from_json(*this, v);
- return v;
- }
-
- template<typename ReferenceType, typename std::enable_if<
- std::is_reference<ReferenceType>::value, int>::type = 0>
- ReferenceType get_ref()
- {
-
- return get_ref_impl<ReferenceType>(*this);
- }
-
- template < typename ReferenceType, typename std::enable_if <
- std::is_reference<ReferenceType>::value&&
- std::is_const<typename std::remove_reference<ReferenceType>::type>::value, int >::type = 0 >
- ReferenceType get_ref() const
- {
-
- return get_ref_impl<ReferenceType>(*this);
- }
-
- template < typename ValueType, typename std::enable_if <
- detail::conjunction <
- detail::negation<std::is_pointer<ValueType>>,
- detail::negation<std::is_same<ValueType, detail::json_ref<basic_json>>>,
- detail::negation<std::is_same<ValueType, typename string_t::value_type>>,
- detail::negation<detail::is_basic_json<ValueType>>,
- detail::negation<std::is_same<ValueType, std::initializer_list<typename string_t::value_type>>>,
- #if defined(JSON_HAS_CPP_17) && (defined(__GNUC__) || (defined(_MSC_VER) && _MSC_VER >= 1910 && _MSC_VER <= 1914))
- detail::negation<std::is_same<ValueType, std::string_view>>,
- #endif
- detail::is_detected_lazy<detail::get_template_function, const basic_json_t&, ValueType>
- >::value, int >::type = 0 >
- JSON_EXPLICIT operator ValueType() const
- {
-
- return get<ValueType>();
- }
-
- binary_t& get_binary()
- {
- if (!is_binary())
- {
- JSON_THROW(type_error::create(302, "type must be binary, but is " + std::string(type_name()), *this));
- }
- return *get_ptr<binary_t*>();
- }
-
- const binary_t& get_binary() const
- {
- if (!is_binary())
- {
- JSON_THROW(type_error::create(302, "type must be binary, but is " + std::string(type_name()), *this));
- }
- return *get_ptr<const binary_t*>();
- }
-
-
-
-
-
-
-
-
- reference at(size_type idx)
- {
-
- if (JSON_HEDLEY_LIKELY(is_array()))
- {
- JSON_TRY
- {
- return set_parent(m_value.array->at(idx));
- }
- JSON_CATCH (std::out_of_range&)
- {
-
- JSON_THROW(out_of_range::create(401, "array index " + std::to_string(idx) + " is out of range", *this));
- }
- }
- else
- {
- JSON_THROW(type_error::create(304, "cannot use at() with " + std::string(type_name()), *this));
- }
- }
-
- const_reference at(size_type idx) const
- {
-
- if (JSON_HEDLEY_LIKELY(is_array()))
- {
- JSON_TRY
- {
- return m_value.array->at(idx);
- }
- JSON_CATCH (std::out_of_range&)
- {
-
- JSON_THROW(out_of_range::create(401, "array index " + std::to_string(idx) + " is out of range", *this));
- }
- }
- else
- {
- JSON_THROW(type_error::create(304, "cannot use at() with " + std::string(type_name()), *this));
- }
- }
-
- reference at(const typename object_t::key_type& key)
- {
-
- if (JSON_HEDLEY_LIKELY(is_object()))
- {
- JSON_TRY
- {
- return set_parent(m_value.object->at(key));
- }
- JSON_CATCH (std::out_of_range&)
- {
-
- JSON_THROW(out_of_range::create(403, "key '" + key + "' not found", *this));
- }
- }
- else
- {
- JSON_THROW(type_error::create(304, "cannot use at() with " + std::string(type_name()), *this));
- }
- }
-
- const_reference at(const typename object_t::key_type& key) const
- {
-
- if (JSON_HEDLEY_LIKELY(is_object()))
- {
- JSON_TRY
- {
- return m_value.object->at(key);
- }
- JSON_CATCH (std::out_of_range&)
- {
-
- JSON_THROW(out_of_range::create(403, "key '" + key + "' not found", *this));
- }
- }
- else
- {
- JSON_THROW(type_error::create(304, "cannot use at() with " + std::string(type_name()), *this));
- }
- }
-
- reference operator[](size_type idx)
- {
-
- if (is_null())
- {
- m_type = value_t::array;
- m_value.array = create<array_t>();
- assert_invariant();
- }
-
- if (JSON_HEDLEY_LIKELY(is_array()))
- {
-
- if (idx >= m_value.array->size())
- {
- #if JSON_DIAGNOSTICS
-
- const auto old_size = m_value.array->size();
- const auto old_capacity = m_value.array->capacity();
- #endif
- m_value.array->resize(idx + 1);
- #if JSON_DIAGNOSTICS
- if (JSON_HEDLEY_UNLIKELY(m_value.array->capacity() != old_capacity))
- {
-
- set_parents();
- }
- else
- {
-
- set_parents(begin() + static_cast<typename iterator::difference_type>(old_size), static_cast<typename iterator::difference_type>(idx + 1 - old_size));
- }
- #endif
- assert_invariant();
- }
- return m_value.array->operator[](idx);
- }
- JSON_THROW(type_error::create(305, "cannot use operator[] with a numeric argument with " + std::string(type_name()), *this));
- }
-
- const_reference operator[](size_type idx) const
- {
-
- if (JSON_HEDLEY_LIKELY(is_array()))
- {
- return m_value.array->operator[](idx);
- }
- JSON_THROW(type_error::create(305, "cannot use operator[] with a numeric argument with " + std::string(type_name()), *this));
- }
-
- reference operator[](const typename object_t::key_type& key)
- {
-
- if (is_null())
- {
- m_type = value_t::object;
- m_value.object = create<object_t>();
- assert_invariant();
- }
-
- if (JSON_HEDLEY_LIKELY(is_object()))
- {
- return set_parent(m_value.object->operator[](key));
- }
- JSON_THROW(type_error::create(305, "cannot use operator[] with a string argument with " + std::string(type_name()), *this));
- }
-
- const_reference operator[](const typename object_t::key_type& key) const
- {
-
- if (JSON_HEDLEY_LIKELY(is_object()))
- {
- JSON_ASSERT(m_value.object->find(key) != m_value.object->end());
- return m_value.object->find(key)->second;
- }
- JSON_THROW(type_error::create(305, "cannot use operator[] with a string argument with " + std::string(type_name()), *this));
- }
-
- template<typename T>
- JSON_HEDLEY_NON_NULL(2)
- reference operator[](T* key)
- {
-
- if (is_null())
- {
- m_type = value_t::object;
- m_value = value_t::object;
- assert_invariant();
- }
-
- if (JSON_HEDLEY_LIKELY(is_object()))
- {
- return set_parent(m_value.object->operator[](key));
- }
- JSON_THROW(type_error::create(305, "cannot use operator[] with a string argument with " + std::string(type_name()), *this));
- }
-
- template<typename T>
- JSON_HEDLEY_NON_NULL(2)
- const_reference operator[](T* key) const
- {
-
- if (JSON_HEDLEY_LIKELY(is_object()))
- {
- JSON_ASSERT(m_value.object->find(key) != m_value.object->end());
- return m_value.object->find(key)->second;
- }
- JSON_THROW(type_error::create(305, "cannot use operator[] with a string argument with " + std::string(type_name()), *this));
- }
-
-
- template < class ValueType, typename std::enable_if <
- detail::is_getable<basic_json_t, ValueType>::value
- && !std::is_same<value_t, ValueType>::value, int >::type = 0 >
- ValueType value(const typename object_t::key_type& key, const ValueType& default_value) const
- {
-
- if (JSON_HEDLEY_LIKELY(is_object()))
- {
-
- const auto it = find(key);
- if (it != end())
- {
- return it->template get<ValueType>();
- }
- return default_value;
- }
- JSON_THROW(type_error::create(306, "cannot use value() with " + std::string(type_name()), *this));
- }
-
- string_t value(const typename object_t::key_type& key, const char* default_value) const
- {
- return value(key, string_t(default_value));
- }
-
- template<class ValueType, typename std::enable_if<
- detail::is_getable<basic_json_t, ValueType>::value, int>::type = 0>
- ValueType value(const json_pointer& ptr, const ValueType& default_value) const
- {
-
- if (JSON_HEDLEY_LIKELY(is_object()))
- {
-
- JSON_TRY
- {
- return ptr.get_checked(this).template get<ValueType>();
- }
- JSON_INTERNAL_CATCH (out_of_range&)
- {
- return default_value;
- }
- }
- JSON_THROW(type_error::create(306, "cannot use value() with " + std::string(type_name()), *this));
- }
-
- JSON_HEDLEY_NON_NULL(3)
- string_t value(const json_pointer& ptr, const char* default_value) const
- {
- return value(ptr, string_t(default_value));
- }
-
- reference front()
- {
- return *begin();
- }
-
- const_reference front() const
- {
- return *cbegin();
- }
-
- reference back()
- {
- auto tmp = end();
- --tmp;
- return *tmp;
- }
-
- const_reference back() const
- {
- auto tmp = cend();
- --tmp;
- return *tmp;
- }
-
- template < class IteratorType, typename std::enable_if <
- std::is_same<IteratorType, typename basic_json_t::iterator>::value ||
- std::is_same<IteratorType, typename basic_json_t::const_iterator>::value, int >::type
- = 0 >
- IteratorType erase(IteratorType pos)
- {
-
- if (JSON_HEDLEY_UNLIKELY(this != pos.m_object))
- {
- JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value", *this));
- }
- IteratorType result = end();
- switch (m_type)
- {
- case value_t::boolean:
- case value_t::number_float:
- case value_t::number_integer:
- case value_t::number_unsigned:
- case value_t::string:
- case value_t::binary:
- {
- if (JSON_HEDLEY_UNLIKELY(!pos.m_it.primitive_iterator.is_begin()))
- {
- JSON_THROW(invalid_iterator::create(205, "iterator out of range", *this));
- }
- if (is_string())
- {
- AllocatorType<string_t> alloc;
- std::allocator_traits<decltype(alloc)>::destroy(alloc, m_value.string);
- std::allocator_traits<decltype(alloc)>::deallocate(alloc, m_value.string, 1);
- m_value.string = nullptr;
- }
- else if (is_binary())
- {
- AllocatorType<binary_t> alloc;
- std::allocator_traits<decltype(alloc)>::destroy(alloc, m_value.binary);
- std::allocator_traits<decltype(alloc)>::deallocate(alloc, m_value.binary, 1);
- m_value.binary = nullptr;
- }
- m_type = value_t::null;
- assert_invariant();
- break;
- }
- case value_t::object:
- {
- result.m_it.object_iterator = m_value.object->erase(pos.m_it.object_iterator);
- break;
- }
- case value_t::array:
- {
- result.m_it.array_iterator = m_value.array->erase(pos.m_it.array_iterator);
- break;
- }
- case value_t::null:
- case value_t::discarded:
- default:
- JSON_THROW(type_error::create(307, "cannot use erase() with " + std::string(type_name()), *this));
- }
- return result;
- }
-
- template < class IteratorType, typename std::enable_if <
- std::is_same<IteratorType, typename basic_json_t::iterator>::value ||
- std::is_same<IteratorType, typename basic_json_t::const_iterator>::value, int >::type
- = 0 >
- IteratorType erase(IteratorType first, IteratorType last)
- {
-
- if (JSON_HEDLEY_UNLIKELY(this != first.m_object || this != last.m_object))
- {
- JSON_THROW(invalid_iterator::create(203, "iterators do not fit current value", *this));
- }
- IteratorType result = end();
- switch (m_type)
- {
- case value_t::boolean:
- case value_t::number_float:
- case value_t::number_integer:
- case value_t::number_unsigned:
- case value_t::string:
- case value_t::binary:
- {
- if (JSON_HEDLEY_LIKELY(!first.m_it.primitive_iterator.is_begin()
- || !last.m_it.primitive_iterator.is_end()))
- {
- JSON_THROW(invalid_iterator::create(204, "iterators out of range", *this));
- }
- if (is_string())
- {
- AllocatorType<string_t> alloc;
- std::allocator_traits<decltype(alloc)>::destroy(alloc, m_value.string);
- std::allocator_traits<decltype(alloc)>::deallocate(alloc, m_value.string, 1);
- m_value.string = nullptr;
- }
- else if (is_binary())
- {
- AllocatorType<binary_t> alloc;
- std::allocator_traits<decltype(alloc)>::destroy(alloc, m_value.binary);
- std::allocator_traits<decltype(alloc)>::deallocate(alloc, m_value.binary, 1);
- m_value.binary = nullptr;
- }
- m_type = value_t::null;
- assert_invariant();
- break;
- }
- case value_t::object:
- {
- result.m_it.object_iterator = m_value.object->erase(first.m_it.object_iterator,
- last.m_it.object_iterator);
- break;
- }
- case value_t::array:
- {
- result.m_it.array_iterator = m_value.array->erase(first.m_it.array_iterator,
- last.m_it.array_iterator);
- break;
- }
- case value_t::null:
- case value_t::discarded:
- default:
- JSON_THROW(type_error::create(307, "cannot use erase() with " + std::string(type_name()), *this));
- }
- return result;
- }
-
- size_type erase(const typename object_t::key_type& key)
- {
-
- if (JSON_HEDLEY_LIKELY(is_object()))
- {
- return m_value.object->erase(key);
- }
- JSON_THROW(type_error::create(307, "cannot use erase() with " + std::string(type_name()), *this));
- }
-
- void erase(const size_type idx)
- {
-
- if (JSON_HEDLEY_LIKELY(is_array()))
- {
- if (JSON_HEDLEY_UNLIKELY(idx >= size()))
- {
- JSON_THROW(out_of_range::create(401, "array index " + std::to_string(idx) + " is out of range", *this));
- }
- m_value.array->erase(m_value.array->begin() + static_cast<difference_type>(idx));
- }
- else
- {
- JSON_THROW(type_error::create(307, "cannot use erase() with " + std::string(type_name()), *this));
- }
- }
-
-
-
-
-
-
-
- template<typename KeyT>
- iterator find(KeyT&& key)
- {
- auto result = end();
- if (is_object())
- {
- result.m_it.object_iterator = m_value.object->find(std::forward<KeyT>(key));
- }
- return result;
- }
-
- template<typename KeyT>
- const_iterator find(KeyT&& key) const
- {
- auto result = cend();
- if (is_object())
- {
- result.m_it.object_iterator = m_value.object->find(std::forward<KeyT>(key));
- }
- return result;
- }
-
- template<typename KeyT>
- size_type count(KeyT&& key) const
- {
-
- return is_object() ? m_value.object->count(std::forward<KeyT>(key)) : 0;
- }
-
- template < typename KeyT, typename std::enable_if <
- !std::is_same<typename std::decay<KeyT>::type, json_pointer>::value, int >::type = 0 >
- bool contains(KeyT && key) const
- {
- return is_object() && m_value.object->find(std::forward<KeyT>(key)) != m_value.object->end();
- }
-
- bool contains(const json_pointer& ptr) const
- {
- return ptr.contains(this);
- }
-
-
-
-
-
-
-
- iterator begin() noexcept
- {
- iterator result(this);
- result.set_begin();
- return result;
- }
-
- const_iterator begin() const noexcept
- {
- return cbegin();
- }
-
- const_iterator cbegin() const noexcept
- {
- const_iterator result(this);
- result.set_begin();
- return result;
- }
-
- iterator end() noexcept
- {
- iterator result(this);
- result.set_end();
- return result;
- }
-
- const_iterator end() const noexcept
- {
- return cend();
- }
-
- const_iterator cend() const noexcept
- {
- const_iterator result(this);
- result.set_end();
- return result;
- }
-
- reverse_iterator rbegin() noexcept
- {
- return reverse_iterator(end());
- }
-
- const_reverse_iterator rbegin() const noexcept
- {
- return crbegin();
- }
-
- reverse_iterator rend() noexcept
- {
- return reverse_iterator(begin());
- }
-
- const_reverse_iterator rend() const noexcept
- {
- return crend();
- }
-
- const_reverse_iterator crbegin() const noexcept
- {
- return const_reverse_iterator(cend());
- }
-
- const_reverse_iterator crend() const noexcept
- {
- return const_reverse_iterator(cbegin());
- }
- public:
-
- JSON_HEDLEY_DEPRECATED_FOR(3.1.0, items())
- static iteration_proxy<iterator> iterator_wrapper(reference ref) noexcept
- {
- return ref.items();
- }
-
- JSON_HEDLEY_DEPRECATED_FOR(3.1.0, items())
- static iteration_proxy<const_iterator> iterator_wrapper(const_reference ref) noexcept
- {
- return ref.items();
- }
-
- iteration_proxy<iterator> items() noexcept
- {
- return iteration_proxy<iterator>(*this);
- }
-
- iteration_proxy<const_iterator> items() const noexcept
- {
- return iteration_proxy<const_iterator>(*this);
- }
-
-
-
-
-
-
-
- bool empty() const noexcept
- {
- switch (m_type)
- {
- case value_t::null:
- {
-
- return true;
- }
- case value_t::array:
- {
-
- return m_value.array->empty();
- }
- case value_t::object:
- {
-
- return m_value.object->empty();
- }
- case value_t::string:
- case value_t::boolean:
- case value_t::number_integer:
- case value_t::number_unsigned:
- case value_t::number_float:
- case value_t::binary:
- case value_t::discarded:
- default:
- {
-
- return false;
- }
- }
- }
-
- size_type size() const noexcept
- {
- switch (m_type)
- {
- case value_t::null:
- {
-
- return 0;
- }
- case value_t::array:
- {
-
- return m_value.array->size();
- }
- case value_t::object:
- {
-
- return m_value.object->size();
- }
- case value_t::string:
- case value_t::boolean:
- case value_t::number_integer:
- case value_t::number_unsigned:
- case value_t::number_float:
- case value_t::binary:
- case value_t::discarded:
- default:
- {
-
- return 1;
- }
- }
- }
-
- size_type max_size() const noexcept
- {
- switch (m_type)
- {
- case value_t::array:
- {
-
- return m_value.array->max_size();
- }
- case value_t::object:
- {
-
- return m_value.object->max_size();
- }
- case value_t::null:
- case value_t::string:
- case value_t::boolean:
- case value_t::number_integer:
- case value_t::number_unsigned:
- case value_t::number_float:
- case value_t::binary:
- case value_t::discarded:
- default:
- {
-
- return size();
- }
- }
- }
-
-
-
-
-
-
-
- void clear() noexcept
- {
- switch (m_type)
- {
- case value_t::number_integer:
- {
- m_value.number_integer = 0;
- break;
- }
- case value_t::number_unsigned:
- {
- m_value.number_unsigned = 0;
- break;
- }
- case value_t::number_float:
- {
- m_value.number_float = 0.0;
- break;
- }
- case value_t::boolean:
- {
- m_value.boolean = false;
- break;
- }
- case value_t::string:
- {
- m_value.string->clear();
- break;
- }
- case value_t::binary:
- {
- m_value.binary->clear();
- break;
- }
- case value_t::array:
- {
- m_value.array->clear();
- break;
- }
- case value_t::object:
- {
- m_value.object->clear();
- break;
- }
- case value_t::null:
- case value_t::discarded:
- default:
- break;
- }
- }
-
- void push_back(basic_json&& val)
- {
-
- if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_array())))
- {
- JSON_THROW(type_error::create(308, "cannot use push_back() with " + std::string(type_name()), *this));
- }
-
- if (is_null())
- {
- m_type = value_t::array;
- m_value = value_t::array;
- assert_invariant();
- }
-
- const auto old_capacity = m_value.array->capacity();
- m_value.array->push_back(std::move(val));
- set_parent(m_value.array->back(), old_capacity);
-
- }
-
- reference operator+=(basic_json&& val)
- {
- push_back(std::move(val));
- return *this;
- }
-
- void push_back(const basic_json& val)
- {
-
- if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_array())))
- {
- JSON_THROW(type_error::create(308, "cannot use push_back() with " + std::string(type_name()), *this));
- }
-
- if (is_null())
- {
- m_type = value_t::array;
- m_value = value_t::array;
- assert_invariant();
- }
-
- const auto old_capacity = m_value.array->capacity();
- m_value.array->push_back(val);
- set_parent(m_value.array->back(), old_capacity);
- }
-
- reference operator+=(const basic_json& val)
- {
- push_back(val);
- return *this;
- }
-
- void push_back(const typename object_t::value_type& val)
- {
-
- if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_object())))
- {
- JSON_THROW(type_error::create(308, "cannot use push_back() with " + std::string(type_name()), *this));
- }
-
- if (is_null())
- {
- m_type = value_t::object;
- m_value = value_t::object;
- assert_invariant();
- }
-
- auto res = m_value.object->insert(val);
- set_parent(res.first->second);
- }
-
- reference operator+=(const typename object_t::value_type& val)
- {
- push_back(val);
- return *this;
- }
-
- void push_back(initializer_list_t init)
- {
- if (is_object() && init.size() == 2 && (*init.begin())->is_string())
- {
- basic_json&& key = init.begin()->moved_or_copied();
- push_back(typename object_t::value_type(
- std::move(key.get_ref<string_t&>()), (init.begin() + 1)->moved_or_copied()));
- }
- else
- {
- push_back(basic_json(init));
- }
- }
-
- reference operator+=(initializer_list_t init)
- {
- push_back(init);
- return *this;
- }
-
- template<class... Args>
- reference emplace_back(Args&& ... args)
- {
-
- if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_array())))
- {
- JSON_THROW(type_error::create(311, "cannot use emplace_back() with " + std::string(type_name()), *this));
- }
-
- if (is_null())
- {
- m_type = value_t::array;
- m_value = value_t::array;
- assert_invariant();
- }
-
- const auto old_capacity = m_value.array->capacity();
- m_value.array->emplace_back(std::forward<Args>(args)...);
- return set_parent(m_value.array->back(), old_capacity);
- }
-
- template<class... Args>
- std::pair<iterator, bool> emplace(Args&& ... args)
- {
-
- if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_object())))
- {
- JSON_THROW(type_error::create(311, "cannot use emplace() with " + std::string(type_name()), *this));
- }
-
- if (is_null())
- {
- m_type = value_t::object;
- m_value = value_t::object;
- assert_invariant();
- }
-
- auto res = m_value.object->emplace(std::forward<Args>(args)...);
- set_parent(res.first->second);
-
- auto it = begin();
- it.m_it.object_iterator = res.first;
-
- return {it, res.second};
- }
-
-
-
- template<typename... Args>
- iterator insert_iterator(const_iterator pos, Args&& ... args)
- {
- iterator result(this);
- JSON_ASSERT(m_value.array != nullptr);
- auto insert_pos = std::distance(m_value.array->begin(), pos.m_it.array_iterator);
- m_value.array->insert(pos.m_it.array_iterator, std::forward<Args>(args)...);
- result.m_it.array_iterator = m_value.array->begin() + insert_pos;
-
-
-
- set_parents();
- return result;
- }
-
- iterator insert(const_iterator pos, const basic_json& val)
- {
-
- if (JSON_HEDLEY_LIKELY(is_array()))
- {
-
- if (JSON_HEDLEY_UNLIKELY(pos.m_object != this))
- {
- JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value", *this));
- }
-
- return insert_iterator(pos, val);
- }
- JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name()), *this));
- }
-
- iterator insert(const_iterator pos, basic_json&& val)
- {
- return insert(pos, val);
- }
-
- iterator insert(const_iterator pos, size_type cnt, const basic_json& val)
- {
-
- if (JSON_HEDLEY_LIKELY(is_array()))
- {
-
- if (JSON_HEDLEY_UNLIKELY(pos.m_object != this))
- {
- JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value", *this));
- }
-
- return insert_iterator(pos, cnt, val);
- }
- JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name()), *this));
- }
-
- iterator insert(const_iterator pos, const_iterator first, const_iterator last)
- {
-
- if (JSON_HEDLEY_UNLIKELY(!is_array()))
- {
- JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name()), *this));
- }
-
- if (JSON_HEDLEY_UNLIKELY(pos.m_object != this))
- {
- JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value", *this));
- }
-
- if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
- {
- JSON_THROW(invalid_iterator::create(210, "iterators do not fit", *this));
- }
- if (JSON_HEDLEY_UNLIKELY(first.m_object == this))
- {
- JSON_THROW(invalid_iterator::create(211, "passed iterators may not belong to container", *this));
- }
-
- return insert_iterator(pos, first.m_it.array_iterator, last.m_it.array_iterator);
- }
-
- iterator insert(const_iterator pos, initializer_list_t ilist)
- {
-
- if (JSON_HEDLEY_UNLIKELY(!is_array()))
- {
- JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name()), *this));
- }
-
- if (JSON_HEDLEY_UNLIKELY(pos.m_object != this))
- {
- JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value", *this));
- }
-
- return insert_iterator(pos, ilist.begin(), ilist.end());
- }
-
- void insert(const_iterator first, const_iterator last)
- {
-
- if (JSON_HEDLEY_UNLIKELY(!is_object()))
- {
- JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name()), *this));
- }
-
- if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
- {
- JSON_THROW(invalid_iterator::create(210, "iterators do not fit", *this));
- }
-
- if (JSON_HEDLEY_UNLIKELY(!first.m_object->is_object()))
- {
- JSON_THROW(invalid_iterator::create(202, "iterators first and last must point to objects", *this));
- }
- m_value.object->insert(first.m_it.object_iterator, last.m_it.object_iterator);
- }
-
- void update(const_reference j)
- {
-
- if (is_null())
- {
- m_type = value_t::object;
- m_value.object = create<object_t>();
- assert_invariant();
- }
- if (JSON_HEDLEY_UNLIKELY(!is_object()))
- {
- JSON_THROW(type_error::create(312, "cannot use update() with " + std::string(type_name()), *this));
- }
- if (JSON_HEDLEY_UNLIKELY(!j.is_object()))
- {
- JSON_THROW(type_error::create(312, "cannot use update() with " + std::string(j.type_name()), *this));
- }
- for (auto it = j.cbegin(); it != j.cend(); ++it)
- {
- m_value.object->operator[](it.key()) = it.value();
- #if JSON_DIAGNOSTICS
- m_value.object->operator[](it.key()).m_parent = this;
- #endif
- }
- }
-
- void update(const_iterator first, const_iterator last)
- {
-
- if (is_null())
- {
- m_type = value_t::object;
- m_value.object = create<object_t>();
- assert_invariant();
- }
- if (JSON_HEDLEY_UNLIKELY(!is_object()))
- {
- JSON_THROW(type_error::create(312, "cannot use update() with " + std::string(type_name()), *this));
- }
-
- if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
- {
- JSON_THROW(invalid_iterator::create(210, "iterators do not fit", *this));
- }
-
- if (JSON_HEDLEY_UNLIKELY(!first.m_object->is_object()
- || !last.m_object->is_object()))
- {
- JSON_THROW(invalid_iterator::create(202, "iterators first and last must point to objects", *this));
- }
- for (auto it = first; it != last; ++it)
- {
- m_value.object->operator[](it.key()) = it.value();
- #if JSON_DIAGNOSTICS
- m_value.object->operator[](it.key()).m_parent = this;
- #endif
- }
- }
-
- void swap(reference other) noexcept (
- std::is_nothrow_move_constructible<value_t>::value&&
- std::is_nothrow_move_assignable<value_t>::value&&
- std::is_nothrow_move_constructible<json_value>::value&&
- std::is_nothrow_move_assignable<json_value>::value
- )
- {
- std::swap(m_type, other.m_type);
- std::swap(m_value, other.m_value);
- set_parents();
- other.set_parents();
- assert_invariant();
- }
-
- friend void swap(reference left, reference right) noexcept (
- std::is_nothrow_move_constructible<value_t>::value&&
- std::is_nothrow_move_assignable<value_t>::value&&
- std::is_nothrow_move_constructible<json_value>::value&&
- std::is_nothrow_move_assignable<json_value>::value
- )
- {
- left.swap(right);
- }
-
- void swap(array_t& other)
- {
-
- if (JSON_HEDLEY_LIKELY(is_array()))
- {
- std::swap(*(m_value.array), other);
- }
- else
- {
- JSON_THROW(type_error::create(310, "cannot use swap() with " + std::string(type_name()), *this));
- }
- }
-
- void swap(object_t& other)
- {
-
- if (JSON_HEDLEY_LIKELY(is_object()))
- {
- std::swap(*(m_value.object), other);
- }
- else
- {
- JSON_THROW(type_error::create(310, "cannot use swap() with " + std::string(type_name()), *this));
- }
- }
-
- void swap(string_t& other)
- {
-
- if (JSON_HEDLEY_LIKELY(is_string()))
- {
- std::swap(*(m_value.string), other);
- }
- else
- {
- JSON_THROW(type_error::create(310, "cannot use swap() with " + std::string(type_name()), *this));
- }
- }
-
- void swap(binary_t& other)
- {
-
- if (JSON_HEDLEY_LIKELY(is_binary()))
- {
- std::swap(*(m_value.binary), other);
- }
- else
- {
- JSON_THROW(type_error::create(310, "cannot use swap() with " + std::string(type_name()), *this));
- }
- }
-
- void swap(typename binary_t::container_type& other)
- {
-
- if (JSON_HEDLEY_LIKELY(is_binary()))
- {
- std::swap(*(m_value.binary), other);
- }
- else
- {
- JSON_THROW(type_error::create(310, "cannot use swap() with " + std::string(type_name()), *this));
- }
- }
-
- public:
-
-
-
-
-
-
- friend bool operator==(const_reference lhs, const_reference rhs) noexcept
- {
- #ifdef __GNUC__
- #pragma GCC diagnostic push
- #pragma GCC diagnostic ignored "-Wfloat-equal"
- #endif
- const auto lhs_type = lhs.type();
- const auto rhs_type = rhs.type();
- if (lhs_type == rhs_type)
- {
- switch (lhs_type)
- {
- case value_t::array:
- return *lhs.m_value.array == *rhs.m_value.array;
- case value_t::object:
- return *lhs.m_value.object == *rhs.m_value.object;
- case value_t::null:
- return true;
- case value_t::string:
- return *lhs.m_value.string == *rhs.m_value.string;
- case value_t::boolean:
- return lhs.m_value.boolean == rhs.m_value.boolean;
- case value_t::number_integer:
- return lhs.m_value.number_integer == rhs.m_value.number_integer;
- case value_t::number_unsigned:
- return lhs.m_value.number_unsigned == rhs.m_value.number_unsigned;
- case value_t::number_float:
- return lhs.m_value.number_float == rhs.m_value.number_float;
- case value_t::binary:
- return *lhs.m_value.binary == *rhs.m_value.binary;
- case value_t::discarded:
- default:
- return false;
- }
- }
- else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_float)
- {
- return static_cast<number_float_t>(lhs.m_value.number_integer) == rhs.m_value.number_float;
- }
- else if (lhs_type == value_t::number_float && rhs_type == value_t::number_integer)
- {
- return lhs.m_value.number_float == static_cast<number_float_t>(rhs.m_value.number_integer);
- }
- else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_float)
- {
- return static_cast<number_float_t>(lhs.m_value.number_unsigned) == rhs.m_value.number_float;
- }
- else if (lhs_type == value_t::number_float && rhs_type == value_t::number_unsigned)
- {
- return lhs.m_value.number_float == static_cast<number_float_t>(rhs.m_value.number_unsigned);
- }
- else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_integer)
- {
- return static_cast<number_integer_t>(lhs.m_value.number_unsigned) == rhs.m_value.number_integer;
- }
- else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_unsigned)
- {
- return lhs.m_value.number_integer == static_cast<number_integer_t>(rhs.m_value.number_unsigned);
- }
- return false;
- #ifdef __GNUC__
- #pragma GCC diagnostic pop
- #endif
- }
-
- template<typename ScalarType, typename std::enable_if<
- std::is_scalar<ScalarType>::value, int>::type = 0>
- friend bool operator==(const_reference lhs, ScalarType rhs) noexcept
- {
- return lhs == basic_json(rhs);
- }
-
- template<typename ScalarType, typename std::enable_if<
- std::is_scalar<ScalarType>::value, int>::type = 0>
- friend bool operator==(ScalarType lhs, const_reference rhs) noexcept
- {
- return basic_json(lhs) == rhs;
- }
-
- friend bool operator!=(const_reference lhs, const_reference rhs) noexcept
- {
- return !(lhs == rhs);
- }
-
- template<typename ScalarType, typename std::enable_if<
- std::is_scalar<ScalarType>::value, int>::type = 0>
- friend bool operator!=(const_reference lhs, ScalarType rhs) noexcept
- {
- return lhs != basic_json(rhs);
- }
-
- template<typename ScalarType, typename std::enable_if<
- std::is_scalar<ScalarType>::value, int>::type = 0>
- friend bool operator!=(ScalarType lhs, const_reference rhs) noexcept
- {
- return basic_json(lhs) != rhs;
- }
-
- friend bool operator<(const_reference lhs, const_reference rhs) noexcept
- {
- const auto lhs_type = lhs.type();
- const auto rhs_type = rhs.type();
- if (lhs_type == rhs_type)
- {
- switch (lhs_type)
- {
- case value_t::array:
-
-
- return (*lhs.m_value.array) < (*rhs.m_value.array);
- case value_t::object:
- return (*lhs.m_value.object) < (*rhs.m_value.object);
- case value_t::null:
- return false;
- case value_t::string:
- return (*lhs.m_value.string) < (*rhs.m_value.string);
- case value_t::boolean:
- return (lhs.m_value.boolean) < (rhs.m_value.boolean);
- case value_t::number_integer:
- return (lhs.m_value.number_integer) < (rhs.m_value.number_integer);
- case value_t::number_unsigned:
- return (lhs.m_value.number_unsigned) < (rhs.m_value.number_unsigned);
- case value_t::number_float:
- return (lhs.m_value.number_float) < (rhs.m_value.number_float);
- case value_t::binary:
- return (*lhs.m_value.binary) < (*rhs.m_value.binary);
- case value_t::discarded:
- default:
- return false;
- }
- }
- else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_float)
- {
- return static_cast<number_float_t>(lhs.m_value.number_integer) < rhs.m_value.number_float;
- }
- else if (lhs_type == value_t::number_float && rhs_type == value_t::number_integer)
- {
- return lhs.m_value.number_float < static_cast<number_float_t>(rhs.m_value.number_integer);
- }
- else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_float)
- {
- return static_cast<number_float_t>(lhs.m_value.number_unsigned) < rhs.m_value.number_float;
- }
- else if (lhs_type == value_t::number_float && rhs_type == value_t::number_unsigned)
- {
- return lhs.m_value.number_float < static_cast<number_float_t>(rhs.m_value.number_unsigned);
- }
- else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_unsigned)
- {
- return lhs.m_value.number_integer < static_cast<number_integer_t>(rhs.m_value.number_unsigned);
- }
- else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_integer)
- {
- return static_cast<number_integer_t>(lhs.m_value.number_unsigned) < rhs.m_value.number_integer;
- }
-
-
-
- return operator<(lhs_type, rhs_type);
- }
-
- template<typename ScalarType, typename std::enable_if<
- std::is_scalar<ScalarType>::value, int>::type = 0>
- friend bool operator<(const_reference lhs, ScalarType rhs) noexcept
- {
- return lhs < basic_json(rhs);
- }
-
- template<typename ScalarType, typename std::enable_if<
- std::is_scalar<ScalarType>::value, int>::type = 0>
- friend bool operator<(ScalarType lhs, const_reference rhs) noexcept
- {
- return basic_json(lhs) < rhs;
- }
-
- friend bool operator<=(const_reference lhs, const_reference rhs) noexcept
- {
- return !(rhs < lhs);
- }
-
- template<typename ScalarType, typename std::enable_if<
- std::is_scalar<ScalarType>::value, int>::type = 0>
- friend bool operator<=(const_reference lhs, ScalarType rhs) noexcept
- {
- return lhs <= basic_json(rhs);
- }
-
- template<typename ScalarType, typename std::enable_if<
- std::is_scalar<ScalarType>::value, int>::type = 0>
- friend bool operator<=(ScalarType lhs, const_reference rhs) noexcept
- {
- return basic_json(lhs) <= rhs;
- }
-
- friend bool operator>(const_reference lhs, const_reference rhs) noexcept
- {
- return !(lhs <= rhs);
- }
-
- template<typename ScalarType, typename std::enable_if<
- std::is_scalar<ScalarType>::value, int>::type = 0>
- friend bool operator>(const_reference lhs, ScalarType rhs) noexcept
- {
- return lhs > basic_json(rhs);
- }
-
- template<typename ScalarType, typename std::enable_if<
- std::is_scalar<ScalarType>::value, int>::type = 0>
- friend bool operator>(ScalarType lhs, const_reference rhs) noexcept
- {
- return basic_json(lhs) > rhs;
- }
-
- friend bool operator>=(const_reference lhs, const_reference rhs) noexcept
- {
- return !(lhs < rhs);
- }
-
- template<typename ScalarType, typename std::enable_if<
- std::is_scalar<ScalarType>::value, int>::type = 0>
- friend bool operator>=(const_reference lhs, ScalarType rhs) noexcept
- {
- return lhs >= basic_json(rhs);
- }
-
- template<typename ScalarType, typename std::enable_if<
- std::is_scalar<ScalarType>::value, int>::type = 0>
- friend bool operator>=(ScalarType lhs, const_reference rhs) noexcept
- {
- return basic_json(lhs) >= rhs;
- }
-
-
-
-
-
-
- #ifndef JSON_NO_IO
-
- friend std::ostream& operator<<(std::ostream& o, const basic_json& j)
- {
-
- const bool pretty_print = o.width() > 0;
- const auto indentation = pretty_print ? o.width() : 0;
-
- o.width(0);
-
- serializer s(detail::output_adapter<char>(o), o.fill());
- s.dump(j, pretty_print, false, static_cast<unsigned int>(indentation));
- return o;
- }
-
- JSON_HEDLEY_DEPRECATED_FOR(3.0.0, operator<<(std::ostream&, const basic_json&))
- friend std::ostream& operator>>(const basic_json& j, std::ostream& o)
- {
- return o << j;
- }
- #endif
-
-
-
-
-
-
-
- template<typename InputType>
- JSON_HEDLEY_WARN_UNUSED_RESULT
- static basic_json parse(InputType&& i,
- const parser_callback_t cb = nullptr,
- const bool allow_exceptions = true,
- const bool ignore_comments = false)
- {
- basic_json result;
- parser(detail::input_adapter(std::forward<InputType>(i)), cb, allow_exceptions, ignore_comments).parse(true, result);
- return result;
- }
-
- template<typename IteratorType>
- JSON_HEDLEY_WARN_UNUSED_RESULT
- static basic_json parse(IteratorType first,
- IteratorType last,
- const parser_callback_t cb = nullptr,
- const bool allow_exceptions = true,
- const bool ignore_comments = false)
- {
- basic_json result;
- parser(detail::input_adapter(std::move(first), std::move(last)), cb, allow_exceptions, ignore_comments).parse(true, result);
- return result;
- }
- JSON_HEDLEY_WARN_UNUSED_RESULT
- JSON_HEDLEY_DEPRECATED_FOR(3.8.0, parse(ptr, ptr + len))
- static basic_json parse(detail::span_input_adapter&& i,
- const parser_callback_t cb = nullptr,
- const bool allow_exceptions = true,
- const bool ignore_comments = false)
- {
- basic_json result;
- parser(i.get(), cb, allow_exceptions, ignore_comments).parse(true, result);
- return result;
- }
-
- template<typename InputType>
- static bool accept(InputType&& i,
- const bool ignore_comments = false)
- {
- return parser(detail::input_adapter(std::forward<InputType>(i)), nullptr, false, ignore_comments).accept(true);
- }
- template<typename IteratorType>
- static bool accept(IteratorType first, IteratorType last,
- const bool ignore_comments = false)
- {
- return parser(detail::input_adapter(std::move(first), std::move(last)), nullptr, false, ignore_comments).accept(true);
- }
- JSON_HEDLEY_WARN_UNUSED_RESULT
- JSON_HEDLEY_DEPRECATED_FOR(3.8.0, accept(ptr, ptr + len))
- static bool accept(detail::span_input_adapter&& i,
- const bool ignore_comments = false)
- {
- return parser(i.get(), nullptr, false, ignore_comments).accept(true);
- }
-
- template <typename InputType, typename SAX>
- JSON_HEDLEY_NON_NULL(2)
- static bool sax_parse(InputType&& i, SAX* sax,
- input_format_t format = input_format_t::json,
- const bool strict = true,
- const bool ignore_comments = false)
- {
- auto ia = detail::input_adapter(std::forward<InputType>(i));
- return format == input_format_t::json
- ? parser(std::move(ia), nullptr, true, ignore_comments).sax_parse(sax, strict)
- : detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia)).sax_parse(format, sax, strict);
- }
- template<class IteratorType, class SAX>
- JSON_HEDLEY_NON_NULL(3)
- static bool sax_parse(IteratorType first, IteratorType last, SAX* sax,
- input_format_t format = input_format_t::json,
- const bool strict = true,
- const bool ignore_comments = false)
- {
- auto ia = detail::input_adapter(std::move(first), std::move(last));
- return format == input_format_t::json
- ? parser(std::move(ia), nullptr, true, ignore_comments).sax_parse(sax, strict)
- : detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia)).sax_parse(format, sax, strict);
- }
- template <typename SAX>
- JSON_HEDLEY_DEPRECATED_FOR(3.8.0, sax_parse(ptr, ptr + len, ...))
- JSON_HEDLEY_NON_NULL(2)
- static bool sax_parse(detail::span_input_adapter&& i, SAX* sax,
- input_format_t format = input_format_t::json,
- const bool strict = true,
- const bool ignore_comments = false)
- {
- auto ia = i.get();
- return format == input_format_t::json
-
- ? parser(std::move(ia), nullptr, true, ignore_comments).sax_parse(sax, strict)
-
- : detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia)).sax_parse(format, sax, strict);
- }
- #ifndef JSON_NO_IO
-
- JSON_HEDLEY_DEPRECATED_FOR(3.0.0, operator>>(std::istream&, basic_json&))
- friend std::istream& operator<<(basic_json& j, std::istream& i)
- {
- return operator>>(i, j);
- }
-
- friend std::istream& operator>>(std::istream& i, basic_json& j)
- {
- parser(detail::input_adapter(i)).parse(false, j);
- return i;
- }
- #endif
-
-
-
-
-
- JSON_HEDLEY_RETURNS_NON_NULL
- const char* type_name() const noexcept
- {
- {
- switch (m_type)
- {
- case value_t::null:
- return "null";
- case value_t::object:
- return "object";
- case value_t::array:
- return "array";
- case value_t::string:
- return "string";
- case value_t::boolean:
- return "boolean";
- case value_t::binary:
- return "binary";
- case value_t::discarded:
- return "discarded";
- case value_t::number_integer:
- case value_t::number_unsigned:
- case value_t::number_float:
- default:
- return "number";
- }
- }
- }
- JSON_PRIVATE_UNLESS_TESTED:
-
-
-
-
- value_t m_type = value_t::null;
-
- json_value m_value = {};
- #if JSON_DIAGNOSTICS
-
- basic_json* m_parent = nullptr;
- #endif
-
-
-
-
-
- public:
-
- static std::vector<std::uint8_t> to_cbor(const basic_json& j)
- {
- std::vector<std::uint8_t> result;
- to_cbor(j, result);
- return result;
- }
- static void to_cbor(const basic_json& j, detail::output_adapter<std::uint8_t> o)
- {
- binary_writer<std::uint8_t>(o).write_cbor(j);
- }
- static void to_cbor(const basic_json& j, detail::output_adapter<char> o)
- {
- binary_writer<char>(o).write_cbor(j);
- }
-
- static std::vector<std::uint8_t> to_msgpack(const basic_json& j)
- {
- std::vector<std::uint8_t> result;
- to_msgpack(j, result);
- return result;
- }
- static void to_msgpack(const basic_json& j, detail::output_adapter<std::uint8_t> o)
- {
- binary_writer<std::uint8_t>(o).write_msgpack(j);
- }
- static void to_msgpack(const basic_json& j, detail::output_adapter<char> o)
- {
- binary_writer<char>(o).write_msgpack(j);
- }
-
- static std::vector<std::uint8_t> to_ubjson(const basic_json& j,
- const bool use_size = false,
- const bool use_type = false)
- {
- std::vector<std::uint8_t> result;
- to_ubjson(j, result, use_size, use_type);
- return result;
- }
- static void to_ubjson(const basic_json& j, detail::output_adapter<std::uint8_t> o,
- const bool use_size = false, const bool use_type = false)
- {
- binary_writer<std::uint8_t>(o).write_ubjson(j, use_size, use_type);
- }
- static void to_ubjson(const basic_json& j, detail::output_adapter<char> o,
- const bool use_size = false, const bool use_type = false)
- {
- binary_writer<char>(o).write_ubjson(j, use_size, use_type);
- }
-
- static std::vector<std::uint8_t> to_bson(const basic_json& j)
- {
- std::vector<std::uint8_t> result;
- to_bson(j, result);
- return result;
- }
-
- static void to_bson(const basic_json& j, detail::output_adapter<std::uint8_t> o)
- {
- binary_writer<std::uint8_t>(o).write_bson(j);
- }
-
- static void to_bson(const basic_json& j, detail::output_adapter<char> o)
- {
- binary_writer<char>(o).write_bson(j);
- }
-
- template<typename InputType>
- JSON_HEDLEY_WARN_UNUSED_RESULT
- static basic_json from_cbor(InputType&& i,
- const bool strict = true,
- const bool allow_exceptions = true,
- const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error)
- {
- basic_json result;
- detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
- auto ia = detail::input_adapter(std::forward<InputType>(i));
- const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);
- return res ? result : basic_json(value_t::discarded);
- }
-
- template<typename IteratorType>
- JSON_HEDLEY_WARN_UNUSED_RESULT
- static basic_json from_cbor(IteratorType first, IteratorType last,
- const bool strict = true,
- const bool allow_exceptions = true,
- const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error)
- {
- basic_json result;
- detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
- auto ia = detail::input_adapter(std::move(first), std::move(last));
- const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);
- return res ? result : basic_json(value_t::discarded);
- }
- template<typename T>
- JSON_HEDLEY_WARN_UNUSED_RESULT
- JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_cbor(ptr, ptr + len))
- static basic_json from_cbor(const T* ptr, std::size_t len,
- const bool strict = true,
- const bool allow_exceptions = true,
- const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error)
- {
- return from_cbor(ptr, ptr + len, strict, allow_exceptions, tag_handler);
- }
- JSON_HEDLEY_WARN_UNUSED_RESULT
- JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_cbor(ptr, ptr + len))
- static basic_json from_cbor(detail::span_input_adapter&& i,
- const bool strict = true,
- const bool allow_exceptions = true,
- const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error)
- {
- basic_json result;
- detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
- auto ia = i.get();
-
- const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);
- return res ? result : basic_json(value_t::discarded);
- }
-
- template<typename InputType>
- JSON_HEDLEY_WARN_UNUSED_RESULT
- static basic_json from_msgpack(InputType&& i,
- const bool strict = true,
- const bool allow_exceptions = true)
- {
- basic_json result;
- detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
- auto ia = detail::input_adapter(std::forward<InputType>(i));
- const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::msgpack, &sdp, strict);
- return res ? result : basic_json(value_t::discarded);
- }
-
- template<typename IteratorType>
- JSON_HEDLEY_WARN_UNUSED_RESULT
- static basic_json from_msgpack(IteratorType first, IteratorType last,
- const bool strict = true,
- const bool allow_exceptions = true)
- {
- basic_json result;
- detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
- auto ia = detail::input_adapter(std::move(first), std::move(last));
- const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::msgpack, &sdp, strict);
- return res ? result : basic_json(value_t::discarded);
- }
- template<typename T>
- JSON_HEDLEY_WARN_UNUSED_RESULT
- JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_msgpack(ptr, ptr + len))
- static basic_json from_msgpack(const T* ptr, std::size_t len,
- const bool strict = true,
- const bool allow_exceptions = true)
- {
- return from_msgpack(ptr, ptr + len, strict, allow_exceptions);
- }
- JSON_HEDLEY_WARN_UNUSED_RESULT
- JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_msgpack(ptr, ptr + len))
- static basic_json from_msgpack(detail::span_input_adapter&& i,
- const bool strict = true,
- const bool allow_exceptions = true)
- {
- basic_json result;
- detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
- auto ia = i.get();
-
- const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::msgpack, &sdp, strict);
- return res ? result : basic_json(value_t::discarded);
- }
-
- template<typename InputType>
- JSON_HEDLEY_WARN_UNUSED_RESULT
- static basic_json from_ubjson(InputType&& i,
- const bool strict = true,
- const bool allow_exceptions = true)
- {
- basic_json result;
- detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
- auto ia = detail::input_adapter(std::forward<InputType>(i));
- const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::ubjson, &sdp, strict);
- return res ? result : basic_json(value_t::discarded);
- }
-
- template<typename IteratorType>
- JSON_HEDLEY_WARN_UNUSED_RESULT
- static basic_json from_ubjson(IteratorType first, IteratorType last,
- const bool strict = true,
- const bool allow_exceptions = true)
- {
- basic_json result;
- detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
- auto ia = detail::input_adapter(std::move(first), std::move(last));
- const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::ubjson, &sdp, strict);
- return res ? result : basic_json(value_t::discarded);
- }
- template<typename T>
- JSON_HEDLEY_WARN_UNUSED_RESULT
- JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_ubjson(ptr, ptr + len))
- static basic_json from_ubjson(const T* ptr, std::size_t len,
- const bool strict = true,
- const bool allow_exceptions = true)
- {
- return from_ubjson(ptr, ptr + len, strict, allow_exceptions);
- }
- JSON_HEDLEY_WARN_UNUSED_RESULT
- JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_ubjson(ptr, ptr + len))
- static basic_json from_ubjson(detail::span_input_adapter&& i,
- const bool strict = true,
- const bool allow_exceptions = true)
- {
- basic_json result;
- detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
- auto ia = i.get();
-
- const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::ubjson, &sdp, strict);
- return res ? result : basic_json(value_t::discarded);
- }
-
- template<typename InputType>
- JSON_HEDLEY_WARN_UNUSED_RESULT
- static basic_json from_bson(InputType&& i,
- const bool strict = true,
- const bool allow_exceptions = true)
- {
- basic_json result;
- detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
- auto ia = detail::input_adapter(std::forward<InputType>(i));
- const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::bson, &sdp, strict);
- return res ? result : basic_json(value_t::discarded);
- }
-
- template<typename IteratorType>
- JSON_HEDLEY_WARN_UNUSED_RESULT
- static basic_json from_bson(IteratorType first, IteratorType last,
- const bool strict = true,
- const bool allow_exceptions = true)
- {
- basic_json result;
- detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
- auto ia = detail::input_adapter(std::move(first), std::move(last));
- const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::bson, &sdp, strict);
- return res ? result : basic_json(value_t::discarded);
- }
- template<typename T>
- JSON_HEDLEY_WARN_UNUSED_RESULT
- JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_bson(ptr, ptr + len))
- static basic_json from_bson(const T* ptr, std::size_t len,
- const bool strict = true,
- const bool allow_exceptions = true)
- {
- return from_bson(ptr, ptr + len, strict, allow_exceptions);
- }
- JSON_HEDLEY_WARN_UNUSED_RESULT
- JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_bson(ptr, ptr + len))
- static basic_json from_bson(detail::span_input_adapter&& i,
- const bool strict = true,
- const bool allow_exceptions = true)
- {
- basic_json result;
- detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
- auto ia = i.get();
-
- const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::bson, &sdp, strict);
- return res ? result : basic_json(value_t::discarded);
- }
-
-
-
-
-
-
-
- reference operator[](const json_pointer& ptr)
- {
- return ptr.get_unchecked(this);
- }
-
- const_reference operator[](const json_pointer& ptr) const
- {
- return ptr.get_unchecked(this);
- }
-
- reference at(const json_pointer& ptr)
- {
- return ptr.get_checked(this);
- }
-
- const_reference at(const json_pointer& ptr) const
- {
- return ptr.get_checked(this);
- }
-
- basic_json flatten() const
- {
- basic_json result(value_t::object);
- json_pointer::flatten("", *this, result);
- return result;
- }
-
- basic_json unflatten() const
- {
- return json_pointer::unflatten(*this);
- }
-
-
-
-
-
-
-
- basic_json patch(const basic_json& json_patch) const
- {
-
- basic_json result = *this;
-
- enum class patch_operations {add, remove, replace, move, copy, test, invalid};
- const auto get_op = [](const std::string & op)
- {
- if (op == "add")
- {
- return patch_operations::add;
- }
- if (op == "remove")
- {
- return patch_operations::remove;
- }
- if (op == "replace")
- {
- return patch_operations::replace;
- }
- if (op == "move")
- {
- return patch_operations::move;
- }
- if (op == "copy")
- {
- return patch_operations::copy;
- }
- if (op == "test")
- {
- return patch_operations::test;
- }
- return patch_operations::invalid;
- };
-
- const auto operation_add = [&result](json_pointer & ptr, basic_json val)
- {
-
- if (ptr.empty())
- {
- result = val;
- return;
- }
-
- json_pointer top_pointer = ptr.top();
- if (top_pointer != ptr)
- {
- result.at(top_pointer);
- }
-
- const auto last_path = ptr.back();
- ptr.pop_back();
- basic_json& parent = result[ptr];
- switch (parent.m_type)
- {
- case value_t::null:
- case value_t::object:
- {
-
- parent[last_path] = val;
- break;
- }
- case value_t::array:
- {
- if (last_path == "-")
- {
-
- parent.push_back(val);
- }
- else
- {
- const auto idx = json_pointer::array_index(last_path);
- if (JSON_HEDLEY_UNLIKELY(idx > parent.size()))
- {
-
- JSON_THROW(out_of_range::create(401, "array index " + std::to_string(idx) + " is out of range", parent));
- }
-
- parent.insert(parent.begin() + static_cast<difference_type>(idx), val);
- }
- break;
- }
-
- case value_t::string:
- case value_t::boolean:
- case value_t::number_integer:
- case value_t::number_unsigned:
- case value_t::number_float:
- case value_t::binary:
- case value_t::discarded:
- default:
- JSON_ASSERT(false);
- }
- };
-
- const auto operation_remove = [this, &result](json_pointer & ptr)
- {
-
- const auto last_path = ptr.back();
- ptr.pop_back();
- basic_json& parent = result.at(ptr);
-
- if (parent.is_object())
- {
-
- auto it = parent.find(last_path);
- if (JSON_HEDLEY_LIKELY(it != parent.end()))
- {
- parent.erase(it);
- }
- else
- {
- JSON_THROW(out_of_range::create(403, "key '" + last_path + "' not found", *this));
- }
- }
- else if (parent.is_array())
- {
-
- parent.erase(json_pointer::array_index(last_path));
- }
- };
-
- if (JSON_HEDLEY_UNLIKELY(!json_patch.is_array()))
- {
- JSON_THROW(parse_error::create(104, 0, "JSON patch must be an array of objects", json_patch));
- }
-
- for (const auto& val : json_patch)
- {
-
- const auto get_value = [&val](const std::string & op,
- const std::string & member,
- bool string_type) -> basic_json &
- {
-
- auto it = val.m_value.object->find(member);
-
- const auto error_msg = (op == "op") ? "operation" : "operation '" + op + "'";
-
- if (JSON_HEDLEY_UNLIKELY(it == val.m_value.object->end()))
- {
-
- JSON_THROW(parse_error::create(105, 0, error_msg + " must have member '" + member + "'", val));
- }
-
- if (JSON_HEDLEY_UNLIKELY(string_type && !it->second.is_string()))
- {
-
- JSON_THROW(parse_error::create(105, 0, error_msg + " must have string member '" + member + "'", val));
- }
-
- return it->second;
- };
-
- if (JSON_HEDLEY_UNLIKELY(!val.is_object()))
- {
- JSON_THROW(parse_error::create(104, 0, "JSON patch must be an array of objects", val));
- }
-
- const auto op = get_value("op", "op", true).template get<std::string>();
- const auto path = get_value(op, "path", true).template get<std::string>();
- json_pointer ptr(path);
- switch (get_op(op))
- {
- case patch_operations::add:
- {
- operation_add(ptr, get_value("add", "value", false));
- break;
- }
- case patch_operations::remove:
- {
- operation_remove(ptr);
- break;
- }
- case patch_operations::replace:
- {
-
- result.at(ptr) = get_value("replace", "value", false);
- break;
- }
- case patch_operations::move:
- {
- const auto from_path = get_value("move", "from", true).template get<std::string>();
- json_pointer from_ptr(from_path);
-
- basic_json v = result.at(from_ptr);
-
-
-
-
- operation_remove(from_ptr);
- operation_add(ptr, v);
- break;
- }
- case patch_operations::copy:
- {
- const auto from_path = get_value("copy", "from", true).template get<std::string>();
- const json_pointer from_ptr(from_path);
-
- basic_json v = result.at(from_ptr);
-
-
-
- operation_add(ptr, v);
- break;
- }
- case patch_operations::test:
- {
- bool success = false;
- JSON_TRY
- {
-
-
- success = (result.at(ptr) == get_value("test", "value", false));
- }
- JSON_INTERNAL_CATCH (out_of_range&)
- {
-
- }
-
- if (JSON_HEDLEY_UNLIKELY(!success))
- {
- JSON_THROW(other_error::create(501, "unsuccessful: " + val.dump(), val));
- }
- break;
- }
- case patch_operations::invalid:
- default:
- {
-
-
- JSON_THROW(parse_error::create(105, 0, "operation value '" + op + "' is invalid", val));
- }
- }
- }
- return result;
- }
-
- JSON_HEDLEY_WARN_UNUSED_RESULT
- static basic_json diff(const basic_json& source, const basic_json& target,
- const std::string& path = "")
- {
-
- basic_json result(value_t::array);
-
- if (source == target)
- {
- return result;
- }
- if (source.type() != target.type())
- {
-
- result.push_back(
- {
- {"op", "replace"}, {"path", path}, {"value", target}
- });
- return result;
- }
- switch (source.type())
- {
- case value_t::array:
- {
-
- std::size_t i = 0;
- while (i < source.size() && i < target.size())
- {
-
- auto temp_diff = diff(source[i], target[i], path + "/" + std::to_string(i));
- result.insert(result.end(), temp_diff.begin(), temp_diff.end());
- ++i;
- }
-
-
-
- const auto end_index = static_cast<difference_type>(result.size());
- while (i < source.size())
- {
-
-
- result.insert(result.begin() + end_index, object(
- {
- {"op", "remove"},
- {"path", path + "/" + std::to_string(i)}
- }));
- ++i;
- }
-
- while (i < target.size())
- {
- result.push_back(
- {
- {"op", "add"},
- {"path", path + "/-"},
- {"value", target[i]}
- });
- ++i;
- }
- break;
- }
- case value_t::object:
- {
-
- for (auto it = source.cbegin(); it != source.cend(); ++it)
- {
-
- const auto path_key = path + "/" + detail::escape(it.key());
- if (target.find(it.key()) != target.end())
- {
-
- auto temp_diff = diff(it.value(), target[it.key()], path_key);
- result.insert(result.end(), temp_diff.begin(), temp_diff.end());
- }
- else
- {
-
- result.push_back(object(
- {
- {"op", "remove"}, {"path", path_key}
- }));
- }
- }
-
- for (auto it = target.cbegin(); it != target.cend(); ++it)
- {
- if (source.find(it.key()) == source.end())
- {
-
- const auto path_key = path + "/" + detail::escape(it.key());
- result.push_back(
- {
- {"op", "add"}, {"path", path_key},
- {"value", it.value()}
- });
- }
- }
- break;
- }
- case value_t::null:
- case value_t::string:
- case value_t::boolean:
- case value_t::number_integer:
- case value_t::number_unsigned:
- case value_t::number_float:
- case value_t::binary:
- case value_t::discarded:
- default:
- {
-
- result.push_back(
- {
- {"op", "replace"}, {"path", path}, {"value", target}
- });
- break;
- }
- }
- return result;
- }
-
-
-
-
-
-
-
- void merge_patch(const basic_json& apply_patch)
- {
- if (apply_patch.is_object())
- {
- if (!is_object())
- {
- *this = object();
- }
- for (auto it = apply_patch.begin(); it != apply_patch.end(); ++it)
- {
- if (it.value().is_null())
- {
- erase(it.key());
- }
- else
- {
- operator[](it.key()).merge_patch(it.value());
- }
- }
- }
- else
- {
- *this = apply_patch;
- }
- }
-
- };
- NLOHMANN_BASIC_JSON_TPL_DECLARATION
- std::string to_string(const NLOHMANN_BASIC_JSON_TPL& j)
- {
- return j.dump();
- }
- }
- namespace std
- {
- template<>
- struct hash<nlohmann::json>
- {
-
- std::size_t operator()(const nlohmann::json& j) const
- {
- return nlohmann::detail::hash(j);
- }
- };
- template<>
- struct less<::nlohmann::detail::value_t>
- {
-
- bool operator()(nlohmann::detail::value_t lhs,
- nlohmann::detail::value_t rhs) const noexcept
- {
- return nlohmann::detail::operator<(lhs, rhs);
- }
- };
- #ifndef JSON_HAS_CPP_20
- template<>
- inline void swap<nlohmann::json>(nlohmann::json& j1, nlohmann::json& j2) noexcept(
- is_nothrow_move_constructible<nlohmann::json>::value&&
- is_nothrow_move_assignable<nlohmann::json>::value
- )
- {
- j1.swap(j2);
- }
- #endif
- }
- JSON_HEDLEY_NON_NULL(1)
- inline nlohmann::json operator "" _json(const char* s, std::size_t n)
- {
- return nlohmann::json::parse(s, s + n);
- }
- JSON_HEDLEY_NON_NULL(1)
- inline nlohmann::json::json_pointer operator "" _json_pointer(const char* s, std::size_t n)
- {
- return nlohmann::json::json_pointer(std::string(s, n));
- }
- #if defined(__clang__)
- #pragma clang diagnostic pop
- #endif
- #undef JSON_ASSERT
- #undef JSON_INTERNAL_CATCH
- #undef JSON_CATCH
- #undef JSON_THROW
- #undef JSON_TRY
- #undef JSON_PRIVATE_UNLESS_TESTED
- #undef JSON_HAS_CPP_11
- #undef JSON_HAS_CPP_14
- #undef JSON_HAS_CPP_17
- #undef JSON_HAS_CPP_20
- #undef NLOHMANN_BASIC_JSON_TPL_DECLARATION
- #undef NLOHMANN_BASIC_JSON_TPL
- #undef JSON_EXPLICIT
- #undef NLOHMANN_CAN_CALL_STD_FUNC_IMPL
- #undef JSON_HEDLEY_ALWAYS_INLINE
- #undef JSON_HEDLEY_ARM_VERSION
- #undef JSON_HEDLEY_ARM_VERSION_CHECK
- #undef JSON_HEDLEY_ARRAY_PARAM
- #undef JSON_HEDLEY_ASSUME
- #undef JSON_HEDLEY_BEGIN_C_DECLS
- #undef JSON_HEDLEY_CLANG_HAS_ATTRIBUTE
- #undef JSON_HEDLEY_CLANG_HAS_BUILTIN
- #undef JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE
- #undef JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE
- #undef JSON_HEDLEY_CLANG_HAS_EXTENSION
- #undef JSON_HEDLEY_CLANG_HAS_FEATURE
- #undef JSON_HEDLEY_CLANG_HAS_WARNING
- #undef JSON_HEDLEY_COMPCERT_VERSION
- #undef JSON_HEDLEY_COMPCERT_VERSION_CHECK
- #undef JSON_HEDLEY_CONCAT
- #undef JSON_HEDLEY_CONCAT3
- #undef JSON_HEDLEY_CONCAT3_EX
- #undef JSON_HEDLEY_CONCAT_EX
- #undef JSON_HEDLEY_CONST
- #undef JSON_HEDLEY_CONSTEXPR
- #undef JSON_HEDLEY_CONST_CAST
- #undef JSON_HEDLEY_CPP_CAST
- #undef JSON_HEDLEY_CRAY_VERSION
- #undef JSON_HEDLEY_CRAY_VERSION_CHECK
- #undef JSON_HEDLEY_C_DECL
- #undef JSON_HEDLEY_DEPRECATED
- #undef JSON_HEDLEY_DEPRECATED_FOR
- #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL
- #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_
- #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED
- #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES
- #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS
- #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION
- #undef JSON_HEDLEY_DIAGNOSTIC_POP
- #undef JSON_HEDLEY_DIAGNOSTIC_PUSH
- #undef JSON_HEDLEY_DMC_VERSION
- #undef JSON_HEDLEY_DMC_VERSION_CHECK
- #undef JSON_HEDLEY_EMPTY_BASES
- #undef JSON_HEDLEY_EMSCRIPTEN_VERSION
- #undef JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK
- #undef JSON_HEDLEY_END_C_DECLS
- #undef JSON_HEDLEY_FLAGS
- #undef JSON_HEDLEY_FLAGS_CAST
- #undef JSON_HEDLEY_GCC_HAS_ATTRIBUTE
- #undef JSON_HEDLEY_GCC_HAS_BUILTIN
- #undef JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE
- #undef JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE
- #undef JSON_HEDLEY_GCC_HAS_EXTENSION
- #undef JSON_HEDLEY_GCC_HAS_FEATURE
- #undef JSON_HEDLEY_GCC_HAS_WARNING
- #undef JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK
- #undef JSON_HEDLEY_GCC_VERSION
- #undef JSON_HEDLEY_GCC_VERSION_CHECK
- #undef JSON_HEDLEY_GNUC_HAS_ATTRIBUTE
- #undef JSON_HEDLEY_GNUC_HAS_BUILTIN
- #undef JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE
- #undef JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE
- #undef JSON_HEDLEY_GNUC_HAS_EXTENSION
- #undef JSON_HEDLEY_GNUC_HAS_FEATURE
- #undef JSON_HEDLEY_GNUC_HAS_WARNING
- #undef JSON_HEDLEY_GNUC_VERSION
- #undef JSON_HEDLEY_GNUC_VERSION_CHECK
- #undef JSON_HEDLEY_HAS_ATTRIBUTE
- #undef JSON_HEDLEY_HAS_BUILTIN
- #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE
- #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS
- #undef JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE
- #undef JSON_HEDLEY_HAS_EXTENSION
- #undef JSON_HEDLEY_HAS_FEATURE
- #undef JSON_HEDLEY_HAS_WARNING
- #undef JSON_HEDLEY_IAR_VERSION
- #undef JSON_HEDLEY_IAR_VERSION_CHECK
- #undef JSON_HEDLEY_IBM_VERSION
- #undef JSON_HEDLEY_IBM_VERSION_CHECK
- #undef JSON_HEDLEY_IMPORT
- #undef JSON_HEDLEY_INLINE
- #undef JSON_HEDLEY_INTEL_CL_VERSION
- #undef JSON_HEDLEY_INTEL_CL_VERSION_CHECK
- #undef JSON_HEDLEY_INTEL_VERSION
- #undef JSON_HEDLEY_INTEL_VERSION_CHECK
- #undef JSON_HEDLEY_IS_CONSTANT
- #undef JSON_HEDLEY_IS_CONSTEXPR_
- #undef JSON_HEDLEY_LIKELY
- #undef JSON_HEDLEY_MALLOC
- #undef JSON_HEDLEY_MCST_LCC_VERSION
- #undef JSON_HEDLEY_MCST_LCC_VERSION_CHECK
- #undef JSON_HEDLEY_MESSAGE
- #undef JSON_HEDLEY_MSVC_VERSION
- #undef JSON_HEDLEY_MSVC_VERSION_CHECK
- #undef JSON_HEDLEY_NEVER_INLINE
- #undef JSON_HEDLEY_NON_NULL
- #undef JSON_HEDLEY_NO_ESCAPE
- #undef JSON_HEDLEY_NO_RETURN
- #undef JSON_HEDLEY_NO_THROW
- #undef JSON_HEDLEY_NULL
- #undef JSON_HEDLEY_PELLES_VERSION
- #undef JSON_HEDLEY_PELLES_VERSION_CHECK
- #undef JSON_HEDLEY_PGI_VERSION
- #undef JSON_HEDLEY_PGI_VERSION_CHECK
- #undef JSON_HEDLEY_PREDICT
- #undef JSON_HEDLEY_PRINTF_FORMAT
- #undef JSON_HEDLEY_PRIVATE
- #undef JSON_HEDLEY_PUBLIC
- #undef JSON_HEDLEY_PURE
- #undef JSON_HEDLEY_REINTERPRET_CAST
- #undef JSON_HEDLEY_REQUIRE
- #undef JSON_HEDLEY_REQUIRE_CONSTEXPR
- #undef JSON_HEDLEY_REQUIRE_MSG
- #undef JSON_HEDLEY_RESTRICT
- #undef JSON_HEDLEY_RETURNS_NON_NULL
- #undef JSON_HEDLEY_SENTINEL
- #undef JSON_HEDLEY_STATIC_ASSERT
- #undef JSON_HEDLEY_STATIC_CAST
- #undef JSON_HEDLEY_STRINGIFY
- #undef JSON_HEDLEY_STRINGIFY_EX
- #undef JSON_HEDLEY_SUNPRO_VERSION
- #undef JSON_HEDLEY_SUNPRO_VERSION_CHECK
- #undef JSON_HEDLEY_TINYC_VERSION
- #undef JSON_HEDLEY_TINYC_VERSION_CHECK
- #undef JSON_HEDLEY_TI_ARMCL_VERSION
- #undef JSON_HEDLEY_TI_ARMCL_VERSION_CHECK
- #undef JSON_HEDLEY_TI_CL2000_VERSION
- #undef JSON_HEDLEY_TI_CL2000_VERSION_CHECK
- #undef JSON_HEDLEY_TI_CL430_VERSION
- #undef JSON_HEDLEY_TI_CL430_VERSION_CHECK
- #undef JSON_HEDLEY_TI_CL6X_VERSION
- #undef JSON_HEDLEY_TI_CL6X_VERSION_CHECK
- #undef JSON_HEDLEY_TI_CL7X_VERSION
- #undef JSON_HEDLEY_TI_CL7X_VERSION_CHECK
- #undef JSON_HEDLEY_TI_CLPRU_VERSION
- #undef JSON_HEDLEY_TI_CLPRU_VERSION_CHECK
- #undef JSON_HEDLEY_TI_VERSION
- #undef JSON_HEDLEY_TI_VERSION_CHECK
- #undef JSON_HEDLEY_UNAVAILABLE
- #undef JSON_HEDLEY_UNLIKELY
- #undef JSON_HEDLEY_UNPREDICTABLE
- #undef JSON_HEDLEY_UNREACHABLE
- #undef JSON_HEDLEY_UNREACHABLE_RETURN
- #undef JSON_HEDLEY_VERSION
- #undef JSON_HEDLEY_VERSION_DECODE_MAJOR
- #undef JSON_HEDLEY_VERSION_DECODE_MINOR
- #undef JSON_HEDLEY_VERSION_DECODE_REVISION
- #undef JSON_HEDLEY_VERSION_ENCODE
- #undef JSON_HEDLEY_WARNING
- #undef JSON_HEDLEY_WARN_UNUSED_RESULT
- #undef JSON_HEDLEY_WARN_UNUSED_RESULT_MSG
- #undef JSON_HEDLEY_FALL_THROUGH
- #endif
|