void CNodedMemoryBuffer::WriteWordField(int iFieldId, WORD wVal) { ASSERT(IsStoring()); WriteInt(iFieldId); WriteDword(sizeof(WORD)); WriteWord(wVal); }
CNodedArchive::CNodedArchive(const CString& strHeader, CFile* pFile, UINT nMode, int nBufSize, void* lpBuf): CArchive(pFile, nMode, nBufSize, lpBuf) { m_iNodeType = ID_END_OF_FIELDS; m_iFieldType = ID_END_OF_FIELDS; m_iFieldSize = 0; m_bNodedFormat = FALSE; if(IsStoring()) { int id = ID_NODED_ARCHIVE; *this << id; *this << strHeader; } else if(IsLoading()) { if(pFile->GetLength() > sizeof(int)) { int id; *this >> id; if(id != ID_NODED_ARCHIVE) { m_bNodedFormat = FALSE; return; } CString str; *this >> str; if(str != strHeader) { m_bNodedFormat = FALSE; return; } m_bNodedFormat = TRUE; } }
void CNodedMemoryBuffer::WriteIntField(int iFieldId, INT iVal) { ASSERT(IsStoring()); WriteInt(iFieldId); WriteDword(sizeof(INT)); WriteInt(iVal); }
void CNodedMemoryBuffer::WriteStringField(int iFieldId, CString strVal) { ASSERT(IsStoring()); WriteInt(iFieldId); WriteDword((strVal.GetLength()+1)*sizeof(char)); WriteString(strVal); }
///////////////////////////// Write /////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////// void CMemoryBuffer::Write(void* lpvData, DWORD dwSize) { ASSERT(IsStoring()); CheckIfSizeIsEnoughAndFixIt(dwSize); memcpy(m_lpvCurrntPos, lpvData, dwSize); m_lpvCurrntPos = (void*) (((DWORD)m_lpvCurrntPos) + dwSize); }
void CNodedMemoryBuffer::WriteField(int iFieldId, void* lpvData, DWORD dwSize) { ASSERT(IsStoring()); WriteInt(iFieldId); WriteDword(dwSize); Write(lpvData, dwSize); }
void CNodedMemoryBuffer::WriteByteField(int iFieldId, BYTE byVal) { ASSERT(IsStoring()); WriteInt(iFieldId); WriteDword(sizeof(BYTE)); WriteByte(byVal); }
void CNodedMemoryBuffer::WriteFloatField(int iFieldId, float fVal) { ASSERT(IsStoring()); WriteInt(iFieldId); WriteDword(sizeof(float)); WriteFloat(fVal); }
void CNodedMemoryBuffer::WriteStringField(int iFieldId, LPSTR lpszVal) { ASSERT(IsStoring()); WriteInt(iFieldId); WriteDword((strlen(lpszVal)+1)*sizeof(char)); WriteString(lpszVal); }
void CNodedMemoryBuffer::WriteDoubleField(int iFieldId, double dVal) { ASSERT(IsStoring()); WriteInt(iFieldId); WriteDword(sizeof(double)); WriteDouble(dVal); }
///////////////////////////// Read //////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////// void CMemoryBuffer::Read(void* lpvData, DWORD dwSize) { ASSERT(!IsStoring()); ASSERT(m_dwSize >= ((DWORD)m_lpvCurrntPos) - ((DWORD)m_lpvMemory) + dwSize); memcpy(lpvData, m_lpvCurrntPos, dwSize); m_lpvCurrntPos = (void*) (((DWORD)m_lpvCurrntPos) + dwSize); }
void CNodedMemoryBuffer::WriteBoolField(int iFieldId, BOOL bVal) { ASSERT(IsStoring()); WriteInt(iFieldId); WriteDword(sizeof(BOOL)); WriteBool(bVal); }
void CNodedMemoryBuffer::WriteLongField(int iFieldId, LONG lVal) { ASSERT(IsStoring()); WriteInt(iFieldId); WriteDword(sizeof(LONG)); WriteLong(lVal); }
void CNodedMemoryBuffer::WriteNodeHeader(int iNodeType) { ASSERT(IsStoring()); int i = ID_FIELD_IS_NODE; WriteInt(i); WriteInt(iNodeType); }
void Serialize(QDataStream& ds, QString& cs) { if(IsStoring(ds)) { ds << cs; } else { ds >> cs; } }
void CMemoryBuffer::CheckIfSizeIsEnoughAndFixIt(DWORD dwSize) { ASSERT(IsStoring()); DWORD dwSizeWritten = ((DWORD) m_lpvCurrntPos) - ((DWORD) m_lpvMemory); DWORD dwSpaceLeft = m_dwSize - dwSizeWritten; if(dwSize >= dwSpaceLeft) { Realloc(dwSize - dwSpaceLeft); } }
void CMemoryBuffer::Realloc(DWORD dwSize) { ASSERT(IsStoring()); DWORD dwSizeWritten = ((DWORD) m_lpvCurrntPos) - ((DWORD) m_lpvMemory); m_dwSize += ((dwSize / m_dwGrow) + 1) * m_dwGrow; m_lpvMemory = realloc(m_lpvMemory, m_dwSize); m_lpvCurrntPos = (void*) (((DWORD)m_lpvMemory) + dwSizeWritten); }
DWORD CMemoryBuffer::CopyData(void* lpvData, DWORD dwSize) { ASSERT(IsStoring()); DWORD dwSizeWritten = ((DWORD) m_lpvCurrntPos) - ((DWORD) m_lpvMemory); if(lpvData == NULL || dwSizeWritten > dwSize) { return dwSizeWritten; } memcpy(lpvData, m_lpvMemory, dwSizeWritten); return 0; }
void Serialize(QDataStream& ds, std::string& ss) { if(IsStoring(ds)) { QString qs(ss.c_str()); ds << qs; } else { QString qs; ds >> qs; ss = qs.toStdString(); // ss = qs.toLocal8Bit().data(); } }
int CMemoryBuffer::ReadString(LPSTR lpszVal, int iSize)//return 0 if size was Enough or the size if not (size includes the null termination char) { ASSERT(!IsStoring()); int iRealSize; for(iRealSize = 1; ; iRealSize++) { ASSERT(m_dwSize >= ((DWORD)m_lpvCurrntPos) - ((DWORD)m_lpvMemory) + iRealSize - 1); if(*((char*)((DWORD)m_lpvCurrntPos) + iRealSize - 1) == '\0') break; } if(lpszVal != NULL && iRealSize <= iSize) { Read(lpszVal, iRealSize); return 0; } else return iRealSize; }
CXMLArchiveNode* CXMLArchive::GetNode(LPCTSTR nodeNameStr) { CString nodeName(nodeNameStr); try { #ifdef USE_MSXML BSTR nodeNameBSTR = nodeName.AllocSysString(); MSXML::IXMLDOMNodePtr fatherNodePtr; #else CMarkup* fatherNodePtr; #endif if (m_nodeList.size() == 0) { fatherNodePtr = m_xmlDocPtr; } else { fatherNodePtr = m_nodeList.top()->m_nodePtr; } if (fatherNodePtr == NULL) { return NULL; } if (IsStoring()) { #ifdef USE_MSXML // Archive is storing CXMLArchiveNode* xmlArchiveNodePtr = new CXMLArchiveNode(this, m_xmlDocPtr->createElement(nodeNameBSTR), fatherNodePtr); ::SysFreeString(nodeNameBSTR); m_nodeList.push(xmlArchiveNodePtr); return xmlArchiveNodePtr; #endif // Archive is storing m_xmlDocPtr->AddChildElem(nodeName); CMarkup* childnodep = new CMarkup(m_xmlDocPtr->GetDoc()); childnodep = m_xmlDocPtr; m_xmlDocPtr->ResetChildPos(); CXMLArchiveNode* xmlArchiveNodePtr = new CXMLArchiveNode(this, childnodep, //m_xmlDocPtr->createElement(nodeNameBSTR), fatherNodePtr); m_nodeList.push(xmlArchiveNodePtr); return xmlArchiveNodePtr; } // Archive is Loading //MSXML::IXMLDOMNodeListPtr nodeListPtr; //MSXML::IXMLDOMNodePtr nodePtr; CMarkup* nodeListPtr; CMarkup* nodePtr; // If child node list is not empty, we are loading using the tags to // create CObject derived objects or collections (like CArray<Cobject* CObject*>, use child list #ifdef USE_MSXML if (m_nodeList.size() > 0) { CXMLArchiveNode* xmlNodePtr = m_nodeList.top(); nodeListPtr = xmlNodePtr->m_childNodeListPtr; if (nodeListPtr != NULL && nodeListPtr->length > 0) { int childIndex = xmlNodePtr->m_childIndex; if (childIndex < nodeListPtr->length) { nodeListPtr->get_item(childIndex, &nodePtr); CXMLArchiveNode* xmlArchiveNodePtr = new CXMLArchiveNode(this, nodePtr, m_xmlDocPtr); m_nodeList.push(xmlArchiveNodePtr); ::SysFreeString(nodeNameBSTR); return xmlArchiveNodePtr; } ASSERT(FALSE); } } #else if (m_nodeList.size() > 0) { CXMLArchiveNode* xmlNodePtr = m_nodeList.top(); nodeListPtr = xmlNodePtr->m_childNodeListPtr; //Block added to calcule length when using CMarkup int length = 0; if (nodeListPtr != NULL){ nodeListPtr->ResetMainPos(); while (nodeListPtr->FindElem()) { length++; } nodeListPtr->ResetMainPos(); } if (nodeListPtr != NULL && length > 0) { int childIndex = xmlNodePtr->m_childIndex; if (childIndex < length) { int index = 0; /*if (nodeListPtr->FindChildElem()) {*/ while (nodeListPtr->FindElem() && index < childIndex) { index++; } nodePtr = new CMarkup(); nodePtr = nodeListPtr; //nodeListPtr->ResetChildPos(); /*}*/ CXMLArchiveNode* xmlArchiveNodePtr = new CXMLArchiveNode(this, nodePtr, m_xmlDocPtr); m_nodeList.push(xmlArchiveNodePtr); return xmlArchiveNodePtr; } ASSERT(FALSE); } } #endif #ifdef USE_MSXML // Get all nodes with this name if (MSXML::IXMLDOMDocumentPtr(fatherNodePtr) != NULL) { // First level node in document ASSERT(!nodeName.IsEmpty()); nodeListPtr = MSXML::IXMLDOMDocumentPtr(fatherNodePtr)->getElementsByTagName(nodeNameBSTR); } else { // Get node with desired name nodeListPtr = MSXML::IXMLDOMElementPtr(fatherNodePtr)->getElementsByTagName(nodeNameBSTR); } ::SysFreeString(nodeNameBSTR); #else bool bResult=fatherNodePtr->FindElem(nodeName); nodeListPtr = new CMarkup(); nodeListPtr = fatherNodePtr; #endif //Get child index from m_nodeList int childIndex = 0; if (m_nodeList.size() > 0) { childIndex = m_nodeList.top()->m_childIndex; } #ifdef USE_MSXML if (childIndex < nodeListPtr->length) { nodeListPtr->get_item(childIndex, &nodePtr); } #else //Block added to calcule length when using CMarkup int length = 0; nodeListPtr->ResetMainPos(); while (nodeListPtr->FindElem()) { length++; } nodeListPtr->ResetMainPos(); if (childIndex < length) { int index = 0; //Check if it has child elements and go inside if so if (nodeName.MakeLower()=="svg" && nodeListPtr->FindChildElem()) { while (index < childIndex && nodeListPtr->FindElem()) { index++; } nodeListPtr->IntoElem(); nodePtr = new CMarkup(); nodePtr = nodeListPtr; nodeListPtr->ResetMainPos(); } else { while (index < childIndex && nodeListPtr->FindElem(nodeName)) { index++; } nodePtr = new CMarkup(); nodePtr = nodeListPtr; } } #endif CXMLArchiveNode* xmlArchiveNodePtr = new CXMLArchiveNode(this, nodePtr, m_xmlDocPtr); m_nodeList.push(xmlArchiveNodePtr); return xmlArchiveNodePtr; } catch (...) { } return NULL; }
CMemoryBuffer::~CMemoryBuffer() { if(IsStoring()) free(m_lpvMemory); }
void CNodedMemoryBuffer::WriteEndOfFields() { ASSERT(IsStoring()); int i = ID_END_OF_FIELDS; WriteInt(i); }