Orxonox  0.0.5 Codename: Arcturus
ConfigFileSection.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 
34 #ifndef _ConfigFileSection_H__
35 #define _ConfigFileSection_H__
36 
37 #include "core/CorePrereqs.h"
38 
39 #include <string>
40 #include <list>
41 #include "util/StringUtils.h"
42 #include "ConfigFileEntry.h"
43 
44 namespace orxonox
45 {
47  // ConfigFileSection //
49 
55  {
56  friend class ConfigFile;
57  friend class SettingsConfigFile;
58 
59  public:
66  inline ConfigFileSection(const std::string& name, const std::string& additionalComment = "")
67  : name_(name)
68  , additionalComment_(additionalComment)
69  , bUpdated_(false)
70  {}
72 
74  inline const std::string& getName() const
75  { return this->name_; }
76 
78  inline void setComment(const std::string& comment)
79  { this->additionalComment_ = comment; }
80 
88  inline void setValue(const std::string& name, const std::string& value, bool bString)
89  { this->getOrCreateEntry(name, value, bString)->setValue(value); }
96  inline const std::string& getValue(const std::string& name, bool bString)
97  {
98  ConfigFileEntry* entry = this->getEntry(name);
99  if (entry)
100  {
101  entry->setString(bString); // if the entry was loaded from the config file, we have to tell it if it's a string
102  return entry->getValue();
103  }
104  return BLANKSTRING;
105  }
113  inline const std::string& getOrCreateValue(const std::string& name, const std::string& fallback, bool bString)
114  { return this->getOrCreateEntry(name, fallback, bString)->getValue(); }
115 
124  inline void setValue(const std::string& name, unsigned int index, const std::string& value, bool bString)
125  { this->getOrCreateEntry(name, index, value, bString)->setValue(value); }
133  inline const std::string& getValue(const std::string& name, unsigned int index, bool bString)
134  {
135  ConfigFileEntry* entry = this->getEntry(name, index);
136  if (entry)
137  {
138  entry->setString(bString); // if the entry was loaded from the config file, we have to tell it if it's a string
139  return entry->getValue();
140  }
141  return BLANKSTRING;
142  }
151  inline const std::string& getOrCreateValue(const std::string& name, unsigned int index, const std::string& fallback, bool bString)
152  { return this->getOrCreateEntry(name, index, fallback, bString)->getValue(); }
153 
154  void deleteVectorEntries(const std::string& name, unsigned int startindex = 0);
155  unsigned int getVectorSize(const std::string& name) const;
156 
157  std::string getFileEntry() const;
158 
159  private:
161  std::list<ConfigFileEntry*>& getEntries()
162  { return this->entries_; }
163  const std::list<ConfigFileEntry*>& getEntries() const
164  { return this->entries_; }
165 
166  std::list<ConfigFileEntry*>::iterator getOrCreateEntryIterator(const std::string& name, const std::string& fallback, bool bString);
167  std::list<ConfigFileEntry*>::iterator getOrCreateEntryIterator(const std::string& name, unsigned int index, const std::string& fallback, bool bString);
168 
169  ConfigFileEntry* getEntry(const std::string& name) const;
177  inline ConfigFileEntry* getOrCreateEntry(const std::string& name, const std::string& fallback, bool bString)
178  { return (*this->getOrCreateEntryIterator(name, fallback, bString)); }
179 
180  ConfigFileEntry* getEntry(const std::string& name, unsigned int index) const;
189  inline ConfigFileEntry* getOrCreateEntry(const std::string& name, unsigned int index, const std::string& fallback, bool bString)
190  { return (*this->getOrCreateEntryIterator(name, index, fallback, bString)); }
191 
194  std::list<ConfigFileEntry*> entries_;
195  bool bUpdated_;
196  };
197 }
198 
199 #endif /* _ConfigFileSection_H__ */
std::string BLANKSTRING
A blank string (""). Used to return a blank string by reference.
Definition: StringUtils.cc:46
const std::string & getOrCreateValue(const std::string &name, const std::string &fallback, bool bString)
Returns the value of a given entry in the section.
Definition: ConfigFileSection.h:113
const std::string & getValue(const std::string &name, bool bString)
Returns the value of a given entry in the section.
Definition: ConfigFileSection.h:96
std::string additionalComment_
The additional comment which is placed after the title of the section in the config file...
Definition: ConfigFileSection.h:193
const std::list< ConfigFileEntry * > & getEntries() const
Definition: ConfigFileSection.h:163
ConfigFileSection(const std::string &name, const std::string &additionalComment="")
Constructor: Initializes the section.
Definition: ConfigFileSection.h:66
std::list< ConfigFileEntry * > entries_
The list of entries in this section.
Definition: ConfigFileSection.h:194
Shared library macros, enums, constants and forward declarations for the core library ...
::std::string string
Definition: gtest-port.h:756
void setValue(const std::string &name, unsigned int index, const std::string &value, bool bString)
Stores the value of an element of a vector in the section.
Definition: ConfigFileSection.h:124
std::list< ConfigFileEntry * > & getEntries()
Returns the list of entries in this section.
Definition: ConfigFileSection.h:161
This class represents a config file, which is stored on the hard-disk and contains config values in d...
Definition: ConfigFile.h:51
void setComment(const std::string &comment)
Changes the comment which is placed after the title of the section in the config file.
Definition: ConfigFileSection.h:78
std::string name_
The name of the section.
Definition: ConfigFileSection.h:192
virtual const std::string & getValue() const =0
Returns the value of the entry.
ConfigFileEntry * getOrCreateEntry(const std::string &name, unsigned int index, const std::string &fallback, bool bString)
Returns the entry that contains an element of a vector with given name.
Definition: ConfigFileSection.h:189
void setValue(const std::string &name, const std::string &value, bool bString)
Stores a value in the section.
Definition: ConfigFileSection.h:88
const std::string & getOrCreateValue(const std::string &name, unsigned int index, const std::string &fallback, bool bString)
Returns the value of a given element of a vector in the section.
Definition: ConfigFileSection.h:151
Child class of ConfigFile, used to store the settings of the game.
Definition: SettingsConfigFile.h:59
Die Wagnis Klasse hat die folgenden Aufgaben:
Definition: ApplicationPaths.cc:66
#define _CoreExport
Definition: CorePrereqs.h:61
bool bUpdated_
True if an entry is created.
Definition: ConfigFileSection.h:195
ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION() fallback()
Fallback implementation, returns an empty list.
Definition: ArgumentCompletionFunctions.cc:67
const std::string & getName() const
Returns the name of the section.
Definition: ConfigFileSection.h:74
virtual void setString(bool bString)=0
Defines if this entry is treated as string which means some special treatment of special characters...
Declaration of several string manipulation functions, used in many parts of the game.
Represents a section in a config file.
Definition: ConfigFileSection.h:54
ConfigFileEntry * getOrCreateEntry(const std::string &name, const std::string &fallback, bool bString)
Returns the entry with given name.
Definition: ConfigFileSection.h:177
internal::String name_
Definition: gtest.cc:2289
const std::string & getValue(const std::string &name, unsigned int index, bool bString)
Returns the value of a given element of a vector in the section.
Definition: ConfigFileSection.h:133
This class represents an entry in the config file.
Definition: ConfigFileEntry.h:49