Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/core/ArgumentCompletionFunctions.cc @ 2728

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

Updated to the new tardis libraries. Seems to work fine.

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