Index: splivarot.cpp =================================================================== RCS file: /cvsroot/inkscape/inkscape/src/splivarot.cpp,v retrieving revision 1.101 diff -d -u -p -r1.101 splivarot.cpp --- splivarot.cpp 4 Feb 2005 21:17:44 -0000 1.101 +++ splivarot.cpp 5 Feb 2005 10:47:12 -0000 @@ -42,18 +42,14 @@ #include "libnr/nr-matrix.h" #include "libnr/nr-point.h" #include "xml/repr.h" -#include "xml/sp-repr-iterators.h" - -#include "algorithms/longest-common-suffix.h" +#include "xml/repr-sorting.h" #include "livarot/Path.h" #include "livarot/Shape.h" #include "livarot/LivarotDefs.h" Path *Path_for_item (SPItem * item,bool doTransformation, bool transformFull = true); -SPRepr *LCA (SPRepr * a, SPRepr * b); bool Ancetre (SPRepr * a, SPRepr * who); -SPRepr *AncetreFils (SPRepr * a, SPRepr * d); void sp_selected_path_boolop (bool_op bop); void sp_selected_path_do_offset (bool expand, double prefOffset); @@ -1491,15 +1487,6 @@ sp_selected_path_simplify (void) // fonctions utilitaires -SPRepr * -AncetreFils (SPRepr * a, SPRepr * d) -{ - if (a == NULL || d == NULL) - return NULL; - if (sp_repr_parent (a) == d) - return a; - return AncetreFils (sp_repr_parent (a), d); -} bool Ancetre (SPRepr * a, SPRepr * who) @@ -1511,28 +1498,6 @@ Ancetre (SPRepr * a, SPRepr * who) return Ancetre (sp_repr_parent (a), who); } -namespace { - -bool same_repr(SPRepr &a, SPRepr &b) { - return &a == &b; -} - -} - -SPRepr * -LCA (SPRepr * a, SPRepr * b) -{ - using Inkscape::Algorithms::longest_common_suffix; - SPRepr *ancestor=longest_common_suffix( - a, b, NULL, &same_repr - ); - if ( ancestor && ancestor->type() != SP_XML_DOCUMENT_NODE ) { - return ancestor; - } else { - return NULL; - } -} - Path * Path_for_item (SPItem * item, bool doTransformation, bool transformFull) { Index: xml/Makefile_insert =================================================================== RCS file: /cvsroot/inkscape/inkscape/src/xml/Makefile_insert,v retrieving revision 1.16 diff -d -u -p -r1.16 Makefile_insert --- xml/Makefile_insert 23 Jan 2005 19:16:58 -0000 1.16 +++ xml/Makefile_insert 5 Feb 2005 10:47:25 -0000 @@ -24,6 +24,8 @@ xml_libspxml_a_SOURCES = \ xml/repr-get-children.h \ xml/repr-io.cpp \ xml/repr-private.h \ + xml/repr-sorting.cpp \ + xml/repr-sorting.h \ xml/repr-util.cpp \ xml/repr.cpp \ xml/repr.h \ Index: xml/repr-util.cpp =================================================================== RCS file: /cvsroot/inkscape/inkscape/src/xml/repr-util.cpp,v retrieving revision 1.36 diff -d -u -p -r1.36 repr-util.cpp --- xml/repr-util.cpp 26 Jan 2005 20:28:22 -0000 1.36 +++ xml/repr-util.cpp 5 Feb 2005 10:47:25 -0000 @@ -34,6 +34,7 @@ #include "svg/stringstream.h" #include "xml/repr.h" +#include "xml/repr-sorting.h" #include "xml/sp-repr-attr.h" struct SPXMLNs { @@ -64,12 +65,6 @@ struct SPXMLNs { static void sp_xml_ns_register_defaults (); static char *sp_xml_ns_auto_prefix (const char *uri); -// The following are in splivarot.cpp but probably should be moved -// here... -SPRepr *LCA (SPRepr * a, SPRepr * b); -bool Ancetre (SPRepr * a, SPRepr * who); -SPRepr *AncetreFils (SPRepr * a, SPRepr * d); - /*##################### # UTILITY #####################*/ diff -d -u xml/repr-sorting.cpp --- xml/repr-sorting.cpp +++ xml/repr-sorting.cpp 2005-02-05 21:32:41.000000000 +1100 @@ -0,0 +1,55 @@ +#include "xml/repr-sorting.h" + +#include "algorithms/longest-common-suffix.h" +#include "xml/repr.h" +#include "xml/sp-repr.h" +#include "xml/sp-repr-iterators.h" + +static bool +same_repr(SPRepr &a, SPRepr &b) +{ + /* todo: I'm not certain that it's legal to take the address of a reference. Check the exact wording of the spec on this matter. */ + return &a == &b; +} + +SPRepr * +LCA(SPRepr *a, SPRepr *b) +{ + using Inkscape::Algorithms::longest_common_suffix; + SPRepr *ancestor = longest_common_suffix( + a, b, NULL, &same_repr + ); + if ( ancestor && ancestor->type() != SP_XML_DOCUMENT_NODE ) { + return ancestor; + } else { + return NULL; + } +} + +/** + * Returns a child of \a ancestor such that ret is itself an ancestor of \a descendent. + * + * The current version returns NULL if ancestor or descendent is NULL, though future versions may + * call g_log. Please update this comment if you rely on the current behaviour. + */ +SPRepr * +AncetreFils(SPRepr *descendent, SPRepr *ancestor) +{ + if (descendent == NULL || ancestor == NULL) + return NULL; + if (sp_repr_parent(descendent) == ancestor) + return descendent; + return AncetreFils(sp_repr_parent(descendent), ancestor); +} + + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : diff -d -u xml/repr-sorting.h --- xml/repr-sorting.h +++ xml/repr-sorting.h 2005-02-05 21:26:24.000000000 +1100 @@ -0,0 +1,6 @@ +/** \file Some functions relevant sorting reprs by position within document. */ + +class SPRepr; + +SPRepr *LCA(SPRepr *a, SPRepr *b); +SPRepr *AncetreFils(SPRepr *descendent, SPRepr *ancestor);