1 // Created on: 2001-10-01
2 // Created by: Julia DOROVSKIKH
3 // Copyright (c) 2001-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <LDOM_OSStream.hxx>
18 #include <Standard_Integer.hxx>
20 // One element of sequence
23 char* buf; // pointer on data string
24 int len; // quantity of really written data
25 LDOM_StringElem* next; // pointer on the next element of a sequence
27 LDOM_StringElem (int aLen)
37 if (next) delete next;
39 friend class LDOM_SBuffer;
42 //=======================================================================
43 //function : LDOM_SBuffer()
45 //=======================================================================
46 LDOM_SBuffer::LDOM_SBuffer (const Standard_Integer theMaxBuf)
47 : myMaxBuf (theMaxBuf), myLength(0)
49 myFirstString = new LDOM_StringElem (theMaxBuf);
50 myCurString = myFirstString;
53 //=======================================================================
54 //function : ~LDOM_SBuffer()
56 //=======================================================================
57 LDOM_SBuffer::~LDOM_SBuffer ()
59 if (myFirstString) delete myFirstString;
62 //=======================================================================
65 //=======================================================================
66 void LDOM_SBuffer::Clear ()
68 if (myFirstString->next) delete myFirstString->next;
69 myFirstString->next = 0;
70 myFirstString->len = 0;
72 myCurString = myFirstString;
75 //=======================================================================
78 //=======================================================================
79 Standard_CString LDOM_SBuffer::str () const
81 char* aRetStr = new char [myLength + 1];
83 LDOM_StringElem* aCurElem = myFirstString;
87 strncpy(aRetStr + aCurLen, aCurElem->buf, aCurElem->len);
88 aCurLen += aCurElem->len;
89 aCurElem = aCurElem->next;
91 *(aRetStr + myLength) = '\0';
96 //=======================================================================
97 //function : overflow()
98 //purpose : redefined virtual
99 //=======================================================================
100 int LDOM_SBuffer::overflow(int c)
103 return xsputn(&cc,1);
106 //=======================================================================
107 //function : underflow
108 //purpose : redefined virtual
109 //=======================================================================
111 int LDOM_SBuffer::underflow()
116 //int LDOM_SBuffer::uflow()
119 //=======================================================================
120 //function : xsputn()
121 //purpose : redefined virtual
122 //=======================================================================
123 int LDOM_SBuffer::xsputn(const char* aStr, int n)
126 int freeLen = myMaxBuf - myCurString->len - 1;
129 strncpy(myCurString->buf + myCurString->len, aStr, aLen);
131 else if (freeLen <= 0)
133 LDOM_StringElem* aNextElem = new LDOM_StringElem(Max(aLen, myMaxBuf));
134 myCurString->next = aNextElem;
135 myCurString = aNextElem;
136 strncpy(myCurString->buf + myCurString->len, aStr, aLen);
138 else // 0 < freeLen < n
140 // copy string by parts
141 strncpy(myCurString->buf + myCurString->len, aStr, freeLen);
142 myCurString->len += freeLen;
143 *(myCurString->buf + myCurString->len) = '\0';
145 LDOM_StringElem* aNextElem = new LDOM_StringElem(Max(aLen, myMaxBuf));
146 myCurString->next = aNextElem;
147 myCurString = aNextElem;
148 strncpy(myCurString->buf + myCurString->len, aStr + freeLen, aLen);
150 myCurString->len += aLen - 1;
151 *(myCurString->buf + myCurString->len) = '\0';
157 //streamsize LDOM_SBuffer::xsgetn(char* s, streamsize n)
158 //{ return _IO_default_xsgetn(this, s, n); }
160 //=======================================================================
161 //function : LDOM_OSStream()
162 //purpose : Constructor
163 //=======================================================================
164 LDOM_OSStream::LDOM_OSStream (const Standard_Integer theMaxBuf)
165 : Standard_OStream (&myBuffer), myBuffer (theMaxBuf)