1999-10-07 18:44:17 +00:00
|
|
|
// -*- C++ -*-
|
2003-08-23 00:17:00 +00:00
|
|
|
/**
|
|
|
|
* \file debug.h
|
2007-05-28 22:27:45 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-21 17:27:08 +00:00
|
|
|
*
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Lars Gullik Bjønnes
|
2003-08-23 00:17:00 +00:00
|
|
|
* \author Jean-Marc Lasgouttes
|
2009-12-29 15:05:37 +00:00
|
|
|
* \author Pavel Sanda
|
2002-03-21 17:27:08 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
1999-10-07 18:44:17 +00:00
|
|
|
|
|
|
|
#ifndef LYXDEBUG_H
|
|
|
|
#define LYXDEBUG_H
|
|
|
|
|
2007-11-14 21:57:43 +00:00
|
|
|
#include "support/strfwd.h"
|
2006-10-21 00:16:43 +00:00
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
namespace std {
|
|
|
|
|
|
|
|
class ios_base;
|
|
|
|
|
|
|
|
template<typename CharT, typename Traits> class basic_streambuf;
|
|
|
|
typedef basic_streambuf<char, char_traits<char> > streambuf;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
namespace lyx {
|
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
/// This is all the different debug levels that we have.
|
|
|
|
namespace Debug {
|
1999-10-07 18:44:17 +00:00
|
|
|
///
|
2007-11-28 22:12:03 +00:00
|
|
|
enum Type {
|
1999-10-07 18:44:17 +00:00
|
|
|
///
|
|
|
|
NONE = 0,
|
|
|
|
///
|
|
|
|
INFO = (1 << 0), // 1
|
|
|
|
///
|
|
|
|
INIT = (1 << 1), // 2
|
|
|
|
///
|
|
|
|
KEY = (1 << 2), // 4
|
|
|
|
///
|
2000-07-24 13:53:19 +00:00
|
|
|
GUI = (1 << 3), // 8
|
1999-10-07 18:44:17 +00:00
|
|
|
///
|
|
|
|
PARSER = (1 << 4), // 16
|
|
|
|
///
|
|
|
|
LYXRC = (1 << 5), // 32
|
|
|
|
///
|
|
|
|
KBMAP = (1 << 6), // 64
|
|
|
|
///
|
|
|
|
LATEX = (1 << 7), // 128
|
|
|
|
///
|
|
|
|
MATHED = (1 << 8), // 256 // Alejandro, please use this.
|
|
|
|
///
|
|
|
|
FONT = (1 << 9), // 512
|
|
|
|
///
|
|
|
|
TCLASS = (1 << 10), // 1024
|
|
|
|
///
|
|
|
|
LYXVC = (1 << 11), // 2048
|
|
|
|
///
|
|
|
|
LYXSERVER = (1 << 12), // 4096
|
|
|
|
///
|
2008-08-15 19:09:42 +00:00
|
|
|
UNDO = (1 << 13), // 8192
|
1999-11-25 17:29:19 +00:00
|
|
|
///
|
2000-01-06 02:44:26 +00:00
|
|
|
ACTION = (1 << 14), // 16384
|
|
|
|
///
|
2000-01-25 12:35:27 +00:00
|
|
|
LYXLEX = (1 << 15),
|
|
|
|
///
|
2000-04-19 14:42:19 +00:00
|
|
|
DEPEND = (1 << 16),
|
|
|
|
///
|
2000-11-14 02:01:57 +00:00
|
|
|
INSETS = (1 << 17),
|
|
|
|
///
|
2001-11-09 13:44:48 +00:00
|
|
|
FILES = (1 << 18),
|
|
|
|
///
|
2001-11-28 16:09:25 +00:00
|
|
|
WORKAREA = (1 << 19),
|
|
|
|
///
|
2002-02-16 12:33:19 +00:00
|
|
|
INSETTEXT = (1 << 20),
|
|
|
|
///
|
2003-02-08 19:18:01 +00:00
|
|
|
GRAPHICS = (1 << 21),
|
|
|
|
/// change tracking
|
2003-09-04 17:01:00 +00:00
|
|
|
CHANGES = (1 << 22),
|
|
|
|
///
|
2003-09-26 14:27:20 +00:00
|
|
|
EXTERNAL = (1 << 23),
|
|
|
|
///
|
2006-03-10 16:10:35 +00:00
|
|
|
PAINTING = (1 << 24),
|
|
|
|
///
|
2007-12-21 08:28:18 +00:00
|
|
|
SCROLLING = (1 << 25),
|
|
|
|
///
|
2007-12-21 20:43:21 +00:00
|
|
|
MACROS = (1 << 26),
|
2008-02-10 19:52:45 +00:00
|
|
|
/// rtl-related
|
|
|
|
RTL = (1 << 27),
|
2008-06-25 10:53:34 +00:00
|
|
|
/// locale related
|
2008-07-14 23:47:54 +00:00
|
|
|
LOCALE = (1 << 28),
|
|
|
|
/// selection
|
|
|
|
SELECTION = (1 << 29),
|
2009-08-17 14:39:00 +00:00
|
|
|
/// Find and Replace
|
|
|
|
FIND = (1 << 30),
|
2007-12-21 20:43:21 +00:00
|
|
|
///
|
2004-06-18 13:31:55 +00:00
|
|
|
DEBUG = (1 << 31),
|
|
|
|
///
|
|
|
|
ANY = 0xffffffff
|
1999-10-07 18:44:17 +00:00
|
|
|
};
|
2003-09-26 14:27:20 +00:00
|
|
|
|
2010-11-06 00:22:47 +00:00
|
|
|
/// Return number of levels
|
2009-12-30 15:09:49 +00:00
|
|
|
int levelCount();
|
|
|
|
|
2010-11-06 00:22:47 +00:00
|
|
|
/// A function to convert debug level string names numerical values
|
2007-11-28 22:12:03 +00:00
|
|
|
Type value(std::string const & val);
|
1999-12-13 15:31:52 +00:00
|
|
|
|
2010-11-06 00:22:47 +00:00
|
|
|
/// A function to convert index of level to their numerical value
|
2009-12-30 15:09:49 +00:00
|
|
|
Type value(int val);
|
|
|
|
|
2009-12-29 15:05:37 +00:00
|
|
|
/// Return description of level
|
|
|
|
std::string const description(Type val);
|
|
|
|
|
|
|
|
/// Return name of level
|
|
|
|
std::string const name(Type val);
|
|
|
|
|
2010-11-06 00:22:47 +00:00
|
|
|
/// Display the tags and descriptions of the current debug level
|
2007-11-28 22:12:03 +00:00
|
|
|
void showLevel(std::ostream & os, Type level);
|
1999-12-13 15:31:52 +00:00
|
|
|
|
2010-11-06 00:22:47 +00:00
|
|
|
/// Show all the possible tags that can be used for debugging
|
2007-11-28 22:12:03 +00:00
|
|
|
void showTags(std::ostream & os);
|
1999-12-13 15:31:52 +00:00
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
} // namespace Debug
|
1999-12-13 21:59:26 +00:00
|
|
|
|
2000-07-15 23:51:46 +00:00
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
inline void operator|=(Debug::Type & d1, Debug::Type d2)
|
1999-11-04 01:40:20 +00:00
|
|
|
{
|
2007-11-28 22:12:03 +00:00
|
|
|
d1 = static_cast<Debug::Type>(d1 | d2);
|
1999-11-04 01:40:20 +00:00
|
|
|
}
|
1999-10-07 18:44:17 +00:00
|
|
|
|
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
class LyXErr
|
|
|
|
{
|
|
|
|
public:
|
2010-11-06 00:22:47 +00:00
|
|
|
LyXErr(): enabled_(true), second_enabled_(false) {}
|
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
/// Disable the stream completely
|
|
|
|
void disable();
|
|
|
|
/// Enable the stream after a possible call of disable()
|
|
|
|
void enable();
|
2010-11-06 00:22:47 +00:00
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
/// Ends output
|
|
|
|
void endl();
|
2010-11-06 00:22:47 +00:00
|
|
|
|
|
|
|
/// Returns stream
|
2007-11-28 22:12:03 +00:00
|
|
|
std::ostream & stream() { return *stream_; }
|
|
|
|
/// Returns stream
|
|
|
|
operator std::ostream &() { return *stream_; }
|
2010-11-06 00:22:47 +00:00
|
|
|
/// Sets stream
|
|
|
|
void setStream(std::ostream & os) { stream_ = &os; }
|
|
|
|
/// Is the stream enabled ?
|
|
|
|
bool enabled() const { return enabled_; }
|
|
|
|
|
|
|
|
/// Returns second stream
|
|
|
|
std::ostream & secondStream() { return *second_stream_; };
|
|
|
|
/// Sets second stream
|
|
|
|
void setSecondStream(std::ostream * os)
|
|
|
|
{ second_enabled_ = (second_stream_ = os); }
|
|
|
|
/// Is the second stream is enabled?
|
|
|
|
bool secondEnabled() { return second_enabled_; }
|
|
|
|
|
|
|
|
/// Sets the debug level
|
|
|
|
void setLevel(Debug::Type t) { dt_ = t; }
|
|
|
|
/// Returns the current debug level
|
|
|
|
Debug::Type level() const { return dt_; }
|
|
|
|
/// Returns true if t is part of the current debug level
|
|
|
|
bool debugging(Debug::Type t = Debug::ANY) const;
|
2009-12-29 15:05:37 +00:00
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
private:
|
|
|
|
/// The current debug level
|
2010-11-06 00:22:47 +00:00
|
|
|
Debug::Type dt_;
|
2007-11-28 22:12:03 +00:00
|
|
|
/// The real stream
|
|
|
|
std::ostream * stream_;
|
2010-11-06 00:22:47 +00:00
|
|
|
/// Is the stream enabled?
|
|
|
|
bool enabled_;
|
2009-12-29 15:05:37 +00:00
|
|
|
/// Next stream for output duplication
|
2010-11-06 00:22:47 +00:00
|
|
|
std::ostream * second_stream_;
|
2009-12-29 15:05:37 +00:00
|
|
|
/// Is the second stream enabled?
|
2010-11-06 00:22:47 +00:00
|
|
|
bool second_enabled_;
|
2007-11-28 22:12:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
namespace support { class FileName; }
|
|
|
|
|
|
|
|
LyXErr & operator<<(LyXErr &, void const *);
|
|
|
|
LyXErr & operator<<(LyXErr &, char const *);
|
|
|
|
LyXErr & operator<<(LyXErr &, char);
|
|
|
|
LyXErr & operator<<(LyXErr &, int);
|
|
|
|
LyXErr & operator<<(LyXErr &, unsigned int);
|
|
|
|
LyXErr & operator<<(LyXErr &, long);
|
|
|
|
LyXErr & operator<<(LyXErr &, unsigned long);
|
|
|
|
LyXErr & operator<<(LyXErr &, double);
|
|
|
|
LyXErr & operator<<(LyXErr &, std::string const &);
|
|
|
|
LyXErr & operator<<(LyXErr &, docstring const &);
|
|
|
|
LyXErr & operator<<(LyXErr &, support::FileName const &);
|
|
|
|
LyXErr & operator<<(LyXErr &, std::ostream &(*)(std::ostream &));
|
|
|
|
LyXErr & operator<<(LyXErr &, std::ios_base &(*)(std::ios_base &));
|
1999-10-13 10:34:07 +00:00
|
|
|
|
2003-09-26 14:27:20 +00:00
|
|
|
extern LyXErr lyxerr;
|
1999-10-07 18:44:17 +00:00
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
} // namespace lyx
|
|
|
|
|
2007-11-30 18:48:35 +00:00
|
|
|
#if USE_BOOST_CURRENT_FUNCTION
|
|
|
|
# include <boost/current_function.hpp>
|
|
|
|
# define CURRENT_POSITION BOOST_CURRENT_FUNCTION ": "
|
2007-11-29 21:10:35 +00:00
|
|
|
#else
|
2007-11-30 18:48:35 +00:00
|
|
|
# define CURRENT_POSITION __FILE__ << "(" << __LINE__ << "): "
|
2007-11-29 21:10:35 +00:00
|
|
|
#endif
|
2007-11-28 22:12:03 +00:00
|
|
|
|
2007-11-15 20:04:51 +00:00
|
|
|
#define LYXERR(type, msg) \
|
|
|
|
do { \
|
2007-11-28 22:12:03 +00:00
|
|
|
if (!lyx::lyxerr.debugging(type)) {} \
|
2007-11-30 18:48:35 +00:00
|
|
|
else { lyx::lyxerr << CURRENT_POSITION << msg; lyx::lyxerr.endl(); } \
|
2007-11-15 20:04:51 +00:00
|
|
|
} while (0)
|
2007-04-01 10:09:49 +00:00
|
|
|
|
2007-12-11 20:28:00 +00:00
|
|
|
#define LYXERR0(msg) \
|
|
|
|
do { \
|
|
|
|
lyx::lyxerr << CURRENT_POSITION << msg; lyx::lyxerr.endl(); \
|
|
|
|
} while (0)
|
|
|
|
|
2007-11-27 20:37:08 +00:00
|
|
|
|
1999-10-07 18:44:17 +00:00
|
|
|
#endif
|