1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
// File: LDOM_OSStream.cxx
// Created: 01.10.01 10:57:37
// Author: Julia DOROVSKIKH
// Copyright: Open Cascade 2001
// History:
#include <LDOM_OSStream.hxx>
#include <string.h>
#include <Standard_Integer.hxx>
// One element of sequence
class LDOM_StringElem
{
char* buf; // pointer on data string
int len; // quantity of really written data
LDOM_StringElem* next; // pointer on the next element of a sequence
LDOM_StringElem (int aLen)
{
buf = new char[aLen];
len = 0;
next = 0;
}
~LDOM_StringElem ()
{
delete [] buf;
if (next) delete next;
}
friend class LDOM_SBuffer;
};
//=======================================================================
//function : LDOM_SBuffer()
//purpose :
//=======================================================================
LDOM_SBuffer::LDOM_SBuffer (const Standard_Integer theMaxBuf)
: myMaxBuf (theMaxBuf), myLength(0)
{
myFirstString = new LDOM_StringElem (theMaxBuf);
myCurString = myFirstString;
}
//=======================================================================
//function : ~LDOM_SBuffer()
//purpose :
//=======================================================================
LDOM_SBuffer::~LDOM_SBuffer ()
{
if (myFirstString) delete myFirstString;
}
//=======================================================================
//function : Clear()
//purpose :
//=======================================================================
void LDOM_SBuffer::Clear ()
{
if (myFirstString->next) delete myFirstString->next;
myFirstString->next = 0;
myFirstString->len = 0;
myLength = 0;
myCurString = myFirstString;
}
//=======================================================================
//function : str()
//purpose :
//=======================================================================
Standard_CString LDOM_SBuffer::str () const
{
char* aRetStr = new char [myLength + 1];
LDOM_StringElem* aCurElem = myFirstString;
int aCurLen = 0;
while (aCurElem)
{
strncpy(aRetStr + aCurLen, aCurElem->buf, aCurElem->len);
aCurLen += aCurElem->len;
aCurElem = aCurElem->next;
}
*(aRetStr + myLength) = '\0';
return aRetStr;
}
//=======================================================================
//function : overflow()
//purpose : redefined virtual
//=======================================================================
int LDOM_SBuffer::overflow(signed char c)
{
char cc = (char)c;
return xsputn(&cc,1);
}
//=======================================================================
//function : underflow
//purpose : redefined virtual
//=======================================================================
int LDOM_SBuffer::underflow()
{
return EOF;
}
//int LDOM_SBuffer::uflow()
//{ return EOF; }
//=======================================================================
//function : xsputn()
//purpose : redefined virtual
//=======================================================================
std::streamsize LDOM_SBuffer::xsputn(const char* aStr, std::streamsize n)
{
int aLen = n + 1;
int freeLen = myMaxBuf - myCurString->len - 1;
if (freeLen >= n)
{
strncpy(myCurString->buf + myCurString->len, aStr, aLen);
}
else if (freeLen <= 0)
{
LDOM_StringElem* aNextElem = new LDOM_StringElem(Max(aLen, myMaxBuf));
myCurString->next = aNextElem;
myCurString = aNextElem;
strncpy(myCurString->buf + myCurString->len, aStr, aLen);
}
else // 0 < freeLen < n
{
// copy string by parts
strncpy(myCurString->buf + myCurString->len, aStr, freeLen);
myCurString->len += freeLen;
*(myCurString->buf + myCurString->len) = '\0';
aLen -= freeLen;
LDOM_StringElem* aNextElem = new LDOM_StringElem(Max(aLen, myMaxBuf));
myCurString->next = aNextElem;
myCurString = aNextElem;
strncpy(myCurString->buf + myCurString->len, aStr + freeLen, aLen);
}
myCurString->len += aLen - 1;
*(myCurString->buf + myCurString->len) = '\0';
myLength += n;
return n;
}
//streamsize LDOM_SBuffer::xsgetn(char* s, streamsize n)
//{ return _IO_default_xsgetn(this, s, n); }
//=======================================================================
//function : LDOM_OSStream()
//purpose : Constructor
//=======================================================================
LDOM_OSStream::LDOM_OSStream (const Standard_Integer theMaxBuf)
: Standard_OStream (&myBuffer), myBuffer (theMaxBuf)
{
init(&myBuffer);
}
|