Handle Types, Identity and EqualityAll geometric objects in LEDA are so-called handle types, i.e., an object of any geometric type is a (smart) pointer to a representation object. Arat_point , for example, is a pointer to a rat_point_rep
and a segment is a pointer to a segment_rep . The
objects of the representation class contain the defining information about
the geometric object and possibly additional information for internal use.
Distinction between Identical and Equal ObjectsIn the following we usepoints as an example. Similar statements are true
for all geometric objects.
Two points The assignment statement and the copy constructor preserve identity. They are implemented by pointer assignments. ExampleThe following program illustrates the difference between identity and equality. See Writing Kernel Independent Code for an explanation for writing POINT. #include <LEDA/point.h> #include <LEDA/geo/float_kernel_names.h> using namespace leda; int main() { POINT p(0,0); POINT q(0,0); POINT r=p; if (identical(p,q)) std::cout << "p and q are identical" << std::endl; else std::cout << "p and q are not identical" << std::endl; //evaluates to false if (p==q) std::cout << "p and q are equal" << std::endl; else std::cout << "p and q are not equal" << std::endl; //evaluates to true if (identical(p,r)) std::cout << "p and r are identical" << std::endl; else std::cout << "p and q are not identical" << std::endl; //evaluates to true if (p==r) std::cout << "p and q are equal" << std::endl; else std::cout << "p and q are not equal" << std::endl; //evaluates to true return 0; } |
See also:Writing Kernel Independent Code |