-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4b151ab
commit 17ca3ff
Showing
7 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ add_projects( | |
boxing | ||
collections | ||
console | ||
configuration | ||
convert | ||
date_time | ||
delegates | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
cmake_minimum_required(VERSION 3.20) | ||
|
||
project(configuration) | ||
find_package(xtd REQUIRED) | ||
|
||
add_projects( | ||
file_settings | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Configuration examples | ||
|
||
[This folder](.) contains console examples used by [Reference Guide](https://gammasoft71.github.io/xtd/reference_guides/latest/) and more. | ||
|
||
* [file_settings](file_settings/README.md) shows how to use [xtd::consiguration::file_settings](https://gammasoft71.github.io/xtd/reference_guides/latest/classxtd_1_1configuration_1_1file__settings.html) object. | ||
|
||
## Build and run any project | ||
|
||
Open "Command Prompt" or "Terminal". Navigate to the folder that contains the project and type the following: | ||
|
||
```shell | ||
xtdc run -t any_project_name | ||
``` |
6 changes: 6 additions & 0 deletions
6
examples/xtd.core.examples/configuration/file_settings/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
cmake_minimum_required(VERSION 3.20) | ||
|
||
project(file_settings) | ||
find_package(xtd REQUIRED) | ||
add_sources(README.md src/file_settings.cpp) | ||
target_type(CONSOLE_APPLICATION) |
39 changes: 39 additions & 0 deletions
39
examples/xtd.core.examples/configuration/file_settings/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# file_settings | ||
|
||
Shows how to use [xtd::consiguration::file_settings](https://gammasoft71.github.io/xtd/reference_guides/latest/classxtd_1_1configuration_1_1file__settings.html) object. | ||
|
||
## Sources | ||
|
||
[src/file_settings.cpp](src/file_settings.cpp) | ||
|
||
[CMakeLists.txt](CMakeLists.txt) | ||
|
||
## Build and run | ||
|
||
Open "Command Prompt" or "Terminal". Navigate to the folder that contains the project and type the following: | ||
|
||
```cmake | ||
xtdc run | ||
``` | ||
|
||
## Output | ||
|
||
``` | ||
---------------------------------------- | ||
"exemple.ini" file content : | ||
# Settings file used by file_settings example. | ||
# Copyright (c) 2024 Gammasoft. All rights reserved. | ||
auto_close = true | ||
caption = file_settings example | ||
[Thread "Process"] | ||
timeout_ = 00:00:00.1000000 | ||
---------------------------------------- | ||
read keys : | ||
auto_close = true | ||
caption = file_settings example | ||
Thread "Process" | ||
---------------------------------------- | ||
``` |
59 changes: 59 additions & 0 deletions
59
examples/xtd.core.examples/configuration/file_settings/src/file_settings.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#include <xtd/configuration/file_settings> | ||
#include <xtd/console> | ||
|
||
using namespace xtd; | ||
using namespace xtd::configuration; | ||
|
||
auto write_file_settings() { | ||
auto file = file_settings("example.ini"); | ||
file.top_file_comment("Settings file used by file_settings example.\nCopyright (c) 2024 Gammasoft. All rights reserved."); | ||
file.write("auto_close", true); | ||
file.write("caption", "file_settings example"); | ||
file.write("Thread \"Process\"", "timeout_", 100_ms); | ||
file.save(); | ||
} | ||
|
||
auto reset_file_settings() { | ||
auto file = file_settings("example.ini"); | ||
file.reset(); | ||
} | ||
|
||
auto read_file_settings() { | ||
auto file = file_settings("example.ini"); | ||
console::write_line("----------------------------------------"); | ||
console::write_line("\"exemple.ini\" file content :"); | ||
console::write_line(file.to_string()); | ||
console::write_line("----------------------------------------"); | ||
console::write_line("read keys :"); | ||
console::write_line("auto_close = {}", file.read("auto_close", false)); | ||
console::write_line("caption = {}", file.read("caption", "example")); | ||
console::write_line("Thread \"Process\"", "time_out = {}", file.read("timeout_", 50_ms)); | ||
console::write_line("----------------------------------------"); | ||
} | ||
|
||
auto main() -> int { | ||
write_file_settings(); | ||
// Uncomment the following line to see what happens if the "example.ini" file doesn't exist. | ||
//reset_file_settings(); | ||
read_file_settings(); | ||
} | ||
|
||
// This code produces the following output: | ||
// | ||
// ---------------------------------------- | ||
// "exemple.ini" file content : | ||
// # Settings file used by file_settings example. | ||
// # Copyright (c) 2024 Gammasoft. All rights reserved. | ||
// | ||
// auto_close = true | ||
// caption = file_settings example | ||
// | ||
// [Thread "Process"] | ||
// timeout_ = 00:00:00.1000000 | ||
// | ||
// ---------------------------------------- | ||
// read keys : | ||
// auto_close = true | ||
// caption = file_settings example | ||
// Thread "Process" | ||
// ---------------------------------------- |