Skip to content

Commit

Permalink
Implement XML::hasSimpleContent() and hasComplexContent()
Browse files Browse the repository at this point in the history
  • Loading branch information
aajanki authored and alexp-sssup committed Apr 21, 2011
1 parent 8ad888f commit 21c5095
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
44 changes: 44 additions & 0 deletions scripting/toplevel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,8 @@ void XML::sinit(Class_base* c)
c->setMethodByQName("attributes",AS3,Class<IFunction>::getFunction(attributes),true);
c->setMethodByQName("localName",AS3,Class<IFunction>::getFunction(localName),true);
c->setMethodByQName("appendChild",AS3,Class<IFunction>::getFunction(appendChild),true);
c->setMethodByQName("hasSimpleContent",AS3,Class<IFunction>::getFunction(_hasSimpleContent),true);
c->setMethodByQName("hasComplexContent",AS3,Class<IFunction>::getFunction(_hasComplexContent),true);
}

void XML::buildFromString(const string& str)
Expand Down Expand Up @@ -756,6 +758,48 @@ ASFUNCTIONBODY(XML,children)
return retObj;
}

ASFUNCTIONBODY(XML,_hasSimpleContent)
{
XML *th=static_cast<XML*>(obj);
return abstract_b(th->hasSimpleContent());
}

ASFUNCTIONBODY(XML,_hasComplexContent)
{
XML *th=static_cast<XML*>(obj);
return abstract_b(th->hasComplexContent());
}

bool XML::hasSimpleContent() const
{
xmlElementType nodetype=node->cobj()->type;
if(nodetype==XML_COMMENT_NODE || nodetype==XML_PI_NODE)
return false;

const xmlpp::Node::NodeList& children=node->get_children();
xmlpp::Node::NodeList::const_iterator it=children.begin();
for(;it!=children.end();++it)
{
if((*it)->cobj()->type==XML_ELEMENT_NODE)
return false;
}

return true;
}

bool XML::hasComplexContent() const
{
const xmlpp::Node::NodeList& children=node->get_children();
xmlpp::Node::NodeList::const_iterator it=children.begin();
for(;it!=children.end();++it)
{
if((*it)->cobj()->type==XML_ELEMENT_NODE)
return true;
}

return false;
}

void XML::recursiveGetDescendantsByQName(XML* root, xmlpp::Node* node, const tiny_string& name, const tiny_string& ns, std::vector<XML*>& ret)
{
assert(root);
Expand Down
4 changes: 4 additions & 0 deletions scripting/toplevel.h
Original file line number Diff line number Diff line change
Expand Up @@ -685,11 +685,15 @@ class XML: public ASObject
ASFUNCTION(appendChild);
ASFUNCTION(localName);
ASFUNCTION(generator);
ASFUNCTION(_hasSimpleContent);
ASFUNCTION(_hasComplexContent);
static void buildTraits(ASObject* o){};
static void sinit(Class_base* c);
void getDescendantsByQName(const tiny_string& name, const tiny_string& ns, std::vector<XML*>& ret);
ASObject* getVariableByMultiname(const multiname& name, bool skip_impl, ASObject* base=NULL);
tiny_string toString(bool debugMsg=false);
bool hasSimpleContent() const;
bool hasComplexContent() const;
};

class XMLList: public ASObject
Expand Down

0 comments on commit 21c5095

Please sign in to comment.