本文整理汇总了C++中XmlNode::getType方法的典型用法代码示例。如果您正苦于以下问题:C++ XmlNode::getType方法的具体用法?C++ XmlNode::getType怎么用?C++ XmlNode::getType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XmlNode
的用法示例。
在下文中一共展示了XmlNode::getType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: generateCodeForNode
bool XmlSchema::generateCodeForNode(const XmlNode* node, String& headerCode, String& sourceCode) const
{
assert(node != NULL);
if (node->getType() == ELEMENT)
{
String structDefinition;
structDefinition += T("///////////////////////////////////////////////////////////////////////////////////////////////////\r\n");
structDefinition += T("struct ");
structDefinition += node->getName();
structDefinition += T("\r\n{\r\n");
//constructor
int index = 0;
NodeIterator iter;
for (XmlNode* child = node->getFirstChild(iter);
child != NULL;
child = node->getNextChild(iter))
{
if (child->isEmpty() && child->getType() == ELEMENT)
{
//simple type
addConstructorItem(child, structDefinition, index);
}
}
if (index > 0)
{
structDefinition += T(" {\r\n }\r\n");
}
//destructor
for (XmlNode* child = node->getFirstChild(iter);
child != NULL;
child = node->getNextChild(iter))
{
if (child->findAttribute(ATTR_RECURSIVE) != NULL
&& child->findAttribute(ATTR_MULTIPLE) == NULL)
{
//recursive pointer, need to delete
structDefinition += T(" ~");
structDefinition += node->getName();
structDefinition += T("()\r\n {\r\n if (Child != NULL)\r\n {\r\n delete Child;\r\n");
structDefinition += T(" Child = NULL;\r\n }\r\n }\r\n");
break; //can't have more than one
}
}
structDefinition += T(" void read(const slim::XmlNode* node);\r\n void write(slim::XmlNode* node) const;\r\n\r\n");
String readingCode;
readingCode += T("///////////////////////////////////////////////////////////////////////////////////////////////////\r\n");
readingCode += T("void ");
readingCode += node->getName();
readingCode += T("::read(const XmlNode* node)\r\n{\r\n assert(node != NULL);\r\n");
readingCode += T("\r\n NodeIterator iter;\r\n const XmlNode* childNode = NULL;\r\n const XmlAttribute* attribute = NULL;\r\n");
String writingCode;
writingCode += T("///////////////////////////////////////////////////////////////////////////////////////////////////\r\n");
writingCode += T("void ");
writingCode += node->getName();
writingCode += T("::write(XmlNode* node) const\r\n{\r\n assert(node != NULL);\r\n\r\n node->clearChild();\r\n node->clearAttribute();");
writingCode += T("\r\n\r\n XmlNode* childNode = NULL;\r\n XmlAttribute* attribute = NULL;\r\n");
size_t typeWidth = getNodeMemberTypeWidth(node);
for (const XmlNode* child = node->getFirstChild(iter);
child != NULL;
child = node->getNextChild(iter))
{
if (child->getType() != ELEMENT)
{
continue;
}
XmlAttribute* multiple = child->findAttribute(ATTR_MULTIPLE);
bool recursive = (child->findAttribute(ATTR_RECURSIVE) != NULL);
if (child->isEmpty() && !recursive)
{
//simple type
if (multiple != NULL && multiple->getBool())
{
addSimpleVector(child, structDefinition, typeWidth, readingCode, writingCode);
}
else
{
addSimpleMember(child, structDefinition, typeWidth, readingCode, writingCode);
}
}
else
{
//struct type
if (multiple != NULL && multiple->getBool())
{
addStructVector(child, structDefinition, typeWidth, readingCode, writingCode);
}
else
{
addStructMember(child, structDefinition, typeWidth, readingCode, writingCode);
}
}
}
structDefinition += T("};\r\n\r\n");
//.........这里部分代码省略.........
示例2: parseNodeStruct
///////////////////////////////////////////////////////////////////////////////////////////////////
//parse data schema from node
//src data node
//dst schema node
bool XmlSchema::parseNodeStruct(XmlNode* dst, XmlNode* src)
{
assert(dst != NULL);
assert(src != NULL);
NodeIterator nodeIterator;
AttributeIterator attriIterator;
for (XmlAttribute* attribute = src->getFirstAttribute(attriIterator);
attribute != NULL;
attribute = src->getNextAttribute(attriIterator))
{
XmlNode* structure = dst->findChild(attribute->getName());
if (structure == NULL)
{
//first time show up
structure = dst->addChild(attribute->getName());
structure->addAttribute(ATTR_TYPE, guessType(attribute->getString()));
structure->addAttribute(ATTR_ATTRIBUTE, T("true"));
}
}
for (XmlNode* child = src->getFirstChild(nodeIterator);
child != NULL;
child = src->getNextChild(nodeIterator))
{
if (child->getType() != ELEMENT)
{
continue;
}
XmlNode* structure = dst->findChild(child->getName());
if (structure == NULL)
{
//first time show up
bool recursive = false;
const XmlNode* parent = dst;
while (parent != NULL)
{
if (Strcmp(parent->getName(), child->getName()) == 0)
{
recursive = true;
break;
}
parent = parent->getParent();
}
structure = dst->addChild(child->getName());
if (recursive)
{
structure->addAttribute(ATTR_RECURSIVE, T("true"));
}
else if (!child->hasChild() && !child->hasAttribute())
{
//simple type, must have a type attribute
structure->addAttribute(ATTR_TYPE, guessType(child->getString()));
}
}
else if (structure->findAttribute(ATTR_ATTRIBUTE) != NULL)
{
//child and attribute can't have same name
return false;
}
XmlAttribute* multiple = structure->findAttribute(ATTR_MULTIPLE);
if (multiple == NULL || !multiple->getBool())
{
NodeIterator iter;
if (src->findFirstChild(child->getName(), iter) != NULL
&& src->findNextChild(child->getName(), iter) != NULL)
{
if (multiple == NULL)
{
multiple = structure->addAttribute(ATTR_MULTIPLE);
}
multiple->setBool(true);
}
}
if (!structure->findAttribute(ATTR_RECURSIVE) && (child->hasChild() || child->hasAttribute()))
{
parseNodeStruct(structure, child);
}
}
return true;
}