2003-09-26 14:27:20 +00:00
|
|
|
|
// -*- C++ -*-
|
|
|
|
|
/**
|
2003-10-08 11:31:51 +00:00
|
|
|
|
* \file debugstream.h
|
2003-09-26 14:27:20 +00:00
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef DEBUG_STREAM_HPP
|
|
|
|
|
#define DEBUG_STREAM_HPP
|
|
|
|
|
|
2003-10-14 13:01:49 +00:00
|
|
|
|
#include <iostream>
|
2003-09-26 14:27:20 +00:00
|
|
|
|
|
2006-03-05 20:49:09 +00:00
|
|
|
|
#include <boost/version.hpp>
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
//namespace lyx {
|
|
|
|
|
|
2006-03-07 08:29:12 +00:00
|
|
|
|
#if BOOST_VERSION < 103300
|
2006-03-05 20:49:09 +00:00
|
|
|
|
# include <boost/test/detail/nullstream.hpp>
|
|
|
|
|
#else
|
|
|
|
|
# include <boost/test/utils/nullstream.hpp>
|
|
|
|
|
#endif
|
2003-09-26 14:27:20 +00:00
|
|
|
|
|
2004-05-20 09:35:30 +00:00
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
# define TEMPORARY_DEBUG_MACRO DEBUG
|
|
|
|
|
# undef DEBUG
|
|
|
|
|
#endif
|
|
|
|
|
|
2003-09-26 14:27:20 +00:00
|
|
|
|
struct debug_trait {
|
|
|
|
|
enum type {
|
|
|
|
|
NONE = 0,
|
|
|
|
|
EMERG = 1,
|
|
|
|
|
ALERT = 2,
|
|
|
|
|
CRIT = 3,
|
|
|
|
|
ERR = 4,
|
|
|
|
|
WARN = 5,
|
|
|
|
|
NOTICE = 6,
|
|
|
|
|
INFO = 7,
|
|
|
|
|
DEBUG = 8,
|
|
|
|
|
ANY = 0xffffff
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static bool match(type a, type b) {
|
|
|
|
|
return (b <= a || (b == ANY && a > NONE));
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2004-05-20 09:35:30 +00:00
|
|
|
|
#ifdef TEMPORARY_DEBUG_MACRO
|
|
|
|
|
# define DEBUG TEMPORARY_DEBUG_MACRO
|
|
|
|
|
# undef TEMPORARY_DEBUG_MACRO
|
|
|
|
|
#endif
|
|
|
|
|
|
2003-09-26 14:27:20 +00:00
|
|
|
|
|
|
|
|
|
template <class dtrait,
|
|
|
|
|
class charT = char,
|
|
|
|
|
class traits = std::char_traits<charT> >
|
|
|
|
|
class basic_debugstream : public std::basic_ostream<charT, traits> {
|
|
|
|
|
public:
|
|
|
|
|
typedef dtrait debug;
|
|
|
|
|
typedef typename debug::type Type;
|
|
|
|
|
|
2003-11-01 13:03:03 +00:00
|
|
|
|
basic_debugstream()
|
Add machinery to output arbitrary unicode characters with LaTeX commands
read from a text file.
* src/encoding.[Ch]
(Encoding::latexChar): New, output a character to LaTeX
(Encoding::validate): New, add needed preamble stuff for a character
(Encodings::read): Read new unicodesymbols file
(Encodings::isCombiningChar): New, is a character a combining char?
* src/paragraph_pimpl.C
(isEncoding): Delete, no longer needed
(getEncoding): New, get the real encoding of a font
(Paragraph::Pimpl::latexSurrogatePair): New, output a surrogate pair
to LaTeX
(Paragraph::Pimpl::simpleTeXBlanks): Use latexSurrogatePair if needed
(Paragraph::Pimpl::simpleTeXSpecialChars): Ditto, and replace several
hardcoded characters with a call of encoding.latexChar()
(Paragraph::Pimpl::validate): replace several hardcoded characters
with a call of encoding.validate()
* src/support/debugstream.h
(basic_debugstream::disable): New, disable the stream completely
(basic_debugstream::enable): New, reenable the stream
* src/lyx_main.[Ch]: Adjust to changes above
* src/paragraph.C: Ditto
* lib/unicodesymbols: New file with UCS4 -> LaTeX command mapping.
It is far from complete yet, but contains most accents on latin
characters.
* lib/Makefile.am: add lib/unicodesymbols
* development/scons/scons_manifest.py: ditto
* development/tools/unicodesymbols.py: Helper script to update
lib/unicodesymbols with new symbols
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16920 a592a061-630c-0410-9148-cb99ea01b6c8
2007-01-28 21:27:45 +00:00
|
|
|
|
: std::basic_ostream<charT, traits>(0), dt(debug::NONE),
|
|
|
|
|
realbuf_(0), enabled_(true)
|
2003-11-01 13:03:03 +00:00
|
|
|
|
{}
|
|
|
|
|
|
2003-09-26 14:27:20 +00:00
|
|
|
|
/// Constructor, sets the debug level to t.
|
|
|
|
|
explicit basic_debugstream(std::basic_streambuf<charT, traits> * buf)
|
Add machinery to output arbitrary unicode characters with LaTeX commands
read from a text file.
* src/encoding.[Ch]
(Encoding::latexChar): New, output a character to LaTeX
(Encoding::validate): New, add needed preamble stuff for a character
(Encodings::read): Read new unicodesymbols file
(Encodings::isCombiningChar): New, is a character a combining char?
* src/paragraph_pimpl.C
(isEncoding): Delete, no longer needed
(getEncoding): New, get the real encoding of a font
(Paragraph::Pimpl::latexSurrogatePair): New, output a surrogate pair
to LaTeX
(Paragraph::Pimpl::simpleTeXBlanks): Use latexSurrogatePair if needed
(Paragraph::Pimpl::simpleTeXSpecialChars): Ditto, and replace several
hardcoded characters with a call of encoding.latexChar()
(Paragraph::Pimpl::validate): replace several hardcoded characters
with a call of encoding.validate()
* src/support/debugstream.h
(basic_debugstream::disable): New, disable the stream completely
(basic_debugstream::enable): New, reenable the stream
* src/lyx_main.[Ch]: Adjust to changes above
* src/paragraph.C: Ditto
* lib/unicodesymbols: New file with UCS4 -> LaTeX command mapping.
It is far from complete yet, but contains most accents on latin
characters.
* lib/Makefile.am: add lib/unicodesymbols
* development/scons/scons_manifest.py: ditto
* development/tools/unicodesymbols.py: Helper script to update
lib/unicodesymbols with new symbols
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16920 a592a061-630c-0410-9148-cb99ea01b6c8
2007-01-28 21:27:45 +00:00
|
|
|
|
: std::basic_ostream<charT, traits>(buf), dt(debug::NONE),
|
|
|
|
|
realbuf_(0), enabled_(true)
|
2003-09-26 14:27:20 +00:00
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
/// Sets the debug level to t.
|
|
|
|
|
void level(Type t) {
|
|
|
|
|
dt = t;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Returns the current debug level.
|
|
|
|
|
Type level() const {
|
|
|
|
|
return dt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Returns true if t is part of the current debug level.
|
|
|
|
|
bool debugging(Type t = debug::ANY) const
|
|
|
|
|
{
|
|
|
|
|
if (debug::match(dt, t)) return true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Returns the no-op stream if t is not part of the
|
|
|
|
|
current debug level otherwise the real debug stream
|
|
|
|
|
is used.
|
|
|
|
|
Use: dbgstream[Debug::INFO] << "Info!\n";
|
|
|
|
|
*/
|
|
|
|
|
std::basic_ostream<charT, traits> & operator[](Type t) {
|
|
|
|
|
if (debug::match(dt, t))
|
|
|
|
|
return *this;
|
|
|
|
|
return nullstream;
|
|
|
|
|
}
|
Add machinery to output arbitrary unicode characters with LaTeX commands
read from a text file.
* src/encoding.[Ch]
(Encoding::latexChar): New, output a character to LaTeX
(Encoding::validate): New, add needed preamble stuff for a character
(Encodings::read): Read new unicodesymbols file
(Encodings::isCombiningChar): New, is a character a combining char?
* src/paragraph_pimpl.C
(isEncoding): Delete, no longer needed
(getEncoding): New, get the real encoding of a font
(Paragraph::Pimpl::latexSurrogatePair): New, output a surrogate pair
to LaTeX
(Paragraph::Pimpl::simpleTeXBlanks): Use latexSurrogatePair if needed
(Paragraph::Pimpl::simpleTeXSpecialChars): Ditto, and replace several
hardcoded characters with a call of encoding.latexChar()
(Paragraph::Pimpl::validate): replace several hardcoded characters
with a call of encoding.validate()
* src/support/debugstream.h
(basic_debugstream::disable): New, disable the stream completely
(basic_debugstream::enable): New, reenable the stream
* src/lyx_main.[Ch]: Adjust to changes above
* src/paragraph.C: Ditto
* lib/unicodesymbols: New file with UCS4 -> LaTeX command mapping.
It is far from complete yet, but contains most accents on latin
characters.
* lib/Makefile.am: add lib/unicodesymbols
* development/scons/scons_manifest.py: ditto
* development/tools/unicodesymbols.py: Helper script to update
lib/unicodesymbols with new symbols
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16920 a592a061-630c-0410-9148-cb99ea01b6c8
2007-01-28 21:27:45 +00:00
|
|
|
|
/// Disable the stream completely
|
|
|
|
|
void disable()
|
|
|
|
|
{
|
|
|
|
|
if (enabled_) {
|
|
|
|
|
realbuf_ = this->rdbuf();
|
|
|
|
|
rdbuf(nullstream.rdbuf());
|
|
|
|
|
enabled_ = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// Enable the stream after a possible call of disable()
|
|
|
|
|
void enable()
|
|
|
|
|
{
|
|
|
|
|
if (!enabled_) {
|
|
|
|
|
this->rdbuf(realbuf_);
|
|
|
|
|
enabled_ = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-09-26 14:27:20 +00:00
|
|
|
|
private:
|
|
|
|
|
/// The current debug level
|
|
|
|
|
Type dt;
|
|
|
|
|
/// The no-op stream.
|
|
|
|
|
boost::basic_onullstream<charT, traits> nullstream;
|
Add machinery to output arbitrary unicode characters with LaTeX commands
read from a text file.
* src/encoding.[Ch]
(Encoding::latexChar): New, output a character to LaTeX
(Encoding::validate): New, add needed preamble stuff for a character
(Encodings::read): Read new unicodesymbols file
(Encodings::isCombiningChar): New, is a character a combining char?
* src/paragraph_pimpl.C
(isEncoding): Delete, no longer needed
(getEncoding): New, get the real encoding of a font
(Paragraph::Pimpl::latexSurrogatePair): New, output a surrogate pair
to LaTeX
(Paragraph::Pimpl::simpleTeXBlanks): Use latexSurrogatePair if needed
(Paragraph::Pimpl::simpleTeXSpecialChars): Ditto, and replace several
hardcoded characters with a call of encoding.latexChar()
(Paragraph::Pimpl::validate): replace several hardcoded characters
with a call of encoding.validate()
* src/support/debugstream.h
(basic_debugstream::disable): New, disable the stream completely
(basic_debugstream::enable): New, reenable the stream
* src/lyx_main.[Ch]: Adjust to changes above
* src/paragraph.C: Ditto
* lib/unicodesymbols: New file with UCS4 -> LaTeX command mapping.
It is far from complete yet, but contains most accents on latin
characters.
* lib/Makefile.am: add lib/unicodesymbols
* development/scons/scons_manifest.py: ditto
* development/tools/unicodesymbols.py: Helper script to update
lib/unicodesymbols with new symbols
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16920 a592a061-630c-0410-9148-cb99ea01b6c8
2007-01-28 21:27:45 +00:00
|
|
|
|
/// The buffer of the real stream
|
|
|
|
|
std::streambuf * realbuf_;
|
|
|
|
|
/// Is the stream enabled?
|
|
|
|
|
bool enabled_;
|
2003-09-26 14:27:20 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef basic_debugstream<debug_trait> debugstream;
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
//} // namespace lyx
|
|
|
|
|
|
2003-09-26 14:27:20 +00:00
|
|
|
|
#endif
|