Skip to content

Commit f63cff6

Browse files
committed
Update documentation
1 parent ac36777 commit f63cff6

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@
22

33
## Motivation
44

5-
A common issue when receiving data either by application from user interface or by server remotely from clients is verifying data integrity and/or specific constraints. A typical approach for implementing complex data validation is writing nested *if-conditions* or chained invocations of partial validation methods. Declarations of the constraints could become intermixed with their implementations. Thus, validation would spread over the code which makes it hard to maintain it. Requirement to construct and show error messages could make everything still more complicated.
5+
Checking data constraints or verifying data integrity is a very common task in programming. A typical approach for complex data validation is writing nested *if-conditions* or chained invocations of partial validation methods. Declarations of the constraints could become intermixed with their implementations, thus, spreading the validation routines over the code. Requirements to construct and show error messages could make everything even more complicated.
66

7-
`cpp-validator` library allows one to declare data constraints with clean statements in certain points of code and apply them in other points of code on demand. If needed, the validation error messages are automatically constructed by taking into account the user's locale.
7+
`cpp-validator` library allows one to declare data constraints with clean statements in certain points of code and apply them in other parts of code on demand. If needed, the validation error messages are automatically constructed by taking into account the user's locale.
88

9-
Minimal example:
9+
Minimal generic example:
1010

1111
```cpp
12-
// define validator
12+
// define a validator
1313
auto v1=validator(
1414
_[key1][key1_1][key1_1_1](gt,100),
15-
_[key2][key2_1](value(ne,"UNKNOWN") ^AND^ size(lte,32))
15+
_[key2][key2_1](value(ne,"UNKNOWN") && size(lte,32))
1616
);
1717

18-
// validate objects
19-
Class1 obj1;
20-
Class2 obj2;
18+
.....
2119

20+
// validate some objects with the validator
21+
// throwing exception if validation fails
2222
validate(obj1,v1);
2323
validate(obj2,v1);
2424
```

docs/index.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,7 @@ There is also a [contains](#contains) operator added to the library for convenie
989989

990990
A [member](#member) existence can also be checked implicitly before applying validation to the [member](#member). Check of member existence is performed by an [adapter](#adapter) if the [adapter](#adapter) supports that. [Default adapter](#default-adapter) and [reporting adapter](#reporting-adapter) provide this feature which can be configured with `set_check_member_exists_before_validation` and `set_unknown_member_mode` adapter methods.
991991

992-
Method `set_check_member_exists_before_validation` enables/disables implicit check of member existence. By default this option is disabled which improves validation performance but can sometimes cause exceptions or other undefined errors. Note that some basic check of property existence or type compatibility might be performed statically at compile time regardless of this flag.
992+
Method `set_check_member_exists_before_validation` enables/disables implicit check of member existence. By default this option is disabled which improves validation performance but can sometimes cause exceptions or other undefined errors. Note that some basic check of property existence or type compatibility might be performed statically at compilation time regardless of this flag.
993993

994994
Method `set_unknown_member_mode` instructs adapter what to do if a member is not found. There are two options:
995995
- ignore missed members and continue validation process;
@@ -2324,7 +2324,7 @@ int main()
23242324
There are a few built-in adapter types implemented in `cpp-validator` library:
23252325
- [default adapter](#default-adapter) that applies validation to an [object](#object) by invoking [operators](#operator) one by one as specified in a [validator](#validator);
23262326
- [reporting adapter](#reporting-adapter) that does the same as [default adapter](#default-adapter) with addition of constructing a [report](#report) describing an error if validation fails;
2327-
- [failed members adapter](#failed-members-adapter) that collects names of object's members that didn't path validation;
2327+
- [failed members adapter](#failed-members-adapter) that collects names of object's members that failed to pass validation;
23282328
- [prevalidation adapter](#prevalidation-adapter) that validates only one [member](#member) and constructs a [report](#report) if validation fails;
23292329
- [filtering adapter](#partial-validation) used to filter member paths before validation.
23302330
@@ -2337,7 +2337,7 @@ There are a few built-in adapter types implemented in `cpp-validator` library:
23372337
### Failed members adapter
23382338
23392339
Failed members adapter is used to collect all members that did not pass the validation.
2340-
This adapter is defined in `hatn/validator/adapters/reporting_adapter.hpp` header. Call `make_failed_members_adapter(obj)` to make adapter for object that must be validated. The list of failed member names can be accessed via `adapter.traits().reporter().failed_members()` after validation.
2340+
This adapter is defined in `hatn/validator/adapters/failed_members_adapter.hpp` header file. Call `make_failed_members_adapter(obj)` to make adapter for object that must be validated. The list of failed member names can be accessed via `adapter.traits().reporter().failed_members()` after validation.
23412341
23422342
There are a few notes about using failed members adapter.
23432343
@@ -2374,7 +2374,7 @@ int main()
23742374
_["field4"](lt,5)
23752375
);
23762376
auto ret=v1.apply(ra1);
2377-
assert(ret.success()); // DO NOT COUNT ON THIS because success() might be returned when validation failed (see below)
2377+
assert(ret.success()); // DO NOT COUNT ON THIS because success() might be true even when validation failed (see below)
23782378
assert(members1.empty()); // members are empty for success validation
23792379
ra1.reset(); // do not forget to reset adapter before next use
23802380
@@ -2385,7 +2385,7 @@ int main()
23852385
(_["field4"](gte,5) && _["field5"](exists,true) && _["field3"](eq,3))
23862386
);
23872387
ret=v2.apply(ra1);
2388-
assert(ret.success()); // success() for failed validation, DO NOT COUNT ON THIS!
2388+
assert(ret.success()); // success()==true for failed validation, DO NOT COUNT ON THIS!
23892389
assert(!members1.empty()); // members are not empty for failed validation
23902390
assert(members1.size()=3);
23912391
assert(members1[0]==std::string("field2"));

0 commit comments

Comments
 (0)