Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-08 10:23:21

0001 // Created on: 1993-02-04
0002 // Created by: Christian CAILLET
0003 // Copyright (c) 1993-1999 Matra Datavision
0004 // Copyright (c) 1999-2014 OPEN CASCADE SAS
0005 //
0006 // This file is part of Open CASCADE Technology software library.
0007 //
0008 // This library is free software; you can redistribute it and/or modify it under
0009 // the terms of the GNU Lesser General Public License version 2.1 as published
0010 // by the Free Software Foundation, with special exception defined in the file
0011 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0012 // distribution for complete text of the license and disclaimer of any warranty.
0013 //
0014 // Alternatively, this file may be used under the terms of Open CASCADE
0015 // commercial license or contractual agreement.
0016 
0017 #ifndef _Interface_FileReaderTool_HeaderFile
0018 #define _Interface_FileReaderTool_HeaderFile
0019 
0020 #include <Standard.hxx>
0021 #include <Standard_DefineAlloc.hxx>
0022 #include <Standard_Handle.hxx>
0023 
0024 #include <Standard_Integer.hxx>
0025 #include <Standard_Transient.hxx>
0026 #include <NCollection_Array1.hxx>
0027 #include <NCollection_HArray1.hxx>
0028 class Interface_Protocol;
0029 class Interface_FileReaderData;
0030 class Interface_InterfaceModel;
0031 class Message_Messenger;
0032 class Interface_Check;
0033 class Standard_Transient;
0034 class Interface_GeneralLib;
0035 class Interface_ReaderLib;
0036 
0037 //! Defines services which are required to load an InterfaceModel
0038 //! from a File. Typically, it may firstly transform a system
0039 //! file into a FileReaderData object, then work on it, not longer
0040 //! considering file contents, to load an Interface Model.
0041 //! It may also work on a FileReaderData already loaded.
0042 //!
0043 //! FileReaderTool provides, on one hand, some general services
0044 //! which are common to all read operations but can be redefined,
0045 //! plus general actions to be performed specifically for each
0046 //! Norm, as deferred methods to define.
0047 //!
0048 //! In particular, FileReaderTool defines the Interface's Unknown
0049 //! and Error entities
0050 class Interface_FileReaderTool
0051 {
0052 public:
0053   DEFINE_STANDARD_ALLOC
0054 
0055   //! Sets Data to a FileReaderData. Works with a Protocol
0056   Standard_EXPORT void SetData(const occ::handle<Interface_FileReaderData>& reader,
0057                                const occ::handle<Interface_Protocol>&       protocol);
0058 
0059   //! Returns the Protocol given at creation time
0060   Standard_EXPORT occ::handle<Interface_Protocol> Protocol() const;
0061 
0062   //! Returns the FileReaderData which is used to work
0063   Standard_EXPORT occ::handle<Interface_FileReaderData> Data() const;
0064 
0065   //! Stores a Model. Used when the Model has been loaded
0066   Standard_EXPORT void SetModel(const occ::handle<Interface_InterfaceModel>& amodel);
0067 
0068   //! Returns the stored Model
0069   Standard_EXPORT occ::handle<Interface_InterfaceModel> Model() const;
0070 
0071   //! Sets Messenger used for outputting messages
0072   Standard_EXPORT void SetMessenger(const occ::handle<Message_Messenger>& messenger);
0073 
0074   //! Returns Messenger used for outputting messages.
0075   //! The returned object is guaranteed to be non-null;
0076   //! default is Message::Messenger().
0077   Standard_EXPORT occ::handle<Message_Messenger> Messenger() const;
0078 
0079   //! Sets trace level used for outputting messages
0080   //! - 0: no trace at all
0081   //! - 1: errors
0082   //! - 2: errors and warnings
0083   //! - 3: all messages
0084   //! Default is 1 : Errors traced
0085   Standard_EXPORT void SetTraceLevel(const int tracelev);
0086 
0087   //! Returns trace level used for outputting messages.
0088   Standard_EXPORT int TraceLevel() const;
0089 
0090   //! Allows controlling whether exception raisings are handled
0091   //! If err is False, they are not (hence, dbx can take control)
0092   //! If err is True, they are, and they are traced
0093   //! (by putting on messenger Entity's Number and file record num)
0094   //! Default given at Model's creation time is True
0095   Standard_EXPORT void SetErrorHandle(const bool err);
0096 
0097   //! Returns ErrorHandle flag
0098   Standard_EXPORT bool ErrorHandle() const;
0099 
0100   //! Fills records with empty entities; once done, each entity can
0101   //! ask the FileReaderTool for any entity referenced through an
0102   //! identifier. Calls Recognize which is specific to each specific
0103   //! type of FileReaderTool
0104   Standard_EXPORT void SetEntities();
0105 
0106   //! Recognizes a record, given its number. Specific to each
0107   //! Interface; called by SetEntities. It can call the basic method
0108   //! RecognizeByLib.
0109   //! Returns False if recognition has failed, True else.
0110   //! <ach> has not to be filled if simply Recognition has failed :
0111   //! it must record true error messages : RecognizeByLib can
0112   //! generate error messages if NewRead is called
0113   //!
0114   //! Note that it works thru a Recognizer (method Evaluate) which
0115   //! has to be memorized before starting
0116   Standard_EXPORT virtual bool Recognize(const int                        num,
0117                                          occ::handle<Interface_Check>&    ach,
0118                                          occ::handle<Standard_Transient>& ent) = 0;
0119 
0120   //! Recognizes a record with the help of Libraries. Can be used
0121   //! to implement the method Recognize.
0122   //! <rlib> is used to find Protocol and CaseNumber to apply
0123   //! <glib> performs the creation (by service NewVoid, or NewRead
0124   //! if NewVoid gave no result)
0125   //! <ach> is a check, which is transmitted to NewRead if it is
0126   //! called, gives a result but which is false
0127   //! <ent> is the result
0128   //! Returns False if recognition has failed, True else
0129   Standard_EXPORT bool RecognizeByLib(const int                        num,
0130                                       Interface_GeneralLib&            glib,
0131                                       Interface_ReaderLib&             rlib,
0132                                       occ::handle<Interface_Check>&    ach,
0133                                       occ::handle<Standard_Transient>& ent) const;
0134 
0135   //! Provides an unknown entity, specific to the Interface
0136   //! called by SetEntities when Recognize has failed (Unknown alone)
0137   //! or by LoadModel when an Entity has caused a Fail on reading
0138   //! (to keep at least its literal description)
0139   //! Uses Protocol to do it
0140   Standard_EXPORT occ::handle<Standard_Transient> UnknownEntity() const;
0141 
0142   //! Creates an empty Model of the norm. Uses Protocol to do it
0143   Standard_EXPORT occ::handle<Interface_InterfaceModel> NewModel() const;
0144 
0145   //! Reads and fills Entities from the FileReaderData set by
0146   //! SetData to an InterfaceModel.
0147   //! It enchains required operations, the specific ones correspond
0148   //! to deferred methods (below) to be defined for each Norm.
0149   //! It manages also error recovery and trace.
0150   //! Remark : it calls SetModel.
0151   //! It Can raise any error which can occur during a load
0152   //! operation, unless Error Handling is set.
0153   //! This method can also be redefined if judged necessary.
0154   Standard_EXPORT void LoadModel(const occ::handle<Interface_InterfaceModel>& amodel);
0155 
0156   //! Reads, Fills and Returns one Entity read from a Record of the
0157   //! FileReaderData. This Method manages also case of Fail or
0158   //! Warning, by producing a ReportEntyty plus , for a Fail, a
0159   //! literal Content (as an UnknownEntity). Performs also Trace
0160   Standard_EXPORT occ::handle<Standard_Transient> LoadedEntity(const int num);
0161 
0162   //! Fills model's header; each Interface defines for its Model its
0163   //! own file header; this method fills it from FileReaderTool.+
0164   //! It is called by AnalyseFile from InterfaceModel
0165   Standard_EXPORT virtual void BeginRead(const occ::handle<Interface_InterfaceModel>& amodel) = 0;
0166 
0167   //! Fills an Entity, given record no; specific to each Interface,
0168   //! called by AnalyseFile from InterfaceModel (which manages its
0169   //! calling arguments)
0170   //! To work, each Interface can define a method in its proper
0171   //! Transient class, like this (given as an example) :
0172   //! AnalyseRecord (me : mutable; FR : in out FileReaderTool;
0173   //! num : Integer; acheck : in out Check)
0174   //! returns Boolean;
0175   //! and call it from AnalyseRecord
0176   //!
0177   //! Returned Value : True if the entity could be loaded, False
0178   //! else (in case of syntactic fail)
0179   Standard_EXPORT virtual bool AnalyseRecord(const int                              num,
0180                                              const occ::handle<Standard_Transient>& anent,
0181                                              occ::handle<Interface_Check>&          acheck) = 0;
0182 
0183   Standard_EXPORT virtual ~Interface_FileReaderTool();
0184 
0185   //! Ends file reading after reading all the entities
0186   //! default is doing nothing; redefinable as necessary
0187   Standard_EXPORT virtual void EndRead(const occ::handle<Interface_InterfaceModel>& amodel);
0188 
0189   //! Clear fields
0190   Standard_EXPORT void Clear();
0191 
0192 protected:
0193   //! Constructor; sets default fields
0194   Standard_EXPORT Interface_FileReaderTool();
0195 
0196 private:
0197   occ::handle<Interface_Protocol>                                   theproto;
0198   occ::handle<Interface_FileReaderData>                             thereader;
0199   occ::handle<Interface_InterfaceModel>                             themodel;
0200   occ::handle<Message_Messenger>                                    themessenger;
0201   int                                                               thetrace;
0202   bool                                                              theerrhand;
0203   int                                                               thenbrep0;
0204   int                                                               thenbreps;
0205   occ::handle<NCollection_HArray1<occ::handle<Standard_Transient>>> thereports;
0206 };
0207 
0208 #endif // _Interface_FileReaderTool_HeaderFile