Changeset 1556 for trunk/yat/utility.h


Ignore:
Timestamp:
Jan 4, 2013, 8:33:14 AM (9 years ago)
Author:
Peter Johansson
Message:

update to latest yat

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/yat/utility.h

    r1512 r1556  
    11#ifndef _theplu_yat_utility_utility_
    2 #define _theplu_yat_utility_utility_ 
    3 
    4 // $Id: utility.h 2820 2012-08-30 00:47:58Z peter $
     2#define _theplu_yat_utility_utility_
     3
     4// $Id: utility.h 2943 2013-01-04 06:38:38Z peter $
    55
    66/*
     
    88  Copyright (C) 2006 Jari Häkkinen
    99  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
    10   Copyright (C) 2009, 2010, 2011, 2012 Peter Johansson
     10  Copyright (C) 2009, 2010, 2011, 2012, 2013 Peter Johansson
    1111
    1212  This file is part of the yat library, http://dev.thep.lu.se/yat
     
    3535#include "Exception.h"
    3636#include "yat_assert.h"
     37
     38#include <gsl/gsl_math.h>
    3739
    3840#include <algorithm>
     
    5456
    5557  /**
     58     Same as posix C function with same name but works on \c
     59     std::string rather than \c char*.
     60
     61     \see http://linux.die.net/man/3/basename
     62
     63     \return everything after last '/'
     64
     65     \since New in yat 0.10
     66   */
     67  std::string basename(const std::string& fn);
     68
     69  /**
    5670     For each element in resulting range assign it to 0.0 if
    5771     corresponding element in input range is NaN else assign it to
     
    6478  */
    6579  template<typename InputIterator, typename OutputIterator>
    66   bool binary_weight(InputIterator first, InputIterator last, 
     80  bool binary_weight(InputIterator first, InputIterator last,
    6781                     OutputIterator result);
    6882
    6983  /**
     84     Same as C function \c chdir but throws on failure (instead of
     85     retrning non-zero).
     86
     87     \throw runtime_error if underlying chdir returns non-zero
     88
     89     \see http://linux.die.net/man/3/chdir
     90
     91     \since New in yat 0.10
     92   */
     93  void chdir(const std::string& dir);
     94
     95  /**
     96     same as C function \c chmod but throws on failure (instead of
     97     returning non-zero).
     98
     99     \see http://linux.die.net/man/3/chmod
     100
     101     \since New in yat 0.10
     102   */
     103  void chmod(const std::string& filename, mode_t mode);
     104
     105  /**
    70106     \brief convert T to a string
    71107
     
    84120  template<typename T>
    85121  T convert(const std::string& s);
     122
     123  /**
     124     @brief Copy file \a source to \a target.
     125
     126     @throw runtime_error if read error of \a source or write error
     127     for \a target is encountered.
     128  */
     129  void copy_file(const std::string& source, const std::string& target);
     130
     131  /**
     132     Same as posix C function with same name but works on \c
     133     std::string rather than \c char*.
     134
     135     \see http://linux.die.net/man/3/dirname
     136
     137     \return everything prior last '/'.
     138
     139     \since New in yat 0.10
     140   */
     141  std::string dirname(const std::string& fn);
     142
     143  /**
     144     \return true if \a str matches \a pattern
     145
     146     \see http://linux.die.net/man/3/fnmatch
     147
     148     \throw runtime_error if returned value from underlying fnmatch is
     149     neither zero nor \c FNM_NOMATCH.
     150
     151     \since New in yat 0.10
     152  */
     153  bool fnmatch(const std::string& pattern, const std::string& str,
     154               int flags=0);
    86155
    87156  /**
     
    194263  template<typename T>
    195264  void load(std::istream& is, std::vector<T>& vec, char sep='\0');
    196  
     265
     266  /**
     267     \return base-2 logarithm of x
     268
     269     \since New in yat 0.10
     270   */
     271  // c++11 provides std::log2 so perhaps we should call that one if
     272  // availalable (but a bit tricky since this is a public header)
     273  template<typename T>
     274  T log2(T x) { return std::log(x)/M_LN2; }
     275
    197276// private namespace
    198277namespace detail {
     
    250329} // end of namespace detail
    251330
     331
     332  /**
     333     \brief create a directory \a dir
     334
     335     \see http://linux.die.net/man/3/mkdir
     336
     337     \throw runtime_error if creation failed
     338   */
     339  void mkdir(const std::string& dir, mode_t mode=0777);
     340
     341  /**
     342     Similar to mkdir(const std::string&, mode_t).
     343
     344     No error if \a dir already exist. Make parent directories as needed.
     345   */
     346  void mkdir_p(const std::string& dir, mode_t mode=0777);
     347
     348  /**
     349     same as C function remove but throws errno_error at failure
     350
     351     \see http://linux.die.net/man/3/remove
     352   */
     353  void remove(const std::string& fn);
     354
     355  /**
     356     same as C function with same name but throws errno_error if error
     357     is encountered
     358
     359     \see http://linux.die.net/man/3/rename
     360
     361     \since New in yat 0.10
     362   */
     363  void rename(const std::string& from, const std::string to);
     364
     365  /**
     366     In \a full_str replace every sub-string \a old_str with \a
     367     new_str;
     368   */
     369  void replace(std::string& full_str, std::string old_str, std::string new_str);
    252370
    253371  // template implementations
     
    350468      pusher(element, vec);
    351469    }
    352   }           
    353 
     470  }
    354471
    355472namespace detail {
Note: See TracChangeset for help on using the changeset viewer.