[uClibc-cvs] CVS uClibc++/include
CVS User gkajmowi
gkajmowi at codepoet.org
Thu Jan 20 18:12:40 UTC 2005
Update of /var/cvs/uClibc++/include
In directory nail:/tmp/cvs-serv11257/include
Modified Files:
sstream streambuf
Log Message:
Sstream cleanups, fixes and improvements.
--- /var/cvs/uClibc++/include/sstream 2005/01/14 23:57:30 1.6
+++ /var/cvs/uClibc++/include/sstream 2005/01/20 18:12:39 1.7
@@ -26,8 +26,10 @@
#include <ios>
#include <istream>
#include <ostream>
-//#include <fstream>
+#include <iostream>
#include <string>
+#include <assert.h>
+#include <unistd.h>
namespace std{
@@ -42,14 +44,14 @@
typedef typename Allocator::size_type size_type;
explicit basic_stringbuf(ios_base::openmode which = ios_base::in | ios_base::out)
- : data(), ielement(0)
+ : data(), ielement(0), oelement(0)
{
basic_streambuf<charT,traits>::openedFor = which;
}
explicit basic_stringbuf(const basic_string<charT,traits,Allocator>& str,
ios_base::openmode which = ios_base::in | ios_base::out)
- : data(str), ielement(0)
+ : data(str), ielement(0), oelement(str.length())
{
basic_streambuf<charT,traits>::openedFor = which;
}
@@ -63,13 +65,13 @@
void str(const basic_string<charT,traits,Allocator>& s){
data = s;
ielement = 0;
+ oelement = data.length();
}
protected:
- /* From basic_streambuf
- ios_base::openmode openedFor; - holds the modes we are supporting
- */
-
+ virtual int sync(){
+ return 0;
+ }
virtual int_type underflow(){
if(ielement >= data.length()){
return traits::eof();
@@ -132,7 +134,12 @@
//Actually add character, if possible
if(basic_streambuf<charT,traits>::openedFor & ios_base::out){
- data.push_back(c);
+ if(oelement >= data.length()){
+ data.push_back(c);
+ }else{
+ data[oelement] = c;
+ }
+ ++oelement;
return c;
}
//Not possible
@@ -145,7 +152,20 @@
}
virtual streamsize xsputn(const char_type* s, streamsize n){
- data.append(s, n);
+ streamsize alen = n;
+ streamsize rlen = data.length() - oelement;
+ if(alen < rlen){
+ rlen = alen;
+ }
+ if( rlen > 0 ){
+ data.replace(oelement, rlen, s);
+ oelement += rlen;
+ alen -= rlen;
+ }
+ if(alen > 0){
+ data.append(s + rlen, alen);
+ oelement += alen;
+ }
return n;
}
@@ -202,6 +222,7 @@
basic_string<charT,traits,Allocator> data;
size_type ielement;
+ size_type oelement;
};
--- /var/cvs/uClibc++/include/streambuf 2005/01/10 20:24:43 1.8
+++ /var/cvs/uClibc++/include/streambuf 2005/01/20 18:12:39 1.9
@@ -118,7 +118,7 @@
}
int_type sputc(char_type c){
- overflow(c);
+ overflow( traits::to_int_type(c) );
return traits::to_int_type(c);
}
More information about the uClibc-cvs
mailing list