42cf5bc1 |
1 | // Created on: 1992-02-10 |
2 | // Created by: Christian CAILLET |
3 | // Copyright (c) 1992-1999 Matra Datavision |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
5 | // |
6 | // This file is part of Open CASCADE Technology software library. |
7 | // |
8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published |
10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
12 | // distribution for complete text of the license and disclaimer of any warranty. |
13 | // |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
16 | |
17 | #ifndef _Interface_FileReaderData_HeaderFile |
18 | #define _Interface_FileReaderData_HeaderFile |
19 | |
20 | #include <Standard.hxx> |
21 | #include <Standard_Type.hxx> |
22 | |
23 | #include <Standard_Integer.hxx> |
24 | #include <TColStd_Array1OfInteger.hxx> |
25 | #include <TColStd_Array1OfTransient.hxx> |
25e59720 |
26 | #include <Standard_Transient.hxx> |
42cf5bc1 |
27 | #include <Standard_CString.hxx> |
28 | #include <Interface_ParamType.hxx> |
29 | #include <Standard_Boolean.hxx> |
30 | #include <Standard_Real.hxx> |
31 | class Interface_ParamSet; |
32 | class Standard_NoSuchObject; |
33 | class TCollection_AsciiString; |
34 | class Interface_FileParameter; |
35 | class Interface_ParamList; |
36 | class Standard_Transient; |
37 | |
38 | |
39 | class Interface_FileReaderData; |
25e59720 |
40 | DEFINE_STANDARD_HANDLE(Interface_FileReaderData, Standard_Transient) |
42cf5bc1 |
41 | |
42 | //! This class defines services which permit to access Data issued |
43 | //! from a File, in a form which does not depend of physical |
44 | //! format : thus, each Record has an attached ParamList (to be |
45 | //! managed) and resulting Entity. |
46 | //! |
47 | //! Each Interface defines its own FileReaderData : on one hand by |
48 | //! defining deferred methods given here, on the other hand by |
49 | //! describing literal data and their accesses, with the help of |
50 | //! basic classes such as String, Array1OfString, etc... |
51 | //! |
52 | //! FileReaderData is used by a FileReaderTool, which is also |
53 | //! specific of each Norm, to read an InterfaceModel of the Norm |
54 | //! FileReaderData inherits TShared to be accessed by Handle : |
55 | //! this allows FileReaderTool to define more easily the specific |
56 | //! methods, and improves memory management. |
25e59720 |
57 | class Interface_FileReaderData : public Standard_Transient |
42cf5bc1 |
58 | { |
59 | |
60 | public: |
61 | |
62 | |
63 | //! Returns the count of registered records |
64 | //! That is, value given for Initialization (can be redefined) |
65 | Standard_EXPORT virtual Standard_Integer NbRecords() const; |
66 | |
67 | //! Returns the count of entities. Depending of each norm, records |
68 | //! can be Entities or SubParts (SubList in STEP, SubGroup in SET |
69 | //! ...). NbEntities counts only Entities, not Subs |
70 | //! Used for memory reservation in InterfaceModel |
71 | //! Default implementation uses FindNextRecord |
72 | //! Can be redefined into a more performant way |
73 | Standard_EXPORT virtual Standard_Integer NbEntities() const; |
74 | |
75 | //! Determines the record number defining an Entity following a |
76 | //! given record number. Specific to each sub-class of |
77 | //! FileReaderData. Returning zero means no record found |
78 | Standard_EXPORT virtual Standard_Integer FindNextRecord (const Standard_Integer num) const = 0; |
79 | |
80 | //! attaches an empty ParamList to a Record |
81 | Standard_EXPORT void InitParams (const Standard_Integer num); |
82 | |
83 | //! Adds a parameter to record no "num" and fills its fields |
84 | //! (EntityNumber is optional) |
85 | //! Warning : <aval> is assumed to be memory-managed elsewhere : it is NOT |
86 | //! copied. This gives a best speed : strings remain stored in |
87 | //! pages of characters |
88 | Standard_EXPORT void AddParam (const Standard_Integer num, const Standard_CString aval, const Interface_ParamType atype, const Standard_Integer nument = 0); |
89 | |
90 | //! Same as above, but gets a AsciiString from TCollection |
91 | //! Remark that the content of the AsciiString is locally copied |
92 | //! (because its content is most often lost after using) |
93 | Standard_EXPORT void AddParam (const Standard_Integer num, const TCollection_AsciiString& aval, const Interface_ParamType atype, const Standard_Integer nument = 0); |
94 | |
95 | //! Same as above, but gets a complete FileParameter |
96 | //! Warning : Content of <FP> is NOT copied : its original address and space |
97 | //! in memory are assumed to be managed elsewhere (see ParamSet) |
98 | Standard_EXPORT void AddParam (const Standard_Integer num, const Interface_FileParameter& FP); |
99 | |
100 | //! Sets a new value for a parameter of a record, given by : |
101 | //! num : record number; nump : parameter number in the record |
102 | Standard_EXPORT void SetParam (const Standard_Integer num, const Standard_Integer nump, const Interface_FileParameter& FP); |
103 | |
104 | //! Returns count of parameters attached to record "num" |
105 | //! If <num> = 0, returns the total recorded count of parameters |
106 | Standard_EXPORT Standard_Integer NbParams (const Standard_Integer num) const; |
107 | |
108 | //! Returns the complete ParamList of a record (read only) |
109 | //! num = 0 to return the whole param list for the file |
110 | Standard_EXPORT Handle(Interface_ParamList) Params (const Standard_Integer num) const; |
111 | |
112 | //! Returns parameter "nump" of record "num", as a complete |
113 | //! FileParameter |
114 | Standard_EXPORT const Interface_FileParameter& Param (const Standard_Integer num, const Standard_Integer nump) const; |
115 | |
116 | //! Same as above, but in order to be modified on place |
117 | Standard_EXPORT Interface_FileParameter& ChangeParam (const Standard_Integer num, const Standard_Integer nump); |
118 | |
119 | //! Returns type of parameter "nump" of record "num" |
120 | //! Returns literal value of parameter "nump" of record "num" |
121 | //! was C++ : return const & |
122 | Standard_EXPORT Interface_ParamType ParamType (const Standard_Integer num, const Standard_Integer nump) const; |
123 | |
124 | //! Same as above, but as a CString |
125 | //! was C++ : return const |
126 | Standard_EXPORT Standard_CString ParamCValue (const Standard_Integer num, const Standard_Integer nump) const; |
127 | |
128 | //! Returns True if parameter "nump" of record "num" is defined |
129 | //! (it is not if its type is ParamVoid) |
130 | Standard_EXPORT Standard_Boolean IsParamDefined (const Standard_Integer num, const Standard_Integer nump) const; |
131 | |
132 | //! Returns record number of an entity referenced by a parameter |
133 | //! of type Ident; 0 if no EntityNumber has been determined |
134 | //! Note that it is used to reference Entities but also Sublists |
135 | //! (sublists are not objects, but internal descriptions) |
136 | Standard_EXPORT Standard_Integer ParamNumber (const Standard_Integer num, const Standard_Integer nump) const; |
137 | |
138 | //! Returns the StepEntity referenced by a parameter |
139 | //! Error if none |
140 | Standard_EXPORT const Handle(Standard_Transient)& ParamEntity (const Standard_Integer num, const Standard_Integer nump) const; |
141 | |
142 | //! Returns the absolute rank of the beginning of a record |
143 | //! (its lsit is from ParamFirstRank+1 to ParamFirstRank+NbParams) |
144 | Standard_EXPORT Standard_Integer ParamFirstRank (const Standard_Integer num) const; |
145 | |
146 | //! Returns the entity bound to a record, set by SetEntities |
147 | Standard_EXPORT const Handle(Standard_Transient)& BoundEntity (const Standard_Integer num) const; |
148 | |
149 | //! Binds an entity to a record |
150 | Standard_EXPORT void BindEntity (const Standard_Integer num, const Handle(Standard_Transient)& ent); |
151 | |
152 | //! Sets the status "Error Load" on, to overside check fails |
153 | //! <val> True : declares unloaded |
154 | //! <val> False : declares loaded |
155 | //! If not called before loading (see FileReaderTool), check fails |
156 | //! give the status |
157 | //! IsErrorLoad says if SetErrorLoad has been called by user |
158 | //! ResetErrorLoad resets it (called by FileReaderTool) |
159 | //! This allows to specify that the currently loaded entity |
160 | //! remains unloaded (because of syntactic fail) |
161 | Standard_EXPORT void SetErrorLoad (const Standard_Boolean val); |
162 | |
163 | //! Returns True if the status "Error Load" has been set (to True |
164 | //! or False) |
165 | Standard_EXPORT Standard_Boolean IsErrorLoad() const; |
166 | |
167 | //! Returns the former value of status "Error Load" then resets it |
168 | //! Used to read the status then ensure it is reset |
169 | Standard_EXPORT Standard_Boolean ResetErrorLoad(); |
170 | |
171 | //! Destructor (waiting for memory management) |
172 | Standard_EXPORT void Destroy(); |
173 | ~Interface_FileReaderData() |
174 | { |
175 | Destroy(); |
176 | } |
177 | |
178 | //! Same spec.s as standard <atof> but 5 times faster |
179 | Standard_EXPORT static Standard_Real Fastof (const Standard_CString str); |
180 | |
181 | |
182 | |
25e59720 |
183 | DEFINE_STANDARD_RTTIEXT(Interface_FileReaderData,Standard_Transient) |
42cf5bc1 |
184 | |
185 | protected: |
186 | |
187 | |
188 | //! Initializes arrays of Entities and of ParamLists attached |
189 | //! to registered records |
190 | //! <nbr> must be the maximum number of records to get (no way to |
191 | //! extend it at run-time) : count entities and sub-entities ... |
192 | //! <npar> is the total count of parameters (if it is not exact, |
193 | //! it will be extented as necessary) |
194 | //! |
195 | //! Hence, to each record can be bound an Entity and a list of |
196 | //! Parameters. Each kind of FileReaderData can add other data, by |
197 | //! having them in parallel (other arrays with same sizes) |
198 | //! Else, it must manage binding between items and their data |
199 | Standard_EXPORT Interface_FileReaderData(const Standard_Integer nbr, const Standard_Integer npar); |
200 | |
201 | //! Returns a parameter given its absolute rank in the file |
202 | //! in order to be consulted or modified in specilaized actions |
203 | Standard_EXPORT Interface_FileParameter& ChangeParameter (const Standard_Integer numpar); |
204 | |
205 | //! For a given absolute rank of parameter, determines the |
206 | //! record to which its belongs, and the parameter number for it |
207 | Standard_EXPORT void ParamPosition (const Standard_Integer numpar, Standard_Integer& num, Standard_Integer& nump) const; |
208 | |
209 | |
210 | |
211 | private: |
212 | |
213 | |
214 | Standard_Integer thenum0; |
215 | Standard_Integer therrload; |
216 | Handle(Interface_ParamSet) theparams; |
217 | TColStd_Array1OfInteger thenumpar; |
218 | TColStd_Array1OfTransient theents; |
219 | |
220 | |
221 | }; |
222 | |
223 | |
224 | |
225 | |
226 | |
227 | |
228 | |
229 | #endif // _Interface_FileReaderData_HeaderFile |