1 /*******************************************************************************
2 * Reverse Polish Notation calculator. *
3 * Copyright (c) 2007-2008, Samuel Fredrickson <kinghajj@gmail.com> *
4 * All rights reserved. *
6 * Redistribution and use in source and binary forms, with or without *
7 * modification, are permitted provided that the following conditions are met: *
8 * * Redistributions of source code must retain the above copyright *
9 * notice, this list of conditions and the following disclaimer. *
10 * * Redistributions in binary form must reproduce the above copyright *
11 * notice, this list of conditions and the following disclaimer in the *
12 * documentation and/or other materials provided with the distribution. *
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER ``AS IS'' AND ANY EXPRESS *
15 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED *
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
17 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY *
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR *
20 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER *
21 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT *
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY *
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
25 ******************************************************************************/
27 /*******************************************************************************
28 * Arguments.h - argument handling for the console port. *
29 ******************************************************************************/
31 #ifndef RPN_CONSOLE_ARGUMENT
32 #define RPN_CONSOLE_ARGUMENT
37 #include "../typedefs.h"
45 void (*f
)(std::vector
<std::string
>&, Calculator
&);
49 : nargs(0), continueProgram(true), f(NULL
)
53 Argument(unsigned nargs
, bool continueProgram
,
54 void (*f
)(std::vector
<std::string
>&, Calculator
&))
55 : nargs(nargs
), continueProgram(continueProgram
), f(f
)
59 bool ContinueProgram() const
61 return continueProgram
;
64 unsigned NumArgs() const
69 void Perform(std::vector
<std::string
>& args
, Calculator
& calc
) const
75 typedef std::map
<std::string
, Argument
> Arguments
;
77 std::vector
<std::string
> vectorize(char **argv
, int argc
);
78 bool processArguments(const std::vector
<std::string
>& args
,
79 const Arguments
& arguments
,
80 Calculator
& calculator
);
81 void setupArguments(Arguments
& arguments
);