Skip to content

Commit

Permalink
[#1] Updated EDS 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 2, 2020
1 parent 39558d2 commit 20546cf
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 6 deletions.
52 changes: 46 additions & 6 deletions generator/src/EDS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
/* Includes -------------------------------------------- */
#include "EDS.hpp"

#include "INIReader.h"

#include <string>
#include <fstream>
#include <iostream>

/* Defines --------------------------------------------- */

Expand All @@ -18,30 +21,67 @@

/* EDS class implementation ---------------------------- */
EDS::EDS() {
/* Empty */
mIni = nullptr;
}

EDS::~EDS() {
/* Empty */
if(nullptr != mIni) {
delete mIni;
}
}

/* Getters */
std::string EDS::fileName(void) const {
return mFileName;
}

/* Setters */
int EDS::setFile(const std::string &pFileName) {
std::fstream lFileStream;
lFileStream.open(pFileName, std::ios::in | std::ios::out);
mFileStream.open(pFileName, std::ios::in | std::ios::out);

/* Check if the file was opened correctly */
if(!lFileStream.is_open()) {
if(!mFileStream.is_open()) {
/* Failed */
return -1;
}

mFileName = pFileName;

lFileStream.close();
mFileStream.close();

return 0;
}

/* Parser */
/**
* @brief Parses the EDS file and sets it's contents
* in this EDS object
*/
int EDS::parseEDSFile(const std::string &pFile) {
mFileStream.open(pFile, std::ios::in | std::ios::out);

/* Check if the file was opened correctly */
if(!mFileStream.is_open()) {
/* Failed */
std::cerr << "[ERROR] <EDS::parseEDSFile> Failed to open file " << pFile << " !" << std::endl;
return -1;
}
/* Close the file, the INIReader will reopen it */
mFileStream.close();

mFileName = pFile;

/* Create a new ini parser */
if(nullptr != mIni) {
/* We already had a INIReader ! */
delete mIni;
}

mIni = new INIReader(mFileName);
if(0 != mIni->ParseError()) {
std::cerr << "[ERROR] <EDS::parseEDSFile> INIReader constructor failed (" << mFileName << ") !" << std::endl;
return -2;
}

return 0;
}
10 changes: 10 additions & 0 deletions generator/src/EDS.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@

/* Includes -------------------------------------------- */
#include <string>
#include <fstream>

/* Defines --------------------------------------------- */

/* Type definitions ------------------------------------ */

/* Forzqrd declarations -------------------------------- */
class INIReader;

/* EDS class ------------------------------------------- */
class EDS {
public:
Expand All @@ -26,8 +30,14 @@ class EDS {

/* Setters */
int setFile(const std::string &pFileName);

/* Parser */
int parseEDSFile(const std::string &pFile);
protected:
std::string mFileName;
std::fstream mFileStream;

INIReader *mIni;

private:
};
Expand Down

0 comments on commit 20546cf

Please sign in to comment.