diff --git a/configure.ac b/configure.ac index f3baf00882..b0156035f1 100644 --- a/configure.ac +++ b/configure.ac @@ -77,13 +77,13 @@ AC_LANG(C++) dnl we do not need that currently (and probably all our supported dnl compiler allow that) dnl LYX_CXX_PARTIAL -LYX_CXX_EXPLICIT +dnl LYX_CXX_EXPLICIT LYX_CXX_GLOBAL_CSTD -LYX_STD_COUNT +dnl LYX_STD_COUNT dnl we disable rtti for now dnl LYX_CXX_RTTI -AC_CHECK_HEADERS(ostream istream sstream locale limits ios) -LYX_CXX_STL_MODERN_STREAMS +dnl AC_CHECK_HEADERS(ostream istream sstream locale limits ios) +dnl LYX_CXX_STL_MODERN_STREAMS ### and now some special lyx flags. AC_ARG_ENABLE(assertions, @@ -100,7 +100,7 @@ if test "x$enable_assertions" = xyes ; then fi ### Library Files -AC_CHECK_LIB(m, sin) +dnl AC_CHECK_LIB(m, sin) ### Add extra directories to check for libraries. LYX_WITH_DIR([extra-lib],[extra library directory],extra_lib, NONE) diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 34727d28bf..cd56bce44d 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -79,6 +79,7 @@ #include #include +#include #include #include #include @@ -1758,7 +1759,7 @@ void Buffer::changeRefsIfUnique(docstring const & from, docstring const & to, } else getLabelList(labels); - if (lyx::count(labels.begin(), labels.end(), from) > 1) + if (std::count(labels.begin(), labels.end(), from) > 1) return; for (InsetIterator it = inset_iterator_begin(inset()); it; ++it) { diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp index fc082c178b..57932680f5 100644 --- a/src/BufferParams.cpp +++ b/src/BufferParams.cpp @@ -39,14 +39,15 @@ #include "frontends/alert.h" #include "insets/InsetListingsParams.h" -#include "support/lyxalgo.h" // for lyx::count #include "support/convert.h" #include "support/Translator.h" #include +#include #include +using std::count; using std::endl; using std::string; using std::istringstream; @@ -1159,7 +1160,7 @@ bool BufferParams::writeLaTeX(odocstream & os, LaTeXFeatures & features, lyxpreamble += "\\makeatother\n\n"; int const nlines = - int(lyx::count(lyxpreamble.begin(), lyxpreamble.end(), '\n')); + int(count(lyxpreamble.begin(), lyxpreamble.end(), '\n')); for (int j = 0; j != nlines; ++j) { texrow.newline(); } diff --git a/src/insets/ExternalSupport.cpp b/src/insets/ExternalSupport.cpp index e214c3e4f2..2210a1bc72 100644 --- a/src/insets/ExternalSupport.cpp +++ b/src/insets/ExternalSupport.cpp @@ -37,6 +37,8 @@ #include +#include + using std::endl; using std::string; using std::vector; @@ -387,7 +389,7 @@ int writeExternal(InsetExternalParams const & params, str = substituteOptions(params, str, format); // FIXME UNICODE os << from_utf8(str); - return int(lyx::count(str.begin(), str.end(),'\n')); + return int(std::count(str.begin(), str.end(),'\n')); } namespace { diff --git a/src/insets/InsetGraphics.cpp b/src/insets/InsetGraphics.cpp index cfb0e326bb..1203d27188 100644 --- a/src/insets/InsetGraphics.cpp +++ b/src/insets/InsetGraphics.cpp @@ -76,7 +76,6 @@ TODO #include "support/convert.h" #include "support/filetools.h" -#include "support/lyxalgo.h" // count #include "support/lyxlib.h" // sum #include "support/lstrings.h" #include "support/os.h" @@ -85,6 +84,7 @@ TODO #include #include +#include #include @@ -823,7 +823,7 @@ int InsetGraphics::latex(Buffer const & buf, odocstream & os, LYXERR(Debug::GRAPHICS) << "InsetGraphics::latex outputting:\n" << latex_str << endl; // Return how many newlines we issued. - return int(lyx::count(latex_str.begin(), latex_str.end(),'\n')); + return int(std::count(latex_str.begin(), latex_str.end(),'\n')); } diff --git a/src/insets/InsetNote.cpp b/src/insets/InsetNote.cpp index d698f69218..1406d0c687 100644 --- a/src/insets/InsetNote.cpp +++ b/src/insets/InsetNote.cpp @@ -28,9 +28,9 @@ #include "MetricsInfo.h" #include "OutputParams.h" -#include "support/lyxalgo.h" #include "support/Translator.h" +#include #include @@ -323,7 +323,7 @@ int InsetNote::latex(Buffer const & buf, odocstream & os, os << str; runparams_in.encoding = runparams.encoding; // Return how many newlines we issued. - return int(lyx::count(str.begin(), str.end(), '\n')); + return int(std::count(str.begin(), str.end(), '\n')); } diff --git a/src/mathed/MathStream.cpp b/src/mathed/MathStream.cpp index c136573957..31f69518de 100644 --- a/src/mathed/MathStream.cpp +++ b/src/mathed/MathStream.cpp @@ -15,17 +15,15 @@ #include "MathExtern.h" #include "MathStream.h" -#include "support/lyxalgo.h" #include "support/textutils.h" +#include namespace lyx { using std::strlen; - - ////////////////////////////////////////////////////////////////////// @@ -154,7 +152,7 @@ WriteStream & operator<<(WriteStream & ws, char const * s) ws.pendingSpace(false); } ws.os() << s; - ws.addlines(int(count(s, s + strlen(s), '\n'))); + ws.addlines(int(std::count(s, s + strlen(s), '\n'))); return ws; } diff --git a/src/support/LaTeXStream.cpp b/src/support/LaTeXStream.cpp new file mode 100644 index 0000000000..b3d9f50362 --- /dev/null +++ b/src/support/LaTeXStream.cpp @@ -0,0 +1,99 @@ +#include "LaTeXStream.h" + +#include +#include + +namespace lyx { + +//////////////////////////////////////////////////////////////// +// +// LaTeXStreamBuffer +// +//////////////////////////////////////////////////////////////// + + +class LaTeXStreamBuffer : public std::streambuf +{ +public: + explicit LaTeXStreamBuffer(std::streambuf * sbuf); + int line() const { return line_; } + +protected: + int overflow(int); + int sync(); + +private: + std::streambuf * sbuf_; + int line_; +}; + + +LaTeXStreamBuffer::LaTeXStreamBuffer(std::streambuf *sb) + : sbuf_(sb), line_(0) +{ + setp(0, 0); + setg(0, 0, 0); +} + +int LaTeXStreamBuffer::overflow(int c) +{ + if (c == '\n') + ++line_; + return c; +} + + +int LaTeXStreamBuffer::sync() +{ + sbuf_->pubsync(); + return 0; +} + + +//////////////////////////////////////////////////////////////// +// +// LaTeXStream +// +//////////////////////////////////////////////////////////////// + +LaTeXStream::LaTeXStream(std::streambuf * sbuf) + : std::ostream(sbuf_ = new LaTeXStreamBuffer(sbuf)) +{} + + +LaTeXStream::~LaTeXStream() +{ + delete sbuf_; +} + + +int LaTeXStream::line() const +{ + return sbuf_->line(); +} + + +//////////////////////////////////////////////////////////////// +// +// Test +// +//////////////////////////////////////////////////////////////// + +#if 0 + +int main(int argc, char *argv[]) +{ + LaTeXStream out(std::cout.rdbuf()); + char c; + while (std::cin) { + if (std::cin.get(c)) + out.put(c); + } + std::cout << "line count: " << out.line() << std::endl; + + return 0; +} + +#endif + +} diff --git a/src/support/Makefile.am b/src/support/Makefile.am index 2e6fc5aa0b..d9c74427c4 100644 --- a/src/support/Makefile.am +++ b/src/support/Makefile.am @@ -52,6 +52,8 @@ liblyxsupport_la_SOURCES = \ gzstream.cpp \ gzstream.h \ kill.cpp \ + LaTeXStream.cpp \ + LaTeXStream.h \ limited_stack.h \ lstrings.cpp \ lstrings.h \ diff --git a/src/support/lyxalgo.h b/src/support/lyxalgo.h index 19c2485a34..b3a08241b4 100644 --- a/src/support/lyxalgo.h +++ b/src/support/lyxalgo.h @@ -73,21 +73,6 @@ OutputIter copy_if(InputIter first, InputIter last, } -/// A slot in replacement for std::count for systems where it is broken. -template -typename std::iterator_traits::difference_type -count (Iterator first, Iterator last, T const & value) -{ -#ifdef HAVE_STD_COUNT - return std::count(first, last, value); -#else - typename std::iterator_traits::difference_type n = 0; - while (first != last) - if (*first++ == value) ++n; - return n; -#endif -} - /// Remove all duplicate entries in c. template void eliminate_duplicates(C & c)