Changeset 1741


Ignore:
Timestamp:
Jan 22, 2009, 11:36:42 PM (14 years ago)
Author:
Peter
Message:

fixes #481

Location:
trunk/yat/utility
Files:
4 edited

Legend:

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

    r1634 r1741  
    33/*
    44  Copyright (C) 2007 Jari Häkkinen, Peter Johansson, Markus Ringnér
    5   Copyright (C) 2008 Peter Johansson
     5  Copyright (C) 2008, 2009 Peter Johansson
    66
    77  This file is part of the yat library, http://dev.thep.lu.se/yat
     
    4343
    4444  CommandLine::CommandLine(std::string str)
    45     : description_(str), free_arg_max_(0)
     45    : description_(str), free_arg_max_(0), parsed_(false)
    4646  {}
    4747
     
    103103  void CommandLine::parse(int argc, char* argv[])
    104104  {   
     105    parsed_=true;
    105106    using namespace std;
    106107    // just in case it is not pristine
     
    182183
    183184
     185  bool CommandLine::parsed(void) const
     186  {
     187    return parsed_;
     188  }
     189
     190
    184191  std::string CommandLine::program_name(void) const
    185192  {
  • trunk/yat/utility/CommandLine.h

    r1487 r1741  
    66/*
    77  Copyright (C) 2007 Jari Häkkinen, Peter Johansson
    8   Copyright (C) 2008 Peter Johansson
     8  Copyright (C) 2008, 2009 Peter Johansson
    99
    1010  This file is part of the yat library, http://dev.thep.lu.se/yat
     
    127127
    128128    /**
     129       \brief has the commandline been parsed already
     130
     131       \return true if parse function has already been called
     132
     133       \since New in yat 0.5
     134    */
     135    bool parsed(void) const;
     136
     137    /**
    129138       @return Name of more; more specifically argv[0] is
    130139       stripped so only string after the last '/' remains.
     
    151160    std::map<char, Option*> short_options_;
    152161    std::map<std::string, Option*> long_options_;
     162    bool parsed_;
    153163    std::string program_name_;
    154164  };
  • trunk/yat/utility/Option.cc

    r1487 r1741  
    33/*
    44  Copyright (C) 2007 Jari Häkkinen, Peter Johansson
    5   Copyright (C) 2008 Peter Johansson
     5  Copyright (C) 2008, 2009 Peter Johansson
    66
    77  This file is part of the yat library, http://dev.thep.lu.se/yat
     
    8888  bool Option::present(void) const
    8989  {
     90    if (!cmd().parsed()) {
     91      std::string s("Option::present called before Commandline was parsed");
     92      throw std::logic_error(s);
     93    }
    9094    return present_;
    9195  }
  • trunk/yat/utility/OptionArg.h

    r1632 r1741  
    66/*
    77  Copyright (C) 2007 Jari Häkkinen, Peter Johansson
    8   Copyright (C) 2008 Peter Johansson
     8  Copyright (C) 2008, 2009 Peter Johansson
    99
    1010  This file is part of the yat library, http://dev.thep.lu.se/yat
     
    2929#include "utility.h"
    3030
     31#include <stdexcept>
    3132#include <string>
    3233#include <sstream>
     
    7576       \return value
    7677    */
    77     T value(void) const { return value_; }
     78    T value(void) const
     79    {
     80      if (!cmd().parsed()) {
     81        std::string s("OptionArg::value called before Commandline was parsed");
     82        throw std::logic_error(s);
     83      }
     84      return value_;
     85    }
    7886
    7987    /**
Note: See TracChangeset for help on using the changeset viewer.