Changeset 465 for trunk/lib/Functor.h


Ignore:
Timestamp:
Aug 24, 2007, 3:28:24 PM (14 years ago)
Author:
Peter Johansson
Message:

fixes #217. Moving functors to a Functor.h and Functor.cc

File:
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/lib/Functor.h

    r463 r465  
    1 #ifndef _theplu_svndigest_utility_
    2 #define _theplu_svndigest_utility_
     1#ifndef _theplu_svndigest_functor_
     2#define _theplu_svndigest_functor_
    33
    44// $Id$
     
    2525*/
    2626
    27 #include <algorithm>
     27//#include <algorithm>
    2828#include <functional>
    29 #include <iosfwd>
     29//#include <iosfwd>
    3030#include <string>
    3131#include <utility>
     
    3636namespace theplu{
    3737namespace svndigest{
    38 
    39   ///
    40   /// @brief Check if access permissions match \a mode. \a mode must
    41   /// be given as r, w, x, or combinations of these letters.
    42   ///
    43   /// @return On success (all requested permissions granted), zero
    44   /// is returned. On error (at least one bit in mode asked for a
    45   /// permission that is denied, or some other error occurred), -1
    46   /// is returned, and errno is set appropriately.
    47   ///
    48   /// @throw An std::runtime_error is thrown when checking for write
    49   /// permissions for a file/direcotry that does not exist.
    50   ///
    51   /// @see access(2)
    52   ///
    53   int access_rights(const std::string& path,const std::string& bits);
    54 
    55   /**
    56      @brief Copy file \a source to \a target.
    57 
    58      @throw std::runtime_error when read error of \a source or write
    59      error for \a target is encountered.
    60   */
    61   void copy_file(const std::string& source, const std::string& target);
    62 
    63   ///
    64   /// @return everything after last '/'
    65   ///
    66   std::string file_name(const std::string&);
    67 
    68   ///
    69   /// @brief environment variable @a var
    70   ///
    71   std::string getenv(const std::string& var);
    72 
    73   ///
    74   /// If @a width is set, size is forced to length @a width. This
    75   /// implies, e.g., that hex(15,2) and hex(17,1) return "0F" and "1",
    76   /// respectively.
    77   ///
    78   /// @return x in hexadecimal base
    79   ///
    80   std::string hex(int x, u_int width=0);
    81 
    82   ///
    83   /// @brief remove trailing whitespaces
    84   ///
    85   std::string htrim(std::string str);
    86 
    87   ///
    88   /// @return true if \a str is an integer
    89   ///
    90   bool is_int(std::string str);
    91 
    92   ///
    93   /// @brief remove leading whitespaces
    94   ///
    95   std::string ltrim(std::string str);
    96 
    97   inline bool match_begin(std::string::const_iterator first,
    98                           std::string::const_iterator last,
    99                           const std::string& str)
    100   { return (std::distance(first, last)>=static_cast<int>(str.size()) &&
    101             std::equal(str.begin(), str.end(), first));
    102   }
    103 
    104   inline bool match_end(std::string::const_reverse_iterator first,
    105                         std::string::const_reverse_iterator last,
    106                         const std::string& str)
    107   { return (std::distance(first,last)>=static_cast<int>(str.size()) &&
    108             std::equal(str.rbegin(), str.rend(), first));
    109   }
    110 
    111   ///
    112   /// Create directory \a dir. The call can fail in many ways, cf. 'man
    113   /// mkdir'.
    114   ///
    115   inline int mkdir(const std::string& dir) { return ::mkdir(dir.c_str(),0777); }
    116 
    117   ///
    118   /// @brief Check whether \a path already exists or not.
    119   ///
    120   /// @return True if \a path exists, false otherwise.
    121   ///
    122   bool node_exist(const std::string& path);
    123 
    124   /**
    125      @return 0 if \a b = 0 otherwise \f$ \frac{100*a}{b} \f$
    126   */
    127   int percent(int a, int b);
    128 
    129   ///
    130   /// @return the current working directory.
    131   ///
    132   std::string pwd(void);
    133 
    134   ///
    135   /// Search finds a subsecuence in [first, last) being identical to @ str
    136   ///
    137   /// @return iterator pointing to first character in found subsequence
    138   ///
    139   /// @see std::search
    140   ///
    141   inline std::string::iterator search(std::string::iterator first,
    142                                       std::string::iterator last,
    143                                       std::string str)
    144   { return std::search(first, last, str.begin(), str.end()); }
    145 
    146   ///
    147   ///
    148   ///
    149   time_t str2time(const std::string&);
    150 
    151   ///
    152   /// If file does not exist create empty file.
    153   ///
    154   void touch(std::string);
    155 
    156   ///
    157   /// remove leading and trailing whitespaces
    158   ///
    159   inline std::string trim(std::string str) { return htrim(ltrim(str)); }
    160 
    161 
    162   template <typename T>
    163   std::string match(std::string::const_iterator& first,
    164                     const std::string::const_iterator& last,
    165                     const T& func)
    166   {
    167     std::string res;
    168     for (;first!=last && func(first); ++first)
    169       res.append(1,*first);
    170     return res;
    171   }
    172 
    173 
    174   std::string match(std::string::const_iterator& first,
    175                     const std::string::const_iterator& last,
    176                     std::string);
    17738
    17839  struct AlNum
Note: See TracChangeset for help on using the changeset viewer.