source: trunk/yat/utility/stl_utility.h @ 869

Last change on this file since 869 was 869, checked in by Peter, 16 years ago

Adding Smith-Waterman local alignment and modified ssearch to use this instead. Also added some convenient max functions in stl_utility.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.2 KB
Line 
1#ifndef _theplu_yat_utility_stl_utility_
2#define _theplu_yat_utility_stl_utility_
3
4// $Id: stl_utility.h 869 2007-09-14 18:59:46Z peter $
5
6/*
7  Copyright (C) 2004 Jari Häkkinen
8  Copyright (C) 2005 Jari Häkkinen, Markus Ringnér, Peter Johansson
9  Copyright (C) 2006, 2007 Jari Häkkinen, Peter Johansson
10
11  This file is part of the yat library, http://trac.thep.lu.se/trac/yat
12
13  The yat library is free software; you can redistribute it and/or
14  modify it under the terms of the GNU General Public License as
15  published by the Free Software Foundation; either version 2 of the
16  License, or (at your option) any later version.
17
18  The yat library is distributed in the hope that it will be useful,
19  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21  General Public License for more details.
22
23  You should have received a copy of the GNU General Public License
24  along with this program; if not, write to the Free Software
25  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26  02111-1307, USA.
27*/
28
29///
30/// \file stl_utility.h
31///
32/// There are a number of useful functionality missing in the Standard
33/// Template Library, STL. This file is an effort to provide
34/// extensions to STL functionality.
35///
36
37#include <algorithm>
38#include <ostream>
39#include <string>
40#include <utility>
41
42namespace std {
43
44  ///
45  /// Print out a pair
46  ///
47  // This is in namespace std because we have not figured out how to have
48  // pair and its operator<< in different namespaces
49  template <class T1, class T2> 
50  std::ostream& operator<<(std::ostream& out, const std::pair<T1,T2>& p) 
51  { out << p.first << "\t" << p.second; return out; }
52
53}
54
55namespace theplu {
56namespace yat {
57namespace utility {
58
59  /**
60     \return max of values
61   */
62  template <typename T>
63  T max(const T& a, const T& b, const T& c)
64  {
65    return std::max(std::max(a,b),c);
66  }
67
68
69  /**
70     \return max of values
71   */
72  template <typename T>
73  T max(const T& a, const T& b, const T& c, const T& d)
74  {
75    return std::max(std::max(a,b), std::max(c,d));
76  }
77
78
79  /**
80     \return max of values
81   */
82  template <typename T>
83  T max(const T& a, const T& b, const T& c, const T& d, const T& e)
84  {
85    return std::max(max(a,b,c,d), e);
86  }
87
88
89  /**
90     \return max of values
91   */
92  template <typename T>
93  T max(const T& a, const T& b, const T& c, const T& d, const T& e, const T& f)
94  {
95    return std::max(max(a,b,c,d), std::max(e,f));
96  }
97
98
99  ///
100  /// @brief Functor comparing pairs using second.
101  ///
102  /// STL provides operator< for the pair.first element, but none for
103  /// pair.second. This template provides this and can be used as the
104  /// comparison object in generic functions such as the STL sort.
105  ///
106  template <class T1,class T2>
107  struct pair_value_compare
108  {
109    ///
110    /// @return true if x.second<y.second or (x.second==y.second and
111    /// x.first<y.first)
112    ///
113    inline bool operator()(const std::pair<T1,T2>& x,
114                           const std::pair<T1,T2>& y) {
115      return ((x.second<y.second) ||
116              (!(y.second<x.second) && (x.first<y.first))); 
117    }
118  };
119
120  ///
121  /// @brief Function converting a string to lower case
122  ///
123  void to_lower(std::string& s);
124
125  ///
126  /// @brief Function converting a string to upper case
127  ///
128  void to_upper(std::string& s);
129
130}}} // of namespace utility, yat, and theplu
131
132#endif
Note: See TracBrowser for help on using the repository browser.