From ab9548d06d4b59852a390e8d98b78b9df5382bd6 Mon Sep 17 00:00:00 2001 From: Enrico Forestieri Date: Sat, 29 Jan 2011 19:44:53 +0000 Subject: [PATCH] In order to avoid code replication, use a template-based solution for all types requiring the exact same code, as suggested by Tommaso. This allows to simply add a single-line instantiation declaration if there's the need of adding another type requiring the same code. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@37366 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/support/docstream.cpp | 36 ++++++++---------------------------- src/support/docstream.h | 10 +++------- 2 files changed, 11 insertions(+), 35 deletions(-) diff --git a/src/support/docstream.cpp b/src/support/docstream.cpp index 56472058c5..3805360618 100644 --- a/src/support/docstream.cpp +++ b/src/support/docstream.cpp @@ -447,15 +447,6 @@ otexstream & operator<<(otexstream & ots, SafeBreakLine) } -otexstream & operator<<(otexstream & ots, SetEnc e) -{ - ots.os() << e; - ots.canBreakLine(true); - ots.protectSpace(false); - return ots; -} - - otexstream & operator<<(otexstream & ots, docstring const & s) { size_t const len = s.length(); @@ -511,31 +502,20 @@ otexstream & operator<<(otexstream & ots, char c) } -otexstream & operator<<(otexstream & ots, double d) +template +otexstream & operator<<(otexstream & ots, Type value) { - ots.os() << d; + ots.os() << value; ots.canBreakLine(true); ots.protectSpace(false); return ots; } - -otexstream & operator<<(otexstream & ots, int i) -{ - ots.os() << i; - ots.canBreakLine(true); - ots.protectSpace(false); - return ots; -} - - -otexstream & operator<<(otexstream & ots, unsigned int i) -{ - ots.os() << i; - ots.canBreakLine(true); - ots.protectSpace(false); - return ots; -} +template otexstream & operator<< (otexstream & os, SetEnc); +template otexstream & operator<< (otexstream &, double); +template otexstream & operator<< (otexstream &, int); +template otexstream & operator<< (otexstream &, unsigned int); +template otexstream & operator<< (otexstream &, unsigned long); } diff --git a/src/support/docstream.h b/src/support/docstream.h index 167bdd1e21..40f8e004db 100644 --- a/src/support/docstream.h +++ b/src/support/docstream.h @@ -112,7 +112,7 @@ public: /// void protectSpace(bool protectspace) { protectspace_ = protectspace; } /// - bool protectSpace() const { return protectspace_; }; + bool protectSpace() const { return protectspace_; } private: /// odocstream & os_; @@ -147,11 +147,8 @@ otexstream & operator<<(otexstream &, char const *); /// otexstream & operator<<(otexstream &, char); /// -otexstream & operator<<(otexstream &, double); -/// -otexstream & operator<<(otexstream &, int); -/// -otexstream & operator<<(otexstream &, unsigned int); +template +otexstream & operator<<(otexstream & ots, Type value); /// Helper struct for changing stream encoding struct SetEnc { @@ -171,7 +168,6 @@ SetEnc setEncoding(std::string const & encoding); \endcode */ odocstream & operator<<(odocstream & os, SetEnc e); -otexstream & operator<<(otexstream & os, SetEnc e); idocstream & operator<<(idocstream & os, SetEnc e); }