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

Method AddAsFirstWithMove

CJsonObject.cpp:3174–3225  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 3

cJSON_CreateArrayFunction · 0.85
cJSON_GetArraySizeFunction · 0.85
cJSON_AddItemToArrayHeadFunction · 0.85

Tested by

no test coverage detected