blob: e3c2196781d6937d0dafb1631300cb1b2be6d871 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
//#include <Interface_Recognizer.ixx>
#include <Standard_NoSuchObject.hxx>
// ATTENTION : TransRecognizer a exactement le meme code ...
// Mais produit un Transient au lieu d un Persistent
// Principe : a un objet de depart (cle), un Recognizer tente d'associer un
// resultat. La classe Recognizer offre le mecanisme general gerant cela
// Chaque classe particuliere (une fois definie l'instanciation) doit fournir
// une methode specifique Eval, qui opere la correspondance
// Eval considere l'objet par tous moyens appropries, et en cas de succes,
// appelle SetOK(result) puis sort (return)
// en cas d'echec, suite au retour d'Eval, Recognizer sait que SetOK n'a pas
// ete appele
Interface_Recognizer::Interface_Recognizer ()
{ hasnext = Standard_False; }
//thekey.Nullify(); inutile, fait par le constructeur ...
Standard_Boolean Interface_Recognizer::Evaluate
(const TheKey& akey, Handle(TheResul)& res)
{
theres.Nullify();
Eval(akey);
if (!theres.IsNull()) {
res = theres;
return Standard_True;
}
else if (hasnext) return thenext->Evaluate(akey,res);
return Standard_False;
}
Handle(TheResul) Interface_Recognizer::Result () const
{
if (!theres.IsNull()) return theres;
if (hasnext) return thenext->Result();
Standard_NoSuchObject::Raise ("Recognizer evaluation has failed");
return theres; // pour calmer le compilateur
}
void Interface_Recognizer::Add (const Handle(Interface_Recognizer)& reco)
{ thenext = reco; hasnext = Standard_True; }
void Interface_Recognizer::SetOK (const Handle(TheResul)& aresult)
{ theres = aresult; }
void Interface_Recognizer::SetKO ()
{ theres.Nullify(); }
|