Exemple #1
0
void RecurseSave(TiXmlNode * pParentNode, CCObject * pParentObj)
{
  if (pParentObj->isOfClass(CCObject::ClassOfCCDictionary))
  {
    TiXmlElement * pDictElement = new TiXmlElement("dict");
    pParentNode->LinkEndChild(pDictElement);

    CCDictionary * pDict = (CCDictionary *)pParentObj;
    for (CCDictionary::iterator it = pDict->begin(); it != pDict->end(); it++)
    {
      TiXmlElement * pKeyElement = new TiXmlElement("key");
      {
        TiXmlText * pKeyText = new TiXmlText(it->first.c_str());
        pKeyElement->LinkEndChild(pKeyText);
      }
      pDictElement->LinkEndChild(pKeyElement);
      CCObject * pObject = it->second;
      RecurseSave(pDictElement, pObject);
    }
  }
  else if (pParentObj->isOfClass(CCObject::ClassOfCCArray))
  {
    TiXmlElement * pArrayElement = new TiXmlElement("array");
    pParentNode->LinkEndChild(pArrayElement);

    CCArray * pValue = (CCArray *)pParentObj;
    for (CCArray::iterator it = pValue->begin(); it != pValue->end(); it++)
    {
      CCObject * pObject = *it;
      RecurseSave(pArrayElement, pObject);
    }
  }
  else if (pParentObj->isOfClass(CCObject::ClassOfCCString))
  {
    CCString * pValue = (CCString *)pParentObj;
    TiXmlElement * pValueElement = new TiXmlElement("string");
    {
      TiXmlText * pValueText = new TiXmlText(ConvertToAString(pValue->c_str()).c_str());
      pValueElement->LinkEndChild(pValueText);
    }
    pParentNode->LinkEndChild(pValueElement);
  }
  else if (pParentObj->isOfClass(CCObject::ClassOfCCBool))
  {
    CCBool * pValue = (CCBool *)pParentObj;
    TiXmlElement * pValueElement = new TiXmlElement(*pValue ? "true" : "false");
    pParentNode->LinkEndChild(pValueElement);
  }
  else if (pParentObj->isOfClass(CCObject::ClassOfCCInteger))
  {
    CCInteger * pValue = (CCInteger *)pParentObj;
    TiXmlElement * pValueElement = new TiXmlElement("integer");
    {
      char szBuf[64] = {0};
      sprintf(szBuf, "%d", (int)(*pValue));
      TiXmlText * pValueText = new TiXmlText(szBuf);
      pValueElement->LinkEndChild(pValueText);
    }
    pParentNode->LinkEndChild(pValueElement);
  }
  else if (pParentObj->isOfClass(CCObject::ClassOfCCReal))
  {
    CCReal * pValue = (CCReal *)pParentObj;
    TiXmlElement * pValueElement = new TiXmlElement("real");
    {
      TiXmlText * pValueText = new TiXmlText(FloatToString((double)(*pValue)));
      pValueElement->LinkEndChild(pValueText);
    }
    pParentNode->LinkEndChild(pValueElement);
  }
  else if (pParentObj->isOfClass(CCObject::ClassOfCCDate))
  {
    CCDate * pValue = (CCDate *)pParentObj;
    TiXmlElement * pValueElement = new TiXmlElement("date");
    {
      char szBuf[64] = {0};
      getTimeString(*pValue, szBuf);
      TiXmlText * pValueText = new TiXmlText(szBuf);
      pValueElement->LinkEndChild(pValueText);
    }
    pParentNode->LinkEndChild(pValueElement);
  }
}