2
// Copyright � 1997 - 2001, Paul C. Gregory
4
// Contact: pgregory@aqsis.com
6
// This library is free software; you can redistribute it and/or
7
// modify it under the terms of the GNU Lesser General Public
8
// License as published by the Free Software Foundation; either
9
// version 2.1 of the License, or (at your option) any later version.
11
// This library is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
// General Public License for more details.
16
// You should have received a copy of the GNU General Public
17
// License along with this library; if not, write to the Free Software
18
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
* \brief Fstream and Gzip output
22
* \author Lionel J. Lacour (intuition01@online.fr)
28
#include "outstream.h"
34
USING_NAMESPACE( libri2rib );
37
void CqStreamGzip::error()
40
const char *cp = gzerror( gzf, e );
44
throw CqError ( RIE_SYSTEM, RIE_ERROR, strerror( errno ), TqFalse );
48
throw CqError( RIE_SYSTEM, RIE_ERROR, cp, TqFalse );
52
CqStream & CqStreamGzip::operator<< ( int i )
54
if ( gzprintf( gzf, "%i", i ) == 0 ) error();
58
CqStream & CqStreamGzip::operator<< ( float f )
60
if ( gzprintf( gzf, "%f", f ) == 0 ) error();
64
CqStream & CqStreamGzip::operator<< ( std::string s )
66
if ( gzputs( gzf, s.c_str() ) == -1 ) error();
70
CqStream & CqStreamGzip::operator<< ( char c )
72
if ( gzputc( gzf, c ) == -1 ) error();
76
void CqStreamGzip::openFile( const char *name )
78
gzf = gzopen( name, "wb" );
81
throw CqError( RIE_NOFILE, RIE_ERROR, "Unable to open file ", name, "", TqFalse );
83
gzsetparams( gzf, Z_DEFAULT_COMPRESSION, Z_DEFAULT_STRATEGY );
86
void CqStreamGzip::openFile( int fdesc )
88
gzf = gzdopen( dup( fdesc ), "wb" );
92
sprintf( c, "%u", fdesc );
93
throw CqError( RIE_NOFILE, RIE_ERROR, "Unable to open file with descriptor=", c, "", TqFalse );
97
void CqStreamGzip::closeFile()
103
void CqStreamGzip::flushFile()
105
// At the end of a procedural RunProgram the
106
// gzip internal state must be reset.
109
gzflush( gzf, Z_FINISH );
116
void CqStreamFDesc::error()
118
throw CqError ( RIE_SYSTEM, RIE_ERROR, strerror( errno ), TqFalse );
121
CqStream & CqStreamFDesc::operator<< ( int i )
123
if ( fprintf( fstr, "%i", i ) < 0 ) error();
127
CqStream & CqStreamFDesc::operator<< ( float f )
129
if ( fprintf( fstr, "%f", f ) < 0 ) error();
133
CqStream & CqStreamFDesc::operator<< ( std::string s )
135
if ( fputs( s.c_str(), fstr ) == EOF ) error();
139
CqStream & CqStreamFDesc::operator<< ( char c )
141
if ( fputc( c, fstr ) == EOF ) error();
145
void CqStreamFDesc::openFile( const char *name )
147
fstr = fopen( name, "wb" );
150
throw CqError( RIE_NOFILE, RIE_ERROR, "Unable to open file ", name, "", TqFalse );
154
void CqStreamFDesc::openFile ( int fdesc )
156
fstr = fdopen ( dup( fdesc ), "wb" );
160
sprintf( c, "%u", fdesc );
161
throw CqError( RIE_NOFILE, RIE_ERROR, "Unable to open file with descriptor=", c, "", TqFalse );
165
void CqStreamFDesc::closeFile()
171
void CqStreamFDesc::flushFile()