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

Method AddWithMove

CJsonObject.cpp:1039–1096  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1037
1038#if __cplusplus < 201101L
1039bool CJsonObject::AddWithMove(const std::string& strKey, CJsonObject& oJsonObject)
1040{
1041 cJSON* pFocusData = NULL;
1042 if (m_pJsonData != NULL)
1043 {
1044 pFocusData = m_pJsonData;
1045 }
1046 else if (m_pExternJsonDataRef != NULL)
1047 {
1048 pFocusData = m_pExternJsonDataRef;
1049 }
1050 else
1051 {
1052 m_pJsonData = cJSON_CreateObject();
1053 m_pKeyTravers = m_pJsonData;
1054 pFocusData = m_pJsonData;
1055 }
1056
1057 if (pFocusData == NULL)
1058 {
1059 m_strErrMsg = "json data is null!";
1060 return(false);
1061 }
1062 if (pFocusData->type != cJSON_Object)
1063 {
1064 m_strErrMsg = "not a json object! json array?";
1065 return(false);
1066 }
1067 if (cJSON_GetObjectItem(pFocusData, strKey.c_str()) != NULL)
1068 {
1069 m_strErrMsg = "key exists!";
1070 return(false);
1071 }
1072 cJSON* pJsonStruct = oJsonObject.m_pJsonData;
1073 oJsonObject.m_pJsonData = NULL;
1074 if (pJsonStruct == NULL)
1075 {
1076 m_strErrMsg = "can not move a non-independent(internal) CJsonObject from one to another.";
1077 return(false);
1078 }
1079 cJSON_AddItemToObject(pFocusData, strKey.c_str(), pJsonStruct);
1080 if (cJSON_GetObjectItem(pFocusData, strKey.c_str()) == NULL)
1081 {
1082 return(false);
1083 }
1084 std::map<std::string, CJsonObject*>::iterator iter = m_mapJsonObjectRef.find(strKey);
1085 if (iter != m_mapJsonObjectRef.end())
1086 {
1087 if (iter->second != NULL)
1088 {
1089 delete (iter->second);
1090 iter->second = NULL;
1091 }
1092 m_mapJsonObjectRef.erase(iter);
1093 }
1094 m_pKeyTravers = pFocusData;
1095 return(true);
1096}

Callers 1

mainFunction · 0.80

Calls 6

cJSON_CreateObjectFunction · 0.85
cJSON_GetObjectItemFunction · 0.85
cJSON_AddItemToObjectFunction · 0.85
cJSON_CreateArrayFunction · 0.85
cJSON_GetArraySizeFunction · 0.85
cJSON_AddItemToArrayFunction · 0.85

Tested by

no test coverage detected