mirror of https://github.com/CGAL/cgal
Recommend object_cast instead of assign
This commit is contained in:
parent
c3500b603f
commit
0c9d10baa6
|
|
@ -75,7 +75,7 @@ assignments, so that you can put them in lists or arrays. Note that
|
||||||
Therefore, there is no automatic conversion from these classes to
|
Therefore, there is no automatic conversion from these classes to
|
||||||
\ccc{Object} Rather this is done with the global function
|
\ccc{Object} Rather this is done with the global function
|
||||||
\ccc{make_object()}. This encapsulation mechanism requires the use of
|
\ccc{make_object()}. This encapsulation mechanism requires the use of
|
||||||
\ccc{assign} to unwrap the encapsulated class.
|
\ccc{object_cast} to unwrap the encapsulated class.
|
||||||
|
|
||||||
\ccExample
|
\ccExample
|
||||||
In the following example, the object type is used as a return value for
|
In the following example, the object type is used as a return value for
|
||||||
|
|
@ -83,14 +83,15 @@ the \ccHtmlNoLinksFrom{intersection} computation, as there are
|
||||||
possibly different return values.
|
possibly different return values.
|
||||||
\ccHtmlLinksOff%
|
\ccHtmlLinksOff%
|
||||||
\begin{cprog}
|
\begin{cprog}
|
||||||
Point_d< Cartesian_d<double> > p;
|
typedef Point_d< Cartesian_d<double> > Point;
|
||||||
Segment_d< Cartesian_d<double> > s, s1, s2;
|
typedef Segment_d< Cartesian_d<double> > Segment;
|
||||||
|
Segment s1, s2;
|
||||||
std::cin >> s1 >> s2;
|
std::cin >> s1 >> s2;
|
||||||
Object obj = intersection(s1, s2);
|
Object obj = intersection(s1, s2);
|
||||||
if ( assign(p, obj) ) {
|
if (const Point *p = object_cast<Point>(&obj) ) {
|
||||||
/* do something with p */
|
/* do something with *p */
|
||||||
} else if ( (assign(s, obj) ) {
|
} else if (const Segment *s = object_cast<Segment>(&obj) ) {
|
||||||
/* do something with s */
|
/* do something with *s */
|
||||||
}
|
}
|
||||||
/* there was no intersection */
|
/* there was no intersection */
|
||||||
\end{cprog}
|
\end{cprog}
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,8 @@
|
||||||
\ccFunction{Object intersection(Type1<R> f1, Type2<R> f2);} {returns
|
\ccFunction{Object intersection(Type1<R> f1, Type2<R> f2);} {returns
|
||||||
the intersection result of $f1$ and $f2$ by means of the polymorphic
|
the intersection result of $f1$ and $f2$ by means of the polymorphic
|
||||||
wrapper type \ccc{Object}. The returned object can be tested for the
|
wrapper type \ccc{Object}. The returned object can be tested for the
|
||||||
intersection result and assigned by means of the operation \ccc{bool
|
intersection result and assigned by means of the \ccc{object_cast}
|
||||||
assign(T& t, Object o)}. \ccPrecond The objects are of the same
|
function. \ccPrecond The objects are of the same dimension.}
|
||||||
dimension.}
|
|
||||||
|
|
||||||
The possible value for types \ccStyle{Type1} and \ccStyle{Type2} and
|
The possible value for types \ccStyle{Type1} and \ccStyle{Type2} and
|
||||||
the possible return values wrapped in \ccc{Object} are the following:
|
the possible return values wrapped in \ccc{Object} are the following:
|
||||||
|
|
@ -156,12 +155,11 @@ The following example demonstrates the most common use of
|
||||||
template <class R>
|
template <class R>
|
||||||
void foo(Segment_d<R> seg, Line_d<R> lin)
|
void foo(Segment_d<R> seg, Line_d<R> lin)
|
||||||
{
|
{
|
||||||
Point_d<R> ipnt; Segment_d<R> iseg;
|
|
||||||
Object result = intersection(seg, lin);
|
Object result = intersection(seg, lin);
|
||||||
if ( assign(ipnt, result) ) {
|
if (const Point_d<R> *ipnt = object_cast<Point_d<R> >(&result) ) {
|
||||||
// handle the point intersection case.
|
// handle the point intersection case with *ipnt.
|
||||||
} else if ( assign(iseg, result) ) {
|
} else if (const Segment_d<R> *iseg = object_cast<Segment_d<R> >(&result) ) {
|
||||||
// handle the segment intersection case.
|
// handle the segment intersection case with *iseg.
|
||||||
} else {
|
} else {
|
||||||
// handle the no intersection case.
|
// handle the no intersection case.
|
||||||
}
|
}
|
||||||
|
|
@ -172,6 +170,3 @@ void foo(Segment_d<R> seg, Line_d<R> lin)
|
||||||
\ccSeeAlso
|
\ccSeeAlso
|
||||||
\ccc{do_intersect}, \ccc{Kernel::Intersect_d}
|
\ccc{do_intersect}, \ccc{Kernel::Intersect_d}
|
||||||
\end{ccRefFunction}
|
\end{ccRefFunction}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue