Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-12 08:47:07

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