From: Christian Bauer Date: Tue, 2 Sep 2003 19:59:12 +0000 (+0000) Subject: - added missing #include X-Git-Tag: release_1-2-0~107 X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=commitdiff_plain;h=6c6c3edbf50fce456ded6a9ec3e88a83ae9d4be3 - added missing #include - reduced the amount of inlining a little --- diff --git a/ginac/class_info.h b/ginac/class_info.h index 808a9878..8f3dcb4e 100644 --- a/ginac/class_info.h +++ b/ginac/class_info.h @@ -29,6 +29,7 @@ #include #include #include +#include namespace GiNaC { @@ -52,31 +53,12 @@ public: } /** Find class_info by name. */ - static const class_info *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 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; - } + static const class_info *find(const std::string &class_name); - typename name_map_type::const_iterator it = name_map.find(class_name); - if (it == name_map.end()) - throw (std::runtime_error("class '" + class_name + "' not registered")); - else - return it->second; - } + /** Dump class hierarchy to std::cout. */ + static void dump_hierarchy(bool verbose = false); + + OPT options; private: struct tree_node { @@ -87,97 +69,125 @@ private: class_info *info; }; - 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 +const class_info *class_info::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 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; } -public: - /** Dump class hierarchy to std::cout. */ - static void dump_hierarchy(bool verbose = false) - { - identify_parents(); + typename name_map_type::const_iterator it = name_map.find(class_name); + if (it == name_map.end()) + throw (std::runtime_error("class '" + class_name + "' not registered")); + else + return it->second; +} - // Create tree nodes for all class_infos - std::vector tree; - for (class_info *p = first; p; p = p->next) - tree.push_back(tree_node(p)); - - // Identify children for all nodes and find the root - tree_node *root = NULL; - for (typename std::vector::iterator i = tree.begin(); i != tree.end(); ++i) { - class_info *p = i->info->get_parent(); - if (p) { - for (typename std::vector::iterator j = tree.begin(); j != tree.end(); ++j) { - if (j->info == p) { - j->add_child(&*i); - break; - } - } - } else - root = &*i; +template +void class_info::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; +} - // Print hierarchy tree starting at the root - dump_tree(root, "", verbose); +template +void class_info::dump_hierarchy(bool verbose) +{ + identify_parents(); + + // Create tree nodes for all class_infos + std::vector tree; + for (class_info *p = first; p; p = p->next) + tree.push_back(tree_node(p)); + + // Identify children for all nodes and find the root + tree_node *root = NULL; + for (typename std::vector::iterator i = tree.begin(); i != tree.end(); ++i) { + class_info *p = i->info->get_parent(); + if (p) { + for (typename std::vector::iterator j = tree.begin(); j != tree.end(); ++j) { + if (j->info == p) { + j->add_child(&*i); + break; + } + } + } else + root = &*i; } - OPT options; + // Print hierarchy tree starting at the root + dump_tree(root, "", verbose); +} -private: - static void identify_parents() - { - if (!parents_identified) { - for (class_info *p = first; p; p = p->next) { - const char *parent_name = p->options.get_parent_name(); - for (class_info *q = first; q; q = q->next) { - if (strcmp(q->options.get_name(), parent_name) == 0) { - p->parent = q; - break; - } +template +void class_info::identify_parents() +{ + if (!parents_identified) { + for (class_info *p = first; p; p = p->next) { + const char *parent_name = p->options.get_parent_name(); + for (class_info *q = first; q; q = q->next) { + if (strcmp(q->options.get_name(), parent_name) == 0) { + p->parent = q; + break; } } - parents_identified = true; } + parents_identified = true; } - - static class_info *first; - class_info *next; - mutable class_info *parent; - - static bool parents_identified; -}; +} template class_info *class_info::first = NULL; template bool class_info::parents_identified = false;