Changeset 979 for trunk/yat


Ignore:
Timestamp:
Oct 21, 2007, 9:46:14 PM (14 years ago)
Author:
Peter
Message:

fixing bug in OptionFile?. Dont try to create FileUtil? for option not present in commandline

Location:
trunk/yat/utility
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/yat/utility/CommandLine.cc

    r975 r979  
    159159    while (std::getline(ss, str, del)){
    160160      vec.push_back(str);
    161       std::cout << "split: push_back() " << vec.back() << std::endl;
    162161    }
    163162    return vec;
  • trunk/yat/utility/OptionFile.cc

    r975 r979  
    3434  OptionFile::OptionFile(CommandLine& cmd, std::string flag,
    3535                         std::string desc, bool exist, std::string bits)
    36     : OptionArg<char*>(cmd, flag, desc), exist_(exist), bits_(bits)
     36    : OptionArg<std::string>(cmd, flag, desc), exist_(exist), bits_(bits)
    3737  {
    3838  }
     
    4141  void OptionFile::do_validate() const
    4242  {   
    43     FileUtil fu(value());
     43    if (!present())
     44      return;
     45    FileUtil fu(value().c_str());
    4446    if (exist_ && !fu.exists()){
    4547      std::stringstream ss;
     
    4749      throw std::runtime_error(ss.str());
    4850    }
    49     // Peter, this loop is stupid but I wanna differentiate the error message
    50     for (size_t i=0; i<bits_.length(); ++i)
    51       switch (bits_[i]) {
    52       case 'r':
    53         if (fu.permissions("r")){
     51    if (fu.permissions(bits_)) {
     52      // Peter, this loop is stupid but I wanna differentiate the error message
     53      for (std::string::const_iterator iter; iter!=bits_.end(); ++iter){
     54        if (*iter=='r' && fu.permissions("r")){
    5455          std::stringstream ss;
    5556          ss << "cannot stat `" << value() << "': No such file or directory";
    5657          throw std::runtime_error(ss.str());
    5758        }
    58         break;
    59       case 'w':
    60         if (fu.permissions("w")){
     59        else if (*iter=='w' && fu.permissions("w")){
    6160          std::stringstream ss;
    6261          ss << "cannot create file `" << value()
     
    6463          throw std::runtime_error(ss.str());
    6564        }
    66         break;
    67       case 'x':
    68         if (fu.permissions("w")){
    69           std::stringstream ss;
    70           ss << value() << ": Permission denied";
    71           throw std::runtime_error(ss.str());
    72         }
    73         break;
    7465      }
     66      std::stringstream ss;
     67      ss << value() << ": Permission denied";
     68      throw std::runtime_error(ss.str());
     69    }
    7570  }
    7671
  • trunk/yat/utility/OptionFile.h

    r975 r979  
    3737     \brief Class for file related options
    3838   */
    39   class OptionFile : public OptionArg<char*>
     39  class OptionFile : public OptionArg<std::string>
    4040  {
    4141  public:
     
    4444       
    4545       \param cmd Commandline Option is associated with
    46        \param name string such as "file" for --file, "f" for -h or
     46       \param name string such as "file" for --file, "f" for -f or
    4747       "f,file" for having both short and long option name
    4848       \param desc string used in help display
    4949       \param exist if true File must exist
    50        \param bits used to check permission on file, @see
    51        FileUtil::permission
     50       \param bits used to check permission on file, see
     51       FileUtil
    5252    */
    5353    OptionFile(CommandLine& cmd, std::string name,
Note: See TracChangeset for help on using the changeset viewer.