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:
parent
f3ee822cc6
commit
33e5585844
|
@ -25,7 +25,10 @@ void IniFile::parse(std::istream &inputStream)
|
||||||
// define actions for state machine
|
// define actions for state machine
|
||||||
// called when key/value pair is complete
|
// called when key/value pair is complete
|
||||||
const auto finishKeyValue = [&scope, &key, &value, &whitespace, this] {
|
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();
|
key.clear();
|
||||||
value.clear();
|
value.clear();
|
||||||
whitespace = 0;
|
whitespace = 0;
|
||||||
|
|
11
io/inifile.h
11
io/inifile.h
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include "../application/global.h"
|
#include "../application/global.h"
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
@ -13,13 +14,13 @@ class LIB_EXPORT IniFile
|
||||||
public:
|
public:
|
||||||
IniFile();
|
IniFile();
|
||||||
|
|
||||||
std::map<std::string, std::multimap<std::string, std::string> > &data();
|
std::vector<std::pair<std::string, std::multimap<std::string, std::string> > > &data();
|
||||||
const std::map<std::string, std::multimap<std::string, std::string> > &data() const;
|
const std::vector<std::pair<std::string, std::multimap<std::string, std::string> > > &data() const;
|
||||||
void parse(std::istream &inputStream);
|
void parse(std::istream &inputStream);
|
||||||
void make(std::ostream &outputStream);
|
void make(std::ostream &outputStream);
|
||||||
|
|
||||||
private:
|
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 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.
|
* - 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;
|
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 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.
|
* - 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;
|
return m_data;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue