Ignore:
Timestamp:
Nov 12, 2010, 5:01:35 AM (11 years ago)
Author:
Peter Johansson
Message:

closes #457. Lifting out plotting functions in Stats into a new class
StatsPlotter?. In same manner lifting out print functions from
Node/Directory/File? into a new hierarchy
NodePrinter/DirectoryPrinter/FilePrinter?. To accomplish these splits
without to much recoding some friendships are introduced. These new
classes are only needed for svndigest (not svncopyright) and are
therefore placed in a library named libsvndigest together with Graph
class and first_page functions. Remaining functionality, shared
between svncopyright and svndigest, are located in libsvndigest_core
and linked into both binaries.

File:
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/lib/NodePrinter.cc

    r1289 r1290  
    2121*/
    2222
    23 #include "Node.h"
     23#include "NodePrinter.h"
    2424
    2525#include "Configuration.h"
     
    2828#include "html_utility.h"
    2929#include "LineTypeParser.h"
     30#include "Node.h"
    3031#include "SVNlog.h"
    3132#include "SVNproperty.h"
     
    4546namespace svndigest{
    4647
    47   std::string Node::project_=std::string();
    48 
    49   Node::Node(const unsigned int level, const std::string& path,
    50              const std::string& local_path, const std::string& project)
    51     : level_(level), path_(path), stats_(path), log_(NULL), 
    52       svninfo_(path)
    53   {
    54     SVNproperty property(path);
    55     binary_=property.binary();
    56     svndigest_ignore_=property.svndigest_ignore();
    57     svncopyright_ignore_=property.svncopyright_ignore();
    58     if (Node::project_==std::string()) // no root directory in local path
    59       Node::project_ = project;
    60     else if (local_path.empty())
    61       local_path_ = file_name(path);
    62     else
    63       local_path_ = local_path + "/" + file_name(path);
    64 
    65     struct stat nodestat;                // C api from sys/stat.h
    66     lstat(path,&nodestat);   // C api from sys/stat.h
    67     link_ = S_ISLNK(nodestat.st_mode);
    68   }
    69 
    70 
    71   Node::~Node(void)
    72   {
    73     if (log_)
    74       delete log_;
    75   }
    76 
    77 
    78   std::string Node::author(void) const
    79   {
    80     if (ignore())
    81       return svninfo_.last_changed_author();
    82     assert(log().commits().size());
    83     return log().latest_commit().author();
    84   }
    85 
    86 
    87   bool Node::dir(void) const
    88   {
    89     return false;
    90   }
    91 
    92 
    93   void Node::html_tablerow(std::ostream& os,
    94                            const std::string& stats_type,
    95                            const std::string& css_class,
    96                            const std::string& user) const
    97   {
    98     os << "<tr class=\"" << css_class << "\">\n"
    99        << "<td class=\"" << node_type() << "\">";
    100     if (svndigest_ignore())
    101       os << name() << " (<i>svndigest:ignore</i>)";
    102     else if (binary())
    103       os << name() << " (<i>binary</i>)";
    104     else if (link_)
    105       os << name() << " (<i>link</i>)";
    106     // there is no output for nodes when user has zero contribution
    107     else if (user!="all" && !tiny_stats_(stats_type,user,LineTypeParser::total))
    108       os << name();
    109     else if (!Configuration::instance().output_file() && !this->dir())
    110       os << name();
    111     else
    112       os << anchor(href(), name());
    113     os << "</td>\n";
    114 
    115     html_tabletd(os, stats_type, user, LineTypeParser::total);
    116     html_tabletd(os, stats_type, user, LineTypeParser::code);
    117     html_tabletd(os, stats_type, user, LineTypeParser::comment);
    118     html_tabletd(os, stats_type, user, LineTypeParser::other);
    119    
    120     os << "<td>" << trac_revision(last_changed_rev()) << "</td>\n"
    121        << "<td>" << author() << "</td>\n"
    122        << "</tr>\n";
    123   }
    124 
    125 
    126   void Node::html_tabletd(std::ostream& os, const std::string& stats_type,
    127                           const std::string& user,
    128                           LineTypeParser::line_type lt) const
    129   {
    130     os << "<td>" << tiny_stats_(stats_type, user, lt);
    131     if (user!="all" && tiny_stats_(stats_type, user, lt))
    132       os << " (" << percent(tiny_stats_(stats_type, user, lt),
    133                             tiny_stats_(stats_type, "all", lt)) << "%)";
    134     os << "</td>\n";
    135   }
    136  
    137 
    138   void Node::init_tiny_stats(void)
    139   {
    140     tiny_stats_.init(stats_);
    141   }
    142 
    143 
    144   const SVNlog& Node::log(void) const
    145   {
    146     if (!log_) {
    147       if (ignore())
    148         log_ = new SVNlog;
    149       else {
    150         log_ = new SVNlog(path());
    151         log_core(*log_);
    152       }
    153     }
    154     return *log_;
    155   }
    156 
    157 
    158   std::string Node::name(void) const
    159   {
    160     std::string res = file_name(path_);
    161     return res;
    162   }
    163 
    164 
    165   std::string Node::output_dir(void) const
    166   {
    167     return output_dir_;
    168   }
    169 
    170 
    171   void Node::path_anchor(std::ostream& os) const
     48  NodePrinter::NodePrinter(void)
     49  {
     50  }
     51
     52  NodePrinter::~NodePrinter(void)
     53  {
     54  }
     55
     56
     57  std::string NodePrinter::output_dir(void) const
     58  {
     59    return node().output_dir_;
     60  }
     61
     62
     63  void NodePrinter::path_anchor(std::ostream& os) const
    17264  {
    17365    os << "<h2 class=\"path\">\n";
    17466    std::vector<std::string> words;
    175     words.reserve(level_+1);
     67    words.reserve(node().level_+1);
    17668    std::string word;
    17769    words.push_back(Node::project_);
    178     std::stringstream ss(local_path());
     70    std::stringstream ss(node().local_path());
    17971    while(getline(ss,word,'/'))
    18072      if (!word.empty()) // ignore double slash in path
     
    18476    else {
    18577      for (size_t i=0; i<words.size()-1; ++i){
    186         os << anchor("index.html", words[i], level_-i, "View " + words[i]);
     78        os << anchor("index.html", words[i], node().level_-i, "View " + words[i]);
    18779        os << "<span class=\"sep\">/</span>";
    18880      }
    189       os << anchor(href(), words.back(), level_+2-words.size(),
     81      os << anchor(node().href(), words.back(), node().level_+2-words.size(),
    19082             "View " + words.back());
    19183    }
     
    19486
    19587
    196   void Node::print(const bool verbose) const
    197   {
    198     if (ignore())
     88  void NodePrinter::print(const bool verbose) const
     89  {
     90    if (node().ignore())
    19991      return;
    200     if (!Configuration::instance().output_file() && !this->dir())
     92    if (!Configuration::instance().output_file() && !node().dir())
    20193      return;
    20294    if (verbose)
    203       std::cout << "Printing output for '" << path_ << "'" << std::endl;
    204     const SVNlog& log = this->log();
     95      std::cout << "Printing output for '" << node().path_ << "'" << std::endl;
     96    const SVNlog& log = node().log();
    20597    typedef std::map<std::string, Stats*>::const_iterator iter;
    20698
    207     const iter end(stats_.stats().end());
    208     for (iter i=stats_.stats().begin();i!=end; ++i){
     99    const iter end(node().stats_.stats().end());
     100    for (iter i=node().stats_.stats().begin();i!=end; ++i){
    209101      print_core(i->first, "all", "total", log);
    210102      print_core(i->first, "all", "code", log);
     
    223115
    224116
    225   void Node::print_author_summary(std::ostream& os,
     117  void NodePrinter::print_author_summary(std::ostream& os,
    226118                                  const Stats& stats,
    227119                                  const std::string& line_type,
     
    244136
    245137    std::string color("light");
    246     if (!dir()) {
     138    if (!node().dir()) {
    247139      os << "<tr class=\"" << color << "\">\n";
    248140      os << "<td class=\"directory\" colspan=\"7\">";
     
    261153      os << "<tr class=\"" << color << "\"><td>";
    262154      os << anchor(*i+"/"+line_type+"/"+output_path()
    263                    ,*i, level_+2, "View statistics for "+*i);
     155                   ,*i, node().level_+2, "View statistics for "+*i);
    264156      os << "</td><td>" << stats.lines(*i)
    265157         << "</td><td>" << stats.code(*i)
     
    281173    os << "<tr class=\"" << color << "\">\n";
    282174    os << "<td>";
    283     if (dir())
    284       if (local_path().empty())
     175    if (node().dir())
     176      if (node().local_path().empty())
    285177        os << anchor("all/"+line_type+"/index.html"
    286                      ,"Total", level_+2, "View statistics for all");
     178                     ,"Total", node().level_+2, "View statistics for all");
    287179      else
    288         os << anchor("all/"+line_type+"/"+local_path()+"/index.html"
    289                      ,"Total", level_+2, "View statistics for all");
     180        os << anchor("all/"+line_type+"/"+node().local_path()+"/index.html"
     181                     ,"Total", node().level_+2, "View statistics for all");
    290182    else
    291       os << anchor("all/"+line_type+"/"+local_path()+".html"
    292                    ,"Total", level_+2, "View statistics for all");
     183      os << anchor("all/"+line_type+"/"+node().local_path()+".html"
     184                   ,"Total", node().level_+2, "View statistics for all");
    293185    os << "</td>\n";
    294186    os << "<td>" << stats.lines() << "</td>\n";
     
    307199
    308200 
    309   const StatsCollection& Node::stats(void) const
    310   {
    311     return stats_;
    312   }
    313 
    314 
    315   StatsCollection& Node::stats(void)
    316   {
    317     return stats_;
    318   }
    319 
    320 
    321   bool Node::svncopyright_ignore(void) const
    322   {
    323     return svncopyright_ignore_;
    324   }
    325 
    326 
    327   std::string Node::url(void) const
    328   {
    329     return svninfo_.url();
    330   }
    331 
    332201}} // end of namespace svndigest and namespace theplu
Note: See TracChangeset for help on using the changeset viewer.