source: trunk/src/stl_utility.h @ 270

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

bug fixes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.4 KB
Line 
1// $Id: stl_utility.h 270 2005-04-13 13:37:14Z peter $
2
3#ifndef _theplu_cpptools_stl_utility_
4#define _theplu_cpptools_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 cpptools {
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    inline bool operator()(const std::pair<T1,T2>& x,
30                           const std::pair<T1,T2>& y) {
31      return ((x.second<y.second) ||
32              (!(y.second<x.second) && (x.first<y.first))); 
33    }
34  };
35
36  ///
37  /// Function return true if string is a number. A number is defined
38  /// to start with '+', '-' or a digit. It must contain at most one
39  /// decimal point '.'. Also it may contain 'E' or 'e' followed by an
40  /// integer (see is_int).
41  ///
42  /// @return true if string is a number
43  ///
44  bool is_float(const std::string&);
45
46  ///
47  /// @return true if every character in string is a digit except the
48  /// first one that may be '+' or '-'
49  ///
50  bool is_int(const std::string&);
51
52  ///
53  /// Function reading from istream to vector of doubles. Function
54  /// reads the line until next '\\n'. The line is splitted with
55  /// respect to whitespaces and push_backed into the vector. The
56  /// vector is emptied before the reading starts.
57  ///
58  /// @return false if end of stream
59  ///
60  bool read_to_double(std::istream&, std::vector<double>&);
61
62  ///
63  /// Function reading from istream to vector of ints. Function
64  /// reads the line until next '\\n'. The line is splitted with
65  /// respect to whitespaces and push_backed into the vector. The
66  /// vector is emptied before the reading starts.
67  ///
68  /// @return false if end of stream
69  ///
70  bool read_to_int(std::istream&, std::vector<int>&);
71
72  ///
73  /// Function reading from istream to vector of strings. Function
74  /// reads the line until next '\\n'. The line is splitted with
75  /// respect to whitespaces and push_backed into the vector. The
76  /// vector is emptied before the reading starts.
77  ///
78  /// @return false if end of stream
79  ///
80  bool read_to_string(std::istream&, std::vector<std::string>&);
81
82
83}} // of namespace cpptools and namespace theplu
84
85#endif
Note: See TracBrowser for help on using the repository browser.