mirror of
https://github.com/mariiaan/minipp.git
synced 2026-05-14 10:11:17 +02:00
Compare commits
24 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8d9d29a684 | |||
| 302b2b9a94 | |||
| c304b50eb3 | |||
| c6aa27f47b | |||
| ceb392a198 | |||
| 1fd3f05ebd | |||
| a518dcac54 | |||
| f465f2eb0f | |||
| 87f39d93f0 | |||
| b8f88e7586 | |||
| 08f4df7b04 | |||
| 4e54e828eb | |||
| 2880cfd2f3 | |||
| 538c977f14 | |||
| d7bc969b70 | |||
| 04dcc77db6 | |||
| 3f96d049e5 | |||
| e3c3b76caa | |||
| 4ee8c32822 | |||
| e13cc5a94e | |||
| ef0f4ba908 | |||
| 43db485cec | |||
| 46e2129787 | |||
| 27b720245c |
36
README.md
36
README.md
@@ -1,6 +1,6 @@
|
|||||||
# minipp
|
# minipp
|
||||||
|
|
||||||
A lightweight, header-only C++14 parser and writer for the mini config format.
|
A lightweight, header-only C++14 parser and writer for the [mini config format](https://github.com/ToyB-Chan/mini-file-format).
|
||||||
|
|
||||||
## Description
|
## Description
|
||||||
minipp provides a convenient way to parse and write configuration files in the "mini" format. This format is characterized by its human-readable structure and nested sections, making it ideal for application configurations.
|
minipp provides a convenient way to parse and write configuration files in the "mini" format. This format is characterized by its human-readable structure and nested sections, making it ideal for application configurations.
|
||||||
@@ -15,17 +15,6 @@ minipp provides a convenient way to parse and write configuration files in the "
|
|||||||
|
|
||||||
- **Single Header**: minipp is a single-header library, meaning you only need to include one file.
|
- **Single Header**: minipp is a single-header library, meaning you only need to include one file.
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
To use minipp in your project:
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
#define MINIPP_IMPLEMENTATION
|
|
||||||
#include "minipp.hpp"
|
|
||||||
```
|
|
||||||
|
|
||||||
Then, you can use `minipp::MiniPPFile` to parse and write mini files throughout your code.
|
|
||||||
|
|
||||||
### Example Usage
|
### Example Usage
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
@@ -45,12 +34,16 @@ int main()
|
|||||||
|
|
||||||
MiniPPFile::Section* gameSection = nullptr;
|
MiniPPFile::Section* gameSection = nullptr;
|
||||||
result = root.GetSubSection("game", &gameSection);
|
result = root.GetSubSection("game", &gameSection);
|
||||||
|
// "Easy" API
|
||||||
|
int64_t test = gameSection.GetValueOrDefault<MiniPPFile::Values::IntValue>("year", 1999);
|
||||||
|
|
||||||
|
// Verbose API
|
||||||
MiniPPFile::Values::StringValue* nameValue = nullptr;
|
MiniPPFile::Values::StringValue* nameValue = nullptr;
|
||||||
result = gameSection->GetValue("name", &nameValue);
|
result = gameSection->GetValue("name", &nameValue);
|
||||||
MiniPPFile::Values::IntValue* yearValue = nullptr;
|
MiniPPFile::Values::IntValue* yearValue = nullptr;
|
||||||
result = gameSection->GetValue("year", &yearValue);
|
result = gameSection->GetValue("year", &yearValue);
|
||||||
|
|
||||||
// Get a sub-section (section of a section (stated in the MINI file with "[game.window]")
|
// Get a sub-section (section of a section, stated in the MINI file with "[game.window]")
|
||||||
MiniPPFile::Section* windowSection = nullptr;
|
MiniPPFile::Section* windowSection = nullptr;
|
||||||
result = gameSection->GetSubSection("window", &windowSection);
|
result = gameSection->GetSubSection("window", &windowSection);
|
||||||
|
|
||||||
@@ -58,12 +51,12 @@ int main()
|
|||||||
// Get a sub-section by using the dot operator
|
// Get a sub-section by using the dot operator
|
||||||
result = gameSection->GetSubSection("window.platform", &windowPlatformSection);
|
result = gameSection->GetSubSection("window.platform", &windowPlatformSection);
|
||||||
|
|
||||||
MiniPPFile::Values::ArrayValue* pointsValue = nullptr;
|
MiniPPFile::Values::ArrayValue* platformTargetsValue = nullptr;
|
||||||
// Retrieve an array by using the relative value path (the game section is a child of the root section)
|
// Retrieve an array by using the relative value path (the game section is a child of the root section)
|
||||||
result = root.GetValue("game.window.platform.targets", &pointsValue);
|
result = root.GetValue("game.window.platform.targets", &platformTargetsValue);
|
||||||
|
|
||||||
// Modify the "targets" array by adding a new value
|
// Modify the "targets" array by adding a new value
|
||||||
pointsValue->GetValues().push_back(std::make_unique<MiniPPFile::Values::StringValue>("haiku"));
|
platformTargetsValue->GetValue().push_back(std::make_unique<MiniPPFile::Values::StringValue>("haiku"));
|
||||||
|
|
||||||
// Serialize the config
|
// Serialize the config
|
||||||
result = file.Write("test_out.mini");
|
result = file.Write("test_out.mini");
|
||||||
@@ -99,9 +92,12 @@ int main()
|
|||||||
// Access values
|
// Access values
|
||||||
MiniPPFile::Values::StringValue* nameValue = nullptr;
|
MiniPPFile::Values::StringValue* nameValue = nullptr;
|
||||||
result = gameSection->GetValue("name", &nameValue);
|
result = gameSection->GetValue("name", &nameValue);
|
||||||
|
|
||||||
|
// .. OR ..
|
||||||
|
|
||||||
|
std::string nameValue = gameSection->GetValueOrDefault<MiniPPFile::Values::StringValue>("name", "Unknown");
|
||||||
|
|
||||||
// Navigate nested sections
|
// Navigate nested sections
|
||||||
|
|
||||||
MiniPPFile::Section* windowSection = nullptr;
|
MiniPPFile::Section* windowSection = nullptr;
|
||||||
result = gameSection->GetSubSection("window", &windowSection);
|
result = gameSection->GetSubSection("window", &windowSection);
|
||||||
|
|
||||||
@@ -121,7 +117,7 @@ int main()
|
|||||||
result = root.GetValue("game.window.platform.points", &pointsValue);
|
result = root.GetValue("game.window.platform.points", &pointsValue);
|
||||||
|
|
||||||
// Modify the array values (or read them)
|
// Modify the array values (or read them)
|
||||||
pointsValue->GetValues().push_back(std::make_unique<MiniPPFile::Values::StringValue>("haiku"));
|
pointsValue->GetValue().push_back(std::make_unique<MiniPPFile::Values::StringValue>("haiku"));
|
||||||
|
|
||||||
```
|
```
|
||||||
5. **Write new files**:
|
5. **Write new files**:
|
||||||
@@ -132,11 +128,11 @@ int main()
|
|||||||
|
|
||||||
## Example
|
## Example
|
||||||
|
|
||||||
An example mini file is contained in this [repository](test.mini). The full mini file format specilization can be found [here](https://github.com/ToyB-Chan/mini-file-format).
|
An example mini file is contained in this [repository](minipp/test.mini). The full mini file format specification can be found [here](https://github.com/ToyB-Chan/mini-file-format).
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
1. Copy the contents of "minipp.hpp" to a new file in your project.
|
1. Copy the contents of [minipp.hpp](minipp/minipp.hpp) to a new file in your project.
|
||||||
2. #Include "minipp.hpp" after defining MINIPP_IMPLEMENTATION in one single cpp file.
|
2. #Include "minipp.hpp" after defining MINIPP_IMPLEMENTATION in one single cpp file.
|
||||||
3. #Include "minipp.hpp" in any other desired files without the IMPLEMENTATION define!
|
3. #Include "minipp.hpp" in any other desired files without the IMPLEMENTATION define!
|
||||||
|
|
||||||
|
|||||||
1621
minipp/minipp.hpp
1621
minipp/minipp.hpp
File diff suppressed because it is too large
Load Diff
2
minipp/simple.mini
Normal file
2
minipp/simple.mini
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
[game]
|
||||||
|
what=["test\t\\yeah", "hai"]
|
||||||
@@ -10,7 +10,7 @@ int main()
|
|||||||
MiniPPFile file;
|
MiniPPFile file;
|
||||||
result = file.Parse("test.mini");
|
result = file.Parse("test.mini");
|
||||||
|
|
||||||
auto& root = file.GetRoot();
|
auto& root = file.GetRoot();
|
||||||
|
|
||||||
MiniPPFile::Section* gameSection = nullptr;
|
MiniPPFile::Section* gameSection = nullptr;
|
||||||
result = root.GetSubSection("game", &gameSection);
|
result = root.GetSubSection("game", &gameSection);
|
||||||
@@ -42,5 +42,6 @@ int main()
|
|||||||
|
|
||||||
result = file.Write("test_out.mini");
|
result = file.Write("test_out.mini");
|
||||||
|
|
||||||
|
int64_t test = root.GetValueOrDefault<MiniPPFile::Values::IntValue>("game.year", 1999);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,13 @@
|
|||||||
[game]
|
[game]
|
||||||
name = "Test Game"
|
name = "Test Game\nNext Line"
|
||||||
version = "1.0.0"
|
version = "1.0.0"
|
||||||
year = 2025
|
year = 2025
|
||||||
completionPercentage = 50.0f
|
completionPercentage = 50.0f
|
||||||
# Should only be true if completionPercentage is 100
|
# Should only be true if completionPercentage is 100
|
||||||
is_completed = false
|
is_completed = false
|
||||||
|
testargs = ["this is a \\\"test\"", "this is\n the next line"]
|
||||||
|
testTestArg = [["yeah", "new\nline"], ["hallo\ttest\n\\\\"]]
|
||||||
|
testEmpty = []
|
||||||
|
|
||||||
# This section is about
|
# This section is about
|
||||||
# the settings of a game window
|
# the settings of a game window
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
[game]
|
[game]
|
||||||
name = "Test Game"
|
testEmpty = []
|
||||||
|
name = "Test Game\nNext Line"
|
||||||
|
testTestArg = [["yeah", "new\nline"], ["hallo\ttest\n\\\\"]]
|
||||||
completionPercentage = 50.000000
|
completionPercentage = 50.000000
|
||||||
version = "1.0.0"
|
version = "1.0.0"
|
||||||
|
testargs = ["this is a \\\"test\"", "this is\n the next line"]
|
||||||
year = 2025
|
year = 2025
|
||||||
# Should only be true if completionPercentage is 100
|
# Should only be true if completionPercentage is 100
|
||||||
is_completed = false
|
is_completed = false
|
||||||
|
|||||||
Reference in New Issue
Block a user