Skip to content

Commit

Permalink
[#2] Added setters to the INI class
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 46dc4c8 commit f4740c6
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
87 changes: 87 additions & 0 deletions generator/src/INI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,93 @@ int INI::getDouble(const std::string &pKey, double &pValue, const std::string &p
return *lEnd == 0 ? -1 : 0;
}


/* Setters */
int INI::setInteger(const std::string &pKey, const int &pValue, const std::string &pSection) {
std::string lVal = std::to_string(pValue);

/* Check if the section exists */
if(mSections.end() != mSections.find(pSection)) {
/* Check if the key exists */
if(mSections.at(pSection).end() != mSections.at(pSection).find(pKey)) {
/* The key does exist ! */
mSections.at(pSection).at(pKey) = lVal;

return 0;
}
}

return -1;
}

int INI::setUnsigned(const std::string &pKey, const unsigned int &pValue, const std::string &pSection) {
std::string lVal = std::to_string(pValue);

/* Check if the section exists */
if(mSections.end() != mSections.find(pSection)) {
/* Check if the key exists */
if(mSections.at(pSection).end() != mSections.at(pSection).find(pKey)) {
/* The key does exist ! */
mSections.at(pSection).at(pKey) = lVal;

return 0;
}
}

return -1;
}

int INI::setString(const std::string &pKey, const std::string &pValue, const std::string &pSection) {
/* Check if the section exists */
if(mSections.end() != mSections.find(pSection)) {
/* Check if the key exists */
if(mSections.at(pSection).end() != mSections.at(pSection).find(pKey)) {
/* The key does exist ! */
mSections.at(pSection).at(pKey) = pValue;

return 0;
}
}

return -1;
}

int INI::setBoolean(const std::string &pKey, const bool &pValue, const std::string &pSection) {
std::string lVal = std::to_string(pValue);

/* Check if the section exists */
if(mSections.end() != mSections.find(pSection)) {
/* Check if the key exists */
if(mSections.at(pSection).end() != mSections.at(pSection).find(pKey)) {
/* The key does exist ! */
mSections.at(pSection).at(pKey) = lVal;

return 0;
}
}

return -1;
}

int INI::setDouble(const std::string &pKey, const double &pValue, const std::string &pSection) {
std::string lVal = std::to_string(pValue);

/* Check if the section exists */
if(mSections.end() != mSections.find(pSection)) {
/* Check if the key exists */
if(mSections.at(pSection).end() != mSections.at(pSection).find(pKey)) {
/* The key does exist ! */
mSections.at(pSection).at(pKey) = lVal;

return 0;
}
}

return -1;
}


/* Generator */
int INI::generateINI(const std::string &pDest) const {

/* Are we overwriting our original INI file ? */
Expand Down
7 changes: 7 additions & 0 deletions generator/src/INI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ class INI {
int getBoolean(const std::string &pKey, bool &pValue, const std::string &pSection = "default") const;
int getDouble(const std::string &pKey, double &pValue, const std::string &pSection = "default") const;

/* Setters */
int setInteger(const std::string &pKey, const int &pValue, const std::string &pSection = "default");
int setUnsigned(const std::string &pKey, const unsigned int &pValue, const std::string &pSection = "default");
int setString(const std::string &pKey, const std::string &pValue, const std::string &pSection = "default");
int setBoolean(const std::string &pKey, const bool &pValue, const std::string &pSection = "default");
int setDouble(const std::string &pKey, const double &pValue, const std::string &pSection = "default");

/* Generator */
int generateINI(const std::string &pDest) const;
protected:
Expand Down

0 comments on commit f4740c6

Please sign in to comment.