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
|
||||
\ccc{Object} Rather this is done with the global function
|
||||
\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
|
||||
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.
|
||||
\ccHtmlLinksOff%
|
||||
\begin{cprog}
|
||||
Point_d< Cartesian_d<double> > p;
|
||||
Segment_d< Cartesian_d<double> > s, s1, s2;
|
||||
typedef Point_d< Cartesian_d<double> > Point;
|
||||
typedef Segment_d< Cartesian_d<double> > Segment;
|
||||
Segment s1, s2;
|
||||
std::cin >> s1 >> s2;
|
||||
Object obj = intersection(s1, s2);
|
||||
if ( assign(p, obj) ) {
|
||||
/* do something with p */
|
||||
} else if ( (assign(s, obj) ) {
|
||||
/* do something with s */
|
||||
if (const Point *p = object_cast<Point>(&obj) ) {
|
||||
/* do something with *p */
|
||||
} else if (const Segment *s = object_cast<Segment>(&obj) ) {
|
||||
/* do something with *s */
|
||||
}
|
||||
/* there was no intersection */
|
||||
\end{cprog}
|
||||
|
|
|
|||
|
|
@ -4,9 +4,8 @@
|
|||
\ccFunction{Object intersection(Type1<R> f1, Type2<R> f2);} {returns
|
||||
the intersection result of $f1$ and $f2$ by means of the polymorphic
|
||||
wrapper type \ccc{Object}. The returned object can be tested for the
|
||||
intersection result and assigned by means of the operation \ccc{bool
|
||||
assign(T& t, Object o)}. \ccPrecond The objects are of the same
|
||||
dimension.}
|
||||
intersection result and assigned by means of the \ccc{object_cast}
|
||||
function. \ccPrecond The objects are of the same dimension.}
|
||||
|
||||
The possible value for types \ccStyle{Type1} and \ccStyle{Type2} and
|
||||
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>
|
||||
void foo(Segment_d<R> seg, Line_d<R> lin)
|
||||
{
|
||||
Point_d<R> ipnt; Segment_d<R> iseg;
|
||||
Object result = intersection(seg, lin);
|
||||
if ( assign(ipnt, result) ) {
|
||||
// handle the point intersection case.
|
||||
} else if ( assign(iseg, result) ) {
|
||||
// handle the segment intersection case.
|
||||
if (const Point_d<R> *ipnt = object_cast<Point_d<R> >(&result) ) {
|
||||
// handle the point intersection case with *ipnt.
|
||||
} else if (const Segment_d<R> *iseg = object_cast<Segment_d<R> >(&result) ) {
|
||||
// handle the segment intersection case with *iseg.
|
||||
} else {
|
||||
// handle the no intersection case.
|
||||
}
|
||||
|
|
@ -172,6 +170,3 @@ void foo(Segment_d<R> seg, Line_d<R> lin)
|
|||
\ccSeeAlso
|
||||
\ccc{do_intersect}, \ccc{Kernel::Intersect_d}
|
||||
\end{ccRefFunction}
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue