/src/ogre/OgreMain/include/OgreConfigFile.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | ----------------------------------------------------------------------------- |
3 | | This source file is part of OGRE |
4 | | (Object-oriented Graphics Rendering Engine) |
5 | | For the latest info, see http://www.ogre3d.org/ |
6 | | |
7 | | Copyright (c) 2000-2014 Torus Knot Software Ltd |
8 | | |
9 | | Permission is hereby granted, free of charge, to any person obtaining a copy |
10 | | of this software and associated documentation files (the "Software"), to deal |
11 | | in the Software without restriction, including without limitation the rights |
12 | | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
13 | | copies of the Software, and to permit persons to whom the Software is |
14 | | furnished to do so, subject to the following conditions: |
15 | | |
16 | | The above copyright notice and this permission notice shall be included in |
17 | | all copies or substantial portions of the Software. |
18 | | |
19 | | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
20 | | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
21 | | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
22 | | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
23 | | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
24 | | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
25 | | THE SOFTWARE. |
26 | | ----------------------------------------------------------------------------- |
27 | | */ |
28 | | #ifndef __ConfigFile_H__ |
29 | | #define __ConfigFile_H__ |
30 | | |
31 | | #include "OgrePrerequisites.h" |
32 | | |
33 | | #include "OgreCommon.h" |
34 | | #include "OgreStringVector.h" |
35 | | #include "OgreHeaderPrefix.h" |
36 | | |
37 | | namespace Ogre { |
38 | | template <typename T> class MapIterator; |
39 | | |
40 | | /** \addtogroup Core |
41 | | * @{ |
42 | | */ |
43 | | /** \addtogroup General |
44 | | * @{ |
45 | | */ |
46 | | /** Class for quickly loading settings from a text file. |
47 | | |
48 | | This class is designed to quickly parse a simple file containing |
49 | | key/value pairs, mainly for use in configuration settings. |
50 | | @par |
51 | | This is a very simplified approach, no multiple values per key |
52 | | are allowed, no grouping or context is being kept etc. |
53 | | @par |
54 | | By default the key/values pairs are tokenised based on a |
55 | | separator of Tab, the colon (:) or equals (=) character. Each |
56 | | key - value pair must end in a carriage return. |
57 | | @par |
58 | | Settings can be optionally grouped in sections, using a header |
59 | | beforehand of the form [SectionName]. |
60 | | */ |
61 | | class _OgreExport ConfigFile : public ConfigAlloc |
62 | | { |
63 | | public: |
64 | | |
65 | | ConfigFile(); |
66 | | /// load from a filename (not using resource group locations) |
67 | | void load(const String& filename, const String& separators = "\t:=", bool trimWhitespace = true); |
68 | | /// load from a filename (using resource group locations) |
69 | | void load(const String& filename, const String& resourceGroup, const String& separators = "\t:=", bool trimWhitespace = true); |
70 | | /// load from a data stream |
71 | | void load(const DataStreamPtr& stream, const String& separators = "\t:=", bool trimWhitespace = true); |
72 | | /// load from a filename (not using resource group locations) |
73 | | void loadDirect(const String& filename, const String& separators = "\t:=", bool trimWhitespace = true); |
74 | | /// load from a filename (using resource group locations) |
75 | | void loadFromResourceSystem(const String& filename, const String& resourceGroup, const String& separators = "\t:=", bool trimWhitespace = true); |
76 | | |
77 | | /** Gets the first setting from the file with the named key. |
78 | | @param key The name of the setting |
79 | | @param section The name of the section it must be in (if any) |
80 | | @param defaultValue The value to return if the setting is not found |
81 | | */ |
82 | | String getSetting(const String& key, const String& section = BLANKSTRING, const String& defaultValue = BLANKSTRING) const; |
83 | | /** Gets all settings from the file with the named key. */ |
84 | | StringVector getMultiSetting(const String& key, const String& section = BLANKSTRING) const; |
85 | | |
86 | | typedef std::multimap<String, String> SettingsMultiMap; |
87 | | typedef MapIterator<SettingsMultiMap> SettingsIterator; |
88 | | /** Gets an iterator for stepping through all the keys / values in the file. */ |
89 | | typedef std::map<String, SettingsMultiMap*> SettingsBySection; |
90 | | typedef std::map<String, SettingsMultiMap> SettingsBySection_; |
91 | | typedef MapIterator<SettingsBySection> SectionIterator; |
92 | | |
93 | | /// @deprecated use getSettingsBySection() |
94 | | OGRE_DEPRECATED SectionIterator getSectionIterator(void); |
95 | | |
96 | | /** Get all the available settings grouped by sections */ |
97 | 0 | const SettingsBySection_& getSettingsBySection() const { |
98 | 0 | return mSettings; |
99 | 0 | } |
100 | | |
101 | | /// @deprecated use getSettings() |
102 | | OGRE_DEPRECATED SettingsIterator getSettingsIterator(const String& section = BLANKSTRING); |
103 | | |
104 | | /** Get all the available settings in a section */ |
105 | | const SettingsMultiMap& getSettings(const String& section = BLANKSTRING) const; |
106 | | |
107 | | /** Clear the settings */ |
108 | | void clear(void); |
109 | | protected: |
110 | | SettingsBySection_ mSettings; |
111 | | SettingsBySection mSettingsPtr; // for backwards compatibility |
112 | | }; |
113 | | /** @} */ |
114 | | /** @} */ |
115 | | |
116 | | } |
117 | | |
118 | | #include "OgreHeaderSuffix.h" |
119 | | |
120 | | #endif |