1 /**
2 * Phoebe DOM Implementation.
3 *
4 * This is a C++ approximation of the W3C DOM model, which follows
5 * fairly closely the specifications in the various .idl files, copies of
6 * which are provided for reference. Most important is this one:
7 *
8 * http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/idl-definitions.html
9 *
10 * Authors:
11 * Bob Jamison
12 *
13 * Copyright (C) 2005 Bob Jamison
14 *
15 * This library is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU Lesser General Public
17 * License as published by the Free Software Foundation; either
18 * version 2.1 of the License, or (at your option) any later version.
19 *
20 * This library is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * Lesser General Public License for more details.
24 *
25 * You should have received a copy of the GNU Lesser General Public
26 * License along with this library; if not, write to the Free Software
27 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 */
30 /**
31 * Our base String stream classes. We implement these to
32 * be based on DOMString
33 *
34 */
37 #include "stringstream.h"
39 namespace org
40 {
41 namespace w3c
42 {
43 namespace dom
44 {
45 namespace io
46 {
50 //#########################################################################
51 //# S T R I N G I N P U T S T R E A M
52 //#########################################################################
55 /**
56 *
57 */
58 StringInputStream::StringInputStream(const DOMString &sourceString)
59 : buffer((DOMString &)sourceString)
60 {
61 position = 0;
62 }
64 /**
65 *
66 */
67 StringInputStream::~StringInputStream()
68 {
70 }
72 /**
73 * Returns the number of bytes that can be read (or skipped over) from
74 * this input stream without blocking by the next caller of a method for
75 * this input stream.
76 */
77 int StringInputStream::available()
78 {
79 return buffer.size() - position;
80 }
83 /**
84 * Closes this input stream and releases any system resources
85 * associated with the stream.
86 */
87 void StringInputStream::close()
88 {
89 }
91 /**
92 * Reads the next byte of data from the input stream. -1 if EOF
93 */
94 int StringInputStream::get()
95 {
96 if (position >= (int)buffer.size())
97 return -1;
98 int ch = (int) buffer[position++];
99 return ch;
100 }
105 //#########################################################################
106 //# S T R I N G O U T P U T S T R E A M
107 //#########################################################################
109 /**
110 *
111 */
112 StringOutputStream::StringOutputStream()
113 {
114 }
116 /**
117 *
118 */
119 StringOutputStream::~StringOutputStream()
120 {
121 }
123 /**
124 * Closes this output stream and releases any system resources
125 * associated with this stream.
126 */
127 void StringOutputStream::close()
128 {
129 }
131 /**
132 * Flushes this output stream and forces any buffered output
133 * bytes to be written out.
134 */
135 void StringOutputStream::flush()
136 {
137 //nothing to do
138 }
140 /**
141 * Writes the specified byte to this output stream.
142 */
143 int StringOutputStream::put(XMLCh ch)
144 {
145 buffer.push_back(ch);
146 return 1;
147 }
152 } //namespace io
153 } //namespace dom
154 } //namespace w3c
155 } //namespace org
157 //#########################################################################
158 //# E N D O F F I L E
159 //#########################################################################