Skip to content

Commit

Permalink
[#2] Generate the INI file in the same order as when read
Browse files Browse the repository at this point in the history
Signed-off-by: Clovis Durand <cd.clovel19@gmail.com>
  • Loading branch information
Clovel committed Mar 3, 2020
1 parent ce56845 commit 4221a25
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
15 changes: 11 additions & 4 deletions generator/src/INI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ INI::INI(const std::string &pFile) {

/* Get the section name */
lSection = lKey.substr(1, lPos - 1);

/* Save the section in the section order vector */
mSectionOrder.push_back(lSection);
continue;
}

Expand Down Expand Up @@ -205,6 +208,10 @@ INI::INI(const std::string &pFile) {

/* Save our entry */
mSections[lSection][lKey] = lValue;

/* Save the entry in the order vector */
mSectionElementOrder[lSection].push_back(lKey);

std::cout << "[INFO ] <INI::INI> [" << lSection << "] " << lKey << " = " << mSections.at(lSection).at(lKey) << std::endl;
}

Expand Down Expand Up @@ -369,14 +376,14 @@ int INI::generateINI(const std::string &pDest) const {
}

/* For each section */
for(const auto &lSectionPair : mSections) {
for(const auto &lSection : mSectionOrder) {
/* Write the section name */
lOutputFileStream << "[" << lSectionPair.first << "]" << std::endl;
lOutputFileStream << "[" << lSection << "]" << std::endl;

/* For each key in the section */
for(const auto &lKeyPair : mSections.at(lSectionPair.first)) {
for(const auto &lKey : mSectionElementOrder.at(lSection)) {
/* Write the key, the equal sign and the value */
lOutputFileStream << lKeyPair.first << "=" << lKeyPair.second << std::endl;
lOutputFileStream << lKey << "=" << mSections.at(lSection).at(lKey) << std::endl;
}

/* Add an empty line between sections.
Expand Down
2 changes: 2 additions & 0 deletions generator/src/INI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class INI {
std::fstream mFileStream;

std::map<std::string, std::map<std::string, std::string>> mSections;
std::map<std::string, std::vector<std::string>> mSectionElementOrder;
std::vector<std::string> mSectionOrder;

private:
};
Expand Down

0 comments on commit 4221a25

Please sign in to comment.