64,649
社区成员
发帖
与我相关
我的任务
分享
//调用函数
ZxyFolder::selectObjectsFolder(options,"Objects");
//其中变量如下
typedef std::map<std::string, std::string> response_t;
typedef std::vector<response_t> options_t;
LLUserAuth::options_t options;
//类定义
class ZxyFolder
{
public:
static void selectObjectsFolder(LLUserAuth::options_t &options,std::string objectname)
{
//backup the options as newoptions
//newoptions=options;
LLUserAuth::options_t newoptions(options);
//newoptions.assign(options.begin(),options.end());
//empty the options
options.clear();
//make root
LLUserAuth::options_t::iterator iter;
//出问题的就是这里,未经过一次迭代,单步跟踪发现发现newoptions已经有值了,18个值呢,这里一次也不执行,直接跳出去了,为什么呢?
for(iter=newoptions.begin();iter!=newoptions.end();iter++)
{
if((*iter)["name"]==objectname)
options.push_back((*iter));
break;
}
//iterator
//iterate until the folder id established
//the result is that a new options will be created
hasChildren(0,options,newoptions);
}
static void hasChildren(int ids,LLUserAuth::options_t &options,LLUserAuth::options_t newoptions)
{
if(ids==options.size()) return; //越界,返回
std::string a1=options[ids]["folder_id"];
LLUserAuth::options_t::iterator iter;
for(iter=newoptions.begin();iter!=newoptions.end();iter++)
{
std::string a2=(*iter)["parent_id"];
if(a1==a2)
{
options.push_back(*iter);
ids++;
hasChildren(ids,options,newoptions); //如果有子目录,递归
}
}
return;
}
};