std::string generate_contents_links(const section &sec, const std::vector<topic>& topics) { std::stringstream res; if (!sec.sections.empty() || !topics.empty()) { res << generate_separate_text_links(); } section_list::const_iterator s; for (s = sec.sections.begin(); s != sec.sections.end(); ++s) { if (is_visible_id((*s)->id)) { std::string link = "<ref>text='" + escape((*s)->title) + "' dst='.." + escape((*s)->id) + "'</ref>"; res << link <<"\n"; } } std::vector<topic>::const_iterator t; for (t = topics.begin(); t != topics.end(); ++t) { if (is_visible_id(t->id)) { std::string link = "<ref>text='" + escape(t->title) + "' dst='" + escape(t->id) + "'</ref>"; res << link <<"\n"; } } return res.str(); }
void help_menu::update_visible_items(const section &sec, unsigned level) { if (level == 0) { // Clear if this is the top level, otherwise append items. visible_items_.clear(); } section_list::const_iterator sec_it; for (sec_it = sec.sections.begin(); sec_it != sec.sections.end(); ++sec_it) { if (is_visible_id((*sec_it)->id)) { const std::string vis_string = get_string_to_show(*(*sec_it), level + 1); visible_items_.push_back(visible_item(*sec_it, vis_string)); if (expanded(*(*sec_it))) { update_visible_items(*(*sec_it), level + 1); } } } topic_list::const_iterator topic_it; for (topic_it = sec.topics.begin(); topic_it != sec.topics.end(); ++topic_it) { if (is_visible_id(topic_it->id)) { const std::string vis_string = get_string_to_show(*topic_it, level + 1); visible_items_.push_back(visible_item(&(*topic_it), vis_string)); } } }
std::string generate_contents_links(const std::string& section_name, config const *help_cfg) { config const §ion_cfg = help_cfg->find_child("section", "id", section_name); if (!section_cfg) { return std::string(); } std::ostringstream res; std::vector<std::string> topics = utils::quoted_split(section_cfg["topics"]); // we use an intermediate structure to allow a conditional sorting typedef std::pair<std::string,std::string> link; std::vector<link> topics_links; std::vector<std::string>::iterator t; // Find all topics in this section. for (t = topics.begin(); t != topics.end(); ++t) { if (config const &topic_cfg = help_cfg->find_child("topic", "id", *t)) { std::string id = topic_cfg["id"]; if (is_visible_id(id)) topics_links.push_back(link(topic_cfg["title"], id)); } } if (section_cfg["sort_topics"] == "yes") { std::sort(topics_links.begin(),topics_links.end()); } if (!topics_links.empty()) { res << generate_separate_text_links(); } std::vector<link>::iterator l; for (l = topics_links.begin(); l != topics_links.end(); ++l) { std::string link = "<ref>text='" + escape(l->first) + "' dst='" + escape(l->second) + "'</ref>"; res << link <<"\n"; } return res.str(); }