Ignore:
Timestamp:
Jan 1, 2007, 4:58:01 PM (16 years ago)
Author:
Jari Häkkinen
Message:

Fixes #10. Removed read_to*(std::vector..) functionality.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/yat/utility/stl_utility.cc

    r715 r723  
    33/*
    44  Copyright (C) 2005 Jari Häkkinen, Peter Johansson, Markus Ringnér
    5   Copyright (C) 2006 Jari Häkkinen
     5  Copyright (C) 2006, 2007 Jari Häkkinen
    66
    77  This file is part of the yat library, http://lev.thep.lu.se/trac/yat
     
    3636namespace utility {
    3737
    38   bool read_to_double(std::istream& is, std::vector<double>& vec)
    39   {
    40     vec.resize(0);
    41     std::vector<std::string> vec_str;
    42     if (read_to_string(is,vec_str)){
    43       for (size_t i=0; i<vec_str.size(); i++) {
    44         if (is_double(vec_str[i])) {
    45           vec.push_back(atof(vec_str[i].c_str()));
    46         }
    47         else if (is_nan(vec_str[i])) {
    48           vec.push_back(std::numeric_limits<double>::quiet_NaN());
    49         }
    50         else {
    51           // Jari, this should be communicated with as an exception.
    52           //          std::cerr << "Warning: '" << vec_str[i]
    53           //                    << "' is not a number." << std::endl;
    54         }
    55       }
    56       return true;
    57     }
    58     else
    59       return false;
    60   }
    61 
    62 
    63   bool read_to_int(std::istream& is, std::vector<int>& vec)
    64   {
    65     vec.resize(0);
    66     std::vector<std::string> vec_str;
    67     if (read_to_string(is,vec_str)){
    68       for (size_t i=0; i<vec_str.size(); i++) {
    69         if (is_int(vec_str[i])) {
    70           vec.push_back(atoi(vec_str[i].c_str()));
    71         }
    72         else if (is_nan(vec_str[i])) {
    73           vec.push_back(std::numeric_limits<int>::quiet_NaN());
    74         }
    75         else {
    76           // Jari, this should be communicated with as an exception.
    77           //          std::cerr << "Warning: '" << vec_str[i]
    78           //                    << "' is not an integer." << std::endl;
    79         }
    80       }
    81       return true;
    82     }
    83     else
    84       return false;
    85   }
    86 
    87 
    88   bool read_to_string(std::istream& is, std::vector<std::string>& vec)
    89   {
    90     vec.resize(0);
    91     std::string s;
    92     if (getline(is, s, '\n')){
    93       std::istringstream line(s);
    94       std::string tmp_string;
    95       while (line >> tmp_string)
    96         vec.push_back(tmp_string);
    97       return true;
    98     }
    99     else
    100       return false;
    101   }
    102 
    103 
    10438  void to_lower(std::string& s)
    10539  {
Note: See TracChangeset for help on using the changeset viewer.