source: trunk/lib/utility/stl_utility.h @ 303

Last change on this file since 303 was 303, checked in by Peter, 17 years ago

docs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.5 KB
Line 
1// $Id: stl_utility.h 303 2005-04-30 16:17:35Z peter $
2
3#ifndef _theplu_utility_stl_utility_
4#define _theplu_utility_stl_utility_
5
6///
7/// \file stl_utility.h
8///
9/// There are a number of useful functionality missing in the Standard
10/// Template Library, STL. This file is an effort to provide
11/// extensions to STL functionality.
12///
13
14#include <string>
15#include <utility>
16#include <vector>
17
18namespace theplu {
19namespace utility {
20
21  ///
22  /// STL provides operator< for the pair.first element, but none for
23  /// pair.second. This template provides this and can be used as the
24  /// comparison object in generic functions such as the STL sort.
25  ///
26  template <class T1,class T2>
27  struct pair_value_compare
28  {
29    ///
30    /// @return true if x.second<y.second or (x.second==y.second and
31    /// x.first<y.first)
32    ///
33    inline bool operator()(const std::pair<T1,T2>& x,
34                           const std::pair<T1,T2>& y) {
35      return ((x.second<y.second) ||
36              (!(y.second<x.second) && (x.first<y.first))); 
37    }
38  };
39
40  ///
41  /// Function return true if string is a number. A number is defined
42  /// to start with '+', '-' or a digit. It must contain at most one
43  /// decimal point '.'. Also it may contain 'E' or 'e' followed by an
44  /// integer (see is_int).
45  ///
46  /// @return true if string is a number
47  ///
48  bool is_float(const std::string&);
49
50  ///
51  /// @return true if every character in string is a digit except the
52  /// first one that may be '+' or '-'
53  ///
54  bool is_int(const std::string&);
55
56  ///
57  /// Function reading from istream to vector of doubles. Function
58  /// reads the line until next '\\n'. The line is splitted with
59  /// respect to whitespaces and push_backed into the vector. The
60  /// vector is emptied before the reading starts.
61  ///
62  /// @return false if end of stream
63  ///
64  bool read_to_double(std::istream&, std::vector<double>&);
65
66  ///
67  /// Function reading from istream to vector of ints. Function
68  /// reads the line until next '\\n'. The line is splitted with
69  /// respect to whitespaces and push_backed into the vector. The
70  /// vector is emptied before the reading starts.
71  ///
72  /// @return false if end of stream
73  ///
74  bool read_to_int(std::istream&, std::vector<int>&);
75
76  ///
77  /// Function reading from istream to vector of strings. Function
78  /// reads the line until next '\\n'. The line is splitted with
79  /// respect to whitespaces and push_backed into the vector. The
80  /// vector is emptied before the reading starts.
81  ///
82  /// @return false if end of stream
83  ///
84  bool read_to_string(std::istream&, std::vector<std::string>&);
85
86
87}} // of namespace utility and namespace theplu
88
89#endif
Note: See TracBrowser for help on using the repository browser.