TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Cast.h
1/****************************************************************************
2* Copyright (c) 2022, CEA
3* All rights reserved.
4*
5* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9*
10* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
11* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
12* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13*
14*****************************************************************************/
15
16
17#ifndef Cast_H
18#define Cast_H
19
20/*! @brief Type information utilities: static_type_info(T): returns the type_info of class T.
21 *
22 * ptr_type_info(p): returns the type_info of the object pointed to by p.
23 * ref_type_info(r): returns the type_info of object r or alias r.
24 * sub_type(T,r): returns 1 iff r is an instance of a subclass of T; 0 otherwise.
25 * Safe casts:
26 * ptr_cast(T,p): returns (T*)(p) iff *p is of a subtype of T; 0 otherwise.
27 * ref_cast(T,r): returns (T&)(r) iff r is of a subtype of T; 0 otherwise.
28 *
29 */
30
31class Type_info;
32
33extern int* bad_ref_cast(const Type_info* t1, const Type_info* t2);
34
35#define static_type_info(T) \
36 T::info()
37#define ptr_type_info(p) \
38 ((p)->get_info())
39#define ref_type_info(r) \
40 ((r).get_info())
41
42#define same_type(T,r) \
43 (((r).get_info())->same(T::info()))
44#define sub_type(T,r) \
45 (T::info_obj.can_cast((r).get_info()) ? 1 : 0)
46#define ptr_cast(T,p) \
47 (T::info_obj.can_cast((p)->get_info()) \
48 ? 0 :bad_ref_cast(T::info(),(p)->get_info()), (T*)(p))
49#define ref_cast(T,r) \
50 (T::info_obj.can_cast((r).get_info()) \
51 ? 0 :bad_ref_cast(T::info(),(r).get_info()), T::self_cast(r))
52#define ref_cast_non_const(T,r) \
53 (T::info_obj.can_cast((r).get_info()) \
54 ? 0 :bad_ref_cast(T::info(),(r).get_info()), (T&)(r))
55#endif
Models type information for Objet_U objects.
Definition Type_info.h:30