Changeset 23 for trunk/lib/utility.h


Ignore:
Timestamp:
Jan 2, 2006, 9:14:57 AM (17 years ago)
Author:
Peter Johansson
Message:

added print functionality

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/utility.h

    r14 r23  
    66#include <algorithm>
    77#include <functional>
     8#include <string>
    89#include <utility>
    910#include <vector>
     
    1213namespace svnstat{
    1314
    14   ///
    15   /// Calculating sum of two vectors.
    16   ///
    17   /// @return resulting vector
    18   ///
    19   template <class T >
    20     struct VectorPlus :
    21   public std::binary_function<std::vector<T>,std::vector<T>,std::vector<T> >
    22     {
    23       std::vector<T> operator()(const std::vector<T>& u,
    24         const std::vector<T>& v) const
    25       {
    26   if ( u.size() > v.size() ){
    27     std::vector<T> res(u.size());
    28     transform(u.begin(), u.end(), v.begin(), res.begin(), std::plus<T>());
    29     copy(u.begin()+v.size(), u.end(), res.begin()+v.size());
    30     return res;
    31   }
     15  ///
     16  /// Calculating sum of two vectors.
     17  ///
     18  /// @return resulting vector
     19  ///
     20  template <class T >
     21  struct VectorPlus :
     22    public std::binary_function<std::vector<T>,std::vector<T>,std::vector<T> >
     23  {
     24    std::vector<T> operator()(const std::vector<T>& u,
     25                              const std::vector<T>& v) const
     26    {
     27      if ( u.size() > v.size() ){
     28        std::vector<T> res(u.size());
     29        transform(u.begin(), u.end(), v.begin(), res.begin(), std::plus<T>());
     30        copy(u.begin()+v.size(), u.end(), res.begin()+v.size());
     31        return res;
     32      }
    3233 
    33   std::vector<T> res(v.size());
    34   transform(v.begin(), v.end(), u.begin(), res.begin(), std::plus<T>());
    35   if ( v.size() > u.size() )
    36     copy(u.begin()+v.size(), u.end(), res.begin()+v.size());
    37   return res;
    38       }
     34      std::vector<T> res(v.size());
     35      transform(v.begin(), v.end(), u.begin(), res.begin(), std::plus<T>());
     36      if ( v.size() > u.size() )
     37        copy(v.begin()+u.size(), v.end(), res.begin()+u.size());
     38      return res;
     39    }
    3940
    40     };
     41  };
    4142
    4243  ///
     
    4445  ///
    4546  template <class Key, class T>
    46     struct PairValuePlus :
    47   public std::binary_function<std::vector<T>,
    48     std::pair<const Key, std::vector<T> >,
    49     std::vector<T> >
    50     {
    51       std::vector<T> operator()(const std::vector<T>& sum,
    52         const std::pair<const Key,std::vector<T> >& p)
    53       {
    54   return VectorPlus<T>()(sum, p.second);
    55       }
    56     };
     47  struct PairValuePlus :
     48    public std::binary_function<std::vector<T>,
     49                                std::pair<const Key, std::vector<T> >,
     50                                std::vector<T> >
     51  {
     52    std::vector<T> operator()(const std::vector<T>& sum,
     53                              const std::pair<const Key,std::vector<T> >& p)
     54    {
     55      return VectorPlus<T>()(sum, p.second);
     56    }
     57  };
     58
     59  ///
     60  struct CodingMore :
     61    public std::binary_function<std::pair<std::string,std::vector<u_int> >,
     62                                std::pair<std::string,std::vector<u_int> >,
     63                                bool >
     64  {
     65    inline bool operator()
     66      (const std::pair<std::string,std::vector<u_int> >& a,
     67       const std::pair<std::string,std::vector<u_int> >& b)
     68    {
     69      if (a.second.back() > b.second.back())
     70        return true;
     71      else if (a.second.back() < b.second.back())
     72        return false;
     73      return a.first < b.first;
     74    }
     75  };
     76
    5777}}
    5878
    59 #endif // end of namespace svnstat end of namespace theplu
     79// end of namespace svnstat end of namespace theplu
     80#endif
Note: See TracChangeset for help on using the changeset viewer.