MCPcopy Create free account
hub / github.com/Bwar/CJsonObject / AddAsFirst

Method AddAsFirst

CJsonObject.cpp:3116–3171  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3114}
3115
3116bool CJsonObject::AddAsFirst(const CJsonObject& oJsonObject)
3117{
3118 cJSON* pFocusData = NULL;
3119 if (m_pJsonData != NULL)
3120 {
3121 pFocusData = m_pJsonData;
3122 }
3123 else if (m_pExternJsonDataRef != NULL)
3124 {
3125 pFocusData = m_pExternJsonDataRef;
3126 }
3127 else
3128 {
3129 m_pJsonData = cJSON_CreateArray();
3130 pFocusData = m_pJsonData;
3131 }
3132
3133 if (pFocusData == NULL)
3134 {
3135 m_strErrMsg = "json data is null!";
3136 return(false);
3137 }
3138 if (pFocusData->type != cJSON_Array)
3139 {
3140 m_strErrMsg = "not a json array! json object?";
3141 return(false);
3142 }
3143 cJSON* pJsonStruct = cJSON_Parse(oJsonObject.ToString().c_str(), &mc_pError);
3144 if (pJsonStruct == NULL)
3145 {
3146 m_strErrMsg = std::string("prase json string error at ") + mc_pError;
3147 return(false);
3148 }
3149 int iArraySizeBeforeAdd = cJSON_GetArraySize(pFocusData);
3150 cJSON_AddItemToArrayHead(pFocusData, pJsonStruct);
3151 int iArraySizeAfterAdd = cJSON_GetArraySize(pFocusData);
3152 if (iArraySizeAfterAdd == iArraySizeBeforeAdd)
3153 {
3154 return(false);
3155 }
3156#if __cplusplus < 201101L
3157 for (std::map<unsigned int, CJsonObject*>::iterator iter = m_mapJsonArrayRef.begin();
3158 iter != m_mapJsonArrayRef.end(); )
3159#else
3160 for (auto iter = m_mapJsonArrayRef.begin(); iter != m_mapJsonArrayRef.end(); )
3161#endif
3162 {
3163 if (iter->second != NULL)
3164 {
3165 delete (iter->second);
3166 iter->second = NULL;
3167 }
3168 m_mapJsonArrayRef.erase(iter++);
3169 }
3170 return(true);
3171}
3172
3173#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