source: trunk/lib/OptionSwitch.cc @ 745

Last change on this file since 745 was 705, checked in by Peter Johansson, 13 years ago

importing classes for commandline parsing from yat. This fixes #349 and #265

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 1.8 KB
Line 
1// $Id: OptionSwitch.cc 705 2008-11-25 23:33:26Z peter $
2
3/*
4  Copyright (C) 2007 Jari Häkkinen, Peter Johansson
5
6  This file is part of svndigest, http://dev.thep.lu.se/svndigest
7
8  svndigest is free software; you can redistribute it and/or modify it
9  under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 3 of the License, or
11  (at your option) any later version.
12
13  svndigest is distributed in the hope that it will be useful, but
14  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 svndigest. 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 svndigest {
29
30  OptionSwitch::OptionSwitch(CommandLine& cmd, std::string flag, 
31                             std::string desc, bool def)
32    : Option(cmd, flag, desc), def_(def), switch_(def)
33  {
34  }
35
36
37  void OptionSwitch::do_parse(std::vector<std::string>::iterator& first, 
38                              const std::vector<std::string>::iterator& last)
39  {   
40    if (first->size()>3 && first->substr(0,3)=="no-")
41      switch_=false;
42    else
43      switch_=true;
44    do_parse2(first, last);
45  }
46
47
48  void OptionSwitch::do_parse2(std::vector<std::string>::iterator first, 
49                               std::vector<std::string>::iterator last)
50  {   
51  }
52
53
54  std::string OptionSwitch::print2(void) const
55  {
56    std::string str;
57    if (long_name().size()){ 
58      str = " --";
59      if (def_ && long_name().size()>3 && long_name().substr(0,3)!="no-")
60        str += "no-";
61      str += long_name();
62    }
63    return str;
64  }
65
66
67  void OptionSwitch::do_validate() const
68  {   
69  }
70
71
72  bool OptionSwitch::value(void) const
73  { 
74    return switch_; 
75  }
76
77
78}} // of namespace svndigest and theplu
Note: See TracBrowser for help on using the repository browser.