1 // Created on: 1993-04-15
2 // Created by: Christian CAILLET
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #ifndef _Interface_LineBuffer_HeaderFile
18 #define _Interface_LineBuffer_HeaderFile
20 #include <NCollection_Array1.hxx>
21 #include <TCollection_HAsciiString.hxx>
23 //! Simple Management of a Line Buffer, to be used by Interface
25 //! While a String is suitable to do that, this class ensures an
26 //! optimised Memory Management, because this is a hard point of
28 class Interface_LineBuffer
35 //! Creates a LineBuffer with an absolute maximum size
36 //! (Default value is only to satisfy compiler requirement)
37 Standard_EXPORT Interface_LineBuffer(const Standard_Integer size = 10);
39 //! Changes Maximum allowed size of Buffer.
40 //! If <max> is Zero, Maximum size is set to the initial size.
41 Standard_EXPORT void SetMax (const Standard_Integer max);
43 //! Sets an Initial reservation for Blank characters
44 //! (this reservation is counted in the size of the current Line)
45 Standard_EXPORT void SetInitial (const Standard_Integer initial);
47 //! Sets a Keep Status at current Length. It means that at next
48 //! Move, the new line will begin by characters between Keep + 1
49 //! and current Length
50 Standard_EXPORT void SetKeep();
52 //! Returns True if there is room enough to add <more> characters
53 //! Else, it is required to Dump the Buffer before refilling it
54 //! <more> is recorded to manage SetKeep status
55 Standard_EXPORT Standard_Boolean CanGet (const Standard_Integer more);
57 //! Returns the Content of the LineBuffer
58 Standard_CString Content() const { return &myLine.First(); }
60 //! Returns the Length of the LineBuffer
61 Standard_Integer Length() const { return myLen + myInit; }
63 //! Clears completely the LineBuffer
64 Standard_EXPORT void Clear();
66 //! Inhibits effect of SetInitial until the next Move (i.e. Keep)
67 //! Then Prepare will not insert initial blanks, but further ones
68 //! will. This allows to cancel initial blanks on an internal Split
69 //! A call to SetInitial has no effect on this until Move
70 Standard_EXPORT void FreezeInitial();
72 //! Fills a AsciiString <str> with the Content of the Line Buffer,
73 //! then Clears the LineBuffer
74 Standard_EXPORT void Move (TCollection_AsciiString& str);
76 //! Same as above, but <str> is known through a Handle
77 Standard_EXPORT void Move (const Handle(TCollection_HAsciiString)& str);
79 //! Same as above, but generates the HAsciiString
80 Standard_EXPORT Handle(TCollection_HAsciiString) Moved();
82 //! Adds a text as a CString. Its Length is evaluated from the
83 //! text (by C function strlen)
84 Standard_EXPORT void Add (const Standard_CString text);
86 //! Adds a text as a CString. Its length is given as <lntext>
87 Standard_EXPORT void Add (const Standard_CString text, const Standard_Integer lntext);
89 //! Adds a text as a AsciiString from TCollection
90 Standard_EXPORT void Add (const TCollection_AsciiString& text);
92 //! Adds a text made of only ONE Character
93 Standard_EXPORT void Add (const Standard_Character text);
97 //! Prepares Move : Inserts Initial Blanks if required, and
98 //! determines if SetKeep can be supported (it cannot be if Length
99 //! + Next String to get (see CanGet) overpass Max Size)
100 Standard_EXPORT void Prepare();
102 //! Keeps characters from SetKeep. If SetKeep is Zero, equivalent
104 Standard_EXPORT void Keep();
108 NCollection_Array1<Standard_Character> myLine;
109 Standard_Integer myMax;
110 Standard_Integer myInit;
111 Standard_Integer myKeep;
112 Standard_Integer myGet;
113 Standard_Integer myLen;
114 Standard_Integer myFriz;
115 Standard_Character myKept;
119 #endif // _Interface_LineBuffer_HeaderFile