本文整理汇总了C++中JsonTree::getChildren方法的典型用法代码示例。如果您正苦于以下问题:C++ JsonTree::getChildren方法的具体用法?C++ JsonTree::getChildren怎么用?C++ JsonTree::getChildren使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonTree
的用法示例。
在下文中一共展示了JsonTree::getChildren方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getNodePtr
//! Find pointer to node at specified path
JsonTree* JsonTree::getNodePtr( const string &relativePath, bool caseSensitive, char separator ) const
{
// Format path into dotted address
std::string path = boost::replace_all_copy( relativePath, "[", std::string( 1, separator ) );
path = boost::replace_all_copy( path, "'", "");
path = boost::replace_all_copy( path, "]", "");
// Start search from this node
JsonTree *curNode = const_cast<JsonTree*>( this );
// Split address at dot and iterate tokens
vector<string> pathComponents = split( path, separator );
for( vector<string>::const_iterator pathIt = pathComponents.begin(); pathIt != pathComponents.end(); ++pathIt ) {
// Declare target node
ConstIter node;
// The key is numeric
if( isIndex( *pathIt ) ) {
// Find child which uses this index as its key
uint32_t index = boost::lexical_cast<int32_t>( *pathIt );
uint32_t i = 0;
for ( node = curNode->getChildren().begin(); node != curNode->getChildren().end(); ++node, i++ ) {
if ( i == index ) {
break;
}
}
} else {
// Iterate children
node = curNode->getChildren().begin();
while( node != curNode->getChildren().end() ) {
// Compare child's key to path component
bool keysMatch = false;
string key1 = node->getKey();
string key2 = *pathIt;
if( caseSensitive && key1 == key2 ) {
keysMatch = true;
} else if ( !caseSensitive && ( boost::iequals( key1, key2 ) ) ) {
keysMatch = true;
}
// Break if found, advance node if not
if( keysMatch ) {
break;
} else {
++node;
}
}
}
// Return null pointer if we're out of nodes to search,
// otherwise assign node and continue to search its children
if( node == curNode->getChildren().end() ) {
return 0;
} else {
curNode = const_cast<JsonTree*>( &( *node ) );
}
}
// Return child
return curNode;
}