1 /*
2  * Copyright 2006-2008 The FLWOR Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <stdexcept>
18 
19 #include "stdafx.h"
20 #include "passthru_streambuf.h"
21 
22 using namespace std;
23 
24 namespace zorba {
25 
26 ///////////////////////////////////////////////////////////////////////////////
27 
passthru_streambuf(char const *,streambuf * orig)28 passthru_streambuf::passthru_streambuf( char const*, streambuf *orig ) :
29   proxy_streambuf( orig )
30 {
31   if ( !orig )
32     throw invalid_argument( "null streambuf" );
33 }
34 
~passthru_streambuf()35 passthru_streambuf::~passthru_streambuf() {
36   // out-of-line since it's virtual
37 }
38 
imbue(std::locale const & loc)39 void passthru_streambuf::imbue( std::locale const &loc ) {
40   original()->pubimbue( loc );
41 }
42 
is_necessary(char const * cc_charset)43 bool passthru_streambuf::is_necessary( char const *cc_charset ) {
44   if ( !*cc_charset )
45     throw invalid_argument( "empty charset" );
46   zstring charset( cc_charset );
47   ascii::trim_whitespace( charset );
48   ascii::to_upper( charset );
49   return charset != "ASCII"
50       && charset != "US-ASCII"
51       && charset != "UTF-8";
52 }
53 
is_supported(char const * cc_charset)54 bool passthru_streambuf::is_supported( char const *cc_charset ) {
55   return !is_necessary( cc_charset );
56 }
57 
58 passthru_streambuf::pos_type
seekoff(off_type o,ios_base::seekdir d,ios_base::openmode m)59 passthru_streambuf::seekoff( off_type o, ios_base::seekdir d,
60                              ios_base::openmode m ) {
61   return original()->pubseekoff( o, d, m );
62 }
63 
64 passthru_streambuf::pos_type
seekpos(pos_type p,ios_base::openmode m)65 passthru_streambuf::seekpos( pos_type p, ios_base::openmode m ) {
66   return original()->pubseekpos( p, m );
67 }
68 
setbuf(char_type * p,streamsize s)69 streambuf* passthru_streambuf::setbuf( char_type *p, streamsize s ) {
70   original()->pubsetbuf( p, s );
71   return this;
72 }
73 
showmanyc()74 streamsize passthru_streambuf::showmanyc() {
75   return original()->in_avail();
76 }
77 
sync()78 int passthru_streambuf::sync() {
79   return original()->pubsync();
80 }
81 
overflow(int_type c)82 passthru_streambuf::int_type passthru_streambuf::overflow( int_type c ) {
83   return original()->sputc( c );
84 }
85 
pbackfail(int_type c)86 passthru_streambuf::int_type passthru_streambuf::pbackfail( int_type c ) {
87   return original()->sputbackc( traits_type::to_char_type( c ) );
88 }
89 
uflow()90 passthru_streambuf::int_type passthru_streambuf::uflow() {
91   return original()->sbumpc();
92 }
93 
underflow()94 passthru_streambuf::int_type passthru_streambuf::underflow() {
95   return original()->sgetc();
96 }
97 
xsgetn(char_type * to,streamsize size)98 streamsize passthru_streambuf::xsgetn( char_type *to, streamsize size ) {
99   return original()->sgetn( to, size );
100 }
101 
xsputn(char_type const * from,streamsize size)102 streamsize passthru_streambuf::xsputn( char_type const *from,
103                                        streamsize size ) {
104   return original()->sputn( from, size );
105 }
106 
107 ///////////////////////////////////////////////////////////////////////////////
108 
109 } // namespace zorba
110 /* vim:set et sw=2 ts=2: */
111