summaryrefslogtreecommitdiffstats
path: root/src/dom/io/domstream.cpp
diff options
context:
space:
mode:
authorKris De Gussem <kris.degussem@gmail.com>2013-03-03 09:18:37 +0000
committerKris <Kris.De.Gussem@hotmail.com>2013-03-03 09:18:37 +0000
commit1279e676eccb0b3786d21fd390e4965f78a003c1 (patch)
tree7caebee8350e7ddced1dfdccb1b34d38a7d47b8c /src/dom/io/domstream.cpp
parentFix autotools deprecation warnings (diff)
downloadinkscape-1279e676eccb0b3786d21fd390e4965f78a003c1.tar.gz
inkscape-1279e676eccb0b3786d21fd390e4965f78a003c1.zip
Preparation to merge /dom/io and /io code (bug #1120585 )
(bzr r12168)
Diffstat (limited to 'src/dom/io/domstream.cpp')
-rw-r--r--src/dom/io/domstream.cpp218
1 files changed, 84 insertions, 134 deletions
diff --git a/src/dom/io/domstream.cpp b/src/dom/io/domstream.cpp
index 21d09662a..b9ff7e9d2 100644
--- a/src/dom/io/domstream.cpp
+++ b/src/dom/io/domstream.cpp
@@ -424,12 +424,11 @@ static int dprintf(Writer &outs, const DOMString &fmt, va_list ap)
//# B A S I C I N P U T S T R E A M
//#########################################################################
-
/**
*
- */
-BasicInputStream::BasicInputStream(const InputStream &sourceStream)
- : source((InputStream &)sourceStream)
+ */
+BasicInputStream::BasicInputStream(InputStream &sourceStream)
+ : source(sourceStream)
{
closed = false;
}
@@ -438,7 +437,7 @@ BasicInputStream::BasicInputStream(const InputStream &sourceStream)
* Returns the number of bytes that can be read (or skipped over) from
* this input stream without blocking by the next caller of a method for
* this input stream.
- */
+ */
int BasicInputStream::available()
{
if (closed)
@@ -446,11 +445,11 @@ int BasicInputStream::available()
return source.available();
}
-
+
/**
* Closes this input stream and releases any system resources
* associated with the stream.
- */
+ */
void BasicInputStream::close()
{
if (closed)
@@ -458,10 +457,10 @@ void BasicInputStream::close()
source.close();
closed = true;
}
-
+
/**
* Reads the next byte of data from the input stream. -1 if EOF
- */
+ */
int BasicInputStream::get()
{
if (closed)
@@ -477,9 +476,9 @@ int BasicInputStream::get()
/**
*
- */
-BasicOutputStream::BasicOutputStream(const OutputStream &destinationStream)
- : destination((OutputStream &)destinationStream)
+ */
+BasicOutputStream::BasicOutputStream(OutputStream &destinationStream)
+ : destination(destinationStream)
{
closed = false;
}
@@ -487,7 +486,7 @@ BasicOutputStream::BasicOutputStream(const OutputStream &destinationStream)
/**
* Closes this output stream and releases any system resources
* associated with this stream.
- */
+ */
void BasicOutputStream::close()
{
if (closed)
@@ -495,40 +494,33 @@ void BasicOutputStream::close()
destination.close();
closed = true;
}
-
+
/**
* Flushes this output stream and forces any buffered output
* bytes to be written out.
- */
+ */
void BasicOutputStream::flush()
{
if (closed)
return;
destination.flush();
}
-
+
/**
* Writes the specified byte to this output stream.
- */
+ */
int BasicOutputStream::put(gunichar ch)
{
if (closed)
return -1;
- if (destination.put(ch) < 0)
- return -1;
- return 1;
+ destination.put(ch);
+ return 1;
}
-
//#########################################################################
//# B A S I C R E A D E R
//#########################################################################
-
-
-/**
- *
- */
BasicReader::BasicReader(Reader &sourceReader)
{
source = &sourceReader;
@@ -538,7 +530,7 @@ BasicReader::BasicReader(Reader &sourceReader)
* Returns the number of bytes that can be read (or skipped over) from
* this reader without blocking by the next caller of a method for
* this reader.
- */
+ */
int BasicReader::available()
{
if (source)
@@ -547,69 +539,65 @@ int BasicReader::available()
return 0;
}
-
+
/**
* Closes this reader and releases any system resources
* associated with the reader.
- */
+ */
void BasicReader::close()
{
if (source)
source->close();
}
-
+
/**
* Reads the next byte of data from the reader.
- */
-int BasicReader::get()
+ */
+gunichar BasicReader::get()
{
if (source)
return source->get();
else
- return -1;
+ return (gunichar)-1;
}
-
-
-
-
-
+
/**
* Reads a line of data from the reader.
- */
-DOMString BasicReader::readLine()
+ */
+Glib::ustring BasicReader::readLine()
{
- DOMString str;
+ Glib::ustring str;
while (available() > 0)
{
- XMLCh ch = get();
+ gunichar ch = get();
if (ch == '\n')
break;
str.push_back(ch);
}
return str;
}
-
+
/**
* Reads a line of data from the reader.
- */
-DOMString BasicReader::readWord()
+ */
+Glib::ustring BasicReader::readWord()
{
- DOMString str;
+ Glib::ustring str;
while (available() > 0)
{
- XMLCh ch = get();
- if (uni_is_space(ch))
+ gunichar ch = get();
+ if (!g_unichar_isprint(ch))
break;
str.push_back(ch);
}
return str;
}
+
-
-static bool getLong(DOMString &str, long *val)
+static bool getLong(Glib::ustring &str, long *val)
{
- const char *begin = str.c_str();
+ const char *begin = str.raw().c_str();
char *end;
long ival = strtol(begin, &end, 10);
if (str == end)
@@ -618,25 +606,23 @@ static bool getLong(DOMString &str, long *val)
return true;
}
-static bool getULong(const DOMString &str, unsigned long *val)
+static bool getULong(Glib::ustring &str, unsigned long *val)
{
- DOMString tmp = str;
- char *begin = (char *)tmp.c_str();
+ const char *begin = str.raw().c_str();
char *end;
unsigned long ival = strtoul(begin, &end, 10);
- if (begin == end)
+ if (str == end)
return false;
*val = ival;
return true;
}
-static bool getDouble(const DOMString &str, double *val)
+static bool getDouble(Glib::ustring &str, double *val)
{
- DOMString tmp = str;
- const char *begin = tmp.c_str();
+ const char *begin = str.raw().c_str();
char *end;
double ival = strtod(begin, &end);
- if (begin == end)
+ if (str == end)
return false;
*val = ival;
return true;
@@ -644,13 +630,9 @@ static bool getDouble(const DOMString &str, double *val)
-
-/**
- *
- */
-Reader &BasicReader::readBool (bool& val )
+const Reader &BasicReader::readBool (bool& val )
{
- DOMString buf = readWord();
+ Glib::ustring buf = readWord();
if (buf == "true")
val = true;
else
@@ -658,96 +640,72 @@ Reader &BasicReader::readBool (bool& val )
return *this;
}
-/**
- *
- */
-Reader &BasicReader::readShort (short& val )
+const Reader &BasicReader::readShort (short& val )
{
- DOMString buf = readWord();
+ Glib::ustring buf = readWord();
long ival;
if (getLong(buf, &ival))
val = (short) ival;
return *this;
}
-/**
- *
- */
-Reader &BasicReader::readUnsignedShort (unsigned short& val )
+const Reader &BasicReader::readUnsignedShort (unsigned short& val )
{
- DOMString buf = readWord();
+ Glib::ustring buf = readWord();
unsigned long ival;
if (getULong(buf, &ival))
val = (unsigned short) ival;
return *this;
}
-/**
- *
- */
-Reader &BasicReader::readInt (int& val )
+const Reader &BasicReader::readInt (int& val )
{
- DOMString buf = readWord();
+ Glib::ustring buf = readWord();
long ival;
if (getLong(buf, &ival))
val = (int) ival;
return *this;
}
-/**
- *
- */
-Reader &BasicReader::readUnsignedInt (unsigned int& val )
+const Reader &BasicReader::readUnsignedInt (unsigned int& val )
{
- DOMString buf = readWord();
+ Glib::ustring buf = readWord();
unsigned long ival;
if (getULong(buf, &ival))
val = (unsigned int) ival;
return *this;
}
-/**
- *
- */
-Reader &BasicReader::readLong (long& val )
+const Reader &BasicReader::readLong (long& val )
{
- DOMString buf = readWord();
+ Glib::ustring buf = readWord();
long ival;
if (getLong(buf, &ival))
val = ival;
return *this;
}
-/**
- *
- */
-Reader &BasicReader::readUnsignedLong (unsigned long& val )
+const Reader &BasicReader::readUnsignedLong (unsigned long& val )
{
- DOMString buf = readWord();
+ Glib::ustring buf = readWord();
unsigned long ival;
if (getULong(buf, &ival))
val = ival;
return *this;
}
-/**
- *
- */
-Reader &BasicReader::readFloat (float& val )
+const Reader &BasicReader::readFloat (float& val )
{
- DOMString buf = readWord();
+ Glib::ustring buf = readWord();
double ival;
if (getDouble(buf, &ival))
val = (float)ival;
return *this;
}
-/**
- *
- */
-Reader &BasicReader::readDouble (double& val )
+const Reader &BasicReader::readDouble (double& val )
{
- DOMString buf = readWord();
+ Glib::ustring buf = readWord();
double ival;
if (getDouble(buf, &ival))
val = ival;
@@ -761,12 +719,12 @@ Reader &BasicReader::readDouble (double& val )
//#########################################################################
-InputStreamReader::InputStreamReader(const InputStream &inputStreamSource)
- : inputStream((InputStream &)inputStreamSource)
+InputStreamReader::InputStreamReader(InputStream &inputStreamSource)
+ : inputStream(inputStreamSource)
{
}
-
+
/**
* Close the underlying OutputStream
@@ -775,7 +733,7 @@ void InputStreamReader::close()
{
inputStream.close();
}
-
+
/**
* Flush the underlying OutputStream
*/
@@ -783,15 +741,15 @@ int InputStreamReader::available()
{
return inputStream.available();
}
-
+
/**
* Overloaded to receive its bytes from an InputStream
* rather than a Reader
*/
-int InputStreamReader::get()
+gunichar InputStreamReader::get()
{
//Do we need conversions here?
- int ch = (XMLCh)inputStream.get();
+ gunichar ch = (gunichar)inputStream.get();
return ch;
}
@@ -818,7 +776,7 @@ StdReader::~StdReader()
delete inputStream;
}
-
+
/**
* Close the underlying OutputStream
@@ -827,7 +785,7 @@ void StdReader::close()
{
inputStream->close();
}
-
+
/**
* Flush the underlying OutputStream
*/
@@ -835,22 +793,21 @@ int StdReader::available()
{
return inputStream->available();
}
-
+
/**
* Overloaded to receive its bytes from an InputStream
* rather than a Reader
*/
-int StdReader::get()
+gunichar StdReader::get()
{
//Do we need conversions here?
- XMLCh ch = (XMLCh)inputStream->get();
+ gunichar ch = (gunichar)inputStream->get();
return ch;
}
-
//#########################################################################
//# B A S I C W R I T E R
//#########################################################################
@@ -1145,13 +1102,6 @@ int StdWriter::put(gunichar ch)
-
-
-
-
-
-
-
//###############################################
//# O P E R A T O R S
//###############################################
@@ -1165,31 +1115,31 @@ int StdWriter::put(gunichar ch)
-Reader& operator>> (Reader &reader, bool& val )
+const Reader& operator>> (Reader &reader, bool& val )
{ return reader.readBool(val); }
-Reader& operator>> (Reader &reader, short &val)
+const Reader& operator>> (Reader &reader, short &val)
{ return reader.readShort(val); }
-Reader& operator>> (Reader &reader, unsigned short &val)
+const Reader& operator>> (Reader &reader, unsigned short &val)
{ return reader.readUnsignedShort(val); }
-Reader& operator>> (Reader &reader, int &val)
+const Reader& operator>> (Reader &reader, int &val)
{ return reader.readInt(val); }
-Reader& operator>> (Reader &reader, unsigned int &val)
+const Reader& operator>> (Reader &reader, unsigned int &val)
{ return reader.readUnsignedInt(val); }
-Reader& operator>> (Reader &reader, long &val)
+const Reader& operator>> (Reader &reader, long &val)
{ return reader.readLong(val); }
-Reader& operator>> (Reader &reader, unsigned long &val)
+const Reader& operator>> (Reader &reader, unsigned long &val)
{ return reader.readUnsignedLong(val); }
-Reader& operator>> (Reader &reader, float &val)
+const Reader& operator>> (Reader &reader, float &val)
{ return reader.readFloat(val); }
-Reader& operator>> (Reader &reader, double &val)
+const Reader& operator>> (Reader &reader, double &val)
{ return reader.readDouble(val); }