Changeset 820 for trunk


Ignore:
Timestamp:
Sep 12, 2009, 4:53:45 PM (12 years ago)
Author:
Peter Johansson
Message:

do not create Option objects dynamically in Parameter class

Location:
trunk/bin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/bin/Parameter.cc

    r795 r820  
    4848
    4949  Parameter::Parameter( int argc, char *argv[])
    50     : cmd_(
    51      "Mandatory arguments to long options are mandatory for short options too.")
     50    : cmd_( std::string("Mandatory arguments to long options ") +
     51            std::string("are mandatory for short options too.")),
     52      config_file_(cmd_, "config-file",
     53                   "configuration file [<ROOT>/.svndigest/config]"),
     54      copyright_(cmd_, "copyright", "update copyright statement"),
     55      force_(cmd_, "f,force",
     56             std::string("if sub-directory named <ROOT> exists in target dire")+
     57             std::string("ctory, remove sub-directory before writing results")),
     58      generate_config_(cmd_, "g,generate-config",
     59                       "write configuration to standard output"),
     60      help_(cmd_),
     61      ignore_cache_(cmd_, "ignore-cache",
     62                    std::string("ignore cache files and analyze ") +
     63                    std::string("everything from repository")),
     64      report_(cmd_, "report", "create no HTML report", true),
     65      revisions_(cmd_, "revisions",
     66                 "use revision number as time scale instead of dates [dates]"),
     67      root_(cmd_, "r,root",
     68            "svn controlled directory to perform statistics on [.]"),
     69      target_(cmd_, "t,target", "output directory [.]"),
     70      verbose_(cmd_, "v,verbose", "explain what is being done"),
     71      version_(cmd_, "version", "print version information and exit", &verbose_)
    5272  {
    5373    init();
     
    6181
    6282    // set default values
    63     if (!root_->present())
    64       root_->value(".");
    65 
    66     if (!target_->present())
    67       target_->value(".");
    68 
    69     if (!config_file_->present())
    70       config_file_->value(concatenate_path(root_->value(),".svndigest/config"));
     83    if (!root_.present())
     84      root_.value(".");
     85
     86    if (!target_.present())
     87      target_.value(".");
     88
     89    if (!config_file_.present())
     90      config_file_.value(concatenate_path(root_.value(),".svndigest/config"));
    7191
    7292    // analyse arguments
     
    7797  Parameter::~Parameter(void)
    7898  {
    79     delete config_file_;
    80     delete copyright_;
    81     delete force_;
    82     delete generate_config_;
    83     delete help_;
    84     delete ignore_cache_;
    85     delete report_;
    86     delete revisions_;
    87     delete root_;
    88     delete target_;
    89     delete verbose_;
    90     delete version_;
    9199  }
    92100
     
    98106    // check root but not if -g option given
    99107    if (!generate_config()) {
    100       check_existence(root_->value());
    101       check_readable(root_->value());
    102       if (chdir(root_->value().c_str())) {
     108      check_existence(root_.value());
     109      check_readable(root_.value());
     110      if (chdir(root_.value().c_str())) {
    103111        std::stringstream ss;
    104         ss << "svndigest: cannot read `" << root_->value() << "': "
     112        ss << "svndigest: cannot read `" << root_.value() << "': "
    105113           << strerror(errno);
    106114        throw yat::utility::cmd_error(ss.str());
    107115      }
    108       root_->value(pwd());
     116      root_.value(pwd());
    109117      chdir(save_wd.c_str());
    110118
    111119      // check target (only if we write report)
    112120      if (report()) {
    113         check_existence(target_->value());
    114         check_readable(target_->value());
    115         std::string base_root = file_name(root_->value());
    116         std::string path = concatenate_path(target_->value(),base_root);
    117         if (access_rights(target_->value().c_str(), "w")) {
     121        check_existence(target_.value());
     122        check_readable(target_.value());
     123        std::string base_root = file_name(root_.value());
     124        std::string path = concatenate_path(target_.value(),base_root);
     125        if (access_rights(target_.value().c_str(), "w")) {
    118126          std::stringstream ss;
    119127          ss << "svndigest: cannot create directory `" << path
     
    127135          throw yat::utility::cmd_error(ss.str());
    128136        }
    129         if (chdir(target_->value().c_str())) {
     137        if (chdir(target_.value().c_str())) {
    130138          std::stringstream ss;
    131           ss << "svndigest: cannot read `" << target_->value() << "': "
     139          ss << "svndigest: cannot read `" << target_.value() << "': "
    132140             << strerror(errno);
    133141          throw yat::utility::cmd_error(ss.str());
    134142        }
    135         target_->value(pwd());
     143        target_.value(pwd());
    136144        chdir(save_wd.c_str());
    137145      }
     
    141149    struct stat nodestat;
    142150    // true also if there is a broken symlink named...
    143     bool config_exists = !lstat(config_file_->value().c_str(), &nodestat);
     151    bool config_exists = !lstat(config_file_.value().c_str(), &nodestat);
    144152    // the latter case in order to catch broken symlink
    145     if (config_file_->present() || config_exists)
     153    if (config_file_.present() || config_exists)
    146154      // throws if file does not exists
    147       check_existence(config_file_->value());
     155      check_existence(config_file_.value());
    148156    if (config_exists) {
    149157      // throws if file is not readable
    150       check_readable(config_file_->value());
    151       stat(config_file_->value().c_str(), &nodestat);
     158      check_readable(config_file_.value());
     159      stat(config_file_.value().c_str(), &nodestat);
    152160      if (!S_ISREG(nodestat.st_mode)) {
    153161        std::stringstream ss;
    154         ss << "svndigest: `" << config_file_->value()
     162        ss << "svndigest: `" << config_file_.value()
    155163           << "' is not a regular file";
    156164        throw yat::utility::cmd_error(ss.str());
     
    182190  std::string Parameter::config_file(void) const
    183191  {
    184     return config_file_->value();
     192    return config_file_.value();
    185193  }
    186194
     
    188196  bool Parameter::copyright(void) const
    189197  {
    190     return copyright_->present();
     198    return copyright_.present();
    191199  }
    192200
     
    194202  bool Parameter::force(void) const
    195203  {
    196     return force_->present();
     204    return force_.present();
    197205  }
    198206
     
    200208  bool Parameter::generate_config(void) const
    201209  {
    202     return generate_config_->present();
     210    return generate_config_.present();
    203211  }
    204212
     
    206214  bool Parameter::ignore_cache(void) const
    207215  {
    208     return ignore_cache_->present();
     216    return ignore_cache_.present();
    209217  }
    210218
     
    214222    // don't use argv[0] because user may rename the binary
    215223    cmd_.program_name() = PACKAGE_NAME;
    216     config_file_=new yat::utility::OptionArg<std::string>(cmd_, "config-file",
    217                                 "configuration file [<ROOT>/.svndigest/config]");
    218     config_file_->print_arg("=FILE");
     224    config_file_.print_arg("=FILE");
     225    root_.print_arg("=ROOT");
     226    target_.print_arg("=TARGET");
    219227    std::stringstream ss;
    220     copyright_ = new yat::utility::OptionSwitch(cmd_, "copyright",
    221                                   "update copyright statement");
    222 
    223     ss << "if sub-directory named <ROOT> exists in target directory, remove "
    224        << "sub-directory before writing results";
    225     force_ = new yat::utility::OptionSwitch(cmd_, "f,force", ss.str());
    226     ss.str("");
    227 
    228     help_ = new yat::utility::OptionHelp(cmd_);
    229     generate_config_ =
    230       new yat::utility::OptionSwitch(cmd_, "g,generate-config",
    231                        "write configuration file to standard output");
    232 
    233     ss.str("");
    234     ss << "ignore cache files and analyze everything from repository";
    235     ignore_cache_ = new yat::utility::OptionSwitch(cmd_, "ignore-cache", ss.str());
    236          
    237     report_ = new yat::utility::OptionSwitch(cmd_, "report", "create no HTML report", true);
    238 
    239     ss.str("");
    240     ss << "use revision numbers as time scale instead of dates [dates]";
    241     revisions_ = new yat::utility::OptionSwitch(cmd_, "revisions", ss.str());
    242 
    243     root_=
    244       new yat::utility::OptionArg<std::string>(cmd_, "r,root",
    245                      "svn controlled directory to perform statistics on [.]");
    246     root_->print_arg("=ROOT");
    247     target_ = new yat::utility::OptionArg<std::string>(cmd_, "t,target",
    248                                          "output directory [.]");
    249     target_->print_arg("=TARGET");
    250    
    251     verbose_ = new yat::utility::OptionSwitch(cmd_, "v,verbose", "explain what is being done");
    252     version_ = new OptionVersion(cmd_, "version",
    253                                  "print version information and exit", verbose_);
    254 
    255     ss.str("");
    256228    ss << "Report bugs to " << PACKAGE_BUGREPORT << ".\n";
    257     help_->post_arguments() = ss.str();
    258     help_->synopsis() =
     229    help_.post_arguments() = ss.str();
     230    help_.synopsis() =
    259231      "Generate statistical report for a subversion repository\n";
    260232  }
     
    263235  bool Parameter::report(void) const
    264236  {
    265     return report_->value();
     237    return report_.value();
    266238  }
    267239
     
    269241  bool Parameter::revisions(void) const
    270242  {
    271     return revisions_->present();
     243    return revisions_.present();
    272244  }
    273245
     
    275247  std::string Parameter::root(void) const
    276248  {
    277     return root_->value();
     249    return root_.value();
    278250  }
    279251
     
    281253  std::string Parameter::targetdir(void) const
    282254  {
    283     return target_->value();
     255    return target_.value();
    284256  }
    285257
     
    287259  bool Parameter::verbose(void) const
    288260  {
    289     return verbose_->present();
     261    return verbose_.present();
    290262  }
    291263
  • trunk/bin/Parameter.h

    r795 r820  
    2424*/
    2525
     26#include "OptionVersion.h"
     27
    2628#include "yat/CommandLine.h"
    2729#include "yat/OptionArg.h"
     30#include "yat/OptionHelp.h"
     31#include "yat/OptionSwitch.h"
     32
    2833
    2934#include <string>
     
    7075
    7176    yat::utility::CommandLine cmd_;
    72     yat::utility::OptionArg<std::string>* config_file_;
    73     yat::utility::OptionSwitch* copyright_;
    74     yat::utility::OptionSwitch* force_;
    75     yat::utility::OptionSwitch* generate_config_;
    76     yat::utility::OptionHelp* help_;
    77     yat::utility::OptionSwitch* ignore_cache_;
    78     yat::utility::OptionSwitch* report_;
    79     yat::utility::OptionSwitch* revisions_;
    80     yat::utility::OptionArg<std::string>* root_;
    81     yat::utility::OptionArg<std::string>* target_;
    82     yat::utility::OptionSwitch* verbose_;
    83     OptionVersion* version_;
     77    yat::utility::OptionArg<std::string> config_file_;
     78    yat::utility::OptionSwitch copyright_;
     79    yat::utility::OptionSwitch force_;
     80    yat::utility::OptionSwitch generate_config_;
     81    yat::utility::OptionHelp help_;
     82    yat::utility::OptionSwitch ignore_cache_;
     83    yat::utility::OptionSwitch report_;
     84    yat::utility::OptionSwitch revisions_;
     85    yat::utility::OptionArg<std::string> root_;
     86    yat::utility::OptionArg<std::string> target_;
     87    yat::utility::OptionSwitch verbose_;
     88    OptionVersion version_;
    8489
    8590  };
Note: See TracChangeset for help on using the changeset viewer.