source: trunk/src/stl_utility.h @ 263

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

modified interface to avoid bug in doxygen

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.2 KB
Line 
1// $Id: stl_utility.h 263 2005-04-11 10:51:50Z 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(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(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.
56  ///
57  /// @return false if end of stream
58  ///
59  bool read_to_double(std::istream&, std::vector<double>&);
60
61  ///
62  /// Function reading from istream to vector of ints. Function
63  /// reads the line until next '\n'. The line is splitted with
64  /// respect to whitespaces and push_backed into the vector.
65  ///
66  /// @return false if end of stream
67  ///
68  bool read_to_int(std::istream&, std::vector<int>&);
69
70  ///
71  /// Function reading from istream to vector of strings. Function
72  /// reads the line until next '\n'. The line is splitted with
73  /// respect to whitespaces and push_backed into the vector.
74  ///
75  /// @return false if end of stream
76  ///
77  bool read_to_string(std::istream&, std::vector<std::string>&);
78
79
80}} // of namespace cpptools and namespace theplu
81
82#endif
Note: See TracBrowser for help on using the repository browser.