40 #ifndef _resourcetextsettingsfile_cpp
41 #define _resourcetextsettingsfile_cpp
43 #include "Resource/textsettingsfile.h"
44 #include "stringtool.h"
45 #include "exception.h"
47 #include <OgreResourceGroupManager.h>
68 Ogre::DataStreamPtr Stream = Ogre::ResourceGroupManager::getSingletonPtr()->openResource(Filename,Group);
69 String CurrentSectionName(
"");
70 SettingsMap* CurrentSection =
new SettingsMap();
71 Sections[CurrentSectionName] = CurrentSection;
73 String Line, SetName, SetVal;
76 Line = Stream->getLine();
77 if (Line.length() > 0 && Line.at(0) !=
'#' && Line.at(0) !=
'@')
79 if (Line.at(0) ==
'[' && Line.at(Line.length()-1) ==
']')
81 CurrentSectionName = Line.substr(1, Line.length() - 2);
82 SectionIterator SecIt = Sections.find(CurrentSectionName);
83 if (SecIt == Sections.end())
85 CurrentSection =
new SettingsMap();
86 Sections[CurrentSectionName] = CurrentSection;
88 CurrentSection = SecIt->second;
91 String::size_type SeparatorPos = Line.find_first_of(Separators,0);
92 if(SeparatorPos != String::npos)
94 SetName = Line.substr(0,SeparatorPos);
95 String::size_type NonSeparatorPos = Line.find_first_not_of(Separators,SeparatorPos);
96 SetVal = (NonSeparatorPos == String::npos) ?
"" : Line.substr(NonSeparatorPos);
102 CurrentSection->insert(SettingsMap::value_type(SetName,SetVal));
113 for( TextSettingsFile::SectionIterator SecIt = Sections.begin() ; SecIt != Sections.end() ; ++SecIt )
115 delete (*SecIt).second;
123 TextSettingsFile::SectionIterator SecIt = Sections.find(Section);
124 if(SecIt == Sections.end())
128 TextSettingsFile::SettingsIterator SetIt = (*SecIt).second->find(Key);
129 if(SetIt == (*SecIt).second->end())
131 MEZZ_EXCEPTION(
Exception::PARAMETERS_EXCEPTION,
"Attempting to access setting \"" + Key +
" in section \"" + Section +
"\" in file \"" + FileName +
"\" which does not exist.");
133 return (*SetIt).second;
140 std::vector<String> Ret;
142 TextSettingsFile::SectionIterator SecIt = Sections.find(Section);
143 if(SecIt != Sections.end())
145 TextSettingsFile::SettingsIterator SetIt = (*SecIt).second->find(Key);
146 while(SetIt != SecIt->second->end() && SetIt->first == Key)
148 Ret.push_back(SetIt->second);
157 return Sections.begin();
162 return Sections.end();
167 TextSettingsFile::SectionIterator SecIt = Sections.find(Section);
168 if(SecIt == Sections.end())
172 return (*SecIt).second->begin();
178 TextSettingsFile::SectionIterator SecIt = Sections.find(Section);
179 if(SecIt == Sections.end())
183 return (*SecIt).second->end();