Structures make it so much easier to organize and consume data. Let's think how a structure could be employed to improve you Config File Generator and Config Reader Library.
In our Reader Library you consumed your config file into an array and returned its pointer to your Driver project. Instead of returning an array of loosely associated values you could have returned a struct if you knew what a struct was at the time.
The same is true of your Config File Generator it could take advantage of many structures. Your config file could be read into a struct but also some things like timezone could be stored in an enum so you can easily validate data the user provides.
- You will refactor your
ConfigReaderLibrary to return astructpointer instead of an string* (string pointer)
-
Your struct should match the fields in your file
first_name last_name timezone ...
-
The definition for your struct should be kept in the libraries .h file so you can use it in your ConfigGenerator without redefining it there.
-
You will write a config file writer function that takes your
structas an argument and exposes the function as a prototype in your .h file -
You might consider renaming your namespace since you are not longer a config reader but this is optional. The signature for this function might look a little like this
bool writeConfig(std::string path, configStruct data)- This will write the data in the struct to the path given.
- This will return a
trueif the file is written successfully. - This will return
falseif the file cannot be opened or written to.
- You will refactor your
Config File Generatorto take advantage of your Config reader library
- It will rely on the
ConfigReaderto read a file path you define as a const in your Generator - When performing
InitandEditoperations your Generator should employ the same struct as yourConfigReaderfor keeping track of your data. - Utilize the
ConfigReader's new writer function to save your file to the file system after init or edit.
- Organize your project files
- Put your
ConfigGeneratorproject in theconfig_generatorfolder of this project - Put your
ConfigReaderlibrary project in theconfig_reader_libfolder - Push and open PR