Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/console/src/core/ArgumentCompleter.h @ 1430

Last change on this file since 1430 was 1430, checked in by landauf, 16 years ago

I start to like it

File size: 4.4 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 <list>
33#include <string>
34
35#include "CorePrereqs.h"
36
37namespace orxonox
38{
39    class _CoreExport ArgumentCompleter
40    {
41        public:
42            ArgumentCompleter(std::list<std::pair<std::string, std::string> > (*function) (void)) : paramCount_(0), function_0_(function) {}
43            ArgumentCompleter(std::list<std::pair<std::string, std::string> > (*function) (const std::string& param1)) : paramCount_(1), function_1_(function) {}
44            ArgumentCompleter(std::list<std::pair<std::string, std::string> > (*function) (const std::string& param1, const std::string& param2)) : paramCount_(2), function_2_(function) {}
45            ArgumentCompleter(std::list<std::pair<std::string, std::string> > (*function) (const std::string& param1, const std::string& param2, const std::string& param3)) : paramCount_(3), function_3_(function) {}
46            ArgumentCompleter(std::list<std::pair<std::string, std::string> > (*function) (const std::string& param1, const std::string& param2, const std::string& param3, const std::string& param4)) : paramCount_(4), function_4_(function) {}
47            ArgumentCompleter(std::list<std::pair<std::string, std::string> > (*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) {}
48
49            std::list<std::pair<std::string, std::string> > operator()(const std::string& param1 = "", const std::string& param2 = "", const std::string& param3 = "", const std::string& param4 = "", const std::string& param5 = "")
50            {
51                switch (this->paramCount_)
52                {
53                    case 0:
54                        return (*this->function_0_)();
55                    case 1:
56                        return (*this->function_1_)(param1);
57                    case 2:
58                        return (*this->function_2_)(param1, param2);
59                    case 3:
60                        return (*this->function_3_)(param1, param2, param3);
61                    case 4:
62                        return (*this->function_4_)(param1, param2, param3, param4);
63                    case 5:
64                        return (*this->function_5_)(param1, param2, param3, param4, param5);
65                    default:
66                        return (*this->function_0_)();
67                }
68            }
69
70        private:
71            unsigned char paramCount_;
72            std::list<std::pair<std::string, std::string> > (*function_0_) (void);
73            std::list<std::pair<std::string, std::string> > (*function_1_) (const std::string& param1);
74            std::list<std::pair<std::string, std::string> > (*function_2_) (const std::string& param1, const std::string& param2);
75            std::list<std::pair<std::string, std::string> > (*function_3_) (const std::string& param1, const std::string& param2, const std::string& param3);
76            std::list<std::pair<std::string, std::string> > (*function_4_) (const std::string& param1, const std::string& param2, const std::string& param3, const std::string& param4);
77            std::list<std::pair<std::string, std::string> > (*function_5_) (const std::string& param1, const std::string& param2, const std::string& param3, const std::string& param4, const std::string& param5);
78    };
79}
80
81#endif /* _ArgumentCompleter_H__ */
Note: See TracBrowser for help on using the repository browser.