Changeset 226 for trunk/lib


Ignore:
Timestamp:
Mar 11, 2007, 8:32:41 PM (14 years ago)
Author:
Peter Johansson
Message:

added reading of config file in Parameter closes ##106 and #98. Move function check_target from svndigest.cc to utility.cc and changed name to node_exist. added support for aliases in Copyright update refs #36

Location:
trunk/lib
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Directory.cc

    r225 r226  
    3737#include <iterator>
    3838#include <list>
     39#include <map>
    3940
    4041#include <cerrno> // Needed to check error state below.
     
    223224
    224225
    225   void Directory::print_copyright(const std::vector<std::string>& dates,
    226                                   const std::vector<std::string>& authors) const
     226  void Directory::print_copyright
     227  (const std::vector<std::string>& dates,
     228   const std::vector<std::string>& authors,
     229   const std::map<std::string, std::string>& alias) const
    227230  {
    228231    if (!ignore()){
    229232      // print daughter nodes, i.e, this function is recursive
    230233      for (NodeConstIterator i = daughters_.begin(); i!=daughters_.end(); ++i)
    231         (*i)->print_copyright(dates, authors);
     234        (*i)->print_copyright(dates, authors, alias);
    232235    }
    233236  }
  • trunk/lib/Directory.h

    r225 r226  
    2828
    2929#include <list>
     30#include <map>
    3031#include <string>
    3132
     
    8081
    8182    void print_copyright(const std::vector<std::string>& dates,
    82                          const std::vector<std::string>& author) const;
     83                         const std::vector<std::string>& author,
     84                         const std::map<std::string, std::string>&) const;
     85
    8386  private:
    8487    ///
  • trunk/lib/File.cc

    r225 r226  
    3232#include <fstream>
    3333#include <iostream>
     34#include <map>
    3435#include <string>
    3536
     
    153154
    154155
    155   void File::print_copyright(const std::vector<std::string>& dates,
    156                              const std::vector<std::string>& authors) const
     156  void File::print_copyright
     157  (const std::vector<std::string>& dates,
     158   const std::vector<std::string>& authors,
     159   const std::map<std::string, std::string>& alias) const
    157160  {
    158161    if (ignore())
     
    160163    assert(dates.size()==authors.size());
    161164    using namespace std;
     165    cout << "Copyright: " << local_path() << std::endl;
    162166    SVN* svn=SVN::instance();
    163167    vector<size_t> rev=svn->revisions(path());
     
    169173      time_t sec = str2time(dates[*i]);
    170174      tm* timeinfo = gmtime(&sec);
    171       copyright[timeinfo->tm_year].insert(authors[*i]);
     175
     176      // find username in map of aliases
     177      map<string, string>::const_iterator name = alias.find(authors[*i]);
     178      // if alias exist insert alias
     179      if (name != alias.begin() )
     180        copyright[timeinfo->tm_year].insert(name->second);
     181      else
     182        // else insert user name
     183        copyright[timeinfo->tm_year].insert(authors[*i]);
    172184    }
    173185   
  • trunk/lib/File.h

    r225 r226  
    2828#include "Node.h"
    2929
     30#include <map>
    3031#include <string>
    3132
     
    7071    void print_blame(std::ofstream&, const std::string line_type) const;
    7172
    72     void print_copyright(const std::vector<std::string>&,
    73                          const std::vector<std::string>&) const;
     73    void print_copyright(const std::vector<std::string>& dates,
     74                         const std::vector<std::string>& author,
     75                         const std::map<std::string, std::string>&) const;
     76
    7477  private:
    7578
  • trunk/lib/Node.h

    r225 r226  
    3131#include "utility.h"
    3232
     33#include <map>
    3334#include <ostream>
    3435#include <stdexcept>
     
    141142    virtual void print(const bool verbose=false) const=0;
    142143
    143     virtual void print_copyright(const std::vector<std::string>& dates,
    144                                  const std::vector<std::string>& author) const=0;
     144    virtual void
     145    print_copyright(const std::vector<std::string>& dates,
     146                    const std::vector<std::string>& author,
     147                    const std::map<std::string, std::string>&) const=0;
    145148
    146149    /**
  • trunk/lib/utility.cc

    r204 r226  
    33/*
    44  Copyright (C) 2006 Jari Häkkinen, Peter Johansson
     5  Copyright (C) 2007 Peter Johansson
    56
    67  This file is part of svndigest, http://lev.thep.lu.se/trac/svndigest
     
    7879
    7980
     81  std::string htrim(std::string str)
     82  {
     83    size_t length=str.size();
     84    while(length && isspace(str[length-1]))
     85      --length;
     86    return str.substr(0,length);
     87  }
     88
     89
     90  std::string ltrim(std::string str)
     91  {
     92    size_t i = 0;
     93    while(i<str.size() && isspace(str[i]))
     94      ++i;
     95    return str.substr(i);
     96  }
     97
     98
     99  bool node_exist(const std::string& path)
     100  {
     101    struct stat buf;
     102    return !stat(path.c_str(),&buf);
     103  }
     104
     105
    80106  std::string pwd(void)
    81107  {
  • trunk/lib/utility.h

    r217 r226  
    6363  std::string getenv(const std::string& var);
    6464
     65  ///
     66  /// @brief remove trailing whitespaces
     67  ///
     68  std::string htrim(std::string str);
     69
     70  ///
     71  /// @brief remove leading whitespaces
     72  ///
     73  std::string ltrim(std::string str);
     74
    6575  inline bool match_begin(std::string::const_iterator first,
    6676                          std::string::const_iterator last,
     
    8494
    8595  ///
     96  /// @brief Check whether \a path already exists or not.
     97  ///
     98  /// @return True if \a path exists, false otherwise.
     99  ///
     100  bool node_exist(const std::string& path);
     101
     102  ///
    86103  /// @return the current working directory.
    87104  ///
     
    97114  ///
    98115  time_t str2time(const std::string&);
     116
     117  ///
     118  /// remove leading and trailing whitespaces
     119  ///
     120  inline std::string trim(std::string str) { return htrim(ltrim(str)); }
    99121
    100122  ///
Note: See TracChangeset for help on using the changeset viewer.