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

Method ReplaceWithMove

CJsonObject.cpp:1691–1735  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1689
1690#if __cplusplus < 201101L
1691bool CJsonObject::ReplaceWithMove(const std::string& strKey, CJsonObject& oJsonObject)
1692{
1693 cJSON* pFocusData = NULL;
1694 if (m_pJsonData == NULL)
1695 {
1696 pFocusData = m_pExternJsonDataRef;
1697 }
1698 else
1699 {
1700 pFocusData = m_pJsonData;
1701 }
1702 if (pFocusData == NULL)
1703 {
1704 m_strErrMsg = "json data is null!";
1705 return(false);
1706 }
1707 if (pFocusData->type != cJSON_Object)
1708 {
1709 m_strErrMsg = "not a json object! json array?";
1710 return(false);
1711 }
1712 cJSON* pJsonStruct = oJsonObject.m_pJsonData;
1713 oJsonObject.m_pJsonData = NULL;
1714 if (pJsonStruct == NULL)
1715 {
1716 m_strErrMsg = "can not move a non-independent(internal) CJsonObject from one to another.";
1717 return(false);
1718 }
1719 cJSON_ReplaceItemInObject(pFocusData, strKey.c_str(), pJsonStruct);
1720 if (cJSON_GetObjectItem(pFocusData, strKey.c_str()) == NULL)
1721 {
1722 return(false);
1723 }
1724 std::map<std::string, CJsonObject*>::iterator iter = m_mapJsonObjectRef.find(strKey);
1725 if (iter != m_mapJsonObjectRef.end())
1726 {
1727 if (iter->second != NULL)
1728 {
1729 delete (iter->second);
1730 iter->second = NULL;
1731 }
1732 m_mapJsonObjectRef.erase(iter);
1733 }
1734 return(true);
1735}
1736#else
1737bool CJsonObject::Replace(const std::string& strKey, CJsonObject&& oJsonObject)
1738{

Callers

nothing calls this directly

Calls 4

cJSON_GetObjectItemFunction · 0.85
cJSON_ReplaceItemInArrayFunction · 0.85
cJSON_GetArrayItemFunction · 0.85

Tested by

no test coverage detected