TrioCFD 1.9.8
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 Informations de types : static_type_info(T) : renvoie le type_info de la classe T.
21 *
22 * ptr_type_info(p) : renvoie le type_info de l'objet pointe par p.
23 * ref_type_info(r) : renvoie le type_info de l'objet r ou de l'alias r
24 * sub_type(T,r) : renvoie 1 ssi r est une instance d'une classe fille de T; 0 sinon.
25 * Les cast securises :
26 * ptr_cast(T,p) : renvoie (T*)(p) ssi *p est d'un sous type de T; 0 sinon.
27 * ref_cast(T,r) : : renvoie (T&)(r) ssi r est d'un sous type de T; 0 sinon.
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
modelise une information de type pour les Objet_U
Definition Type_info.h:30