18#include <Synonyme_info.h>
33int * Type_info::types_homonymes=0;
35int Type_info::nb_classes=0;
36int Type_info::les_types_memsize=0;
40static inline int strcmp_uppercase(
const char *n1,
const char *n2)
47 c1 = (
unsigned char) ::toupper(n1[i]);
48 c2 = (
unsigned char) ::toupper(n2[i]);
52 while ((delta == 0) && (c1 != 0) && (c2 != 0));
61 int existe_deja = search_type_info_name(
name(), index);
64 for (
int i = index; i<nb_classes-1; i++)
66 les_types[i] = les_types[i+1];
67 types_homonymes[i] = types_homonymes[i+1];
80 if ((nb_classes==0)&& (les_types_memsize!=0))
83 delete [] types_homonymes;
99int Type_info::search_type_info_name(
const char *nom,
int& index)
104 int imax = nb_classes;
108 int milieu = (imin + imax) / 2;
109 int comparaison = strcmp_uppercase(nom, les_types[milieu]->
name());
110 if (comparaison == 0)
139 synonym_name_((
Nom*) 0),
146 Cerr <<
"Type_info::Type_info(const char* nom,Objet_U* (*f)()...)\n";
147 Cerr <<
" Error : name == 0" << finl;
170 synonym_name_((
Nom*) 0),
177 Cerr <<
"Type_info::Type_info(const char* nom,Objet_U* (*f)()...)\n";
178 Cerr <<
" Error : name == 0" << finl;
191void Type_info::ajouter_type(
const Type_info& type_info)
202 c = type_info.names_[i];
206 if (synonym_found==1)
208 Cerr <<
"More than 1 synonym found in " << type_info.names_ << finl;
209 Cerr <<
"Not supported yet !" << finl;
216 c = type_info.names_[i];
219 Cerr <<
"Error in a classname which can't finished by | : " << type_info.names_ << finl;
238 synonym_name_ =
new Nom(B);
239 synonym_ =
new Synonyme_info(synonym_name_->getChar(),name_->getChar());
242 if (les_types_memsize <= nb_classes + 1)
244 static const int INCREMENT = 512;
246 les_types_memsize += INCREMENT;
248 for (
int j = 0; j < nb_classes; j++)
249 nouveau[j] = les_types[j];
253 int * temp =
new int[les_types_memsize];
254 for (
int j = 0; j < nb_classes; j++)
255 temp[j] = types_homonymes[j];
256 delete[] types_homonymes;
257 types_homonymes = temp;
264 Cerr<<
" class "<<type_info.
name()<<
" already exists as a synonym which is forbidden!!!!"<<finl;
268 existe_deja = search_type_info_name(type_info.
name(), index);
271 types_homonymes[index] = 1;
274 if (strcmp(string_macro_trio(
"VECT",titi),
"VECT"))
276 if (strncmp(type_info.
name(),
"Iterateur_",10))
278 Cerr<<
" type "<<type_info.
name()<<
" is in double and it is not allowed!!!!"<<finl;
286 for (
int j = nb_classes; j > index; j--)
288 les_types[j] = les_types[j-1];
289 types_homonymes[j] = types_homonymes[j-1];
291 les_types[index] = &type_info;
292 types_homonymes[index] = 0;
306 os << b[i]->name() <<
" ";
317 os <<
"There is " << nb_classes <<
" classes:" << finl;
321 os << les_types[i]->name() <<
" inherits from ";
322 les_types[i]->bases(os);
351 if (cree_instance == 0)
353 Cerr <<
"Error in Type_info::instance()\n";
354 Cerr <<
" The type " <<
name() <<
" is not instantiable" << finl;
358 Objet_U * ainstance = (*cree_instance)();
405 for (
int i = 0; i < nb_bases_; i++)
411 for (
int i = 0; i < nb_bases_; i++)
412 if (b[i]->
has_base(p, direct))
return 1;
439 int resultat =
has_base(type, direct);
450 return strcmp(
name(),other_name)==0;
472 const Nom& nom_mere = mere.
name();
476 if( les_types[i]->
has_base(nom_mere, 0) )
477 if (!les_types[i]->
same(nom_mere))
483 if(compteur==0)
return 0;
489 if( les_types[i]->
has_base(nom_mere, 0) )
490 if (!les_types[i]->
same(nom_mere))
509 Cerr << type <<
"is not a type recognized by TRUST Unitaire " << finl;
516 if( les_types[i]->
same(type) )
536 if (search_type_info_name(type_name, index))
538 if (types_homonymes[index] == 0)
540 type_info = les_types[index];
546 Cerr <<
"const Type_info * Type_info::type_info_from_name(const char * type_name)\n";
547 Cerr <<
" The type " << type_name <<
" has several homonymous\n";
548 Cerr <<
" We doing as if the type is unknown..." << finl;
560 return (cree_instance != 0);
class Nom: a character string for naming TRUST objects.
An array of character strings (VECT(Nom)).
Base class for TRUST objects (Objet_U).
static void exit(int exit_code=-1)
Exit routine for TRUST within a Kokkos region.
Base class for output streams.
static int est_un_synonyme(const char *)
Tests whether a class synonym exists: if there is a class T whose Synonyme_info has.
Models type information for Objet_U objects.
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 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.