mirror of
https://github.com/mariiaan/minipp.git
synced 2026-05-14 10:11:17 +02:00
Merge branch 'master' of https://github.com/mariiaan/minipp
This commit is contained in:
21
README.md
21
README.md
@@ -34,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);
|
||||||
|
|
||||||
@@ -47,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");
|
||||||
@@ -88,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);
|
||||||
|
|
||||||
@@ -110,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**:
|
||||||
@@ -121,7 +128,7 @@ int main()
|
|||||||
|
|
||||||
## Example
|
## Example
|
||||||
|
|
||||||
An example mini file is contained in this [repository](minipp/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
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user