Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/libraries/core/ArgumentCompletionFunctions.cc @ 5904

Last change on this file since 5904 was 5781, checked in by rgrieder, 15 years ago

Reverted trunk again. We might want to find a way to delete these revisions again (x3n's changes are still available as diff in the commit mails).

  • Property svn:eol-style set to native
File size: 5.9 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#include "ArgumentCompletionFunctions.h"
30
31#include <map>
32#include <boost/version.hpp>
33#include <boost/filesystem.hpp>
34
35#include "util/Convert.h"
36#include "util/StringUtils.h"
37#include "Identifier.h"
38#include "ConfigValueContainer.h"
39#include "TclThreadManager.h"
40
41// Boost 1.36 has some issues with deprecated functions that have been omitted
42#if (BOOST_VERSION == 103600)
43#  define BOOST_LEAF_FUNCTION filename
44#else
45#  define BOOST_LEAF_FUNCTION leaf
46#endif
47
48namespace orxonox
49{
50    namespace autocompletion
51    {
52        ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(fallback)()
53        {
54            return ArgumentCompletionList();
55        }
56
57        ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(files)(const std::string& fragment)
58        {
59            ArgumentCompletionList dirlist;
60            ArgumentCompletionList filelist;
61
62            try
63            {
64                boost::filesystem::path input(fragment);
65                boost::filesystem::path startdirectory(input.branch_path());
66
67                if (!boost::filesystem::exists(startdirectory))
68                {
69                    startdirectory = ".";
70                }
71#ifdef ORXONOX_PLATFORM_WINDOWS
72                else
73                {
74                    std::string dir = startdirectory.string();
75                    if (dir.size() > 0 && dir[dir.size() - 1] == ':')
76                        startdirectory = dir + '/';
77                }
78#endif
79
80                boost::filesystem::directory_iterator file(startdirectory);
81                boost::filesystem::directory_iterator end;
82
83                while (file != end)
84                {
85                    if (boost::filesystem::is_directory(*file))
86                        dirlist.push_back(ArgumentCompletionListElement((*file).string() + '/', getLowercase((*file).string()) + '/', (*file).BOOST_LEAF_FUNCTION() + '/'));
87                    else
88                        filelist.push_back(ArgumentCompletionListElement((*file).string(), getLowercase((*file).string()), (*file).BOOST_LEAF_FUNCTION()));
89                    ++file;
90                }
91            }
92            catch (...) {}
93
94            filelist.insert(filelist.begin(), dirlist.begin(), dirlist.end());
95            return filelist;
96        }
97
98        ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(configvalueclasses)()
99        {
100            ArgumentCompletionList classlist;
101
102            for (std::map<std::string, Identifier*>::const_iterator it = Identifier::getIdentifierMapBegin(); it != Identifier::getIdentifierMapEnd(); ++it)
103                if ((*it).second->hasConfigValues())
104                    classlist.push_back(ArgumentCompletionListElement((*it).second->getName(), getLowercase((*it).first)));
105
106            return classlist;
107        }
108
109        ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(configvalues)(const std::string& fragment, const std::string& classname)
110        {
111            ArgumentCompletionList configvalues;
112            std::map<std::string, Identifier*>::const_iterator identifier = Identifier::getIdentifierMap().find(classname);
113
114            if (identifier != Identifier::getIdentifierMapEnd() && (*identifier).second->hasConfigValues())
115            {
116                for (std::map<std::string, ConfigValueContainer*>::const_iterator it = (*identifier).second->getConfigValueMapBegin(); it != (*identifier).second->getConfigValueMapEnd(); ++it)
117                    configvalues.push_back(ArgumentCompletionListElement((*it).second->getName(), getLowercase((*it).first)));
118            }
119
120            return configvalues;
121        }
122
123        ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(configvalue)(const std::string& fragment, const std::string& varname, const std::string& classname)
124        {
125            ArgumentCompletionList oldvalue;
126            std::map<std::string, Identifier*>::const_iterator identifier = Identifier::getLowercaseIdentifierMap().find(getLowercase(classname));
127            if (identifier != Identifier::getLowercaseIdentifierMapEnd())
128            {
129                std::map<std::string, ConfigValueContainer*>::const_iterator variable = (*identifier).second->getLowercaseConfigValueMap().find(getLowercase(varname));
130                if (variable != (*identifier).second->getLowercaseConfigValueMapEnd())
131                {
132                    std::string valuestring = (*variable).second->toString();
133                    oldvalue.push_back(ArgumentCompletionListElement(valuestring, getLowercase(valuestring), "Old value: " + valuestring));
134                }
135            }
136            return oldvalue;
137        }
138
139        ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(tclthreads)()
140        {
141            std::list<unsigned int> threadnumbers = TclThreadManager::getInstance().getThreadList();
142            ArgumentCompletionList threads;
143
144            for (std::list<unsigned int>::const_iterator it = threadnumbers.begin(); it != threadnumbers.end(); ++it)
145                threads.push_back(ArgumentCompletionListElement(multi_cast<std::string>(*it)));
146
147            return threads;
148        }
149    }
150}
Note: See TracBrowser for help on using the repository browser.