当前位置: 首页>>代码示例>>C++>>正文


C++ AbstractNode::type方法代码示例

本文整理汇总了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;
}
开发者ID:semenovf,项目名称:jq-settings-xml-qt4,代码行数:41,代码来源:XmlSettings.cpp

示例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);
}
开发者ID:semenovf,项目名称:jq-settings-xml-qt4,代码行数:72,代码来源:XmlSettings.cpp


注:本文中的AbstractNode::type方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。