Skip to content
/ C2P Public

C++ 配置转参数工具。User configurations to program parameters.

Notifications You must be signed in to change notification settings

falrom/C2P

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

C2P

C++ 配置转参数工具。
User configurations to program parameters.

Parse user inputs (such as command line arguments or config files) to configuration struct, then generate program parameters.

[DefaultValues] --parse-> [ValueTree] \                    [Rules]
                                       \                      |
[ ConfigFiles ] --parse-> [ValueTree] --join-> [Config] --transform-> [Param]
                                       /
[CLI-Arguments] --parse-> [ValueTree] /

Transform from Config to Param with Rules

Generally, Config should be defined in a human-friendly format, while Param needs to be closer to the program's input requirements. Defining Param as a cached data type that the program can directly work with (avoiding redundant checks and type conversions) also helps improve performance. The bridge that connects the two is the Rules.

Define your own Config and Param types separately. Then, create a set of Rules to:

  • Handle part of the conversion from Config to Param.
  • Perform input validation and report errors if requirements are not met.

Finally, call the transform function to apply these Rules.

Parsing Config from IO

We treat various user inputs as the source and parse them into a common intermediate value tree (composed of multiple ValueNodes). After that, you can define the conversion from value tree to Config as well as override rules for different input methods.

Some tools are provided for parsing inputs, such as JSON serialization/deserialization, command-line argument parsing (TODO), etc. All of these produce a value tree as the output.

About

C++ 配置转参数工具。User configurations to program parameters.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published