"Fossies" - the Fresh Open Source Software Archive

Member "doc_html/Kernel_23/upgrading_object.html" (8 Nov 2019, 11099 Bytes) of package /linux/misc/CGAL-4.14.2-doc_html.tar.xz:


Caution: In this restricted "Fossies" environment the current HTML page may not be correctly presentated and may have some non-functional links. You can here alternatively try to browse the pure source code or just view or download the uninterpreted raw source code. If the rendering is insufficient you may try to find and view the page on the CGAL-4.14.2-doc_html.tar.xz project site itself.

\( \newcommand{\E}{\mathrm{E}} \) \( \newcommand{\A}{\mathrm{A}} \) \( \newcommand{\R}{\mathrm{R}} \) \( \newcommand{\N}{\mathrm{N}} \) \( \newcommand{\Q}{\mathrm{Q}} \) \( \newcommand{\Z}{\mathrm{Z}} \) \( \def\ccSum #1#2#3{ \sum_{#1}^{#2}{#3} } \def\ccProd #1#2#3{ \sum_{#1}^{#2}{#3} }\)

CGAL 4.14.2 - 2D and 3D Linear Geometry Kernel
Upgrading from CGAL::Object to boost::variant

Code can be upgraded by using either boost::get or the boost::static_visitor<T>.

#include <CGAL/intersections.h>
template<typename R>
struct Intersection_visitor : public boost::static_visitor<> {
void operator()(const Point_2& p) const
{ // Point_2
}
void operator()(const Segment_2& s) const
{ // Segment_2
}
};
template <class R>
void foo(Segment_2<R> seg, Line_2<R> lin)
{
CGAL::Object obj = intersection(seg, lin);
if(const Point_2* foo = object_cast<Point_2>(&obj)) {
// Point_2
} else if(const Segment_2* foo = object_cast<Segment_2>(&obj)) {
// Segment_2
} else {
// empty
}
// becomes
auto result = intersection(seg, lin);
if(result) {
if(const Point_2* foo = boost::get<Point_2>(&*result)) {
// Point_2
} else if(const Segment_2* foo = boost::get<Segment_2>(&*result)) {
// Segment_2
}
} else {
// empty
}
// or with boost::static_visitor<T>
if(result) { boost::apply_visitor(Intersection_visitor(), *result); }
else { // empty
}
}