using a vector instead of a map for the scopes

Finding a specific scope might be more unhandy
but this way the original order is preserved.
This commit is contained in:
Martchus 2015-09-16 17:36:52 +02:00
parent f3ee822cc6
commit 33e5585844
2 changed files with 10 additions and 6 deletions

View File

@ -25,7 +25,10 @@ void IniFile::parse(std::istream &inputStream)
// define actions for state machine
// called when key/value pair is complete
const auto finishKeyValue = [&scope, &key, &value, &whitespace, this] {
m_data[scope].insert(make_pair(key, value));
if(m_data.empty() || m_data.back().first != scope) {
m_data.emplace_back(make_pair(scope, decltype(m_data)::value_type::second_type()));
}
m_data.back().second.insert(make_pair(key, value));
key.clear();
value.clear();
whitespace = 0;

View File

@ -3,6 +3,7 @@
#include "../application/global.h"
#include <vector>
#include <map>
#include <string>
@ -13,13 +14,13 @@ class LIB_EXPORT IniFile
public:
IniFile();
std::map<std::string, std::multimap<std::string, std::string> > &data();
const std::map<std::string, std::multimap<std::string, std::string> > &data() const;
std::vector<std::pair<std::string, std::multimap<std::string, std::string> > > &data();
const std::vector<std::pair<std::string, std::multimap<std::string, std::string> > > &data() const;
void parse(std::istream &inputStream);
void make(std::ostream &outputStream);
private:
std::map<std::string, std::multimap<std::string, std::string> > m_data;
std::vector<std::pair<std::string, std::multimap<std::string, std::string> > > m_data;
};
/*!
@ -35,7 +36,7 @@ inline IniFile::IniFile()
* - The values in the returned map are maps representing "key = value"-pairs within the scope.
* - The data might be modified an saved using the make() method.
*/
inline std::map<std::string, std::multimap<std::string, std::string> > &IniFile::data()
inline std::vector<std::pair<std::string, std::multimap<std::string, std::string> > > &IniFile::data()
{
return m_data;
}
@ -46,7 +47,7 @@ inline std::map<std::string, std::multimap<std::string, std::string> > &IniFile:
* - The keys in the returned map represent the [scope name]s.
* - The values in the returned map are maps representing "key = value"-pairs within the scope.
*/
inline const std::map<std::string, std::multimap<std::string, std::string> > &IniFile::data() const
inline const std::vector<std::pair<std::string, std::multimap<std::string, std::string> > > &IniFile::data() const
{
return m_data;
}