Code cleanup & factoring of commands module.
[rpn.git] / src / typedefs.h
blob56e79e9bf43b4fcff0cc039053db2b538a1f185d
1 /*******************************************************************************
2 * Reverse Polish Notation calculator. *
3 * Copyright (c) 2007-2009, Samuel Fredrickson <kinghajj@gmail.com> *
4 * All rights reserved. *
5 * *
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. *
13 * *
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 *
24 * DAMAGE. *
25 ******************************************************************************/
27 /*******************************************************************************
28 * typedefs.h - header for typedefs or forward declarations. *
29 ******************************************************************************/
31 #ifndef RPN_TYPEDEFS_H
32 #define RPN_TYPEDEFS_H
34 #include <list>
35 #include <map>
36 #include <string>
37 #include <vector>
39 namespace RPN
41 ////////////////////////////////////////////////////////////////////////////
42 // FORWARD DECLARATIONS //
43 ////////////////////////////////////////////////////////////////////////////
45 class Calculator;
46 class Command;
47 class HelpItem;
49 ////////////////////////////////////////////////////////////////////////////
50 // TYPEDEFS //
51 ////////////////////////////////////////////////////////////////////////////
53 #ifdef RPN_DOUBLE
54 //! The type operated on by the calculator.
55 typedef double Value;
56 #elif RPN_LONG_DOUBLE
57 //! The type operated on by the calculator.
58 typedef long double Value;
59 #else
60 #error Please choose either RPN_DOUBLE or RPN_LONG_DOUBLE.
61 #endif
62 //! The type of an operator function.
63 typedef Value (*Operator)(Value a, Value b);
64 //! The type of a collection of commands.
65 typedef std::map<std::string, Command> Commands;
66 //! The type of a collection of operators.
67 typedef std::map<std::string, Operator> Operators;
68 //! The type of a collection of variables.
69 typedef std::map<std::string, Value> Variables;
70 //! The type of the stack used by the calculator.
71 typedef std::list<Value> Stack;
72 //! The type of the history stack used by the calculator.
73 typedef std::list<Stack> History;
74 //! The type of a command member function. All commands must be members
75 //! of the Calculator class.
76 typedef void (Calculator::*CommandPtr)(std::vector<std::string>&);
77 //! A list of help items.
78 typedef std::list<HelpItem> HelpItems;
81 #endif