Confy Configure projects effortlessly! 💻
This a project configuration file parser and system originally created for the Snowball Programming Language!
- Header only C++ library (bringing fast parsing times)
- Statically types (with syntax previously defined by the project executor)
- Enables efficient memory management through smart pointers
- Cross-platform compatibility for versatile deployment
- Comprehensive error handling for robust development
auto root = confy::Interface::create({
{"project", confy::Type::Object({
{"name", confy::Type::String},
{"version", confy::Type::String},
{"authors", confy::Type::Array(confy::Type::String)},
{"description", confy::Type::String},
})},
});
auto result = confy::parse_file(root, "./project.confy");
// { errors: {}, root: ... }
Will be able to parse:
# haha, you cant see me!
project {
name = "MyLib"
version = "1.0.0"
author = ["Your Name"]
description = "A project created with Confy!"
}
- A set of values of values that can be accessed by name
Types::Object({
{"name": Type},
...
});
myObject {
name = type
}
- A set of values with the same type that can contain an infinite ammount of elements (from 0 to infinity)
Types::Array(Type);
myArray = ["Hello", "Adios", "Ñog"]
- An array of characters (it's just a string)
Types::String;
myName = "mauro!"
- A number from -inf to inf that can contain decimal places (represented as a double in the backend)
Types::Number;
myNumber = 25
- Utility types are used to validate the given data.
- To enable the utility classes, define the
CONFY_USE_UTILS
macro before includingconfy.hpp
- If the validation returns an error, it will be thrown and the parsing will fail
- A number that must be bigger than
N1
MinNumType<10>::create();
myNumber = 12
- A number that must be less than
N1
MaxNumType<10>::create();
myNumber 6
- A number that must be bigger than
N1
and less thanN2
RangeNumType<10, 20>::create();
myNumber = 12
- The parsed string's length must be bigger than
S1
MinStrType<3>::create();
myString = "hello there"
- The parsed string's must satisfy the given regex
StrRegexType::create("*");
myString = "I dont know how regex works"
- To create your own validation type, create a new class inheriting from a
primitive type
(likeNumType
orStringType
). - Override the
validate
method where it's value may depend from which type is being inherited from.
Example of a class that only accepts if a string starts with "hello".
class MyCustomType : public confy::StringType {
public:
// Validate takes a `double` if it inherits from `confy::NumType`!
std::optional<std::string> validate(const std::string& value) const override {
if (s.rfind("hello", 0) == 0) {
return std::nullopt;
}
return "String must start with 'hello'!";
}
// Optional but it's nice to have a generator function
static std::shared_ptr<MyCustomType> create() {
return std::make_shared<MyCustomType>();
}
}
Usage
{"myStr": MyCustomType::create()}
This will work as (ignore the duplicate name error):
myStr = "hello world"
myStr = "hello mauro"
# error!
myStr = "goodbye :("