]> git.lyx.org Git - lyx.git/blobdiff - src/support/translator.h
lyxserver cleanup patch + andre's small patches
[lyx.git] / src / support / translator.h
index c138391658121721d8a7033c73439c50e3a25ed4..e211aa468d447067215919fe83342c79796e35b3 100644 (file)
@@ -4,7 +4,7 @@
  * 
  *          LyX, The Document Processor
  *          Copyright 1995 Matthias Ettrich.
- *          Copyright 1995-2000 The LyX Team.
+ *          Copyright 1995-2001 The LyX Team.
  *
  *          This file Copyright 2000 Baruch Even
  * ================================================= */
 #include <functional>
 
 #include "support/LAssert.h"
-
-// Functors used in the template.
-
-///
-template<typename T1, typename T2>
-class equal_1st_in_pair {
-public:
-       ///
-       equal_1st_in_pair(T1 const & value) : value_(value) {}
-       ///
-       typedef std::pair<T1, T2> pair_type;
-       ///
-       bool operator() (pair_type const & p) const {
-               return p.first == value_;
-       }
-private:
-       ///
-       T1 const & value_;
-};
-
-
-///
-template<typename T1, typename T2>
-class equal_2nd_in_pair {
-public:
-       ///
-       equal_2nd_in_pair(T2 const & value) : value_(value) {}
-       ///
-       typedef std::pair<T1, T2> pair_type;
-       ///
-       bool operator() (pair_type const & p) const {
-               return p.second == value_;
-       }
-private:
-       ///
-       T2 const & value_;
-};
-
-
+#include "support/lyxfunctional.h"
 /** This class template is used to translate between two elements, specifically
     it was worked out to translate between an enum and strings when reading
     the lyx file.
@@ -87,16 +49,16 @@ public:
        
        /// Find the mapping for the first argument
        T2 const & find(T1 const & first) const {
-               Assert(!map.empty());
+               lyx::Assert(!map.empty());
                
                // For explanation see the next find() function.
                Map::const_iterator it =
                        std::find_if(map.begin(), map.end(),
-                                    equal_1st_in_pair<T1, T2>(first)
+                                    lyx::equal_1st_in_pair<T1, T2>(first)
                                );
                
                if (it != map.end()) {
-                       return (*it).second;
+                       return it->second;
                } else {
                        return default_t2;
                }
@@ -104,7 +66,7 @@ public:
        
        /// Find the mapping for the second argument
        T1 const & find(T2 const & second) const {
-               Assert(!map.empty());
+               lyx::Assert(!map.empty());
                
                // The idea is as follows:
                // find_if() will try to compare the data in the vector with
@@ -119,11 +81,11 @@ public:
                // equal_to( select2nd(pair) , second)
                Map::const_iterator it =
                        std::find_if(map.begin(), map.end(),
-                                    equal_2nd_in_pair<T1, T2>(second)
+                                    lyx::equal_2nd_in_pair<T1, T2>(second)
                                );
                
                if (it != map.end())
-                       return (*it).first;
+                       return it->first;
                else {
                        return default_t1;
                }