- static void dump_tree(tree_node *n, const std::string & prefix, bool verbose)
- {
- std::string name = n->info->options.get_name();
- std::cout << name;
- if (verbose)
- std::cout << " [ID 0x" << std::hex << std::setw(8) << std::setfill('0') << n->info->options.get_id() << std::dec << "]" << std::endl;
-
- size_t num_children = n->children.size();
- if (num_children) {
- for (size_t i = 0; i < num_children; ++i) {
- if (verbose) {
- std::cout << prefix << " +- ";
- if (i == num_children - 1)
- dump_tree(n->children[i], prefix + " ", verbose);
- else
- dump_tree(n->children[i], prefix + " | ", verbose);
- } else {
- std::string spaces(name.size(), ' ');
- if (i > 0)
- std::cout << prefix << spaces;
- if (num_children == 1)
- std::cout << " --- ";
- else if (i > 0)
- std::cout << " +- ";
- else
- std::cout << " -+- ";
- if (i == num_children - 1)
- dump_tree(n->children[i], prefix + spaces + " ", verbose);
- else
- dump_tree(n->children[i], prefix + spaces + " | ", verbose);
- }
- }
- } else if (!verbose)
- std::cout << std::endl;
+ static void dump_tree(tree_node *n, const std::string & prefix, bool verbose);
+ static void identify_parents();
+
+ static class_info *first;
+ class_info *next;
+ mutable class_info *parent;
+
+ static bool parents_identified;
+};
+
+template <class OPT>
+const class_info<OPT> *class_info<OPT>::find(const std::string &class_name)
+{
+ // Use a map for faster lookup. The registered_class_info list doesn't
+ // change at run-time, so it's sufficient to construct the map once
+ // on the first trip through this function.
+ typedef std::map<std::string, const class_info *> name_map_type;
+ static name_map_type name_map;
+ static bool name_map_initialized = false;
+
+ if (!name_map_initialized) {
+ // Construct map
+ const class_info *p = first;
+ while (p) {
+ name_map[p->options.get_name()] = p;
+ p = p->next;
+ }
+ name_map_initialized = true;