Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions ini/ini.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ inline int ini_parse(const char* filename, ini_handler handler, void* user) {
class INIReader {
public:
// Empty Constructor
INIReader(){};
INIReader() {};

// Construct INIReader and parse given filename. See ini.h for more info
// about the parsing.
Expand Down Expand Up @@ -593,18 +593,25 @@ inline int INIReader::ValueHandler(void* user, const char* section,

class INIWriter {
public:
INIWriter(){};
INIWriter() {};
/**
* @brief Write the contents of an INI file to a new file
* @param filepath The path of the output file
* @param reader The INIReader object to write to the file
* @param overwrite Whether to just overwrite an existing file
* @throws std::runtime_error if the output file already exists or cannot be
* opened
*/
inline static void write(const std::string& filepath,
const INIReader& reader) {
if (struct stat buf; stat(filepath.c_str(), &buf) == 0) {
throw std::runtime_error("file: " + filepath + " already exist.");
const INIReader& reader,
const bool& overwrite = false) {
if (overwrite) {
std::remove(filepath.c_str());
} else {
if (struct stat buf; stat(filepath.c_str(), &buf) == 0) {
throw std::runtime_error("file: " + filepath +
" already exists.");
}
}
std::ofstream out;
out.open(filepath);
Expand Down
Loading