本文整理汇总了C++中AbstractNode::type方法的典型用法代码示例。如果您正苦于以下问题:C++ AbstractNode::type方法的具体用法?C++ AbstractNode::type怎么用?C++ AbstractNode::type使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AbstractNode
的用法示例。
在下文中一共展示了AbstractNode::type方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: remove
bool XmlSettingsEntry::remove( QStringList &xpath )
{
QStringList::ConstIterator itXPath;
AbstractNode *node = NULL;
QString lastElem(xpath.last()); /* last element from xpath */
xpath.removeLast();
XmlSettingsEntry entry( find(xpath, itXPath, node) );
if( itXPath != xpath.end() ) {
return false;
}
JQ_ASSERT(node);
if( node->type() == AbstractNode::Map ) {
MapNode *mapNode = dynamic_cast<MapNode*>(node);
MapNode::iterator it = mapNode->find( lastElem );
if( it == mapNode->end() )
return false;
mapNode->erase( it );
m_master->m_modified = true;
return true;
}
if( node->type() == AbstractNode::Vector ) {
JQ_ASSERT( lastElem.startsWith("[") );
JQ_ASSERT( lastElem.endsWith("]") && lastElem.size() > 2 );
bool ok;
int index = lastElem.mid(1, lastElem.size()-2).toUInt(&ok);
JQ_ASSERT(ok == true);
VectorNode *vectorNode = dynamic_cast<VectorNode*>(node);
vectorNode->erase( vectorNode->begin() + index );
m_master->m_modified = true;
return true;
}
return false;
}
示例2: makeBranch
XmlSettingsEntry XmlSettingsEntry::makeBranch( const QStringList &xpath )
{
QStringList::ConstIterator itXPath;
AbstractNode *node = NULL;
XmlSettingsEntry entry( find(xpath, itXPath, node) );
if( itXPath != xpath.end() ) {
JQ_ASSERT(node);
m_master->clearErrors();
AbstractNode::Type nodeType = node->type();
// Error
if( nodeType == AbstractNode::Scalar )
return XmlSettingsEntry( entry.m_master );
QStringList::ConstIterator itXPathEnd = xpath.end();
for(; itXPath != itXPathEnd; itXPath++ ) {
QString elem(*itXPath);
switch( nodeType ) {
case AbstractNode::Map:
{
MapNode *mapNode = (MapNode*)node;
if( itXPath + 1 == itXPathEnd ) { // Last element, must be a scalar
(*mapNode)[elem] = (node = new ScalarNode());
} else {
(*mapNode)[elem] = (node = new VectorNode());
}
}
nodeType = AbstractNode::Vector;
break;
case AbstractNode::Vector:
if( elem.startsWith("[") ) {
JQ_ASSERT( elem.endsWith("]") && elem.size() > 2 );
VectorNode *vectorNode = (VectorNode*)node;
bool ok;
int index = elem.mid(1, elem.size()-2).toUInt(&ok);
JQ_ASSERT(ok == true);
if( index >= vectorNode->size() ) {
vectorNode->resize(index+1);
}
int sz = vectorNode->size();
for( int i = 0; i < sz; i++ ) {
if( !(*vectorNode)[i] )
(*vectorNode)[i] = (node = new MapNode() );
}
if( itXPath + 1 == itXPathEnd ) { // Last element, must be a scalar
MapNode *mapNode = dynamic_cast<MapNode*>((*vectorNode)[index]);
(*mapNode)[__TEXT_PSEUDO_ELEMENT] = (node = new ScalarNode());
}
} else {
return XmlSettingsEntry(m_master);
}
nodeType = AbstractNode::Map;
break;
default: //AbstractNode::Scalar:
return XmlSettingsEntry(m_master);
}
}
}
return XmlSettingsEntry(m_master, node);
}