Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/libraries/core/command/ArgumentCompleter.h @ 7401

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

merged doc branch back to trunk

  • Property svn:eol-style set to native
File size: 7.2 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/**
30    @defgroup ArgumentCompletion Argument completion
31    @ingroup Command
32*/
33
34/**
35    @file
36    @ingroup Command ArgumentCompletion
37    @brief Definition of the orxonox::ArgumentCompleter class that is used to execute @ref ArgumentCompletionFunctions.h "argument completion functions".
38
39    An ArgumentCompleter can be assigned to an orxonox::ConsoleCommand using
40    @ref orxonox::ConsoleCommand::argumentCompleter "argumentCompleter()".
41    The ArgumentCompleter calls an argument completion function that is defined
42    in ArgumentCompletionFunctions.h. This can be used to list possible arguments
43    for console commands and to allow auto-completion.
44
45    Instances of ArgumentCompleter are usually not created manually but rather
46    by the macros defined in ArgumentCompletionFunctions.h. There you'll also
47    find some examples.
48
49    @see See the @ref ArgumentCompletionExample "examples".
50*/
51
52#ifndef _ArgumentCompleter_H__
53#define _ArgumentCompleter_H__
54
55#include "core/CorePrereqs.h"
56#include "ArgumentCompletionListElement.h"
57
58namespace orxonox
59{
60    /**
61        @brief This class executes an argument completion function and returns a list of the possible arguments.
62
63        ArgumentCompleter is used to wrap argument completion functions as defined
64        in ArgumentCompletionFunctions.h and can be assigned to a ConsoleCommand to
65        create a list of possible arguments.
66
67        @see See ArgumentCompleter.h for more information.
68        @see See @ref ArgumentCompletionExample "ArgumentCompletionFunctions.h" for an example.
69    */
70    class _CoreExport ArgumentCompleter
71    {
72        public:
73            ArgumentCompleter(ArgumentCompletionList (*function) (void), bool bUseMultipleWords) : bUseMultipleWords_(bUseMultipleWords), paramCount_(0), function_0_(function) {} ///< Constructor, assigns a function-pointer with no arguments.
74            ArgumentCompleter(ArgumentCompletionList (*function) (const std::string& param1), bool bUseMultipleWords) : bUseMultipleWords_(bUseMultipleWords), paramCount_(1), function_1_(function) {} ///< Constructor, assigns a function-pointer with one argument.
75            ArgumentCompleter(ArgumentCompletionList (*function) (const std::string& param1, const std::string& param2), bool bUseMultipleWords) : bUseMultipleWords_(bUseMultipleWords), paramCount_(2), function_2_(function) {} ///< Constructor, assigns a function-pointer with two arguments.
76            ArgumentCompleter(ArgumentCompletionList (*function) (const std::string& param1, const std::string& param2, const std::string& param3), bool bUseMultipleWords) : bUseMultipleWords_(bUseMultipleWords), paramCount_(3), function_3_(function) {} ///< Constructor, assigns a function-pointer with three arguments.
77            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) {} ///< Constructor, assigns a function-pointer with four arguments.
78            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) {} ///< Constructor, assigns a function-pointer with five arguments.
79
80            /**
81                @brief Calls the argument completion function with a maximum of five parameters.
82                @return Returns the list of possible arguments, created by the argument completion function
83            */
84            ArgumentCompletionList operator()(const std::string& param1 = "", const std::string& param2 = "", const std::string& param3 = "", const std::string& param4 = "", const std::string& param5 = "")
85            {
86                switch (this->paramCount_)
87                {
88                    case 0:
89                        return (*this->function_0_)();
90                    case 1:
91                        return (*this->function_1_)(param1);
92                    case 2:
93                        return (*this->function_2_)(param1, param2);
94                    case 3:
95                        return (*this->function_3_)(param1, param2, param3);
96                    case 4:
97                        return (*this->function_4_)(param1, param2, param3, param4);
98                    case 5:
99                        return (*this->function_5_)(param1, param2, param3, param4, param5);
100                    default:
101                        return ArgumentCompletionList();
102                }
103            }
104
105            /// Returns true if the argument completion list supports multiple words.
106            inline bool useMultipleWords() const
107                { return this->bUseMultipleWords_; }
108
109        private:
110            bool bUseMultipleWords_;    ///< If true, the argument completion list supports multiple words
111            unsigned char paramCount_;  ///< The number of parameters of the argument completion function
112            ArgumentCompletionList (*function_0_) (void);   ///< Function-pointer for an argument completion function with no arguments
113            ArgumentCompletionList (*function_1_) (const std::string& param1);   ///< Function-pointer for an argument completion function with one argument
114            ArgumentCompletionList (*function_2_) (const std::string& param1, const std::string& param2);   ///< Function-pointer for an argument completion function with two arguments
115            ArgumentCompletionList (*function_3_) (const std::string& param1, const std::string& param2, const std::string& param3);   ///< Function-pointer for an argument completion function with three arguments
116            ArgumentCompletionList (*function_4_) (const std::string& param1, const std::string& param2, const std::string& param3, const std::string& param4);   ///< Function-pointer for an argument completion function with four arguments
117            ArgumentCompletionList (*function_5_) (const std::string& param1, const std::string& param2, const std::string& param3, const std::string& param4, const std::string& param5);   ///< Function-pointer for an argument completion function with five arguments
118    };
119}
120
121#endif /* _ArgumentCompleter_H__ */
Note: See TracBrowser for help on using the repository browser.