Provide a type for an error code with an optional error message.
More...
Namespaces |
namespace | bdld |
Detailed Description
- Outline
-
-
- Purpose:
- Provide a type for an error code with an optional error message.
-
- Classes:
-
- See also:
- Component bdld_datum, Component bdld_datumudt
-
- Description:
- This component defines a complex-constrained value-semantic attribute class
bdld::DatumError
representing an error code with an optional descriptive error message. This component holds a reference to the error message that was supplied at construction. Accessors inside Datum
class that need to return an error value, return an instance of DatumError
.
-
- Usage:
- This section illustrates intended use of this component.
-
- Example 1: Basic DatumError usage:
- Suppose we need a function to verify if newly created password meets basic security requirements. Password must contain at least one uppercase letter, one lowercase letter, one numeral and one special symbol. The following code illustrates how to use
bdld::DatumError
to notify user about password weaknesses.
- First, we need to write a verification function:
bdld::DatumError verifyNewPassword(const char *password)
{
bool uppercasePresence = false;
bool lowercasePresence = false;
bool numeralPresence = false;
bool specialSymbolPresence = false;
Passed string analysis: while (*password) {
if (*password >= 'A' && *password <= 'Z') {
uppercasePresence = true;
}
if (*password >= 'a' && *password <= 'z') {
lowercasePresence = true;
}
if (*password >= '0' && *password <= '9') {
numeralPresence = true;
}
if (*password >= '!' && *password <= '.') {
specialSymbolPresence = true;
}
++password;
}
Result compilation: Next, we need to create password for verification and call our function: Then, check the results: Finally, we can print the result to the output stream: