@@ -651,16 +651,17 @@ See examples below.
651651``` cpp
652652#include < dracosha/validator/validator.hpp>
653653#include < dracosha/validator/validate.hpp>
654+ #include < dracosha/validator/operators/lexicographical.hpp>
654655#include < dracosha/validator/prevalidation/set_validated.hpp>
655656
656657// define structure with member variables and member setter method
657658struct Foo
658659{
659660 std::string bar_value;
660-
661+
661662 uint32_t other_value;
662663 size_t some_size;
663-
664+
664665 void set_bar_value(std::string val)
665666 {
666667 bar_value=std::move(val);
@@ -694,39 +695,34 @@ using namespace DRACOSHA_VALIDATOR_NAMESPACE;
694695
695696int main()
696697{
698+ // define validator of custom properties
699+ auto v=validator(
700+ _ [ bar_value] ( ilex_ne,"UNKNOWN" ) , // case insensitive lexicographical not equal
701+ _ [ other_value] ( gte,1000 )
702+ );
697703
698- // define validator of custom properties
699- auto v=validator(
700- _ [ bar_value] ( ilex_ne,"UNKNOWN" ) , // case insensitive lexicographical not equal
701- _ [ other_value] ( gte,1000 )
702- );
704+ Foo foo_instance;
703705
704- Foo foo_instance ;
706+ error_report err ;
705707
706- error_report err;
708+ // call setter with valid data
709+ set_validated(foo_instance,_[bar_value],"Hello world",v,err);
710+ assert(!err);
707711
708- // call setter with valid data
709- set_validated(foo_instance,bar_value,"Hello world",v,err);
710- if (!err)
711- {
712- // object's member is set
713- }
712+ // call setter with invalid data
713+ set_validated(foo_instance,_[bar_value],"unknown",v,err);
714+ assert(err);
715+ if (err)
716+ {
717+ // object's member is not set
718+ std::cerr << err.message() << std::endl;
719+ assert(err.message()==std::string("bar_value must be not equal to UNKNOWN"));
720+ }
714721
715- // call setter with invalid data
716- set_validated(foo_instance,bar_value,"unknown",v,err);
717- if (err)
718- {
719- // object's member is not set
720- std::cerr << err.message() << std::endl;
721- /* prints:
722-
723- "bar_value must be not equal to UNKNOWN"
724-
725- * /
722+ std::cout << "Example 26 done" << std::endl;
723+ return 0;
726724}
727725
728- return 0;
729- }
730726```
731727
732728#### unset_validated
@@ -2094,6 +2090,7 @@ To use aggregation with modifier the modifier must be provided as an argument to
20942090See examples below.
20952091
20962092``` cpp
2093+ #include < map>
20972094#include < dracosha/validator/validator.hpp>
20982095#include < dracosha/validator/properties/pair.hpp>
20992096
@@ -2512,6 +2509,8 @@ See example below.
25122509#include < dracosha/validator/value_transformer.hpp>
25132510#include < dracosha/validator/validator.hpp>
25142511
2512+ using namespace DRACOSHA_VALIDATOR_NAMESPACE ;
2513+
25152514namespace {
25162515// define handler that returns a size of provided string
25172516size_t string_size(const std::string& val) noexcept
0 commit comments