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

Method AddAsFirst

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

Source from the content-addressed store, hash-verified

3175}
3176
3177bool CJsonObject::AddAsFirst(const CJsonObject& oJsonObject)
3178{
3179 cJSON* pFocusData = NULL;
3180 if (m_pJsonData != NULL)
3181 {
3182 pFocusData = m_pJsonData;
3183 }
3184 else if (m_pExternJsonDataRef != NULL)
3185 {
3186 pFocusData = m_pExternJsonDataRef;
3187 }
3188 else
3189 {
3190 m_pJsonData = cJSON_CreateArray();
3191 pFocusData = m_pJsonData;
3192 }
3193
3194 if (pFocusData == NULL)
3195 {
3196 m_strErrMsg = "json data is null!";
3197 return(false);
3198 }
3199 if (pFocusData->type != cJSON_Array)
3200 {
3201 m_strErrMsg = "not a json array! json object?";
3202 return(false);
3203 }
3204 cJSON* pJsonStruct = cJSON_Parse(oJsonObject.ToString().c_str(), &mc_pError);
3205 if (pJsonStruct == NULL)
3206 {
3207 m_strErrMsg = std::string("prase json string error at ") + mc_pError;
3208 return(false);
3209 }
3210 int iArraySizeBeforeAdd = cJSON_GetArraySize(pFocusData);
3211 cJSON_AddItemToArrayHead(pFocusData, pJsonStruct);
3212 int iArraySizeAfterAdd = cJSON_GetArraySize(pFocusData);
3213 if (iArraySizeAfterAdd == iArraySizeBeforeAdd)
3214 {
3215 return(false);
3216 }
3217#if __cplusplus < 201101L
3218 for (std::map<unsigned int, CJsonObject*>::iterator iter = m_mapJsonArrayRef.begin();
3219 iter != m_mapJsonArrayRef.end(); )
3220#else
3221 for (auto iter = m_mapJsonArrayRef.begin(); iter != m_mapJsonArrayRef.end(); )
3222#endif
3223 {
3224 if (iter->second != NULL)
3225 {
3226 delete (iter->second);
3227 iter->second = NULL;
3228 }
3229 m_mapJsonArrayRef.erase(iter++);
3230 }
3231 return(true);
3232}
3233
3234#if __cplusplus < 201101L

Callers

nothing calls this directly

Calls 9

cJSON_CreateArrayFunction · 0.85
cJSON_ParseFunction · 0.85
cJSON_GetArraySizeFunction · 0.85
cJSON_AddItemToArrayHeadFunction · 0.85
cJSON_CreateStringFunction · 0.85
cJSON_CreateIntFunction · 0.85
cJSON_CreateBoolFunction · 0.85
cJSON_CreateDoubleFunction · 0.85
ToStringMethod · 0.80

Tested by

no test coverage detected