Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:04:08

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