Attempt to fix incomplete type lists.

This commit is contained in:
Kristoffer Erlandsson 2004-06-16 14:11:38 +00:00
parent d038aa13e7
commit b146be532b
2 changed files with 60 additions and 14 deletions

View File

@ -78,7 +78,7 @@ namespace {
if (child_cfg != NULL) { if (child_cfg != NULL) {
help::section child_section; help::section child_section;
parse_config_internal(help_cfg, child_cfg, child_section, level + 1); parse_config_internal(help_cfg, child_cfg, child_section, level + 1);
sec.sections.push_back(child_section); sec.add_section(child_section);
} }
else { else {
std::stringstream ss; std::stringstream ss;
@ -139,6 +139,31 @@ bool topic::operator<(const topic &t) const {
return id < t.id; return id < t.id;
} }
section::section(const std::string _title, const std::string _id, const topic_list &_topics,
const std::vector<section> &_sections)
: title(_title), id(_id), topics(_topics) {
std::transform(_sections.begin(), _sections.end(), std::back_inserter(sections),
create_section());
}
section::~section() {
std::for_each(sections.begin(), sections.end(), delete_section());
}
section::section(const section &sec)
: title(sec.title), id(sec.id), topics(sec.topics) {
std::transform(sec.sections.begin(), sec.sections.end(),
std::back_inserter(sections), create_section());
}
section& section::operator=(const section &sec) {
std::transform(sec.sections.begin(), sec.sections.end(),
std::back_inserter(sections), create_section());
return *this;
}
bool section::operator==(const section &sec) const { bool section::operator==(const section &sec) const {
return sec.id == id; return sec.id == id;
} }
@ -147,8 +172,13 @@ bool section::operator<(const section &sec) const {
return id < sec.id; return id < sec.id;
} }
void section::add_section(const section &s) {
sections.push_back(new section(s));
}
void section::clear() { void section::clear() {
topics.clear(); topics.clear();
std::for_each(sections.begin(), sections.end(), delete_section());
sections.clear(); sections.clear();
} }
@ -193,10 +223,10 @@ void help_menu::update_visible_items(const section &sec, unsigned level) {
} }
section_list::const_iterator sec_it; section_list::const_iterator sec_it;
for (sec_it = sec.sections.begin(); sec_it != sec.sections.end(); sec_it++) { for (sec_it = sec.sections.begin(); sec_it != sec.sections.end(); sec_it++) {
const std::string vis_string = get_string_to_show(*sec_it, level); const std::string vis_string = get_string_to_show(*(*sec_it), level);
visible_items_.push_back(visible_item(&(*sec_it), vis_string)); visible_items_.push_back(visible_item(*sec_it, vis_string));
if (expanded((*sec_it))) { if (expanded(*(*sec_it))) {
update_visible_items(*sec_it, level + 1); update_visible_items(*(*sec_it), level + 1);
} }
} }
topic_list::const_iterator topic_it; topic_list::const_iterator topic_it;
@ -271,7 +301,7 @@ bool help_menu::select_topic_internal(const topic &t, const section &sec) {
} }
section_list::const_iterator sit; section_list::const_iterator sit;
for (sit = sec.sections.begin(); sit != sec.sections.end(); sit++) { for (sit = sec.sections.begin(); sit != sec.sections.end(); sit++) {
if (select_topic_internal(t, *sit)) { if (select_topic_internal(t, *(*sit))) {
expand(sec); expand(sec);
return true; return true;
} }
@ -1058,7 +1088,7 @@ const topic *find_topic(const section &sec, const std::string &id) {
} }
section_list::const_iterator sit; section_list::const_iterator sit;
for (sit = sec.sections.begin(); sit != sec.sections.end(); sit++) { for (sit = sec.sections.begin(); sit != sec.sections.end(); sit++) {
const topic *t = find_topic(*sit, id); const topic *t = find_topic(*(*sit), id);
if (t != NULL) { if (t != NULL) {
return t; return t;
} }

View File

@ -32,6 +32,9 @@ struct help_manager {
~help_manager(); ~help_manager();
}; };
struct section;
typedef std::list<section *> section_list;
/// A topic contains a title, an id and some text. /// A topic contains a title, an id and some text.
struct topic { struct topic {
@ -45,25 +48,29 @@ struct topic {
std::string title, id, text; std::string title, id, text;
}; };
typedef std::list<topic> topic_list;
/// A section contains topics and sections along with title and ID. /// A section contains topics and sections along with title and ID.
struct section { struct section {
section(const std::string _title, const std::string _id, const std::list<topic> &_topics, section(const std::string _title, const std::string _id, const topic_list &_topics,
const std::list<section> &_sections) const std::vector<section> &_sections);
: title(_title), id(_id), topics(_topics), sections(_sections) {}
section() : title(""), id("") {} section() : title(""), id("") {}
section(const section&);
section& operator=(const section&);
~section();
/// Two sections are equal if their IDs are equal. /// Two sections are equal if their IDs are equal.
bool operator==(const section &) const; bool operator==(const section &) const;
/// Comparison on the ID. /// Comparison on the ID.
bool operator<(const section &) const; bool operator<(const section &) const;
void add_section(const section &s);
void clear(); void clear();
std::string title, id; std::string title, id;
std::list<topic> topics; topic_list topics;
std::list<section> sections; section_list sections;
}; };
typedef std::list<topic> topic_list;
typedef std::list<section> section_list;
/// To be used as a function object to locate sections and topics /// To be used as a function object to locate sections and topics
/// with a specified ID. /// with a specified ID.
@ -75,6 +82,15 @@ public:
private: private:
const std::string id_; const std::string id_;
}; };
struct delete_section {
void operator()(section *s) { delete s; }
};
struct create_section {
section *operator()(const section *s) { return new section(*s); }
section *operator()(const section &s) { return new section(s); }
};
/// The menu to the left in the help browser, where topics can be /// The menu to the left in the help browser, where topics can be
/// navigated through and chosen. /// navigated through and chosen.