Skip to content

Commit e28cf77

Browse files
committed
Merge branch 'release/Initial-Release'
2 parents 08fba0f + 160b10f commit e28cf77

File tree

5 files changed

+32
-170
lines changed

5 files changed

+32
-170
lines changed

README.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# raw_config_file_handling
2-
This small single header library allows handling of ini-style config-files. In addition to the standard ini-format, this library allows values with more than one parameter (separation with commas).
2+
This small single header library allows handling of ini-style config-files. In addition to the standard ini-format, this library allows values with more than one parameter (separation with commas). Comments in the config-file are getting ignored. The standard comment-character is the semicolon (;), but also custom characters could be set.
33
Example of this config-file format:
44
```ini
5-
[GENERAL]
6-
BALL_COUNT=2
5+
;Comment1
6+
[GENERAL];Comment2
7+
BALL_COUNT=2;Comment3
78

89
[BALL]
9-
BALL_COLOR_RGB=0,0,255
10+
BALL_RGB_COLOR=0,0,255
1011
...
1112
```
1213
### Installation
@@ -21,7 +22,7 @@ struct Configuration { //program configuration
2122
vector<int> BallColorRGB;
2223
};
2324
```
24-
2. Inherit from the base class (RawConfigFileHandler) and implement setConfig/getConfig Methods and optional features (for a more advanced use, see the example folder):
25+
3. Inherit from the base class (RawConfigFileHandler) and implement setConfig/getConfig Methods and optional features (for a more advanced use, see the example folder):
2526
```cpp
2627
class ConfigFileHandler : public RawConfigFileHandler {
2728
public:
@@ -86,9 +87,6 @@ public:
8687
### Built With
8788
* [Visual Studio 2019](https://visualstudio.microsoft.com/)
8889

89-
### Note
90-
The example solution was built with Visual Studio 2019. If you are using other versions of VS you might need to change some settings.
91-
9290
### Author
9391
**Daniel Duller** - [dadul96](https://github.com/dadul96)
9492

raw_config_file_handling/example/example.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "raw_config_file_handling.hpp"
1+
#include "../raw_config_file_handling.hpp"
22

33
//set up a structure that includes all desired config-parameters:
44
struct Configuration { //program configuration
@@ -20,7 +20,7 @@ class ConfigFileHandler : public RawConfigFileHandler {
2020
//constructor for initializing the flags:
2121
ConfigFileHandler() : SuccessfulReading(false), SuccessfulWriting(false) {}
2222

23-
//create a function that assigns the RawConfigData (from base class) to the Configuration-struct:
23+
//create a method that assigns the RawConfigData (from base class) to the Configuration-struct:
2424
void getConfig() {
2525
constexpr int DesiredParameterCount = 2; //number of expected parameters (for checking if the reading was successful)
2626
int ParameterCount = 0;
@@ -56,7 +56,7 @@ class ConfigFileHandler : public RawConfigFileHandler {
5656
}
5757
}
5858

59-
//create a function that assigns the Configuration-struct to the RawConfigData (in base class) in order to write a config file:
59+
//create a method that assigns the Configuration-struct to the RawConfigData (in base class) in order to write a config file:
6060
void setConfig() {
6161
int i = 0;
6262
RawConfigData.clear();
@@ -85,8 +85,12 @@ class ConfigFileHandler : public RawConfigFileHandler {
8585
int main() {
8686
ConfigFileHandler ConfigHandler1;
8787

88+
ConfigHandler1.setCommentChar('#'); //changing the comment character from ";" (default) to "#"
89+
8890
ConfigHandler1.setFilePath("C:\\dev\\VS2019_repos\\raw_config_file_handling\\raw_config_file_handling\\example\\example_config.ini"); //setting the path of the config-file (enter your desired path)
8991

92+
cout << ConfigHandler1.getCommentChar() << endl; //printing the set comment character
93+
9094
cout << ConfigHandler1.getFilePath() << endl; //printing the path of the config-file
9195

9296
ConfigHandler1.getConfig(); //reading config-file
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
[GENERAL]
2-
BALL_COUNT=2
1+
#Comment1
2+
[GENERAL]#Comment2
3+
BALL_COUNT=2#Comment3
34

45
[BALL]
56
BALL_RGB_COLOR=0,0,255

raw_config_file_handling/example/raw_config_file_handling.hpp renamed to raw_config_file_handling/raw_config_file_handling.hpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ struct ConfigDataStruct {
2222
class RawConfigFileHandler {
2323
private:
2424
string FilePath;
25+
char CommentChar;
2526

2627
protected:
2728
vector<ConfigDataStruct> RawConfigData;
@@ -41,13 +42,19 @@ class RawConfigFileHandler {
4142

4243
while (getline(inFile, Input))
4344
{
45+
int CommentCharPos = -1;
4446
int Char1Pos = -1;
4547
int Char2Pos = -1;
4648

4749
string Key;
4850
string RawValue;
4951
vector<string> Value;
5052

53+
if ((CommentCharPos = Input.find(CommentChar)) >= 0)
54+
{
55+
Input.erase(CommentCharPos, Input.size());
56+
}
57+
5158
if ((Char1Pos = Input.find(Char1)) > 0)
5259
{
5360
Key = RawValue = Input;
@@ -126,7 +133,7 @@ class RawConfigFileHandler {
126133
}
127134

128135
public:
129-
RawConfigFileHandler() : FilePath("config.ini") {}
136+
RawConfigFileHandler() : FilePath("config.ini"), CommentChar(';') {}
130137

131138
void setFilePath(string pFilePath) {
132139
FilePath = pFilePath;
@@ -136,6 +143,14 @@ class RawConfigFileHandler {
136143
return FilePath;
137144
}
138145

146+
void setCommentChar(char pCommentChar) {
147+
CommentChar = pCommentChar;
148+
}
149+
150+
char getCommentChar() {
151+
return CommentChar;
152+
}
153+
139154
void printRawConfigData() {
140155
for (size_t i = 0; i < RawConfigData.size(); i++)
141156
{

raw_config_file_handling/source/raw_config_file_handling.hpp

Lines changed: 0 additions & 156 deletions
This file was deleted.

0 commit comments

Comments
 (0)