Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-16 08:29:35

0001 // Created on: 1993-04-15
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_LineBuffer_HeaderFile
0018 #define _Interface_LineBuffer_HeaderFile
0019 
0020 #include <NCollection_Array1.hxx>
0021 #include <TCollection_HAsciiString.hxx>
0022 
0023 //! Simple Management of a Line Buffer, to be used by Interface
0024 //! File Writers.
0025 //! While a String is suitable to do that, this class ensures an
0026 //! optimised Memory Management, because this is a hard point of
0027 //! File Writing.
0028 class Interface_LineBuffer
0029 {
0030 public:
0031   DEFINE_STANDARD_ALLOC
0032 
0033   //! Creates a LineBuffer with an absolute maximum size
0034   //! (Default value is only to satisfy compiler requirement)
0035   Standard_EXPORT Interface_LineBuffer(const Standard_Integer size = 10);
0036 
0037   //! Changes Maximum allowed size of Buffer.
0038   //! If <max> is Zero, Maximum size is set to the initial size.
0039   Standard_EXPORT void SetMax(const Standard_Integer max);
0040 
0041   //! Sets an Initial reservation for Blank characters
0042   //! (this reservation is counted in the size of the current Line)
0043   Standard_EXPORT void SetInitial(const Standard_Integer initial);
0044 
0045   //! Sets a Keep Status at current Length. It means that at next
0046   //! Move, the new line will begin by characters between Keep + 1
0047   //! and current Length
0048   Standard_EXPORT void SetKeep();
0049 
0050   //! Returns True if there is room enough to add <more> characters
0051   //! Else, it is required to Dump the Buffer before refilling it
0052   //! <more> is recorded to manage SetKeep status
0053   Standard_EXPORT Standard_Boolean CanGet(const Standard_Integer more);
0054 
0055   //! Returns the Content of the LineBuffer
0056   Standard_CString Content() const { return &myLine.First(); }
0057 
0058   //! Returns the Length of the LineBuffer
0059   Standard_Integer Length() const { return myLen + myInit; }
0060 
0061   //! Clears completely the LineBuffer
0062   Standard_EXPORT void Clear();
0063 
0064   //! Inhibits effect of SetInitial until the next Move (i.e. Keep)
0065   //! Then Prepare will not insert initial blanks, but further ones
0066   //! will. This allows to cancel initial blanks on an internal Split
0067   //! A call to SetInitial has no effect on this until Move
0068   Standard_EXPORT void FreezeInitial();
0069 
0070   //! Fills a AsciiString <str> with the Content of the Line Buffer,
0071   //! then Clears the LineBuffer
0072   Standard_EXPORT void Move(TCollection_AsciiString& str);
0073 
0074   //! Same as above, but <str> is known through a Handle
0075   Standard_EXPORT void Move(const Handle(TCollection_HAsciiString)& str);
0076 
0077   //! Same as above, but generates the HAsciiString
0078   Standard_EXPORT Handle(TCollection_HAsciiString) Moved();
0079 
0080   //! Adds a text as a CString. Its Length is evaluated from the
0081   //! text (by C function strlen)
0082   Standard_EXPORT void Add(const Standard_CString text);
0083 
0084   //! Adds a text as a CString. Its length is given as <lntext>
0085   Standard_EXPORT void Add(const Standard_CString text, const Standard_Integer lntext);
0086 
0087   //! Adds a text as a AsciiString from TCollection
0088   Standard_EXPORT void Add(const TCollection_AsciiString& text);
0089 
0090   //! Adds a text made of only ONE Character
0091   Standard_EXPORT void Add(const Standard_Character text);
0092 
0093 private:
0094   //! Prepares Move : Inserts Initial Blanks if required, and
0095   //! determines if SetKeep can be supported (it cannot be if Length
0096   //! + Next String to get (see CanGet) overpass Max Size)
0097   Standard_EXPORT void Prepare();
0098 
0099   //! Keeps characters from SetKeep. If SetKeep is Zero, equivalent
0100   //! to Clear
0101   Standard_EXPORT void Keep();
0102 
0103 private:
0104   NCollection_Array1<Standard_Character> myLine;
0105   Standard_Integer                       myMax;
0106   Standard_Integer                       myInit;
0107   Standard_Integer                       myKeep;
0108   Standard_Integer                       myGet;
0109   Standard_Integer                       myLen;
0110   Standard_Integer                       myFriz;
0111   Standard_Character                     myKept;
0112 };
0113 
0114 #endif // _Interface_LineBuffer_HeaderFile