| 1074 | |
| 1075 | #if __cplusplus < 201101L |
| 1076 | bool CJsonObject::AddWithMove(const std::string& strKey, CJsonObject& oJsonObject) |
| 1077 | { |
| 1078 | cJSON* pFocusData = NULL; |
| 1079 | if (m_pJsonData != NULL) |
| 1080 | { |
| 1081 | pFocusData = m_pJsonData; |
| 1082 | } |
| 1083 | else if (m_pExternJsonDataRef != NULL) |
| 1084 | { |
| 1085 | pFocusData = m_pExternJsonDataRef; |
| 1086 | } |
| 1087 | else |
| 1088 | { |
| 1089 | m_pJsonData = cJSON_CreateObject(); |
| 1090 | m_pKeyTravers = m_pJsonData; |
| 1091 | pFocusData = m_pJsonData; |
| 1092 | } |
| 1093 | |
| 1094 | if (pFocusData == NULL) |
| 1095 | { |
| 1096 | m_strErrMsg = "json data is null!"; |
| 1097 | return(false); |
| 1098 | } |
| 1099 | if (pFocusData->type != cJSON_Object) |
| 1100 | { |
| 1101 | m_strErrMsg = "not a json object! json array?"; |
| 1102 | return(false); |
| 1103 | } |
| 1104 | if (cJSON_GetObjectItem(pFocusData, strKey.c_str()) != NULL) |
| 1105 | { |
| 1106 | m_strErrMsg = "key exists!"; |
| 1107 | return(false); |
| 1108 | } |
| 1109 | cJSON* pJsonStruct = oJsonObject.m_pJsonData; |
| 1110 | oJsonObject.m_pJsonData = NULL; |
| 1111 | if (pJsonStruct == NULL) |
| 1112 | { |
| 1113 | m_strErrMsg = "can not move a non-independent(internal) CJsonObject from one to another."; |
| 1114 | return(false); |
| 1115 | } |
| 1116 | cJSON_AddItemToObject(pFocusData, strKey.c_str(), pJsonStruct); |
| 1117 | if (cJSON_GetObjectItem(pFocusData, strKey.c_str()) == NULL) |
| 1118 | { |
| 1119 | return(false); |
| 1120 | } |
| 1121 | std::map<std::string, CJsonObject*>::iterator iter = m_mapJsonObjectRef.find(strKey); |
| 1122 | if (iter != m_mapJsonObjectRef.end()) |
| 1123 | { |
| 1124 | if (iter->second != NULL) |
| 1125 | { |
| 1126 | delete (iter->second); |
| 1127 | iter->second = NULL; |
| 1128 | } |
| 1129 | m_mapJsonObjectRef.erase(iter); |
| 1130 | } |
| 1131 | m_pKeyTravers = pFocusData; |
| 1132 | return(true); |
| 1133 | } |
nothing calls this directly
no test coverage detected