1 | /* |
---|
2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
3 | * > www.orxonox.net < |
---|
4 | * |
---|
5 | * |
---|
6 | * License notice: |
---|
7 | * |
---|
8 | * This program is free software; you can redistribute it and/or |
---|
9 | * modify it under the terms of the GNU General Public License |
---|
10 | * as published by the Free Software Foundation; either version 2 |
---|
11 | * of the License, or (at your option) any later version. |
---|
12 | * |
---|
13 | * This program 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 |
---|
16 | * GNU 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
21 | * |
---|
22 | * Author: |
---|
23 | * Fabian 'x3n' Landau |
---|
24 | * Co-authors: |
---|
25 | * ... |
---|
26 | * |
---|
27 | */ |
---|
28 | |
---|
29 | #ifndef _ArgumentCompleter_H__ |
---|
30 | #define _ArgumentCompleter_H__ |
---|
31 | |
---|
32 | #include "CorePrereqs.h" |
---|
33 | #include "ArgumentCompletionListElement.h" |
---|
34 | |
---|
35 | namespace orxonox |
---|
36 | { |
---|
37 | class _CoreExport ArgumentCompleter |
---|
38 | { |
---|
39 | public: |
---|
40 | ArgumentCompleter(ArgumentCompletionList (*function) (void)) : paramCount_(0), function_0_(function) {} |
---|
41 | ArgumentCompleter(ArgumentCompletionList (*function) (const std::string& param1)) : paramCount_(1), function_1_(function) {} |
---|
42 | ArgumentCompleter(ArgumentCompletionList (*function) (const std::string& param1, const std::string& param2)) : paramCount_(2), function_2_(function) {} |
---|
43 | ArgumentCompleter(ArgumentCompletionList (*function) (const std::string& param1, const std::string& param2, const std::string& param3)) : paramCount_(3), function_3_(function) {} |
---|
44 | ArgumentCompleter(ArgumentCompletionList (*function) (const std::string& param1, const std::string& param2, const std::string& param3, const std::string& param4)) : paramCount_(4), function_4_(function) {} |
---|
45 | ArgumentCompleter(ArgumentCompletionList (*function) (const std::string& param1, const std::string& param2, const std::string& param3, const std::string& param4, const std::string& param5)) : paramCount_(5), function_5_(function) {} |
---|
46 | |
---|
47 | ArgumentCompletionList operator()(const std::string& param1 = "", const std::string& param2 = "", const std::string& param3 = "", const std::string& param4 = "", const std::string& param5 = "") |
---|
48 | { |
---|
49 | switch (this->paramCount_) |
---|
50 | { |
---|
51 | case 0: |
---|
52 | return (*this->function_0_)(); |
---|
53 | case 1: |
---|
54 | return (*this->function_1_)(param1); |
---|
55 | case 2: |
---|
56 | return (*this->function_2_)(param1, param2); |
---|
57 | case 3: |
---|
58 | return (*this->function_3_)(param1, param2, param3); |
---|
59 | case 4: |
---|
60 | return (*this->function_4_)(param1, param2, param3, param4); |
---|
61 | case 5: |
---|
62 | return (*this->function_5_)(param1, param2, param3, param4, param5); |
---|
63 | default: |
---|
64 | return ArgumentCompletionList(); |
---|
65 | } |
---|
66 | } |
---|
67 | |
---|
68 | private: |
---|
69 | unsigned char paramCount_; |
---|
70 | ArgumentCompletionList (*function_0_) (void); |
---|
71 | ArgumentCompletionList (*function_1_) (const std::string& param1); |
---|
72 | ArgumentCompletionList (*function_2_) (const std::string& param1, const std::string& param2); |
---|
73 | ArgumentCompletionList (*function_3_) (const std::string& param1, const std::string& param2, const std::string& param3); |
---|
74 | ArgumentCompletionList (*function_4_) (const std::string& param1, const std::string& param2, const std::string& param3, const std::string& param4); |
---|
75 | ArgumentCompletionList (*function_5_) (const std::string& param1, const std::string& param2, const std::string& param3, const std::string& param4, const std::string& param5); |
---|
76 | }; |
---|
77 | } |
---|
78 | |
---|
79 | #endif /* _ArgumentCompleter_H__ */ |
---|