Don't include <iostream> and "using" declarations in header files
<iostream> sucks in expensive initialization of the standard streams and isn't appropriate in a header file. Use <istream> and <ostream> instead. using declarations should never appear at global scope in a header file; source files get to decide what they want to use in their namespace.
This commit is contained in:
@@ -33,6 +33,9 @@
|
||||
|
||||
#include "sgstream.hxx"
|
||||
|
||||
using std::string;
|
||||
using std::istream;
|
||||
|
||||
sg_gzifstream::sg_gzifstream()
|
||||
: istream(&gzbuf)
|
||||
{
|
||||
|
||||
@@ -45,14 +45,10 @@
|
||||
|
||||
#include <simgear/misc/zfstream.hxx>
|
||||
|
||||
SG_USING_STD(string);
|
||||
SG_USING_STD(istream);
|
||||
|
||||
|
||||
/**
|
||||
* An envelope class for gzifstream.
|
||||
*/
|
||||
class sg_gzifstream : private gzifstream_base, public istream
|
||||
class sg_gzifstream : private gzifstream_base, public std::istream
|
||||
{
|
||||
public:
|
||||
/** Default constructor */
|
||||
@@ -64,7 +60,7 @@ public:
|
||||
* @param name name of file
|
||||
* @param io_mode file open mode(s) "or'd" together
|
||||
*/
|
||||
sg_gzifstream( const string& name,
|
||||
sg_gzifstream( const std::string& name,
|
||||
ios_openmode io_mode = ios_in | ios_binary );
|
||||
|
||||
/**
|
||||
@@ -79,7 +75,7 @@ public:
|
||||
* @param name name of file
|
||||
* @param io_mode file open mode(s) "or'd" together
|
||||
*/
|
||||
void open( const string& name,
|
||||
void open( const std::string& name,
|
||||
ios_openmode io_mode = ios_in|ios_binary );
|
||||
|
||||
/**
|
||||
@@ -108,14 +104,14 @@ private:
|
||||
* An istream manipulator that skips to end of line.
|
||||
* @param in input stream
|
||||
*/
|
||||
istream& skipeol( istream& in );
|
||||
std::istream& skipeol( std::istream& in );
|
||||
|
||||
/**
|
||||
* \relates sg_gzifstream
|
||||
* An istream manipulator that skips over white space.
|
||||
* @param in input stream
|
||||
*/
|
||||
istream& skipws( istream& in );
|
||||
std::istream& skipws( std::istream& in );
|
||||
|
||||
/**
|
||||
* \relates sg_gzifstream
|
||||
@@ -123,7 +119,7 @@ istream& skipws( istream& in );
|
||||
* Ignores comments that start with '#'.
|
||||
* @param in input stream
|
||||
*/
|
||||
istream& skipcomment( istream& in );
|
||||
std::istream& skipcomment( std::istream& in );
|
||||
|
||||
|
||||
#endif /* _SGSTREAM_HXX */
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
// Allocate memory for 'get' buffer and zero all buffer pointers.
|
||||
//
|
||||
gzfilebuf::gzfilebuf()
|
||||
: streambuf(),
|
||||
: std::streambuf(),
|
||||
file(NULL),
|
||||
#if defined( __MWERKS__ ) || __GNUC__ > 2
|
||||
mode(ios_openmode(0)),
|
||||
@@ -174,10 +174,10 @@ gzfilebuf::close()
|
||||
// }
|
||||
|
||||
|
||||
streampos
|
||||
gzfilebuf::seekoff( streamoff, ios_seekdir, int )
|
||||
std::streampos
|
||||
gzfilebuf::seekoff( std::streamoff, ios_seekdir, int )
|
||||
{
|
||||
return streampos(EOF);
|
||||
return std::streampos(EOF);
|
||||
}
|
||||
|
||||
gzfilebuf::int_type
|
||||
|
||||
+11
-16
@@ -36,21 +36,16 @@
|
||||
# include <streambuf>
|
||||
# include <istream>
|
||||
|
||||
# define ios_openmode ios_base::openmode
|
||||
# define ios_in ios_base::in
|
||||
# define ios_out ios_base::out
|
||||
# define ios_app ios_base::app
|
||||
# define ios_binary ios_base::binary
|
||||
# define ios_openmode std::ios_base::openmode
|
||||
# define ios_in std::ios_base::in
|
||||
# define ios_out std::ios_base::out
|
||||
# define ios_app std::ios_base::app
|
||||
# define ios_binary std::ios_base::binary
|
||||
|
||||
# define ios_seekdir ios_base::seekdir
|
||||
# define ios_seekdir std::ios_base::seekdir
|
||||
|
||||
# define ios_badbit ios_base::badbit
|
||||
# define ios_failbit ios_base::failbit
|
||||
|
||||
SG_USING_STD(streambuf);
|
||||
SG_USING_STD(ios_base);
|
||||
SG_USING_STD(streampos);
|
||||
SG_USING_STD(streamoff);
|
||||
# define ios_badbit std::ios_base::badbit
|
||||
# define ios_failbit std::ios_base::failbit
|
||||
|
||||
#else
|
||||
|
||||
@@ -88,7 +83,7 @@ SG_USING_STD(streamoff);
|
||||
#ifdef SG_NEED_STREAMBUF_HACK
|
||||
class gzfilebuf : public __streambuf
|
||||
#else
|
||||
class gzfilebuf : public streambuf
|
||||
class gzfilebuf : public std::streambuf
|
||||
#endif
|
||||
{
|
||||
public:
|
||||
@@ -132,7 +127,7 @@ public:
|
||||
bool is_open() const { return (file != NULL); }
|
||||
|
||||
/** @return stream position */
|
||||
virtual streampos seekoff( streamoff off, ios_seekdir way, int which );
|
||||
virtual std::streampos seekoff( std::streamoff off, ios_seekdir way, int which );
|
||||
|
||||
/** sync the stream */
|
||||
virtual int sync();
|
||||
@@ -143,7 +138,7 @@ protected:
|
||||
#ifndef SG_HAVE_STD_INCLUDES
|
||||
virtual int_type overflow( int_type c = traits_type::eof() );
|
||||
#else
|
||||
virtual int_type overflow( int_type c = streambuf::traits_type::eof() );
|
||||
virtual int_type overflow( int_type c = std::streambuf::traits_type::eof() );
|
||||
#endif
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user