#ifndef compareimpl_hh #define compareimpl_hh #include #include #include namespace compareimpl { bool have_nulls(const void *p, const void *q, int &res); int compare_ns(xmlNsPtr a, xmlNsPtr b); template int compare_name(TPtr p, TPtr q) { assert(p->name); assert(q->name); // 9Aug2003: There's also xmlStrcmp(), but the library routine has // a pretty good chance of being faster than straight C... int name = strcmp(reinterpret_cast(p->name), reinterpret_cast(q->name)); if (name) { return name; } int res; if (have_nulls(p->ns, q->ns, res)) { return res; } else { return compare_ns(p->ns, q->ns); } } template std::set get_set(TPtr p) { std::set out; while (p) { out.insert(p); p = p->next; } return out; } template int compare_set(TPtr p, TPtr q) { std::set a = get_set(p); std::set b = get_set(q); std::equal_to is_equal; std::less is_less; typename std::set::const_iterator i = a.begin(); typename std::set::const_iterator j = b.begin(); while ((i != a.end()) && (j != b.end())) { if (!is_equal(*i, *j)) { return is_less(*i, *j) ? -1 : 1; } ++i; ++j; } if (i == a.end()) { return j != b.end() ? -1 : 0; } else { return 1; } } } #endif