Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/ipv6/src/libraries/core/command/ArgumentCompleter.h @ 7758

Last change on this file since 7758 was 7284, checked in by landauf, 14 years ago

merged consolecommands3 branch back to trunk.

note: the console command interface has changed completely, but the documentation is not yet up to date. just copy an existing command and change it to your needs, it's pretty self-explanatory. also the include files related to console commands are now located in core/command/. in the game it should work exactly like before, except for some changes in the auto-completion.

  • Property svn:eol-style set to native
File size: 4.5 KB
Line 
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 "core/CorePrereqs.h"
33#include "ArgumentCompletionListElement.h"
34
35namespace orxonox
36{
37    class _CoreExport ArgumentCompleter
38    {
39        public:
40            ArgumentCompleter(ArgumentCompletionList (*function) (void), bool bUseMultipleWords) : bUseMultipleWords_(bUseMultipleWords), paramCount_(0), function_0_(function) {}
41            ArgumentCompleter(ArgumentCompletionList (*function) (const std::string& param1), bool bUseMultipleWords) : bUseMultipleWords_(bUseMultipleWords), paramCount_(1), function_1_(function) {}
42            ArgumentCompleter(ArgumentCompletionList (*function) (const std::string& param1, const std::string& param2), bool bUseMultipleWords) : bUseMultipleWords_(bUseMultipleWords), paramCount_(2), function_2_(function) {}
43            ArgumentCompleter(ArgumentCompletionList (*function) (const std::string& param1, const std::string& param2, const std::string& param3), bool bUseMultipleWords) : bUseMultipleWords_(bUseMultipleWords), 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), bool bUseMultipleWords) : bUseMultipleWords_(bUseMultipleWords), 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), bool bUseMultipleWords) : bUseMultipleWords_(bUseMultipleWords), 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            inline bool useMultipleWords() const
69                { return this->bUseMultipleWords_; }
70
71        private:
72            bool bUseMultipleWords_;
73            unsigned char paramCount_;
74            ArgumentCompletionList (*function_0_) (void);
75            ArgumentCompletionList (*function_1_) (const std::string& param1);
76            ArgumentCompletionList (*function_2_) (const std::string& param1, const std::string& param2);
77            ArgumentCompletionList (*function_3_) (const std::string& param1, const std::string& param2, const std::string& param3);
78            ArgumentCompletionList (*function_4_) (const std::string& param1, const std::string& param2, const std::string& param3, const std::string& param4);
79            ArgumentCompletionList (*function_5_) (const std::string& param1, const std::string& param2, const std::string& param3, const std::string& param4, const std::string& param5);
80    };
81}
82
83#endif /* _ArgumentCompleter_H__ */
Note: See TracBrowser for help on using the repository browser.