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

Last change on this file since 865 was 865, checked in by Peter, 14 years ago

changing URL to http://trac.thep.lu.se/trac/yat

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