Pavel Sanda wrote: >> I do not really understand either why we need this STREAM_OPERATOR macro. > > why we need is quite clear - there is xtimes the same code and we dont want to > copy nad paste it. i dont like the macro solution but i failed to produce > template which would be desirable for this. either my c++ skills are lacking > or > it is not possible to instantiate operator templates out of class body - > compiler takes the template without problems but but linker claims not to find > instances needed. and yes this is the most ugly part. maybe our c++ wizard > Andre' have an idea? :) > > pavel >
After the reply to JMarc I also tought about a template solution. Attached a patch, but it's tested only with msvc. Peter
Index: src/support/debug.cpp =================================================================== --- src/support/debug.cpp (Revision 32670) +++ src/support/debug.cpp (Arbeitskopie) @@ -192,45 +192,46 @@ // It seems not possible to instantiate operator template out of class body -#define STREAM_OPERATOR(t) \ -{\ - if (l.enabled()){\ - l.stream() << t;\ - if (l.second_used()){\ - l.second() << t;\ - ProgressInterface::instance()->lyxerrFlush();\ - }\ - }\ - return l;\ +template<class T> +LyXErr & toStream(LyXErr & l, T t) +{ + if (l.enabled()){ + l.stream() << t; + if (l.second_used()){ + l.second() << t; + ProgressInterface::instance()->lyxerrFlush(); + } + } + return l; } LyXErr & operator<<(LyXErr & l, void const * t) -STREAM_OPERATOR(t) +{ return toStream(l, t); } LyXErr & operator<<(LyXErr & l, char const * t) -STREAM_OPERATOR(t) +{ return toStream(l, t); } LyXErr & operator<<(LyXErr & l, char t) -STREAM_OPERATOR(t) +{ return toStream(l, t); } LyXErr & operator<<(LyXErr & l, int t) -STREAM_OPERATOR(t) +{ return toStream(l, t); } LyXErr & operator<<(LyXErr & l, unsigned int t) -STREAM_OPERATOR(t) +{ return toStream(l, t); } LyXErr & operator<<(LyXErr & l, long t) -STREAM_OPERATOR(t) +{ return toStream(l, t); } LyXErr & operator<<(LyXErr & l, unsigned long t) -STREAM_OPERATOR(t) +{ return toStream(l, t); } LyXErr & operator<<(LyXErr & l, double t) -STREAM_OPERATOR(t) +{ return toStream(l, t); } LyXErr & operator<<(LyXErr & l, string const & t) -STREAM_OPERATOR(t) +{ return toStream(l, t); } LyXErr & operator<<(LyXErr & l, docstring const & t) -STREAM_OPERATOR(to_utf8(t)); +{ return toStream(l, to_utf8(t)); } LyXErr & operator<<(LyXErr & l, FileName const & t) -STREAM_OPERATOR(t) +{ return toStream(l, t); } LyXErr & operator<<(LyXErr & l, ostream &(*t)(ostream &)) -STREAM_OPERATOR(t) +{ return toStream(l, t); } LyXErr & operator<<(LyXErr & l, ios_base &(*t)(ios_base &)) -STREAM_OPERATOR(t) +{ return toStream(l, t); } // The global instance