7fd59977 |
1 | -- File: StepWriter.cdl |
2 | -- Created: Tue Feb 11 19:54:04 1992 |
3 | -- Author: Christian CAILLET |
4 | -- <cky@phobox> |
5 | ---Copyright: Matra Datavision 1992 |
6 | |
7 | |
8 | class StepWriter from StepData |
9 | |
10 | ---Purpose : manages atomic file writing, under control of StepModel (for |
11 | -- general organisation of file) and each class of Transient |
12 | -- (for its own parameters) : prepares text to be written then |
13 | -- writes it |
14 | -- A stream cannot be used because Step limits line length at 72 |
15 | -- In more, a specific object offers more appropriate functions |
16 | |
17 | uses Integer, Boolean, Real, Character, Transient, Logical from StepData, -- OStream, |
18 | AsciiString from TCollection, HAsciiString from TCollection, |
19 | HSequenceOfHAsciiString, HArray1OfInteger, |
20 | LineBuffer, FloatWriter, CheckIterator, |
21 | StepModel, WriterLib, Protocol from StepData, |
22 | SelectMember from StepData, Field from StepData, PDescr from StepData, |
23 | FieldList from StepData, ESDescr from StepData, |
24 | HArray1OfReal from TColStd |
25 | |
26 | raises InterfaceMismatch |
27 | |
28 | is |
29 | |
30 | Create (amodel : StepModel) returns StepWriter; |
31 | ---Purpose : Creates an empty StepWriter from a StepModel. The StepModel |
32 | -- provides the Number of Entities, as identifiers for File |
33 | |
34 | -- Options for Sending Forms -- |
35 | |
36 | LabelMode (me : in out) returns Integer; |
37 | ---Purpose : ModeLabel controls how to display entity ids : |
38 | -- 0 (D) gives entity number in the model |
39 | -- 1 gives the already recorded label (else, its number) |
40 | -- Warning : conflicts are not controlled |
41 | ---C++ : return & |
42 | |
43 | TypeMode (me : in out) returns Integer; |
44 | ---Purpose : TypeMode controls the type form to use : |
45 | -- 0 (D) for normal long form |
46 | -- 1 for short form (if a type name has no short form, normal |
47 | -- long form is then used) |
48 | ---C++ : return & |
49 | |
50 | FloatWriter (me : in out) returns FloatWriter; |
51 | ---Purpose : Returns the embedded FloatWriter, which controls sending Reals |
52 | -- Use this method to access FloatWriter in order to consult or |
53 | -- change its options (MainFormat, FormatForRange,ZeroSuppress), |
54 | -- because it is returned as the address of its field |
55 | ---C++ : return & |
56 | |
57 | -- -- Description of Scopes -- -- (to be done before sending) |
58 | |
59 | SetScope (me : in out; numscope,numin : Integer) |
60 | ---Purpose : Declares the Entity Number <numscope> to correspond to a Scope |
61 | -- which contains the Entity Number <numin>. Several calls to the |
62 | -- same <numscope> add Entities in this Scope, in this order. |
63 | raises InterfaceMismatch; |
64 | ---Purpose: Error if <numin> is already declared in the Scope |
65 | -- Warning : the declaration of the Scopes is assumed to be consistent, |
66 | -- i.e. <numin> is not referenced from outside this Scope |
67 | -- (not checked here) |
68 | |
69 | IsInScope (me; num : Integer) returns Boolean; |
70 | ---Purpose : Returns True if an Entity identified by its Number is in a Scope |
71 | |
72 | -- -- Sending Parts of a Model -- -- |
73 | |
74 | SendModel (me : in out; protocol : Protocol from StepData; |
75 | headeronly : Boolean = Standard_False) |
76 | ---Purpose : Sends the complete Model, included HEADER and DATA Sections |
77 | -- Works with a WriterLib defined through a Protocol |
78 | -- If <headeronly> is given True, only the HEADER Section is sent |
79 | -- (used to Dump the Header of a StepModel) |
80 | raises InterfaceMismatch; |
81 | -- Error if any of the called Send's falls in Error |
82 | |
83 | SendHeader (me : in out); |
84 | ---Purpose : Begins model header |
85 | |
86 | SendData (me : in out) raises InterfaceMismatch; |
87 | ---Purpose : Begins data section; error if EndSec was not set |
88 | |
89 | SendEntity (me : in out; nument : Integer; lib : WriterLib) |
90 | ---Purpose : Send an Entity of the Data Section. If it corresponds to a |
91 | -- Scope, also Sends the Scope informations and contained Items |
92 | raises InterfaceMismatch; |
93 | -- Error if any of the called Send's falls in Error |
94 | |
95 | EndSec (me : in out); |
96 | ---Purpose : sets end of section; to be done before passing to next one |
97 | |
98 | EndFile (me : in out) raises InterfaceMismatch; |
99 | ---Purpose : sets end of file; error is EndSec was not set |
100 | |
101 | -- -- Managing line -- -- |
102 | |
103 | AddString (me : in out; str : AsciiString from TCollection; more : Integer = 0) |
104 | is private; |
105 | ---Purpose : adds a string to current line; first flushes it if full |
106 | -- (72 char); more allows to ask a reserve at end of line : flush |
107 | -- is done if remaining length (to 72) is less than <more> |
108 | |
109 | AddString (me : in out; str : CString; lnstr : Integer; more : Integer = 0) |
110 | is private; |
111 | ---Purpose : Same as above, but the string is given by CString + Length |
112 | |
113 | |
114 | NewLine (me : in out; evenempty : Boolean); |
115 | ---Purpose : flushes current line; if empty, flushes it (defines a new |
116 | -- empty line) if evenempty is True; else, skips it |
117 | |
118 | JoinLast (me : in out; newline : Boolean); |
119 | ---Purpose : joins current line to last one, only if new length is 72 max |
120 | -- if newline is True, a new current line begins; else, current |
121 | -- line is set to the last line (once joined) itself an can be |
122 | -- completed |
123 | |
124 | Indent (me : in out; onent : Boolean); |
125 | ---Purpose : asks that further indentations will begin at position of |
126 | -- entity first opening bracket; else they begin at zero (def) |
127 | -- for each sublist level, two more blancks are added at beginning |
128 | -- (except for text continuation, which must begin at true zero) |
129 | |
130 | -- -- Sending entities -- -- |
131 | |
132 | SendIdent (me : in out; ident : Integer); |
133 | ---Purpose : begins an entity with an ident plus '=' (at beginning of line) |
134 | -- entity ident is its Number given by the containing Model |
135 | -- Warning : <ident> must be, either Number or Label, according LabelMode |
136 | |
137 | SendScope (me : in out); |
138 | ---Purpose : sets a begin of Scope (ends this line) |
139 | |
140 | SendEndscope (me : in out); |
141 | ---Purpose : sets an end of Scope (on a separate line) |
142 | |
143 | Comment (me : in out; mode : Boolean); |
144 | ---Purpose : sets a comment mark : if mode is True, begins Comment zone, |
145 | -- if mode is False, ends Comment zone (if one is begun) |
146 | |
147 | SendComment (me : in out; text : HAsciiString from TCollection) |
148 | raises InterfaceMismatch; |
149 | ---Purpose : sends a comment. Error if we are not inside a comment zone |
150 | |
151 | SendComment (me : in out; text : CString) raises InterfaceMismatch; |
152 | ---Purpose : same as above but accepts a CString (ex.: "..." directly) |
153 | |
154 | StartEntity (me : in out; atype : AsciiString from TCollection); |
155 | ---Purpose : sets entity's StepType, opens brakets, starts param no to 0 |
156 | -- params are separated by comma |
157 | -- Remark : for a Multiple Type Entity (see Express ANDOR clause) |
158 | -- StartComplex must be called before sending componants, then |
159 | -- each "Componant" must be send separately (one call to |
160 | -- StartEntity for each one) : the Type which preceeds is then |
161 | -- automaticaly closed. Once all the componants have been sent, |
162 | -- EndComplex must be called, then and only then EndEntity |
163 | |
164 | StartComplex (me : in out); |
165 | ---Purpose : sends the start of a complex entity, which is a simple open |
166 | -- bracket (without increasing braket level) |
167 | -- It must be called JUST AFTER SendEntity and BEFORE sending |
168 | -- componants, each one begins by StartEntity |
169 | |
170 | EndComplex (me : in out); |
171 | ---Purpose : sends the end of a complex entity : a simple closed bracket |
172 | -- It must be called AFTER sending all the componants and BEFORE |
173 | -- the final call to EndEntity |
174 | |
175 | -- -- Sending Parameters -- -- |
176 | |
177 | SendField (me : in out; fild : Field; descr : PDescr); |
178 | ---Purpose : Sends the content of a field, controlled by its descriptor |
179 | -- If the descriptor is not defined, follows the description |
180 | -- detained by the field itself |
181 | |
182 | SendSelect (me : in out; sm : SelectMember; descr : PDescr); |
183 | ---Purpose : Sends a SelectMember, which cab be named or not |
184 | |
185 | SendList (me : in out; list : FieldList; descr : ESDescr); |
186 | ---Purpose : Send the content of an entity as being a FieldList controlled |
187 | -- by its descriptor. This includes start and end brackets but |
188 | -- not the entity type |
189 | |
190 | OpenSub (me : in out); |
191 | ---Purpose : open a sublist by a '(' |
192 | |
193 | OpenTypedSub (me : in out; subtype : CString); |
194 | ---Purpose : open a sublist with its type then a '(' |
195 | |
196 | CloseSub (me : in out); |
197 | ---Purpose : closes a sublist by a ')' |
198 | |
199 | AddParam (me : in out); |
200 | ---Purpose : prepares adding a parameter (that is, adds ',' except for |
201 | -- first one); normally for internal use; can be used to send |
202 | -- a totally empty parameter (with no litteral value) |
203 | |
204 | Send (me : in out; val : Integer); |
205 | ---Purpose : sends an integer parameter |
206 | |
207 | Send (me : in out; val : Real); |
208 | ---Purpose : sends a real parameter (wroks with FloatWriter) |
209 | |
210 | Send (me : in out; val : AsciiString from TCollection); |
211 | ---Purpose : sends a text given as string (it will be set between '...') |
212 | |
213 | Send (me : in out; val : Transient); |
214 | ---Purpose : sends a reference to an entity (its identifier with '#') |
215 | -- REMARK 1 : a Null <val> is interpreted as "Undefined" |
216 | -- REMARK 2 : for an HAsciiString which is not recorded in the |
217 | -- Model, it is send as its String Content, between quotes |
218 | |
219 | SendBoolean (me : in out; val : Boolean); |
220 | ---Purpose : sends a Boolean as .T. for True or .F. for False |
221 | -- (it is an useful case of Enum, which is built-in) |
222 | |
223 | SendLogical (me : in out; val : Logical from StepData); |
224 | ---Purpose : sends a Logical as .T. or .F. or .U. according its Value |
225 | -- (it is a standard case of Enum for Step, and is built-in) |
226 | |
227 | SendString (me : in out; val : AsciiString from TCollection); |
228 | ---Purpose : sends a string exactly as it is given |
229 | |
230 | SendString (me : in out; val : CString); |
231 | ---Purpose : sends a string exactly as it is given |
232 | |
233 | SendEnum (me : in out; val : AsciiString from TCollection); |
234 | ---Purpose : sends an enum given by String (litteral expression) |
235 | -- adds '.' around it if not done |
236 | -- Remark : val can be computed by class EnumTool from StepData: |
237 | -- StepWriter.SendEnum (myenum.Text(enumval)); |
238 | |
239 | SendEnum (me : in out; val : CString); |
240 | ---Purpose : sends an enum given by String (litteral expression) |
241 | -- adds '.' around it if not done |
242 | |
243 | SendArrReal(me : in out; anArr : HArray1OfReal from TColStd); |
244 | ---Purpose : sends an array of real |
245 | |
246 | SendUndef (me : in out); |
247 | ---Purpose : sends an undefined (optionnal absent) parameter (by '$') |
248 | |
249 | SendDerived (me : in out); |
250 | ---Purpose : sends a "Derived" parameter (by '*'). A Derived Parameter has |
251 | -- been inherited from a Super-Type then redefined as being |
252 | -- computed by a function. Hence its value in file is senseless. |
253 | |
254 | EndEntity (me : in out) raises InterfaceMismatch; |
255 | ---Purpose : sends end of entity (closing bracket plus ';') |
256 | -- Error if count of opened-closed brackets is not null |
257 | |
258 | -- -- Printing on an output -- -- |
259 | |
260 | CheckList (me) returns CheckIterator; |
261 | ---Purpose : Returns the check-list, which has received possible checks : |
262 | -- for unknown entities, badly loaded ones, null or unknown |
263 | -- references |
264 | |
265 | NbLines (me) returns Integer; |
266 | ---Purpose : Returns count of Lines |
267 | |
268 | Line (me; num : Integer) returns HAsciiString from TCollection; |
269 | ---Purpose : Returns a Line given its rank in the File |
270 | |
271 | Print (me : in out; S : in out OStream) returns Boolean; |
272 | ---Purpose : writes result on an output defined as an OStream |
273 | -- then clears it |
274 | |
275 | fields |
276 | |
277 | themodel : StepModel; |
278 | thefile : HSequenceOfHAsciiString; |
279 | thecurr : LineBuffer; |
280 | thesect : Boolean; -- False at very start or after EndSec |
281 | thecomm : Boolean; -- are we in inside a comment |
282 | thefirst : Boolean; -- True on first parameter, False on following ones |
283 | themult : Boolean; -- True after sending first type (for Multiple Type) |
284 | thelevel : Integer; -- current sublist level |
285 | theindent : Boolean; -- True to indent at entity opening bracket |
286 | theindval : Integer; -- position of entity opening bracket |
287 | |
288 | thetypmode : Integer; |
289 | thefloatw : FloatWriter; -- control of sending Reals |
290 | |
291 | thechecks : CheckIterator; |
292 | thenum : Integer; |
293 | |
294 | thelabmode : Integer; |
295 | thescopebeg : HArray1OfInteger; |
296 | thescopeend : HArray1OfInteger; |
297 | thescopenext : HArray1OfInteger; |
298 | |
299 | end StepWriter; |