source: trunk/yat/utility/utility.cc @ 825

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

removed minmax functions and moved shuffle into vector.*

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.1 KB
Line 
1// $Id: utility.cc 825 2007-03-19 12:46:10Z peter $
2
3/*
4  Copyright (C) 2005 Jari Häkkinen, Markus Ringnér
5  Copyright (C) 2006 Jari Häkkinen
6  Copyright (C) 2007 Peter Johansson
7
8  This file is part of the yat library, http://lev.thep.lu.se/trac/yat
9
10  The yat library is free software; you can redistribute it and/or
11  modify it under the terms of the GNU General Public License as
12  published by the Free Software Foundation; either version 2 of the
13  License, or (at your option) any later version.
14
15  The yat library is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  General Public License for more details.
19
20  You should have received a copy of the GNU General Public License
21  along with this program; if not, write to the Free Software
22  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23  02111-1307, USA.
24*/
25
26#include "utility.h"
27
28#include "matrix.h"
29#include "stl_utility.h"
30#include "vector.h"
31#include "yat/random/random.h"
32
33#include <sstream>
34#include <string>
35
36namespace theplu {
37namespace yat {
38namespace utility {
39
40  bool is_double(const std::string& s)
41  {
42    std::stringstream ss(s);
43    double a;
44    ss>>a;
45    if(ss.fail()) 
46      return false;
47    // Check that nothing is left on stream
48    std::string b;
49    ss >> b;
50    return (b.size() ? false : true);
51  }
52 
53  bool is_float(const std::string& s)
54  {
55    std::stringstream ss(s);
56    float a;
57    ss>>a;
58    if(ss.fail()) 
59      return false;
60    // Check that nothing is left on stream
61    std::string b;
62    ss >> b;
63    return (b.size() ? false : true);
64  }
65
66  bool is_int(const std::string& s)
67  {
68    std::stringstream ss(s);
69    int a;
70    ss >> a;
71    if(ss.fail()) 
72      return false;
73    // Check that nothing is left on stream
74    std::string b;
75    ss >> b;
76    return (b.size() ? false : true);
77  }
78
79  bool is_nan(const std::string& s)
80  {
81    std::stringstream ss(s);
82    std::string s2;
83    ss >> s2; // to trim surrounding whitespaces
84    to_lower(s2);
85    // Check that nothing is left on stream
86    std::string s3;
87    ss >> s3;
88    if(s3.size())
89      return false;
90    std::string nan("nan");
91    return (nan==s2);
92  }
93
94
95
96}}} // end of namespace utility, yat and thep
Note: See TracBrowser for help on using the repository browser.