Better support for various streams implementations

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@229 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jean-Marc Lasgouttes 1999-10-22 09:45:25 +00:00
parent f157947948
commit 28aa3975e6
8 changed files with 123 additions and 32 deletions

View File

@ -1,3 +1,24 @@
1999-10-22 Jean-Marc Lasgouttes <Jean-Marc.Lasgouttes@inria.fr>
* configure.in: use LYX_CXX_STL_MODERN_STREAMS; check for headers
<ostream> and <istream>.
* acinclude.m4 (LYX_CXX_STL_MODERN_STREAMS): new test. Checks
whether <fstream> provides the latest standard features, or if we
have an oldstyle library (like in egcs).
(LYX_CXX_STL_STRING): fix the test.
* src/support/DebugStream.{C,h}: use L{I,O}stream.h and condition the
code on MODERN_STL_STREAM.
* src/support/lyxstring.h: use L{I,O}stream.h.
* src/support/L{I,O}stream.h: new files, designed to setup
correctly streams for our use
- includes the right header depending on STL capabilities
- puts std::ostream and std::endl (for LOStream.h) or
std::istream (LIStream.h) in toplevel namespace.
1999-10-22 Lars Gullik Bjønnes <larsbj@lyx.org>
* src/insets/figinset.C: added ifdef guards around the fl_free

View File

@ -281,6 +281,7 @@ AC_DEFUN(LYX_CXX_STL_STACK,[
AC_CACHE_CHECK(for broken STL stack template,lyx_cv_broken_stack,
[AC_TRY_COMPILE([
#include <stack>
using std::stack;
],[
stack<int> stakk;
stakk.push(0);
@ -292,6 +293,22 @@ if test $lyx_cv_broken_stack = yes ; then
correctly])
fi])
dnl Usage: LYX_CXX_STL_MODERN_STREAMS : checks whether the C++ compiler
dnl supports modern STL streams
AC_DEFUN(LYX_CXX_STL_MODERN_STREAMS,[
AC_CACHE_CHECK(for modern STL streams,lyx_cv_modern_streams,
[AC_TRY_COMPILE([
#include <fstream>
],[
std::streambuf * test = std::cerr.rdbuf();
test->pubsync();
],lyx_cv_modern_streams=yes,lyx_cv_modern_streams=no)
])
if test $lyx_cv_modern_streams = yes ; then
AC_DEFINE(MODERN_STL_STREAMS, 1,
[Define if you have modern standard-compliant STL streams])
fi])
dnl Usage: LYX_CXX_STL_STRING : checks whether the C++ compiler
dnl has a working stl string container, the check is really stupid
@ -306,6 +323,7 @@ AC_DEFUN(LYX_CXX_STL_STRING,[
],[
AC_TRY_COMPILE([
#include <string>
using std::string;
],[
string a("hello there");
a.clear();
@ -315,16 +333,20 @@ AC_DEFUN(LYX_CXX_STL_STRING,[
with_included_string=no
],[
with_included_string=yes
AC_DEFINE(USE_INCLUDED_STRING, 1,
[Define to use the lyxstring class bundled with LyX.])
lyx_flags="$lyx_flags included-string"
])
])
if test x$with_included_string = xyes ; then
AC_DEFINE(USE_INCLUDED_STRING, 1,
[Define to use the lyxstring class bundled with LyX.])
lyx_flags="$lyx_flags included-string"
fi
AM_CONDITIONAL(USE_LYXSTRING, test x$with_included_string = xyes)
AC_MSG_RESULT([$with_included_string])
])
dnl LYX_CXX_MUTABLE
AC_DEFUN(LYX_CXX_MUTABLE, [
AC_REQUIRE([LYX_PROG_CXX])

View File

@ -67,8 +67,10 @@ LYX_CXX_STL_STRING
LYX_CXX_NAMESPACES
LYX_CXX_CHEADERS
LYX_CXX_RTTI
AC_CHECK_HEADERS(ostream istream)
LYX_CXX_STL_MODERN_STREAMS
### Libarary Files
### Library Files
dnl by testing these we check if it is ok to have
dnl -lc and -lm as args to the compiler
AC_CHECK_LIB(m, sin)

View File

@ -6,7 +6,6 @@
// but should be adaptable to any project.
//#define TEST_DEBUGSTREAM
//#define MODERN_STL
//#include "DebugStream.h"
#include "debug.h"
@ -14,10 +13,16 @@
// Since the current C++ lib in egcs does not have a standard implementation
// of basic_streambuf and basic_filebuf we don't have to include this
// header.
#ifdef MODERN_STL
#ifdef MODERN_STL_STREAMS
#include <fstream>
#endif
using std::streambuf;
using std::streamsize;
using std::filebuf;
using std::cerr;
using std::ios;
ostream & operator<<(ostream & o, Debug::type t)
{
return o << int(t);
@ -54,7 +59,7 @@ public:
protected:
///
virtual int sync() {
#ifdef MODERN_STL
#ifdef MODERN_STL_STREAMS
sb2->pubsync();
return sb1->pubsync();
#else
@ -64,7 +69,7 @@ protected:
}
///
virtual streamsize xsputn(char const * p, streamsize n) {
#ifdef MODERN_STL
#ifdef MODERN_STL_STREAMS
sb2->sputn(p, n);
return sb1->sputn(p, n);
#else
@ -74,7 +79,7 @@ protected:
}
///
virtual int overflow(int c = EOF) {
#ifdef MODERN_STL
#ifdef MODERN_STL_STREAMS
sb2->sputc(c);
return sb1->sputc(c);
#else
@ -98,7 +103,7 @@ public:
protected:
///
virtual int sync() {
#ifdef MODERN_STL
#ifdef MODERN_STL_STREAMS
return sb->pubsync();
#else
return sb->sync();
@ -106,7 +111,7 @@ protected:
}
///
virtual streamsize xsputn(char const * p, streamsize n) {
#ifdef MODERN_STL
#ifdef MODERN_STL_STREAMS
return sb->sputn(p, n);
#else
return sb->xsputn(p, n);
@ -114,7 +119,7 @@ protected:
}
///
virtual int overflow(int c = EOF) {
#ifdef MODERN_STL
#ifdef MODERN_STL_STREAMS
return sb->sputc(c);
#else
return sb->overflow(c);

View File

@ -12,25 +12,7 @@
#ifndef DEBUGSTREAM_H
#define DEBUGSTREAM_H
#ifdef _STANDARD_C_PLUS_PLUS
#define MODERN_STL
#endif
#ifdef MODERN_STL
#include <ostream>
#else
#include <iostream>
#endif
//#ifdef MODERN_STL
using std::ostream;
using std::streambuf;
using std::streamsize;
using std::filebuf;
using std::cerr;
using std::ios;
using std::endl;
//#endif
#include "LOstream.h"
#ifdef TEST_DEBUGSTREAM
#include <string>

28
src/support/LIstream.h Normal file
View File

@ -0,0 +1,28 @@
// -*- C++ -*-
/* This file is part of
* ======================================================
*
* LyX, The Document Processor
*
* Copyright (C) 1995 Matthias Ettrich
* Copyright (C) 1995-1999 The LyX Team.
*
*======================================================*/
#ifndef LISTREAM_H
#define LISTREAM_H
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#ifdef HAVE_ISTREAM
#include <istream>
#else
#include <iostream>
#endif
using std::istream;
#endif

29
src/support/LOstream.h Normal file
View File

@ -0,0 +1,29 @@
// -*- C++ -*-
/* This file is part of
* ======================================================
*
* LyX, The Document Processor
*
* Copyright (C) 1995 Matthias Ettrich
* Copyright (C) 1995-1999 The LyX Team.
*
*======================================================*/
#ifndef LOSTREAM_H
#define LOSTREAM_H
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#ifdef HAVE_OSTREAM
#include <ostream>
#else
#include <iostream>
#endif
using std::ostream;
using std::endl;
#endif

View File

@ -29,6 +29,9 @@
#include <config.h> // needed at least for compilers that do not
#endif // understand `explicit' (JMarc)
#include "LOstream.h"
#include "LIstream.h"
#if 0
#include <iterator>
#endif
@ -588,7 +591,6 @@ lyxstring operator+(lyxstring::value_type a, lyxstring const & b);
lyxstring operator+(lyxstring const & a, lyxstring::value_type const * b);
lyxstring operator+(lyxstring const & a, lyxstring::value_type b);
class istream; class ostream;
istream & operator>>(istream &, lyxstring &);
ostream & operator<<(ostream &, lyxstring const &);
istream & getline(istream &, lyxstring &, lyxstring::value_type delim = '\n');