source: trunk/yat/utility/OptionSwitch.cc @ 1634

Last change on this file since 1634 was 1634, checked in by Peter, 13 years ago

Fixed bug in CommandLine? how --no-switches are handled

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 1.8 KB
Line 
1// $Id: OptionSwitch.cc 1634 2008-11-19 22:37:11Z peter $
2
3/*
4  Copyright (C) 2007 Jari Häkkinen, Peter Johansson
5
6  This file is part of the yat library, http://dev.thep.lu.se/yat
7
8  The yat library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 3 of the
11  License, or (at your option) any later version.
12
13  The yat library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with yat. If not, see <http://www.gnu.org/licenses/>.
20*/
21
22#include "OptionSwitch.h"
23
24#include <sstream>
25#include <string>
26
27namespace theplu {
28namespace yat {
29namespace utility {
30
31
32  OptionSwitch::OptionSwitch(CommandLine& cmd, std::string flag, 
33                             std::string desc, bool def)
34    : Option(cmd, flag, desc), def_(def), switch_(def)
35  {
36  }
37
38
39  void OptionSwitch::do_parse(std::vector<std::string>::iterator& first, 
40                              const std::vector<std::string>::iterator& last)
41  {   
42    if (first->size()>3 && first->substr(0,3)=="no-")
43      switch_=false;
44    else
45      switch_=true;
46    do_parse2(first, last);
47  }
48
49
50  void OptionSwitch::do_parse2(std::vector<std::string>::iterator first, 
51                               std::vector<std::string>::iterator last)
52  {   
53  }
54
55
56  std::string OptionSwitch::print2(void) const
57  {
58    std::string str;
59    if (long_name().size()){ 
60      str = " --";
61      if (def_ && long_name().size()>3 && long_name().substr(0,3)!="no-")
62        str += "no-";
63      str += long_name();
64    }
65    return str;
66  }
67
68
69  void OptionSwitch::do_validate() const
70  {   
71  }
72
73
74  bool OptionSwitch::value(void) const
75  { 
76    return switch_; 
77  }
78
79
80}}} // of namespace utility, yat, and theplu
Note: See TracBrowser for help on using the repository browser.