Changeset 327


Ignore:
Timestamp:
May 31, 2005, 1:00:20 AM (16 years ago)
Author:
Jari Häkkinen
Message:

Moved non-STL specific functionality outside of stl_utility.h

Location:
trunk/lib/utility
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/utility/Makefile.am

    r319 r327  
    1010libutility_la_SOURCES = \
    1111  Alignment.cc FileIO.cc kNNI.cc Merge.cc NNI.cc PCA.cc\
    12   random_singleton.cc stl_utility.cc SVD.cc WeNNI.cc
     12  random_singleton.cc stl_utility.cc SVD.cc utility.cc WeNNI.cc
    1313
    1414include_utilitydir = $(includedir)/c++_tools/utility
     
    1616include_utility_HEADERS = \
    1717  Alignment.h FileIO.h kNNI.h Merge.h NNI.h PCA.h random_singleton.h \
    18   stl_utility.h SVD.h WeNNI.h
     18  stl_utility.h SVD.h utility.h WeNNI.h
    1919
  • trunk/lib/utility/stl_utility.cc

    r301 r327  
    22
    33#include <c++_tools/utility/stl_utility.h>
     4#include <c++_tools/utility/utility.h>
    45
    56#include <iostream>
     
    1112namespace utility {
    1213
    13   bool is_float(const std::string& s)
    14   {
    15     // have decimal point
    16     bool dp = false; 
    17     size_t i = 0;
    18     if (s[i] == '-' || s[i] == '+') {
    19       i++;
    20       // empty after sign
    21       if (i >= s.size())
    22         return false;                         
    23     }
    24     bool isf = false;
    25     while(i<s.size()){
    26       if (s[i] < '0' || s[i] > '9'){
    27           if (s[i] == '.') {
    28             // two decimals
    29             if (dp)
    30               return false;               
    31             else
    32               dp = true;
    33           }
    34           else if (s[i] == 'E' || s[i] == 'e'){
    35             i++;
    36             // nothing following E
    37             if (i >=s.size())
    38               return false;           
    39             std::string tmp_str(s,i) ;
    40             return is_int(tmp_str);
    41           }
    42       }
    43       else
    44         isf = true;                       
    45       i++;
    46     }
    47     return isf;
    48   }
    4914 
    50   bool is_int(const std::string& s)
    51   {
    52     size_t i = 0;
    53     if (s[i] == '-' || s[i] == '+') {             
    54       i++;
    55       // nothing following sign
    56       if (i >= s.size())
    57         return false;
    58     }
    59     while (i<s.size()) {
    60       if (s[i] < '0' ||  s[i] > '9')
    61         return false;
    62       i++;
    63     }
    64     return true;
    65   }
    66 
    6715  bool read_to_double(std::istream& is, std::vector<double>& vec)
    6816  {
     
    8230      return false;
    8331  }
     32
     33
    8434
    8535  bool read_to_int(std::istream& is, std::vector<int>& vec)
     
    10151  }
    10252
     53
     54
    10355  bool read_to_string(std::istream& is, std::vector<std::string>& vec)
    10456  {
  • trunk/lib/utility/stl_utility.h

    r303 r327  
    3939
    4040  ///
    41   /// Function return true if string is a number. A number is defined
    42   /// to start with '+', '-' or a digit. It must contain at most one
    43   /// decimal point '.'. Also it may contain 'E' or 'e' followed by an
    44   /// integer (see is_int).
    45   ///
    46   /// @return true if string is a number
    47   ///
    48   bool is_float(const std::string&);
    49 
    50   ///
    51   /// @return true if every character in string is a digit except the
    52   /// first one that may be '+' or '-'
    53   ///
    54   bool is_int(const std::string&);
    55 
    56   ///
    5741  /// Function reading from istream to vector of doubles. Function
    5842  /// reads the line until next '\\n'. The line is splitted with
Note: See TracChangeset for help on using the changeset viewer.