0.6.0-1 release
[manu/suphp.git] / src / CommandLine.cpp
1 /*
2     suPHP - (c)2002-2005 Sebastian Marsching <sebastian@marsching.com>
3
4     This file is part of suPHP.
5
6     suPHP is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     suPHP is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with suPHP; if not, write to the Free Software
18     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
20
21 #include <stdexcept>
22 #include <string>
23
24 #include "OutOfRangeException.hpp"
25
26 #include "CommandLine.hpp"
27
28 using namespace suPHP;
29
30 suPHP::CommandLine::CommandLine() {
31     /* do nothing */
32 }
33
34 int suPHP::CommandLine::count() const {
35     return this->arguments.size();
36 }
37
38 std::string suPHP::CommandLine::getArgument(int pos) const
39     throw (OutOfRangeException) {
40     try {
41         return this->arguments.at(pos);
42     } catch (std::out_of_range& e) {
43         throw OutOfRangeException("Index out of range", __FILE__, __LINE__);
44     }
45 }
46
47 void suPHP::CommandLine::setArgument(int pos, std::string arg) {
48     if (pos >= this->arguments.size()) {
49         for (int i=0; i<(this->arguments.size() - pos); i++) {
50             this->arguments.push_back(std::string(""));
51         }
52     }
53     this->arguments.at(pos) = arg;
54 }
55
56 void suPHP::CommandLine::putArgument(std::string arg) {
57     this->arguments.push_back(arg);
58 }
59
60 std::string& suPHP::CommandLine::operator[](int index) 
61     throw (OutOfRangeException) {
62     try {
63         return this->arguments.at(index);
64     } catch (std::out_of_range& ex) {
65         throw OutOfRangeException("Index out of range", __FILE__, __LINE__);
66     }
67 }
68
69
70 int suPHP::CommandLine::size() const {
71     return this->arguments.size();
72 }