1 // Created on: 2001-10-01
2 // Created by: Julia DOROVSKIKH
3 // Copyright (c) 2001-2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
21 #include <LDOM_OSStream.hxx>
23 #include <Standard_Integer.hxx>
25 // One element of sequence
28 char* buf; // pointer on data string
29 int len; // quantity of really written data
30 LDOM_StringElem* next; // pointer on the next element of a sequence
32 LDOM_StringElem (int aLen)
42 if (next) delete next;
44 friend class LDOM_SBuffer;
47 //=======================================================================
48 //function : LDOM_SBuffer()
50 //=======================================================================
51 LDOM_SBuffer::LDOM_SBuffer (const Standard_Integer theMaxBuf)
52 : myMaxBuf (theMaxBuf), myLength(0)
54 myFirstString = new LDOM_StringElem (theMaxBuf);
55 myCurString = myFirstString;
58 //=======================================================================
59 //function : ~LDOM_SBuffer()
61 //=======================================================================
62 LDOM_SBuffer::~LDOM_SBuffer ()
64 if (myFirstString) delete myFirstString;
67 //=======================================================================
70 //=======================================================================
71 void LDOM_SBuffer::Clear ()
73 if (myFirstString->next) delete myFirstString->next;
74 myFirstString->next = 0;
75 myFirstString->len = 0;
77 myCurString = myFirstString;
80 //=======================================================================
83 //=======================================================================
84 Standard_CString LDOM_SBuffer::str () const
86 char* aRetStr = new char [myLength + 1];
88 LDOM_StringElem* aCurElem = myFirstString;
92 strncpy(aRetStr + aCurLen, aCurElem->buf, aCurElem->len);
93 aCurLen += aCurElem->len;
94 aCurElem = aCurElem->next;
96 *(aRetStr + myLength) = '\0';
101 //=======================================================================
102 //function : overflow()
103 //purpose : redefined virtual
104 //=======================================================================
105 int LDOM_SBuffer::overflow(int c)
108 return xsputn(&cc,1);
111 //=======================================================================
112 //function : underflow
113 //purpose : redefined virtual
114 //=======================================================================
116 int LDOM_SBuffer::underflow()
121 //int LDOM_SBuffer::uflow()
124 //=======================================================================
125 //function : xsputn()
126 //purpose : redefined virtual
127 //=======================================================================
128 int LDOM_SBuffer::xsputn(const char* aStr, int n)
131 int freeLen = myMaxBuf - myCurString->len - 1;
134 strncpy(myCurString->buf + myCurString->len, aStr, aLen);
136 else if (freeLen <= 0)
138 LDOM_StringElem* aNextElem = new LDOM_StringElem(Max(aLen, myMaxBuf));
139 myCurString->next = aNextElem;
140 myCurString = aNextElem;
141 strncpy(myCurString->buf + myCurString->len, aStr, aLen);
143 else // 0 < freeLen < n
145 // copy string by parts
146 strncpy(myCurString->buf + myCurString->len, aStr, freeLen);
147 myCurString->len += freeLen;
148 *(myCurString->buf + myCurString->len) = '\0';
150 LDOM_StringElem* aNextElem = new LDOM_StringElem(Max(aLen, myMaxBuf));
151 myCurString->next = aNextElem;
152 myCurString = aNextElem;
153 strncpy(myCurString->buf + myCurString->len, aStr + freeLen, aLen);
155 myCurString->len += aLen - 1;
156 *(myCurString->buf + myCurString->len) = '\0';
162 //streamsize LDOM_SBuffer::xsgetn(char* s, streamsize n)
163 //{ return _IO_default_xsgetn(this, s, n); }
165 //=======================================================================
166 //function : LDOM_OSStream()
167 //purpose : Constructor
168 //=======================================================================
169 LDOM_OSStream::LDOM_OSStream (const Standard_Integer theMaxBuf)
170 : Standard_OStream (&myBuffer), myBuffer (theMaxBuf)