]> git.lyx.org Git - features.git/commitdiff
In order to avoid code replication, use a template-based solution for
authorEnrico Forestieri <forenr@lyx.org>
Sat, 29 Jan 2011 19:44:53 +0000 (19:44 +0000)
committerEnrico Forestieri <forenr@lyx.org>
Sat, 29 Jan 2011 19:44:53 +0000 (19:44 +0000)
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
src/support/docstream.h

index 56472058c56e3a0c713785a585ddc39f2a484742..38053606185077a13c4d69241b8d167617c9ac23 100644 (file)
@@ -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)
-{
-       ots.os() << d;
-       ots.canBreakLine(true);
-       ots.protectSpace(false);
-       return ots;
-}
-
-
-otexstream & operator<<(otexstream & ots, int i)
+template <typename Type>
+otexstream & operator<<(otexstream & ots, Type value)
 {
-       ots.os() << i;
+       ots.os() << value;
        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<< <SetEnc>(otexstream & os, SetEnc);
+template otexstream & operator<< <double>(otexstream &, double);
+template otexstream & operator<< <int>(otexstream &, int);
+template otexstream & operator<< <unsigned int>(otexstream &, unsigned int);
+template otexstream & operator<< <unsigned long>(otexstream &, unsigned long);
 
 }
 
index 167bdd1e218a042dd2aa30a1f7bd4bab71d2d59b..40f8e004dbceaf624469b2a81cf25912c55c4fd4 100644 (file)
@@ -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 <typename Type>
+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);
 
 }