Release
[hcoop/zz_old/debian/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 if (pos >= this->arguments.size() || pos < 0) {
41 throw OutOfRangeException("Index out of range", __FILE__, __LINE__);
42 }
43 try {
44 return this->arguments[pos];
45 } catch (std::out_of_range& e) {
46 throw OutOfRangeException("Index out of range", __FILE__, __LINE__);
47 }
48 }
49
50 void suPHP::CommandLine::setArgument(int pos, std::string arg) {
51 if (pos >= this->arguments.size()) {
52 for (int i=0; i<(this->arguments.size() - pos); i++) {
53 this->arguments.push_back(std::string(""));
54 }
55 }
56 this->arguments[pos] = arg;
57 }
58
59 void suPHP::CommandLine::putArgument(std::string arg) {
60 this->arguments.push_back(arg);
61 }
62
63 std::string& suPHP::CommandLine::operator[](int index)
64 throw (OutOfRangeException) {
65 if (index >= this->arguments.size() || index < 0) {
66 throw OutOfRangeException("Index out of range", __FILE__, __LINE__);
67 }
68 try {
69 return this->arguments[index];
70 } catch (std::out_of_range& ex) {
71 throw OutOfRangeException("Index out of range", __FILE__, __LINE__);
72 }
73 }
74
75
76 int suPHP::CommandLine::size() const {
77 return this->arguments.size();
78 }