1 -- File: Interface_FileReaderTool.cdl
2 -- Created: Thu Feb 4 17:00:08 1993
3 -- Author: Christian CAILLET
5 ---Copyright: Matra Datavision 1993
8 deferred class FileReaderTool from Interface
10 ---Purpose : Defines services which are required to load an InterfaceModel
11 -- from a File. Typically, it may firstly transform a system
12 -- file into a FileReaderData object, then work on it, not longer
13 -- considering file contents, to load an Interface Model.
14 -- It may also work on a FileReaderData already loaded.
16 -- FileReaderTool provides, on one hand, some general services
17 -- which are common to all read operations but can be redefined,
18 -- plus general actions to be performed specifically for each
19 -- Norm, as deferred methods to define.
21 -- In particular, FileReaderTool defines the Interface's Unknown
24 uses Integer, Boolean, Transient, HArray1OfTransient,
25 FileReaderData, InterfaceModel, Check, Protocol from Interface,
26 Messenger from Message,
29 raises DomainError, NoSuchObject
34 Initialize returns FileReaderTool from Interface;
35 ---Purpose: Constructor; sets default fields
37 SetData (me : in out; reader : mutable FileReaderData;
38 protocol : Protocol from Interface);
39 ---Purpose : Sets Data to a FileReaderData. Works with a Protocol
41 Protocol (me) returns Protocol from Interface;
42 ---Purpose : Returns the Protocol given at creation time
44 Data (me) returns mutable FileReaderData;
45 ---Purpose : Returns the FileReaderData which is used to work
47 SetModel (me : in out; amodel : mutable InterfaceModel);
48 ---Purpose : Stores a Model. Used when the Model has been loaded
50 Model (me) returns mutable InterfaceModel;
51 ---Purpose : Returns the stored Model
53 -- -- setting empty entities before loading model -- --
55 SetMessenger (me: out; messenger: Messenger from Message);
56 ---Purpose : Sets Messenger used for outputting messages
58 Messenger (me) returns Messenger from Message;
59 ---Purpose : Returns Messenger used for outputting messages.
60 -- The returned object is guaranteed to be non-null;
61 -- default is Message::Messenger().
63 SetTraceLevel (me: out; tracelev: Integer);
64 ---Purpose : Sets trace level used for outputting messages
65 -- - 0: no trace at all
67 -- - 2: errors and warnings
69 -- Default is 1 : Errors traced
71 TraceLevel (me) returns Integer;
72 ---Purpose : Returns trace level used for outputting messages.
74 SetErrorHandle (me : in out; err : Boolean);
75 ---Purpose : Allows controlling whether exception raisings are handled
76 -- If err is False, they are not (hence, dbx can take control)
77 -- If err is True, they are, and they are traced
78 -- (by putting on messenger Entity's Number and file record num)
79 -- Default given at Model's creation time is True
81 ErrorHandle (me) returns Boolean;
82 ---Purpose : Returns ErrorHandle flag
84 -- -- setting empty entities before loading model -- --
86 SetEntities (me : in out);
87 ---Purpose : Fills records with empty entities; once done, each entity can
88 -- ask the FileReaderTool for any entity referenced through an
89 -- identifier. Calls Recognize which is specific to each specific
90 -- type of FileReaderTool
92 Recognize (me : in out; num : Integer;
93 ach : in out Check; ent : out mutable Transient)
94 returns Boolean is deferred;
95 ---Purpose : Recognizes a record, given its number. Specific to each
96 -- Interface; called by SetEntities. It can call the basic method
98 -- Returns False if recognition has failed, True else.
99 -- <ach> has not to be filled if simply Recognition has failed :
100 -- it must record true error messages : RecognizeByLib can
101 -- generate error messages if NewRead is called
103 -- Note that it works thru a Recognizer (method Evaluate) which
104 -- has to be memorized before starting
106 RecognizeByLib (me; num : Integer;
107 glib : in out GeneralLib; rlib : in out ReaderLib;
108 ach : in out Check; ent : out mutable Transient)
110 ---Purpose : Recognizes a record with the help of Libraries. Can be used
111 -- to implement the method Recognize.
112 -- <rlib> is used to find Protocol and CaseNumber to apply
113 -- <glib> performs the creation (by service NewVoid, or NewRead
114 -- if NewVoid gave no result)
115 -- <ach> is a check, which is transmitted to NewRead if it is
116 -- called, gives a result but which is false
117 -- <ent> is the result
118 -- Returns False if recognition has failed, True else
120 UnknownEntity (me) returns mutable Transient;
121 ---Purpose : Provides an unknown entity, specific to the Interface
122 -- called by SetEntities when Recognize has failed (Unknown alone)
123 -- or by LoadModel when an Entity has caused a Fail on reading
124 -- (to keep at least its literal description)
125 -- Uses Protocol to do it
127 -- -- loading entities into the model -- --
129 NewModel (me) returns mutable InterfaceModel;
130 ---Purpose : Creates an empty Model of the norm. Uses Protocol to do it
132 LoadModel (me : in out; amodel : mutable InterfaceModel)
134 ---Purpose : Reads and fills Entities from the FileReaderData set by
135 -- SetData to an InterfaceModel.
136 -- It enchains required operations, the specific ones correspond
137 -- to deferred methods (below) to be defined for each Norm.
138 -- It manages also error recovery and trace.
139 -- Remark : it calls SetModel.
140 -- It Can raise any error which can occur during a load
141 -- operation, unless Error Handling is set.
142 -- This method can also be redefined if judged necessary.
144 LoadedEntity (me : in out; num : Integer) returns mutable Transient;
145 ---Purpose : Reads, Fills and Returns one Entity read from a Record of the
146 -- FileReaderData. This Method manages also case of Fail or
147 -- Warning, by producing a ReportEntyty plus , for a Fail, a
148 -- literal Content (as an UnknownEntity). Performs also Trace
150 BeginRead (me : in out; amodel : mutable InterfaceModel) is deferred;
151 ---Purpose : Fills model's header; each Interface defines for its Model its
152 -- own file header; this method fills it from FileReaderTool.+
153 -- It is called by AnalyseFile from InterfaceModel
155 AnalyseRecord (me : in out;
156 num : Integer; anent : mutable Transient; acheck : in out Check)
157 returns Boolean is deferred;
158 ---Purpose : Fills an Entity, given record no; specific to each Interface,
159 -- called by AnalyseFile from InterfaceModel (which manages its
160 -- calling arguments)
161 -- To work, each Interface can define a method in its proper
162 -- Transient class, like this (given as an example) :
163 -- AnalyseRecord (me : mutable; FR : in out FileReaderTool;
164 -- num : Integer; acheck : in out Check)
166 -- and call it from AnalyseRecord
168 -- Returned Value : True if the entity could be loaded, False
169 -- else (in case of syntactic fail)
171 Destroy (me: in out) is virtual;
172 ---C++ : alias "Standard_EXPORT virtual ~Interface_FileReaderTool() { Destroy(); }"
174 EndRead (me : in out; amodel : mutable InterfaceModel) is virtual;
175 ---Purpose : Ends file reading after reading all the entities
176 -- default is doing nothing; redefinable as necessary
180 ---Purpose : Clear filelds
184 theproto : Protocol from Interface;
185 thereader : FileReaderData;
186 themodel : InterfaceModel;
187 themessenger:Messenger from Message;
188 thetrace : Integer; -- trace level (exceptions,errors, etc...)
189 theerrhand : Boolean; -- to handle or not exceptions
190 thenbrep0 : Integer; -- (reports at creation time)
191 thenbreps : Integer; -- (all reports)
192 thereports : HArray1OfTransient;