TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Type_info.h
1/****************************************************************************
2* Copyright (c) 2023, 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#ifndef Type_info_included
17#define Type_info_included
18class Objet_U;
19class Nom;
20class Noms;
21class Sortie;
22class Synonyme_info;
23
24
25/*! @brief Models type information for Objet_U objects.
26 *
27 * @sa Objet_U Nom
28 */
30{
31public:
32 ~Type_info();
33 Type_info(const char* name, Objet_U* (*f)(), int nb_bases=0, const Type_info** bases=0);
34 Type_info(const char* name, int nb_bases=0, const Type_info** bases=0);
35
36 inline const Nom& name() const
37 {
38 return *name_;
39 };
40 inline int can_cast(const Type_info* p) const;
41
42 int same(const Type_info* p) const;
43 int same(const Nom&) const;
44 int has_base(const Type_info* p, int direct=0) const;
45 int has_base(const Nom& , int direct=0) const;
46 Sortie& bases(Sortie&) const;
47 Objet_U* instance() const;
48 int instanciable() const;
49
50 // Static methods:
51 static Sortie& hierarchie(Sortie&) ;
52 static int est_un_type(const char*) ;
53 static int les_sous_types(const Nom&, Noms& sous_types);
54 static int les_sous_types(const Type_info&, Noms& sous_types);
55 static const Type_info * type_info_from_name(const char * type_name);
56 static Objet_U* instance(const char* typ);
57
58protected:
59
60private:
61 Type_info(Type_info&) {}; // Copy constructor disabled
62 Type_info& operator=(Type_info&); // Assignment operator disabled
63 void ajouter_type(const Type_info& type_info);
64 static int search_type_info_name(const char *nom, int& index);
65
66 // Possible names (eg: A|B)
67 const char* names_ = "rien";
68 // Name and its synonym
69 mutable Nom * name_ = nullptr; // (eg: A)
70 mutable Nom * synonym_name_ = nullptr; // (eg: B)
71 // Object synonym:
72 Synonyme_info* synonym_= nullptr; // Synonym
73
74 // Number of base classes of this class
75 int nb_bases_ = -1;
76 // List of Type_info for the base classes of this class
77 const Type_info** b= nullptr;
78 // Pointer to the static "cree_instance" method of the class
79 // (null if the class is not instantiable)
80 Objet_U* (*cree_instance)()= nullptr;
81
82 // List of Type_info for classes declared by declare_base/declare_instanciable
83 // The list is sorted alphabetically (case-insensitive)
84 static const Type_info** les_types;
85 // For each type registered in "les_types", if multiple classes share the same name,
86 // then types_homonymes != 0.
87 static int * types_homonymes;
88 // Number of classes registered in "les_types" and "types_homonymes"
89 static int nb_classes;
90 // Memory size of the "les_types" and "types_homonymes" arrays
91 // (arrays resized by blocks)
92 static int les_types_memsize;
93};
94
95/*! @brief Traverses the type hierarchy. Returns 1 if p points to a subtype of the current type.
96 *
97 * @param p Pointer to the type to test.
98 * @return 1 if p points to a subtype of the current type, 0 otherwise.
99 */
100inline int Type_info::can_cast(const Type_info* p) const
101{
102 return ( (same(p)) || (p->has_base(this)) );
103}
104
105#endif
class Nom: a character string for naming TRUST objects.
Definition Nom.h:31
An array of character strings (VECT(Nom)).
Definition Noms.h:26
Base class for TRUST objects (Objet_U).
Definition Objet_U.h:68
Base class for output streams.
Definition Sortie.h:52
Models synonym information for Objet_U objects.
Models type information for Objet_U objects.
Definition Type_info.h:30
int instanciable() const
Returns 1 if the associated type is instantiable (cree_instance is non-null), 0 otherwise.
static int les_sous_types(const Nom &, Noms &sous_types)
Returns the names of the subtypes for a parent type identified by name.
Type_info(const char *name, Objet_U *(*f)(), int nb_bases=0, const Type_info **bases=0)
Constructor from a name, a factory function, and an array of base types.
Objet_U * instance() const
Creates an instance of the class associated with the type_info.
int has_base(const Type_info *p, int direct=0) const
Tests whether a type belongs to the base types of the considered type. If direct == 0,...
int can_cast(const Type_info *p) const
Traverses the type hierarchy. Returns 1 if p points to a subtype of the current type.
Definition Type_info.h:100
int same(const Type_info *p) const
Returns 1 if this==p, 0 otherwise.
static int est_un_type(const char *)
Tests whether a class of the given type exists. If a class T whose Type_info has the name nom exists,...
static Sortie & hierarchie(Sortie &)
Writes the full hierarchy of the considered type to an output stream.
static const Type_info * type_info_from_name(const char *type_name)
Static method that returns a pointer to the Type_info whose name is "type_name".
Sortie & bases(Sortie &) const
Writes the base types of the current type to an output stream.
const Nom & name() const
Definition Type_info.h:36