Orxonox  0.0.5 Codename: Arcturus
ArgumentCompleter.h
Go to the documentation of this file.
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 
52 #ifndef _ArgumentCompleter_H__
53 #define _ArgumentCompleter_H__
54 
55 #include "core/CorePrereqs.h"
57 
58 namespace orxonox
59 {
71  {
72  public:
73  ArgumentCompleter(ArgumentCompletionList (*function) (void), bool bUseMultipleWords) : bUseMultipleWords_(bUseMultipleWords), paramCount_(0), function_0_(function) {}
74  ArgumentCompleter(ArgumentCompletionList (*function) (const std::string& param1), bool bUseMultipleWords) : bUseMultipleWords_(bUseMultipleWords), paramCount_(1), function_1_(function) {}
75  ArgumentCompleter(ArgumentCompletionList (*function) (const std::string& param1, const std::string& param2), bool bUseMultipleWords) : bUseMultipleWords_(bUseMultipleWords), paramCount_(2), function_2_(function) {}
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) {}
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) {}
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) {}
79 
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 
106  inline bool useMultipleWords() const
107  { return this->bUseMultipleWords_; }
108 
109  private:
111  unsigned char paramCount_;
112  ArgumentCompletionList (*function_0_) (void);
113  ArgumentCompletionList (*function_1_) (const std::string& param1);
114  ArgumentCompletionList (*function_2_) (const std::string& param1, const std::string& param2);
115  ArgumentCompletionList (*function_3_) (const std::string& param1, const std::string& param2, const std::string& param3);
116  ArgumentCompletionList (*function_4_) (const std::string& param1, const std::string& param2, const std::string& param3, const std::string& param4);
117  ArgumentCompletionList (*function_5_) (const std::string& param1, const std::string& param2, const std::string& param3, const std::string& param4, const std::string& param5);
118  };
119 }
120 
121 #endif /* _ArgumentCompleter_H__ */
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)
Constructor, assigns a function-pointer with five arguments.
Definition: ArgumentCompleter.h:78
ArgumentCompleter(ArgumentCompletionList(*function)(const std::string &param1, const std::string &param2), bool bUseMultipleWords)
Constructor, assigns a function-pointer with two arguments.
Definition: ArgumentCompleter.h:75
Shared library macros, enums, constants and forward declarations for the core library ...
::std::string string
Definition: gtest-port.h:756
bool useMultipleWords() const
Returns true if the argument completion list supports multiple words.
Definition: ArgumentCompleter.h:106
unsigned char paramCount_
The number of parameters of the argument completion function.
Definition: ArgumentCompleter.h:111
ArgumentCompleter(ArgumentCompletionList(*function)(const std::string &param1, const std::string &param2, const std::string &param3), bool bUseMultipleWords)
Constructor, assigns a function-pointer with three arguments.
Definition: ArgumentCompleter.h:76
typedef void(ENET_CALLBACK *ENetPacketFreeCallback)(struct _ENetPacket *)
Die Wagnis Klasse hat die folgenden Aufgaben:
Definition: ApplicationPaths.cc:66
#define _CoreExport
Definition: CorePrereqs.h:61
std::list< ArgumentCompletionListElement > ArgumentCompletionList
Definition: ArgumentCompletionListElement.h:49
ArgumentCompletionList operator()(const std::string &param1="", const std::string &param2="", const std::string &param3="", const std::string &param4="", const std::string &param5="")
Calls the argument completion function with a maximum of five parameters.
Definition: ArgumentCompleter.h:84
ArgumentCompleter(ArgumentCompletionList(*function)(void), bool bUseMultipleWords)
Constructor, assigns a function-pointer with no arguments.
Definition: ArgumentCompleter.h:73
ArgumentCompleter(ArgumentCompletionList(*function)(const std::string &param1, const std::string &param2, const std::string &param3, const std::string &param4), bool bUseMultipleWords)
Constructor, assigns a function-pointer with four arguments.
Definition: ArgumentCompleter.h:77
bool bUseMultipleWords_
If true, the argument completion list supports multiple words.
Definition: ArgumentCompleter.h:110
Definition of ArgumentCompletionList, which is used in argument completion functions, and its element.
This class executes an argument completion function and returns a list of the possible arguments...
Definition: ArgumentCompleter.h:70
ArgumentCompleter(ArgumentCompletionList(*function)(const std::string &param1), bool bUseMultipleWords)
Constructor, assigns a function-pointer with one argument.
Definition: ArgumentCompleter.h:74