1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
3 // The content of this file is subject to the Open CASCADE Technology Public
4 // License Version 6.5 (the "License"). You may not use the content of this file
5 // except in compliance with the License. Please obtain a copy of the License
6 // at http://www.opencascade.org and read it completely before using this file.
8 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11 // The Original Code and all software distributed under the License is
12 // distributed on an "AS IS" basis, without warranty of any kind, and the
13 // Initial Developer hereby disclaims all such warranties, including without
14 // limitation, any warranties of merchantability, fitness for a particular
15 // purpose or non-infringement. Please see the License for the specific terms
16 // and conditions governing the rights and limitations under the License.
18 #include <Interface_LineBuffer.ixx>
19 #include <Standard_OutOfRange.hxx>
23 // LineBuffer, c est une String avec une Longueur reservee fixe au depart
24 // et une longueur effective <thelen>. theline(thelen+1) vaut '\0'
28 Interface_LineBuffer::Interface_LineBuffer (const Standard_Integer size)
29 : theline (size+1,' ')
31 theline.SetValue(1,'\0');
32 themax = size; theinit = thelen = theget = thekeep = thefriz = 0;
35 void Interface_LineBuffer::SetMax (const Standard_Integer max)
37 if (max > theline.Length()) Standard_OutOfRange::Raise
38 ("Interface LineBuffer : SetMax");
39 if (max <= 0) themax = theline.Length();
44 void Interface_LineBuffer::SetInitial (const Standard_Integer initial)
46 if (thefriz > 0) return;
47 if (initial >= themax) Standard_OutOfRange::Raise
48 ("Interface LineBuffer : SetInitial");
49 if (initial <= 0) theinit = 0;
50 else theinit = initial;
53 void Interface_LineBuffer::SetKeep ()
54 { thekeep = -thelen; }
56 Standard_Boolean Interface_LineBuffer::CanGet (const Standard_Integer more)
59 if ((thelen + theinit + more) <= themax) return Standard_True;
60 if (thekeep < 0) thekeep = -thekeep;
61 return Standard_False;
64 Standard_CString Interface_LineBuffer::Content () const
65 { return theline.ToCString(); }
67 Standard_Integer Interface_LineBuffer::Length () const
68 { return thelen + theinit; } // +theinit : longueur vraie avec blancs
70 void Interface_LineBuffer::FreezeInitial ()
71 { thefriz = theinit+1; theinit = 0; }
73 void Interface_LineBuffer::Clear ()
75 theget = thekeep = thelen = thefriz = 0;
76 theline.SetValue(1,'\0');
79 // .... RESULTATS ....
81 void Interface_LineBuffer::Prepare ()
83 // ATTENTION aux blanx initiaux
85 Standard_Integer i; // svv Jan11 2000 : porting on DEC
87 if( (thelen +theinit) > themax)
90 for (i = thelen + 1; i > 0; i --) {
91 theline.SetValue(i + theinit, theline.Value(i));
93 for (i = 1; i <= theinit; i ++) theline.SetValue(i,' ');
95 // GERER KEEP : est-il jouable ? sinon, annuler. sioui, noter la jointure
96 if (thekeep > 0) thekeep += (theinit+1); // theinit, et +1 car Keep INCLUS
98 { if ((thelen + theget + theinit - thekeep) >= themax) thekeep = 0; }
100 { thekept = theline.Value(thekeep); theline.SetValue(thekeep,'\0'); }
103 void Interface_LineBuffer::Keep ()
105 // Si Keep, sauver de thekeep + 1 a thelen (+1 pour 0 final)
107 theline.SetValue(1,thekept);
108 for (Standard_Integer i = thekeep+1; i <= thelen+theinit+1; i ++) {
109 theline.SetValue(i-thekeep+1, theline.Value(i));
111 thelen = thelen+theinit-thekeep+1;
114 theget = thekeep = 0;
115 if (thefriz > 0) { theinit = thefriz - 1; thefriz = 0; }
119 void Interface_LineBuffer::Move (TCollection_AsciiString& str)
122 str.AssignCat(theline.ToCString());
126 void Interface_LineBuffer::Move (const Handle(TCollection_HAsciiString)& str)
129 str->AssignCat(theline.ToCString());
133 Handle(TCollection_HAsciiString) Interface_LineBuffer::Moved ()
136 Handle(TCollection_HAsciiString) R =
137 new TCollection_HAsciiString(theline.ToCString());
144 void Interface_LineBuffer::Add (const Standard_CString text)
145 { Add (text,strlen(text)); }
147 void Interface_LineBuffer::Add
148 (const Standard_CString text, const Standard_Integer lntext)
150 Standard_Integer lnt =
151 (lntext > (themax-thelen-theinit) ? (themax-thelen-theinit) : lntext);
152 for (Standard_Integer i = 1; i <= lnt; i ++)
153 theline.SetValue (thelen+i, text[i-1]);
155 theline.SetValue (thelen+1, '\0');
158 void Interface_LineBuffer::Add (const TCollection_AsciiString& text)
159 { Add ( text.ToCString() , text.Length() ); }
161 void Interface_LineBuffer::Add (const Standard_Character text)
163 theline.SetValue (thelen+1,text);
165 theline.SetValue (thelen+1,'\0');