Bonjour, j'ai déjà posté ailleurs, mais j'ai peu d'espérance d'avoir une réponse dans des temps acceptable. Surtout que j'ai trouvé une solution.
Ce que je voudrais faire : C'est initialisé une variable de type accès à une chaîne englobé dans un enregistrement abstrait contrôlé et limité.
Voila ce que j'ai fait.
le paquetage "np", racine de la bibliothèque.
Spécification :
Code ada : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 package Np is pragma Pure (Np); end Np;
Le paquetage "np-human", mon type abstrait T_Info(Hidden : Boolean).
Spécification :
Code ada : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 with Ada.Unchecked_Deallocation; with Ada.Finalization; package Np.human is type String_Access is access all String; type Info(Hidden : Boolean) is abstract new Ada.Finalization.Limited_Controlled with private; procedure Initialize(I : in out Info); procedure Finalize(I : in out Info); private type Info(Hidden : Boolean) is abstract new Ada.Finalization.Limited_Controlled with record Info : String_Access; end record; procedure Free is new Ada.Unchecked_Deallocation(String, String_access); end Np.Human;
Coprs : dans lequel j'espérais saisir l'info.
Code ada : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 with Text_Io; package body Np.human is procedure Initialize(I : in out Info) is begin null; -- ici, j'expérais saisir l'info; end Initialize; procedure Finalize(I : in out Info) is begin Free(I.Info); end Finalize; end Np.Human;
Le paquetage "np-human-status, mon type effectif de classe T_Info(False).
Spécification :
Corps :
Code ada : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8 package Np.Human.Status is type T_Status is new info(False) with null record; procedure Initialize(I : in out T_Status); procedure Finalize(I : in out T_Status); end Np.Human.Status;
Code ada : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 with Text_Io; package body Np.Human.Status is procedure Initialize(I : in out T_Status) is begin Text_Io.Put("Status : "); end Initialize; procedure Finalize(I : in out T_Status) is begin null; end Finalize; end Np.Human.Status;
Le main :
Code ada : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10 with Np, Np.Human, Np.Human.Status; use Np; procedure Main is Status : Human.Status.T_Status; begin null; end Main;
Donc, pour résoudre le problème, j'appelle Human.Initialize dans Human.Status.Initialize.
Je ne sais pas si c'est convenable.
De plus, à présent je souhaiterais pouvoir "contrôler" chaque initialisation.
En effet, admettons que je veuille initialise un type "T_User" définit par :
- le nom : (de type Info)
- l'adresse : (de type Info)
- le prénom : (de type Info)
.../...
etc.
Je voudrais pourvoir afficher un message particulier pour chaque initialisation
Comment devrais-je m'y prendre ?
Merci bien pour votre aide.
Partager