42cf5bc1 |
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 |
5 | // |
6 | // This file is part of Open CASCADE Technology software library. |
7 | // |
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. |
13 | // |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
16 | |
17 | #ifndef _Interface_LineBuffer_HeaderFile |
18 | #define _Interface_LineBuffer_HeaderFile |
19 | |
20 | #include <Standard.hxx> |
21 | #include <Standard_DefineAlloc.hxx> |
22 | #include <Standard_Handle.hxx> |
23 | |
24 | #include <TCollection_AsciiString.hxx> |
25 | #include <Standard_Integer.hxx> |
26 | #include <Standard_Character.hxx> |
27 | #include <Standard_Boolean.hxx> |
28 | #include <Standard_CString.hxx> |
29 | class Standard_OutOfRange; |
30 | class TCollection_AsciiString; |
31 | class TCollection_HAsciiString; |
32 | |
33 | |
34 | //! Simple Management of a Line Buffer, to be used by Interface |
35 | //! File Writers. |
36 | //! While a String is suitable to do that, this class ensures an |
37 | //! optimised Memory Management, because this is a hard point of |
38 | //! File Writing. |
39 | class Interface_LineBuffer |
40 | { |
41 | public: |
42 | |
43 | DEFINE_STANDARD_ALLOC |
44 | |
45 | |
46 | //! Creates a LineBuffer with an absolute maximum size |
47 | //! (Default value is only to satisfy compiler requirement) |
48 | Standard_EXPORT Interface_LineBuffer(const Standard_Integer size = 10); |
49 | |
50 | //! Changes Maximum allowed size of Buffer. |
51 | //! If <max> is Zero, Maximum size is set to the initial size. |
52 | Standard_EXPORT void SetMax (const Standard_Integer max); |
53 | |
54 | //! Sets an Initial reservation for Blank characters |
55 | //! (this reservation is counted in the size of the current Line) |
56 | Standard_EXPORT void SetInitial (const Standard_Integer initial); |
57 | |
58 | //! Sets a Keep Status at current Length. It means that at next |
59 | //! Move, the new line will begin by characters between Keep + 1 |
60 | //! and current Length |
61 | Standard_EXPORT void SetKeep(); |
62 | |
63 | //! Returns True if there is room enough to add <more> characters |
64 | //! Else, it is required to Dump the Buffer before refilling it |
65 | //! <more> is recorded to manage SetKeep status |
66 | Standard_EXPORT Standard_Boolean CanGet (const Standard_Integer more); |
67 | |
68 | //! Returns the Content of the LineBuffer |
69 | //! was C++ : return const |
70 | Standard_EXPORT Standard_CString Content() const; |
71 | |
72 | //! Returns the Length of the LineBuffer |
73 | Standard_EXPORT Standard_Integer Length() const; |
74 | |
75 | //! Clears completely the LineBuffer |
76 | Standard_EXPORT void Clear(); |
77 | |
78 | //! Inhibits effect of SetInitial until the next Move (i.e. Keep) |
79 | //! Then Prepare will not insert initial blanks, but further ones |
80 | //! will. This allows to cancel initial blanks on an internal Split |
81 | //! A call to SetInitial has no effect on this until Move |
82 | Standard_EXPORT void FreezeInitial(); |
83 | |
84 | //! Fills a AsciiString <str> with the Content of the Line Buffer, |
85 | //! then Clears the LineBuffer |
86 | Standard_EXPORT void Move (TCollection_AsciiString& str); |
87 | |
88 | //! Same as above, but <str> is known through a Handle |
89 | Standard_EXPORT void Move (const Handle(TCollection_HAsciiString)& str); |
90 | |
91 | //! Same as above, but generates the HAsciiString |
92 | Standard_EXPORT Handle(TCollection_HAsciiString) Moved(); |
93 | |
94 | //! Adds a text as a CString. Its Length is evaluated from the |
95 | //! text (by C function strlen) |
96 | Standard_EXPORT void Add (const Standard_CString text); |
97 | |
98 | //! Adds a text as a CString. Its length is given as <lntext> |
99 | Standard_EXPORT void Add (const Standard_CString text, const Standard_Integer lntext); |
100 | |
101 | //! Adds a text as a AsciiString from TCollection |
102 | Standard_EXPORT void Add (const TCollection_AsciiString& text); |
103 | |
104 | //! Adds a text made of only ONE Character |
105 | Standard_EXPORT void Add (const Standard_Character text); |
106 | |
107 | |
108 | |
109 | |
110 | protected: |
111 | |
112 | |
113 | |
114 | |
115 | |
116 | private: |
117 | |
118 | |
119 | //! Prepares Move : Inserts Initial Blanks if required, and |
120 | //! determines if SetKeep can be supported (it cannot be if Length |
121 | //! + Next String to get (see CanGet) overpass Max Size) |
122 | Standard_EXPORT void Prepare(); |
123 | |
124 | //! Keeps characters from SetKeep. If SetKeep is Zero, equivalent |
125 | //! to Clear |
126 | Standard_EXPORT void Keep(); |
127 | |
128 | |
129 | TCollection_AsciiString theline; |
130 | Standard_Integer themax; |
131 | Standard_Integer theinit; |
132 | Standard_Integer thekeep; |
133 | Standard_Integer theget; |
134 | Standard_Integer thelen; |
135 | Standard_Integer thefriz; |
136 | Standard_Character thekept; |
137 | |
138 | |
139 | }; |
140 | |
141 | |
142 | |
143 | |
144 | |
145 | |
146 | |
147 | #endif // _Interface_LineBuffer_HeaderFile |