MCPcopy Create free account
hub / github.com/OpenDriveLab/OpenLane / Add

Method Add

eval/LANE_evaluation/lane2d/src/CJsonObject.cpp:1013–1073  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1011}
1012
1013bool CJsonObject::Add(const std::string& strKey, const CJsonObject& oJsonObject)
1014{
1015 cJSON* pFocusData = NULL;
1016 if (m_pJsonData != NULL)
1017 {
1018 pFocusData = m_pJsonData;
1019 }
1020 else if (m_pExternJsonDataRef != NULL)
1021 {
1022 pFocusData = m_pExternJsonDataRef;
1023 }
1024 else
1025 {
1026 m_pJsonData = cJSON_CreateObject();
1027 m_pKeyTravers = m_pJsonData;
1028 pFocusData = m_pJsonData;
1029 }
1030
1031 if (pFocusData == NULL)
1032 {
1033 m_strErrMsg = "json data is null!";
1034 return(false);
1035 }
1036 if (pFocusData->type != cJSON_Object)
1037 {
1038 m_strErrMsg = "not a json object! json array?";
1039 return(false);
1040 }
1041 if (cJSON_GetObjectItem(pFocusData, strKey.c_str()) != NULL)
1042 {
1043 m_strErrMsg = "key exists!";
1044 return(false);
1045 }
1046 cJSON* pJsonStruct = cJSON_Parse(oJsonObject.ToString().c_str(), &mc_pError) ;
1047 if (pJsonStruct == NULL)
1048 {
1049 m_strErrMsg = std::string("prase json string error at ") + mc_pError;
1050 return(false);
1051 }
1052 cJSON_AddItemToObject(pFocusData, strKey.c_str(), pJsonStruct);
1053 if (cJSON_GetObjectItem(pFocusData, strKey.c_str()) == NULL)
1054 {
1055 return(false);
1056 }
1057#if __cplusplus < 201101L
1058 std::map<std::string, CJsonObject*>::iterator iter = m_mapJsonObjectRef.find(strKey);
1059#else
1060 auto iter = m_mapJsonObjectRef.find(strKey);
1061#endif
1062 if (iter != m_mapJsonObjectRef.end())
1063 {
1064 if (iter->second != NULL)
1065 {
1066 delete (iter->second);
1067 iter->second = NULL;
1068 }
1069 m_mapJsonObjectRef.erase(iter);
1070 }

Callers

nothing calls this directly

Calls 12

cJSON_CreateObjectFunction · 0.85
cJSON_GetObjectItemFunction · 0.85
cJSON_ParseFunction · 0.85
cJSON_AddItemToObjectFunction · 0.85
cJSON_CreateStringFunction · 0.85
cJSON_CreateIntFunction · 0.85
cJSON_CreateBoolFunction · 0.85
cJSON_CreateDoubleFunction · 0.85
cJSON_CreateArrayFunction · 0.85
cJSON_GetArraySizeFunction · 0.85
cJSON_AddItemToArrayFunction · 0.85
ToStringMethod · 0.80

Tested by

no test coverage detected