Пример #1
0
//得到子树节点,const
int ZCE_Conf_PropertyTree::path_get_childiter(const std::string &path_str,
        ZCE_Conf_PropertyTree::const_child_iterator &child_iter) const
{

    //找到
    size_t str_pos = path_str.find(SEPARATOR_STRING, 0);

    std::string start_str(path_str, 0, str_pos);

    CHILDREN_NOTE_TYPE::const_iterator iter_tmp = child_node_.find(start_str);
    //如果没有找到
    if (child_node_.end() == iter_tmp)
    {
        ZCE_LOG(RS_ERROR, "[zcelib][%s]Read config path fail, path[%s] .",
                __ZCE_FUNC__,
                path_str.c_str());
        return -1;
    }

    const ZCE_Conf_PropertyTree *child_tree = &(iter_tmp->second);

    //还有路径,进行递归查询
    if (str_pos != std::string::npos)
    {
        std::string remain_str(path_str, str_pos + 1);
        return child_tree->path_get_childiter(remain_str, child_iter);
    }
    else
    {
        //这儿无非是提前返回了,
        child_iter = iter_tmp;
        return 0;
    }
}
Пример #2
0
//得到子树节点,const的,
int ZCE_Conf_PropertyTree::get_child(const std::string &path_str,
                                     const PROPERTY_TREE_NODE *& const_child_data) const
{

    const_child_data = NULL;

    //就是找自己
    if ( 0 == path_str.length() )
    {
        const_child_data = this;
        return 0;
    }

    //
    size_t str_pos =  path_str.find("|", 0);

    std::string start_str(path_str, 0, str_pos);

    PROPERTY_TREE_MAP::const_iterator iter_tmp = child_node_map_.find(start_str);

    if ( child_node_map_.end() == iter_tmp )
    {
        return -1;
    }

    const PROPERTY_TREE_NODE *child_tree = &(iter_tmp->second);

    //还有路径,进行递归查询
    if (str_pos != std::string::npos)
    {
        std::string remain_str(path_str, str_pos + 1);
        return child_tree->get_child(remain_str, const_child_data);
    }
    else
    {
        //这儿无非是提前返回了,
        const_child_data = child_tree;
        return 0;
    }
}