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

Last change on this file since 1275 was 1275, checked in by Jari Häkkinen, 15 years ago

Updating copyright statements.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 1.9 KB
Line 
1// $Id: OptionSwitch.cc 1275 2008-04-11 06:10:12Z jari $
2
3/*
4  Copyright (C) 2007 Jari Häkkinen, Peter Johansson
5
6  This file is part of the yat library, http://trac.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 2 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 this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21  02111-1307, USA.
22*/
23
24#include "OptionSwitch.h"
25
26#include <sstream>
27#include <string>
28
29namespace theplu {
30namespace yat {
31namespace utility {
32
33
34  OptionSwitch::OptionSwitch(CommandLine& cmd, std::string flag, 
35                             std::string desc, bool def)
36    : Option(cmd, flag, desc), def_(def), switch_(def)
37  {
38  }
39
40
41  void OptionSwitch::do_parse(std::vector<std::string>::iterator first, 
42                              std::vector<std::string>::iterator last)
43  {   
44    if (long_name().size()>3 && long_name().substr(0,3)=="no-")
45      switch_=false;
46    else
47      switch_=true;
48    do_parse2(first, last);
49  }
50
51
52  void OptionSwitch::do_parse2(std::vector<std::string>::iterator first, 
53                               std::vector<std::string>::iterator last)
54  {   
55  }
56
57
58  std::string OptionSwitch::print2(void) const
59  {
60    std::string str;
61    if (long_name().size()){ 
62      str = " --";
63      if (def_ && long_name().size()>3 && long_name().substr(0,3)!="no-")
64        str += "no-";
65      str += long_name();
66    }
67    return str;
68  }
69
70
71  void OptionSwitch::do_validate() const
72  {   
73  }
74
75
76  bool OptionSwitch::value(void) const
77  { 
78    return switch_; 
79  }
80
81
82}}} // of namespace utility, yat, and theplu
Note: See TracBrowser for help on using the repository browser.