void CImageLoader::ReadData(void) { BSTR nodeName; m_hr = m_pDocument->get_documentElement(&m_pElement); if (FAILED(m_hr) || m_pElement == NULL) { AfxMessageBox(L"Empty document!"); } // ROOT 노드에 이름을 알아오자 m_pElement->get_nodeName(&nodeName); TRACE(L"------------------------------------------\n"); TRACE(L"ROOT NODE : %s\n", CString(nodeName)); TRACE(L"------------------------------------------\n"); // CHILD 를 위해서 준비중 MSXML::IXMLDOMNode* pChild = NULL; m_hr = m_pElement->get_firstChild(&pChild); if (!m_bGdiPlus) { FindChildNode(pChild); } else { #ifdef _GDIPLUS_H FindChildNodeGdiPlus(pChild); #endif; } SysFreeString(nodeName); }
Node* Node::AddChildNode(Node* child) { QString key(child->GetName()); mChildren.insert(key, child); mChildren[key].SetParent(this); mChildren[key].Initialize(); return FindChildNode(key, false); }
bool XmlConfig::DoReadString(const wxString& key, wxString *pStr) const { wxXmlNode* node = FindChildNode(m_pathNode, key); if (node != NULL && ReadXmlNode(node, key, *pStr)) { return true; } else { return false; } }
Node* Node::AddChildNode(Node* child) { if(child != nullptr) { QString key(child->GetName()); mChildren.insert(key, child); mChildren[key].SetParent(this); mChildren[key].Initialize(); if(!mIsEnabled) child->Disable(); return FindChildNode(key, false); } else { return nullptr; } }
bool XmlConfig::DoReadLong(const wxString& key, long *pl) const { wxXmlNode* node = FindChildNode(m_pathNode, key); wxString data; if (node != NULL && ReadXmlNode(node, key, data)) { return data.ToLong(pl); } else { return false; } }
wxXmlNode* XmlConfig::GetGroupNode(const wxArrayString& parts) const { wxXmlNode* node = m_root; for (unsigned int i = 0; i < parts.Count(); ++i) { wxXmlNode* child = FindChildNode(node, parts[i]); if (child == NULL) { return NULL; } node = child; } return node; }
void Node::RemoveChildNode(const std::string& name) { if(FindChildNode(name, false) != nullptr) { mChildren.erase(name); } }
void Node::RemoveChildNode(const QString& name) { if(FindChildNode(name, false) != nullptr) { FindChildNode(name, false)->Deinitialize(); // destroy recursively mChildren.erase(name); } }
static void AppendSubtree ( const XMP_Node * sourceNode, XMP_Node * destParent, const bool replaceOld, const bool deleteEmpty ) { XMP_NodePtrPos destPos; XMP_Node * destNode = FindChildNode ( destParent, sourceNode->name.c_str(), kXMP_ExistingOnly, &destPos ); bool valueIsEmpty = false; if ( deleteEmpty ) { if ( XMP_PropIsSimple ( sourceNode->options ) ) { valueIsEmpty = sourceNode->value.empty(); } else { valueIsEmpty = sourceNode->children.empty(); } } if ( deleteEmpty & valueIsEmpty ) { if ( destNode != 0 ) { delete ( destNode ); destParent->children.erase ( destPos ); } } else if ( destNode == 0 ) { // The one easy case, the destination does not exist. CloneSubtree ( sourceNode, destParent ); } else if ( replaceOld ) { // The destination exists and should be replaced. destNode->value = sourceNode->value; // *** Should use SetNode. destNode->options = sourceNode->options; destNode->RemoveChildren(); destNode->RemoveQualifiers(); CloneOffspring ( sourceNode, destNode ); #if 0 // *** XMP_DebugBuild destNode->_valuePtr = destNode->value.c_str(); #endif } else { // The destination exists and is not totally replaced. Structs and arrays are merged. XMP_OptionBits sourceForm = sourceNode->options & kXMP_PropCompositeMask; XMP_OptionBits destForm = destNode->options & kXMP_PropCompositeMask; if ( sourceForm != destForm ) return; if ( sourceForm == kXMP_PropValueIsStruct ) { // To merge a struct process the fields recursively. E.g. add simple missing fields. The // recursive call to AppendSubtree will handle deletion for fields with empty values. for ( size_t sourceNum = 0, sourceLim = sourceNode->children.size(); sourceNum != sourceLim; ++sourceNum ) { const XMP_Node * sourceField = sourceNode->children[sourceNum]; AppendSubtree ( sourceField, destNode, replaceOld, deleteEmpty ); if ( deleteEmpty && destNode->children.empty() ) { delete ( destNode ); destParent->children.erase ( destPos ); } } } else if ( sourceForm & kXMP_PropArrayIsAltText ) { // Merge AltText arrays by the xml:lang qualifiers. Make sure x-default is first. Make a // special check for deletion of empty values. Meaningful in AltText arrays because the // xml:lang qualifier provides unambiguous source/dest correspondence. for ( size_t sourceNum = 0, sourceLim = sourceNode->children.size(); sourceNum != sourceLim; ++sourceNum ) { const XMP_Node * sourceItem = sourceNode->children[sourceNum]; if ( sourceItem->qualifiers.empty() || (sourceItem->qualifiers[0]->name != "xml:lang") ) continue; XMP_Index destIndex = LookupLangItem ( destNode, sourceItem->qualifiers[0]->value ); if ( deleteEmpty && sourceItem->value.empty() ) { if ( destIndex != -1 ) { delete ( destNode->children[destIndex] ); destNode->children.erase ( destNode->children.begin() + destIndex ); if ( destNode->children.empty() ) { delete ( destNode ); destParent->children.erase ( destPos ); } } } else { if ( destIndex != -1 ) continue; // Not replacing, keep the existing item. if ( (sourceItem->qualifiers[0]->value != "x-default") || destNode->children.empty() ) { CloneSubtree ( sourceItem, destNode ); } else { XMP_Node * destItem = new XMP_Node ( destNode, sourceItem->name, sourceItem->value, sourceItem->options ); CloneOffspring ( sourceItem, destItem ); destNode->children.insert ( destNode->children.begin(), destItem ); } } } } else if ( sourceForm & kXMP_PropValueIsArray ) { // Merge other arrays by item values. Don't worry about order or duplicates. Source // items with empty values do not cause deletion, that conflicts horribly with merging. for ( size_t sourceNum = 0, sourceLim = sourceNode->children.size(); sourceNum != sourceLim; ++sourceNum ) { const XMP_Node * sourceItem = sourceNode->children[sourceNum]; size_t destNum, destLim; for ( destNum = 0, destLim = destNode->children.size(); destNum != destLim; ++destNum ) { const XMP_Node * destItem = destNode->children[destNum]; if ( ItemValuesMatch ( sourceItem, destItem ) ) break; } if ( destNum == destLim ) CloneSubtree ( sourceItem, destNode ); } } } } // AppendSubtree
// ѹËõ int CYTCompress::Compress(char * inbuf, unsigned short inlen, char * outbuf, unsigned short outlen) { if(inlen > 8192) { return -1; } unsigned char * buf = (unsigned char *)inbuf; Init(); memset(outbuf, 0, outlen); unsigned short limitsize = min(outlen, inlen); int errorcode; int inputptr = 1; int charecter; unsigned int index; int nextcode = 258; unsigned int outbitptr = 0; unsigned int outbitsize = 9; int nextbumpsize = 512; int stringcode = (int)buf[0]; while(inputptr < inlen) { charecter = (int)buf[inputptr]; index = FindChildNode(stringcode, charecter); if(index == (unsigned int)(-1)) { return -1; } if(m_dictory[index].codevalue != -1) { stringcode = (int)m_dictory[index].codevalue; } else { m_dictory[index].codevalue = (short)nextcode; m_dictory[index].parentcode = (short)stringcode; m_dictory[index].character = (char)charecter; if((errorcode = PutBit(outbuf, limitsize, outbitptr, stringcode, outbitsize)) < 0) { return errorcode; } nextcode++; stringcode = charecter; outbitptr += outbitsize; if(nextcode >= nextbumpsize) { if((errorcode = PutBit(outbuf, limitsize, outbitptr, (unsigned int)257, outbitsize)) < 0) { return errorcode; } outbitptr += outbitsize; outbitsize++; nextbumpsize = nextbumpsize << 1; } } inputptr++; } if((errorcode = PutBit(outbuf, limitsize, outbitptr, stringcode, outbitsize)) < 0) { return errorcode; } if((errorcode = PutBit(outbuf, limitsize, outbitptr+outbitsize, 256, outbitsize)) < 0) { return errorcode; } outbitptr += outbitsize + outbitsize; int retsize = 0; if((outbitptr % 8) != 0) { retsize = (outbitptr >> 3) + 1; }
bool XmlConfig::HasEntry(const wxString& strName) const { return FindChildNode(m_pathNode, strName) != NULL; }
static void FixupQualifiedNode ( XMP_Node * xmpParent ) { size_t qualNum, qualLim; size_t childNum, childLim; XMP_Enforce ( (xmpParent->options & kXMP_PropValueIsStruct) && (! xmpParent->children.empty()) ); XMP_Node * valueNode = xmpParent->children[0]; XMP_Enforce ( valueNode->name == "rdf:value" ); xmpParent->qualifiers.reserve ( xmpParent->qualifiers.size() + xmpParent->children.size() + valueNode->qualifiers.size() ); // Move the qualifiers on the value node to the parent. Make sure an xml:lang qualifier stays at // the front. Check for duplicate names between the value node's qualifiers and the parent's // children. The parent's children are about to become qualifiers. Check here, between the // groups. Intra-group duplicates are caught by AddChildNode. qualNum = 0; qualLim = valueNode->qualifiers.size(); if ( valueNode->options & kXMP_PropHasLang ) { if ( xmpParent->options & kXMP_PropHasLang ) XMP_Throw ( "Redundant xml:lang for rdf:value element", kXMPErr_BadXMP ); XMP_Node * langQual = valueNode->qualifiers[0]; XMP_Assert ( langQual->name == "xml:lang" ); langQual->parent = xmpParent; xmpParent->options |= kXMP_PropHasLang; if ( xmpParent->qualifiers.empty() ) { xmpParent->qualifiers.push_back ( langQual ); // *** Should use utilities to add qual & set parent. } else { xmpParent->qualifiers.insert ( xmpParent->qualifiers.begin(), langQual ); } valueNode->qualifiers[0] = 0; // We just moved it to the parent. qualNum = 1; // Start the remaining copy after the xml:lang qualifier. } for ( ; qualNum != qualLim; ++qualNum ) { XMP_Node * currQual = valueNode->qualifiers[qualNum]; if ( FindChildNode ( xmpParent, currQual->name.c_str(), kXMP_ExistingOnly ) != 0 ) { XMP_Throw ( "Duplicate qualifier node", kXMPErr_BadXMP ); } currQual->parent = xmpParent; xmpParent->qualifiers.push_back ( currQual ); valueNode->qualifiers[qualNum] = 0; // We just moved it to the parent. } valueNode->qualifiers.clear(); // ! There should be nothing but null pointers. // Change the parent's other children into qualifiers. This loop starts at 1, child 0 is the // rdf:value node. Put xml:lang at the front, append all others. for ( childNum = 1, childLim = xmpParent->children.size(); childNum != childLim; ++childNum ) { XMP_Node * currQual = xmpParent->children[childNum]; bool isLang = (currQual->name == "xml:lang"); currQual->options |= kXMP_PropIsQualifier; currQual->parent = xmpParent; if ( isLang ) { if ( xmpParent->options & kXMP_PropHasLang ) XMP_Throw ( "Duplicate xml:lang qualifier", kXMPErr_BadXMP ); xmpParent->options |= kXMP_PropHasLang; } else if ( currQual->name == "rdf:type" ) { xmpParent->options |= kXMP_PropHasType; } if ( (! isLang) || xmpParent->qualifiers.empty() ) { xmpParent->qualifiers.push_back ( currQual ); } else { xmpParent->qualifiers.insert ( xmpParent->qualifiers.begin(), currQual ); } xmpParent->children[childNum] = 0; // We just moved it to the qualifiers. } if ( ! xmpParent->qualifiers.empty() ) xmpParent->options |= kXMP_PropHasQualifiers; // Move the options and value last, other checks need the parent's original options. Move the // value node's children to be the parent's children. Delete the now useless value node. XMP_Assert ( xmpParent->options & (kXMP_PropValueIsStruct | kRDF_HasValueElem) ); xmpParent->options &= ~ (kXMP_PropValueIsStruct | kRDF_HasValueElem); xmpParent->options |= valueNode->options; xmpParent->value.swap ( valueNode->value ); #if 0 // *** XMP_DebugBuild xmpParent->_valuePtr = xmpParent->value.c_str(); #endif xmpParent->children[0] = 0; // ! Remove the value node itself before the swap. xmpParent->children.swap ( valueNode->children ); for ( size_t childNum = 0, childLim = xmpParent->children.size(); childNum != childLim; ++childNum ) { XMP_Node * currChild = xmpParent->children[childNum]; currChild->parent = xmpParent; } delete valueNode; } // FixupQualifiedNode
static XMP_Node * AddChildNode ( XMP_Node * xmpParent, const XML_Node & xmlNode, const XMP_StringPtr value, bool isTopLevel ) { #if 0 cout << "AddChildNode, parent = " << xmpParent->name << ", child = " << xmlNode.name; cout << ", value = \"" << value << '"'; if ( isTopLevel ) cout << ", top level"; cout << endl; #endif if ( xmlNode.ns.empty() ) { XMP_Throw ( "XML namespace required for all elements and attributes", kXMPErr_BadRDF ); } XMP_StringPtr childName = xmlNode.name.c_str(); const bool isArrayItem = (xmlNode.name == "rdf:li"); const bool isValueNode = (xmlNode.name == "rdf:value"); XMP_OptionBits childOptions = 0; if ( isTopLevel ) { // Lookup the schema node, adjust the XMP parent pointer. XMP_Assert ( xmpParent->parent == 0 ); // Incoming parent must be the tree root. XMP_Node * schemaNode = FindSchemaNode ( xmpParent, xmlNode.ns.c_str(), kXMP_CreateNodes ); if ( schemaNode->options & kXMP_NewImplicitNode ) schemaNode->options ^= kXMP_NewImplicitNode; // Clear the implicit node bit. // *** Should use "opt &= ~flag" (no conditional), need runtime check for proper 32 bit code. xmpParent = schemaNode; // If this is an alias set the isAlias flag in the node and the hasAliases flag in the tree. if ( sRegisteredAliasMap->find ( xmlNode.name ) != sRegisteredAliasMap->end() ) { childOptions |= kXMP_PropIsAlias; schemaNode->parent->options |= kXMP_PropHasAliases; } } // Make sure that this is not a duplicate of a named node. if ( ! (isArrayItem | isValueNode) ) { if ( FindChildNode ( xmpParent, childName, kXMP_ExistingOnly ) != 0 ) { XMP_Throw ( "Duplicate property or field node", kXMPErr_BadXMP ); } } // Add the new child to the XMP parent node. XMP_Node * newChild = new XMP_Node ( xmpParent, childName, value, childOptions ); if ( (! isValueNode) || xmpParent->children.empty() ) { xmpParent->children.push_back ( newChild ); } else { xmpParent->children.insert ( xmpParent->children.begin(), newChild ); } if ( isValueNode ) { if ( isTopLevel || (! (xmpParent->options & kXMP_PropValueIsStruct)) ) XMP_Throw ( "Misplaced rdf:value element", kXMPErr_BadRDF ); xmpParent->options |= kRDF_HasValueElem; } if ( isArrayItem ) { if ( ! (xmpParent->options & kXMP_PropValueIsArray) ) XMP_Throw ( "Misplaced rdf:li element", kXMPErr_BadRDF ); newChild->name = kXMP_ArrayItemName; #if 0 // *** XMP_DebugBuild newChild->_namePtr = newChild->name.c_str(); #endif } return newChild; } // AddChildNode