Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/sound4/src/libraries/core/ArgumentCompletionFunctions.cc @ 6457

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

Changed the way config values associated with general settings (ConfigFileType::Settings) are handled:

  • ConfigFileManager only handles config files listed in the ConfigFileType enum (normal enum again)
  • ConfigFileManager only takes care of ConfigFiles and returns a pointer to the right one, just two functions left. —> use like: ConfigFileManager::getInstance().getConfigFile(myType)→doSomething();
  • Moved all code (except for the argument completion functions) relating to ConfigFileType::Settings to a new class: SettingsConfigFile, which is a Singleton (it doesn't make sense to have multiple instances unless you start coding a lot more)
  • SettingsConfigFile handles config value containers according to their section and entry in the ini file, not according to class and variables names. (In most cases it will be class and variable names though)
  • SettingsConfigFile supports:
    • clear() (removes any file entries not associated to a config value container)
    • updateConfigValues() (does exactly that through the identifier)
    • config, tconfig and getConfig
    • commands listed above are exported to tolua, and tconfig, config and getConfig were given shortcuts in Lua (e.g. orxonox.config)
  • If you need to organise ConfigFiles yourself, just do it without the ConfigFileManager, like the KeyBinder does.
  • All getValue() functions have been split into getOrCreateValue() and getValue(), which is const
  • Removed obsolete config value management code in the Identifier (it still stores and destroys them and provides access to them)

All of that leads to one HUGE advantage:
"config OutputHandler softDebugLevelInGameConsole"
works now :D (any further implications are up to the reader…)
(it didn't work before because the actual config value container is in the InGameConsole singleton)

  • Property svn:eol-style set to native
File size: 5.8 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 "ConfigFileManager.h"
39#include "ConfigValueContainer.h"
40#include "TclThreadManager.h"
41
42// Boost 1.36 has some issues with deprecated functions that have been omitted
43#if (BOOST_VERSION == 103600)
44#  define BOOST_LEAF_FUNCTION filename
45#else
46#  define BOOST_LEAF_FUNCTION leaf
47#endif
48
49namespace orxonox
50{
51    namespace autocompletion
52    {
53        ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(fallback)()
54        {
55            return ArgumentCompletionList();
56        }
57
58        ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(files)(const std::string& fragment)
59        {
60            ArgumentCompletionList dirlist;
61            ArgumentCompletionList filelist;
62
63            try
64            {
65                boost::filesystem::path input(fragment);
66                boost::filesystem::path startdirectory(input.branch_path());
67
68                if (!boost::filesystem::exists(startdirectory))
69                {
70                    startdirectory = ".";
71                }
72#ifdef ORXONOX_PLATFORM_WINDOWS
73                else
74                {
75                    const std::string& dir = startdirectory.string();
76                    if (dir.size() > 0 && dir[dir.size() - 1] == ':')
77                        startdirectory = dir + '/';
78                }
79#endif
80
81                boost::filesystem::directory_iterator file(startdirectory);
82                boost::filesystem::directory_iterator end;
83
84                while (file != end)
85                {
86                    if (boost::filesystem::is_directory(*file))
87                        dirlist.push_back(ArgumentCompletionListElement(file->string() + '/', getLowercase(file->string()) + '/', file->BOOST_LEAF_FUNCTION() + '/'));
88                    else
89                        filelist.push_back(ArgumentCompletionListElement(file->string(), getLowercase(file->string()), file->BOOST_LEAF_FUNCTION()));
90                    ++file;
91                }
92            }
93            catch (...) {}
94
95            filelist.insert(filelist.begin(), dirlist.begin(), dirlist.end());
96            return filelist;
97        }
98
99        ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(settingssections)()
100        {
101            ArgumentCompletionList sectionList;
102
103            const std::set<std::string>& names = SettingsConfigFile::getInstance().getSectionNames();
104            for (std::set<std::string>::const_iterator it = names.begin(); it != names.end(); ++it)
105                sectionList.push_back(ArgumentCompletionListElement(*it, getLowercase(*it)));
106
107            return sectionList;
108        }
109
110        ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(settingsentries)(const std::string& fragment, const std::string& section)
111        {
112            ArgumentCompletionList entryList;
113            SettingsConfigFile& settings = SettingsConfigFile::getInstance();
114            const std::string& sectionLC = getLowercase(section);
115
116            SettingsConfigFile::ContainerMap::const_iterator upper = settings.getContainerUpperBound(sectionLC);
117            for (SettingsConfigFile::ContainerMap::const_iterator it = settings.getContainerLowerBound(sectionLC); it != upper; ++it)
118                entryList.push_back(ArgumentCompletionListElement(it->second.second->getName(), it->second.first));
119
120            return entryList;
121        }
122
123        ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(settingsvalue)(const std::string& fragment, const std::string& entry, const std::string& section)
124        {
125            ArgumentCompletionList oldValue;
126            SettingsConfigFile& settings = SettingsConfigFile::getInstance();
127            const std::string& sectionLC = getLowercase(section);
128            const std::string& entryLC = getLowercase(entry);
129
130            SettingsConfigFile::ContainerMap::const_iterator upper = settings.getContainerUpperBound(sectionLC);
131            for (SettingsConfigFile::ContainerMap::const_iterator it = settings.getContainerLowerBound(sectionLC); it != upper; ++it)
132            {
133                if (it->second.first == entryLC)
134                {
135                    const std::string& valuestring = it->second.second->toString();
136                    oldValue.push_back(ArgumentCompletionListElement(valuestring, getLowercase(valuestring), "Old value: " + valuestring));
137                }
138            }
139
140            return oldValue;
141        }
142
143        ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(tclthreads)()
144        {
145            std::list<unsigned int> threadnumbers = TclThreadManager::getInstance().getThreadList();
146            ArgumentCompletionList threads;
147
148            for (std::list<unsigned int>::const_iterator it = threadnumbers.begin(); it != threadnumbers.end(); ++it)
149                threads.push_back(ArgumentCompletionListElement(multi_cast<std::string>(*it)));
150
151            return threads;
152        }
153    }
154}
Note: See TracBrowser for help on using the repository browser.