Files
yugioh-legacy-engine/server/gframe/CXMLRegistry/CXMLNode.cpp
T
donnyandClaude Fable 5.1 da27435cdb server: import the duel server (nanahira/ygopro server at 52c868ce)
The server tree of https://code.moenext.com/nanahira/ygopro.git, branch
server, commit 52c868ce071ea0f2fcb0cf39bf2fb4151d12b90c, stock: gframe/,
premake5.lua, .ci/, LICENSE, and gframe/ygopro.rc + .ico (upstream keeps
them in resource/ and copies them in before building). No game assets, no
scripts, no ocgcore submodule: the core is ../core.

The third-party sources upstream's Windows CI downloads are vendored here
at the positions its premake expects, each with its premake fragment from
upstream's premake/ folder inside it: lua 5.4.8, sqlite 3.53.3, libevent
2.1.13-stable (tests, samples and autotools helpers left out; the files
its Windows prebuild copies into include/ left out), zlib 1.3.2 (contrib
and examples left out), xz 5.8.3 (src/liblzma + src/common only), and
irrlicht 1.9 from mycard at 20f86d25: include/ plus the source/Irrlicht
headers and the 11 .cpp files the server's zip reader project compiles.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-14 20:58:21 -07:00

175 lines
4.8 KiB
C++

#include "CXMLNode.h"
CXMLNODETYPE CXMLNode::getType() { return type; }
void CXMLNode::setType(CXMLNODETYPE newtype) { type = newtype; }
void CXMLNode::setName(const wchar_t* newname) { name = newname; }
const wchar_t* CXMLNode::getName() { return name.c_str(); }
CXMLNode *CXMLNode::getThis() { return this; }
void CXMLNode::setValue(const wchar_t* newvalue) {
value = newvalue;
}
CXMLNode *CXMLNode::getParent() {
return parent;
}
void CXMLNode::setParent(CXMLNode *newparent) {
parent = newparent;
}
/*
bool CXMLNode::getValueAsBool() {
if(!value.size()) return false;
if(value.equals_ignore_case((core::stringw)"true")) return true;
return false;
}
s32 CXMLNode::getValueAsInt() {
if(!value.size()) return 0;
return _wtoi(value.c_str());
}
const wchar_t* CXMLNode::getValueAsCStr() {
if(!value.size()) return false;
return value.c_str();
}
*/
/*
u16 CXMLNode::getChildCount() {
return children.getSize();
}
irr::core::list<CXMLNode*>::Iterator CXMLNode::getFirstChild() {
//if(children.empty()) return 0;
return children.begin();
}
irr::core::list<CXMLNode*>::Iterator CXMLNode::getLastChild() {
//if(children.empty()) return 0;
return children.getLast();
}
*/
const wchar_t* CXMLNode::getValue() {
return value.c_str();
}
void CXMLNode::addChild(CXMLNode *newchild) {
children.push_back(newchild);
}
void CXMLNode::drop() {
if(children.getSize() != 0) {
core::list<CXMLNode*>::Iterator it;
for( it = children.begin(); it != children.end(); it++ ) {
( *it )->drop();
}
children.clear();
}
}
CXMLNode *CXMLNode::findChildByName(const wchar_t *name) {
core::list<CXMLNode*>::Iterator it;
core::stringw tmp;
CXMLNode *node = NULL;
tmp = name;
for( it = children.begin(); it != children.end(); it++ ) {
if(tmp.equals_ignore_case((*it)->getName())) {
node = (*it);
break;
}
}
return node;
}
core::array<const wchar_t*> *CXMLNode::listChildrenByType(CXMLNODETYPE nodetype) {
core::array<const wchar_t*> *ret = new core::array<const wchar_t*>;
//core::stringw construct = L"";
core::list<CXMLNode*>::Iterator it;
for( it = children.begin(); it != children.end(); it++ ) {
if((*it)->getType() == nodetype) {
ret->push_front((*it)->getName());
}
}
return ret;
}
core::array<const wchar_t*> *CXMLNode::listNonNodeChildren() {
return listChildrenByType(CXMLNODETYPE_VALUE);
}
core::array<const wchar_t*> *CXMLNode::listNodeChildren() {
return listChildrenByType(CXMLNODETYPE_NODE);
}
void CXMLNode::populateTreeView(irr::gui::IGUITreeViewNode *node) {
irr::gui::IGUITreeViewNode *myNode;
irr::core::stringw myText;
core::list<CXMLNode*>::Iterator it;
// If I'm a value, I have nothing to add, my parent will do that
if(type == CXMLNODETYPE_VALUE) return;
// So I'm a node, if im not the toplevel node, write me
if(parent != NULL) {
//myText = L"(Key) ";
myText += getName();
myNode = node->addChildBack(myText.c_str());
}
else
myNode = node;
// If I dont have children, I'm done
if(children.empty()) return;
// setup my children
for( it = children.begin(); it != children.end(); it++ ) {
switch((*it)->getType()) {
case CXMLNODETYPE_NODE :
myText = L"";
myText += (core::stringw)(*it)->getName();
(*it)->populateTreeView(myNode);
break;
case CXMLNODETYPE_VALUE :
myText = L"";
myText += (core::stringw)(*it)->getName();
myText += L":";
myText += (core::stringw)(*it)->getValue();
myNode->addChildBack(myText.c_str());
}
}
}
void CXMLNode::writeOut(io::IXMLWriter* xml) {
core::array<core::stringw> names;
core::array<core::stringw> values;
core::list<CXMLNode*>::Iterator it;
bool nodeChildren = false;
// If I'm a value, I have nothing to write, I'll be written by my parent
if(type == CXMLNODETYPE_VALUE) return;
// If I'm a node with no values, which also means no children write as empty and return
if(children.empty()) {
xml->writeElement(name.c_str(),true);
xml->writeLineBreak();
return;
}
// Need to figure out myself first
for( it = children.begin(); it != children.end(); it++ ) {
// cache all my values for writing, and set a flag if I have node children, ie non empty
switch((*it)->getType()) {
case CXMLNODETYPE_VALUE:
names.push_front((core::stringw)(*it)->getName());
values.push_front((core::stringw)(*it)->getValue());
break;
case CXMLNODETYPE_NODE:
nodeChildren = true;
}
}
// At this point I just need to write myself
xml->writeElement(name.c_str(),nodeChildren?false:true,names,values);
xml->writeLineBreak();
// Now I need to see if I have to tell my node children to write
if(!nodeChildren) return;
for( it = children.begin(); it != children.end(); it++ ) {
// If I have a node child, tell it to write, recursion made easy!
if((*it)->getType() == CXMLNODETYPE_NODE) {
(*it)->writeOut(xml);
}
}
xml->writeClosingTag(name.c_str());
xml->writeLineBreak();
}