|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r73104 - sandbox/SOC/2011/checks/boost/checks
From: pierre.talbot.6114_at_[hidden]
Date: 2011-07-14 10:42:32
Author: trademark
Date: 2011-07-14 10:42:31 EDT (Thu, 14 Jul 2011)
New Revision: 73104
URL: http://svn.boost.org/trac/boost/changeset/73104
Log:
Move the doxygen documentation to the checks_fwd file.
Improved documentation.
Change the typename (in -> <algo_name>_iter
out -> <algo_name>_checkdigit )
Text files modified:
sandbox/SOC/2011/checks/boost/checks/checks_fwd.hpp | 197 +++++++++++++++++++++++++++++--------
sandbox/SOC/2011/checks/boost/checks/modulus.hpp | 205 +++++++++------------------------------
2 files changed, 198 insertions(+), 204 deletions(-)
Modified: sandbox/SOC/2011/checks/boost/checks/checks_fwd.hpp
==============================================================================
--- sandbox/SOC/2011/checks/boost/checks/checks_fwd.hpp (original)
+++ sandbox/SOC/2011/checks/boost/checks/checks_fwd.hpp 2011-07-14 10:42:31 EDT (Thu, 14 Jul 2011)
@@ -51,62 +51,167 @@
*/
-/*
+#ifndef BOOST_CHECK_CHECKS_FWD_HPP
+#define BOOST_CHECK_CHECKS_FWD_HPP
-DELETE THIS AFTER READING!
-
-It is redundant for production of html and pdf output,
-but useful to allow just Doxygen manuals (no Quickbook text or indexing).
-
-Standalone Doxygen can provide a more convenient compact index of
-the classes, files, namespaces and functions.
-They provide the Doxygen comments, but not any text from Quickbook.
-
-These manuals are quickly produced using the Doxywizard GUI frontend.
-A suitable doxyfile holding the list of files to include etc
-is conveniently placed in a /doc/doxygen sub-folder.
-Selecting this as the working directory from which doxygen will run as Step 1,
-and the run tab, and "run doxygen' in Step 2 should generate
-an html with index.html in the /doxygen sub-folder.
-
-The mainpage should give a pointer to the full html and/or pdf versions
-that provide the full Quickbook generated information.
-
-I:/boost-sandbox/tools/quick_auto_dox_index/libs/quick_auto_dox_index/doc/html/index.html
-QuickBook Auto Doxygen Indexed Manual
-
-*/
+#ifdef _MSC_VER
+ #pragma once
+#endif // _MSC_VER
namespace boost{
namespace checks{
// Provides forward declaration of all Boost.Checks functions:
- template <typename out, typename in>
- inline out compute_luhn(in &begin, const in &end, unsigned int nbr_digits=0);
-
- template <typename in>
- inline char compute_luhn(in &begin, const in &end, unsigned int nbr_digits=0);
-
- template <typename in>
- inline bool check_luhn(in &begin, const in &end, unsigned int nbr_digits=0);
+/** Validate the check digit of the number provided with the Luhn algorithm.
+ * \tparam luhn_iter Iterator with at least the caracteristics of an input iterator. It The beginning or the ending of a sequence of character.
+ * \param[in,out] begin The beginning of the sequence to check.
+ * \param[in] end One off the limit of the sequence to check.
+ * \param[in] nbr_digits The number of digits on which the Luhn algorithm will operate. If the size is < 1, the luhn algorithm will validate the check digit with all the digit encountered.
+ * \pre The parameters begin and end must be two valid initialized iterators. They represent a sequence of character encoded in big-endian mode in a format compatible with the 7 bits ASCII.
+ * \post begin is equal to the position of the check digit plus one if the expression provided is correct, otherwise is equal to end.
+ * \returns true is returned if the expression given have a valid check digit and have nbr_digits (or more than 0 digit if nbr_digits is equal to 0).
+ */
+ template <typename luhn_iter>
+ bool check_luhn(luhn_iter &begin, const luhn_iter &end, unsigned int nbr_digits=0);
+
+/** Calculate the check digit of the number provided with the Luhn algorithm.
+ * \tparam luhn_iter Iterator with at least the caracteristics of an input iterator. It The beginning or the ending of a sequence of character.
+ * \param[in,out] begin The beginning of the sequence to check.
+ * \param[in] end One off the limit of the sequence to check.
+ * \param[in] nbr_digits The number of digits on which the Luhn algorithm will operate. If the size is < 1, the luhn algorithm will calculate the check digit with all the digit encountered.
+ * \pre begin and end are valid initialized iterators. They represent a sequence of character encoded in big-endian mode in a format compatible with the 7 bits ASCII.
+ * \post begin is equal to the position of the last digit encountered plus one if the expression provided is correct, otherwise is equal to end.
+ * \returns 0 is returned if the expression given have not nbr_digits (or no digit if nbr_digits is equal to 0). Otherwise the ASCII character of the check digit is returned.
+ */
+ template <typename luhn_iter>
+ char compute_luhn(luhn_iter &begin, const luhn_iter &end, unsigned int nbr_digits=0);
- template <typename in>
- inline bool check_mod11(in &begin, const in &end, unsigned int nbr_digits=0);
+/** Calculate the check digit of the number provided with the Luhn algorithm.
+ * \tparam luhn_iter Iterator with at least the caracteristics of an input iterator. It The beginning or the ending of a sequence of character.
+ * \tparam luhn_checkdigit Type in which the check digit will be returned.
+ * \param[in,out] begin The beginning of the sequence to check.
+ * \param[in] end One off the limit of the sequence to check.
+ * \param[in] nbr_digits The number of digits on which the Luhn algorithm will operate. If the size is < 1, the luhn algorithm will calculate the check digit with all the digit encountered.
+ * \pre begin and end are valid initialized iterators. They represent a sequence of character encoded in big-endian mode in a format compatible with the 7 bits ASCII.
+ * \post begin is equal to the position of the last digit encountered plus one if the expression provided is correct, otherwise is equal to end.
+ * \returns 0 is returned if the expression given have not nbr_digits (or no digit if nbr_digits is equal to 0). Otherwise the ASCII character of the check digit is returned.
+ */
+ template <typename luhn_checkdigit, typename luhn_iter>
+ luhn_checkdigit compute_luhn(luhn_iter &begin, const luhn_iter &end, unsigned int nbr_digits=0);
+
+/** Validate the check digit of the number provided with the modulus 10 algorithm.
+ * \tparam mod10_iter Iterator with at least the caracteristics of an input iterator. It The beginning or the ending of a sequence of character.
+ * \param[in,out] begin The beginning of the sequence to check.
+ * \param[in] end One off the limit of the sequence to check.
+ * \param[in] weight The weight pattern of the sequence starting on the left of the expression. If weight is null, the algorithm will apply a weight of 1 on the sequence.
+ * \param[in] nbr_digits The number of digits on which the modulus 10 algorithm will operate. If the size is < 1, the modulus 10 algorithm will validate the check digit with all the digit encountered.
+ * \pre begin and end are valid initialized iterators. They represent a sequence of character encoded in big-endian mode in a format compatible with the 7 bits ASCII.
+ * \post begin is equal to the position of the check digit plus one if the expression provided is correct, otherwise is equal to end.
+ * \returns true is returned if the expression given have a valid check digit and have nbr_digits (or more than 0 digit if nbr_digits is equal to 0).
+ */
+ template <typename mod10_iter>
+ bool check_mod10(mod10_iter &begin, const mod10_iter &end, unsigned int weight[], unsigned int nbr_digits=0);
+
+/** Compute the check digit of the number provided with the modulus 10 algorithm.
+ * \tparam mod10_iter with at least the caracteristics of an input iterator. It The beginning or the ending of a sequence of character.
+ * \param[in,out] begin The beginning of the sequence to check.
+ * \param[in] end One off the limit of the sequence to check.
+ * \param[in] weight The weight pattern of the sequence starting on the left of the expression. If weight is null, the algorithm will apply a weight of 1 on the sequence.
+ * \param[in] nbr_digits The number of digits on which the modulus 10 algorithm will operate. If the size is < 1, the modulus 10 algorithm will calculate the check digit with all the digit encountered.
+ * \pre begin and end are valid initialized iterators. They represent a sequence of character encoded in big-endian mode in a format compatible with the 7 bits ASCII.
+ * \post begin is equal to the position of the last digit encountered plus one if the expression provided is correct, otherwise is equal to end.
+ * \returns 0 is returned if the expression given have not nbr_digits (or no digit if nbr_digits is equal to 0). Otherwise the ASCII character of the check digit is returned.
+ */
+ template <typename mod10_iter>
+ char compute_mod10(mod10_iter &begin, const mod10_iter &end, unsigned int weight[], unsigned int nbr_digits=0);
+
+/** Compute the check digit of the number provided with the modulus 10 algorithm.
+ * \tparam mod10_iter Iterator with at least the caracteristics of an input iterator. It The beginning or the ending of a sequence of character.
+ * \tparam mod10_checkdigit Type in which the check digit will be returned.
+ * \param[in,out] begin The beginning of the sequence to check.
+ * \param[in] end One off the limit of the sequence to check.
+ * \param[in] weight The weight pattern of the sequence starting on the left of the expression. If weight is null, the algorithm will apply a weight of 1 on the sequence.
+ * \param[in] nbr_digits The number of digits on which the modulus 10 algorithm will operate. If the size is < 1, the modulus 10 algorithm will calculate the check digit with all the digit encountered.
+ * \pre begin and end are valid initialized iterators. They represent a sequence of character encoded in big-endian mode in a format compatible with the 7 bits ASCII.
+ * \post begin is equal to the position of the last digit encountered plus one if the expression provided is correct, otherwise is equal to end.
+ * \returns 0 is returned if the expression given have not nbr_digits (or no digit if nbr_digits is equal to 0). Otherwise the ASCII character of the check digit is returned.
+ */
+ template <typename mod10_checkdigit, typename mod10_iter>
+ mod10_checkdigit compute_mod10(mod10_iter &begin, const mod10_iter &end, unsigned int weight[], unsigned int nbr_digits=0);
+
+/** Calculate the check digit of the number provided with the modulus 11 algorithm.
+ * \tparam mod11_iter Iterator with at least the caracteristics of an input iterator. It The beginning or the ending of a sequence of character.
+ * \param[in,out] begin The beginning of the sequence to check.
+ * \param[in] end One off the limit of the sequence to check.
+ * \param[in] nbr_digits The number of digits on which the MOD11 algorithm will operate. If the size is < 1, the MOD11 algorithm will calculate the check digit with all the digit encountered.
+ If the size isn't precised and if the character 'X' or 'x' is encountered, the end of the number will be considered ;
+ if the size is precised, the character 'X' or 'x' will be ignored unless it is the last character.
+ * \pre begin and end are valid initialized iterators. They represent a sequence of character encoded in big-endian mode in a format compatible with the 7 bits ASCII.
+ * \post begin is equal to the position of the last digit encountered plus one if the expression provided is correct, otherwise is equal to end.
+ * \returns 0 is returned if the expression given have not nbr_digits (or no digit if nbr_digits is equal to 0). Otherwise the ASCII character of the check digit is returned.
+*/
+ template <typename mod11_iter>
+ bool check_mod11(mod11_iter &begin, const mod11_iter &end, unsigned int nbr_digits=0);
- template <typename out, typename in>
- inline out compute_mod11(in &begin, const in &end, unsigned int nbr_digits=0);
+/** Validate the check digit of the number provided with the modulus 11 algorithm.
+ * \tparam mod11_iter Iterator with at least the caracteristics of an input iterator. It The beginning or the ending of a sequence of character.
+ * \param[in,out] begin The beginning of the sequence to check.
+ * \param[in] end One off the limit of the sequence to check.
+ * \param[in] nbr_digits The number of digits on which the Luhn algorithm will operate. If the size is < 1, the luhn algorithm will validate the check digit with all the digit encountered.
+ * \pre begin and end are valid initialized iterators. They represent a sequence of character encoded in big-endian mode in a format compatible with the 7 bits ASCII.
+ * \post begin is equal to the position of the check digit plus one if the expression provided is correct, otherwise is equal to end.
+ * \returns true is returned if the expression given have a valid check digit and have nbr_digits (or more than 0 digit if nbr_digits is equal to 0).
+ */
+ template <typename mod11_iter>
+ char compute_mod11(mod11_iter &begin, const mod11_iter &end, unsigned int nbr_digits=0);
+
+/** Validate the check digit of the number provided with the modulus 11 algorithm.
+ * \tparam mod11_iter Iterator with at least the caracteristics of an input iterator. It The beginning or the ending of a sequence of character.
+ * \tparam mod11_checkdigit Type in which the check digit will be returned.
+ * \param[in,out] begin The beginning of the sequence to check.
+ * \param[in] end One off the limit of the sequence to check.
+ * \param[in] nbr_digits The number of digits on which the Luhn algorithm will operate. If the size is < 1, the luhn algorithm will validate the check digit with all the digit encountered.
+ * \pre begin and end are valid initialized iterators. They represent a sequence of character encoded in big-endian mode in a format compatible with the 7 bits ASCII.
+ * \post begin is equal to the position of the check digit plus one if the expression provided is correct, otherwise is equal to end.
+ * \returns true is returned if the expression given have a valid check digit and have nbr_digits (or more than 0 digit if nbr_digits is equal to 0).
+ */
+ template <typename mod11_checkdigit, typename mod11_iter>
+ mod11_checkdigit compute_mod11(mod11_iter &begin, const mod11_iter &end, unsigned int nbr_digits=0);
- template <typename in>
- inline char compute_mod11(in &begin, const in &end, unsigned int nbr_digits=0);
+
- template <typename in>
- inline bool check_mod10(in &begin, const in &end, unsigned int weight[], unsigned int nbr_digits=0);
- template <typename in>
- inline char compute_mod10(in &begin, const in &end, unsigned int weight[], unsigned int nbr_digits=0);
-
- template <typename out, typename in>
- inline out compute_mod10(in &begin, const in &end, unsigned int weight[], unsigned int nbr_digits=0);
+ /*!!!
+The modulus 97 algorithm wait for a sequence of numbers only ! and will not do anything else that sum the digits and calculate the modulus of this sum.
+If you need to check an IBAN use the algorithms in iban.hpp */
+
+/** Compute the check digit of the number provided with the modulus 97 algorithm.
+ * \tparam mod97_iter Iterator with at least the caracteristics of an input iterator. It represents the beginning or the ending of a sequence of character.
+ * \param[in,out] begin The beginning of the sequence to check.
+ * \param[in] end One off the limit of the sequence to check.
+ * \param[in] nbr_digits The number of digits on which the modulus 97 algorithm will operate. If the size is < 1, the modulus 97 algorithm will calculate the check digit with all the digit encountered.
+ * \pre begin and end are valid initialized iterators. They represent a sequence of character encoded in big-endian mode in a format compatible with the 7 bits ASCII.
+ * \post begin is equal to the position of the last digit encountered plus one if the expression provided is correct, otherwise is equal to end.
+ * \returns 0 is returned if the expression given have not nbr_digits (or no digit if nbr_digits is equal to 0). Otherwise the ASCII characters of the check digits are returned.
+ */
+
+ template <typename mod97_iter>
+ char compute_mod97(mod97_iter &begin, const mod97_iter &end, unsigned int nbr_digits=0);
+
+/** Validate the check digit of the number provided with the modulus 97 algorithm.
+ * \tparam mod97_iter Iterator with at least the caracteristics of an input iterator. It represents the beginning or the ending of a sequence of character.
+ * \param[in,out] begin The beginning of the sequence to check.
+ * \param[in] end One off the limit of the sequence to check.
+ * \param[in] nbr_digits The number of digits on which the modulus 97 algorithm will operate. If the size is < 1, the modulus 97 algorithm will validate the check digit with all the digit encountered.
+ * \pre begin and end are valid initialized iterators. They represent a sequence of character encoded in big-endian mode in a format compatible with the 7 bits ASCII.
+ * \post begin is equal to the position of the check digits plus one if the expression provided is correct, otherwise is equal to end.
+ * \returns true is returned if the expression given have a valid check digit and have nbr_digits (or more than 0 digit if nbr_digits is equal to 0).
+ */
+ template <typename mod97_iter>
+ bool check_mod97(mod97_iter &begin, const mod97_iter &end, unsigned int nbr_digits=0);
+
}
-}
\ No newline at end of file
+}
+
+#endif \\ BOOST_CHECK_CHECKS_FWD_HPP
\ No newline at end of file
Modified: sandbox/SOC/2011/checks/boost/checks/modulus.hpp
==============================================================================
--- sandbox/SOC/2011/checks/boost/checks/modulus.hpp (original)
+++ sandbox/SOC/2011/checks/boost/checks/modulus.hpp 2011-07-14 10:42:31 EDT (Thu, 14 Jul 2011)
@@ -5,29 +5,23 @@
// http://www.boost.org/LICENSE_1_0.txt
// See http://www.boost.org for updates, documentation, and revision history.
-#ifndef BOOST_CHECK_MOD_INCLUDED
-#define BOOST_CHECK_MOD_INCLUDED
+#ifndef BOOST_CHECK_MODULUS_HPP
+#define BOOST_CHECK_MODULUS_HPP
+
+#ifdef _MSC_VER
+ #pragma once
+#endif // _MSC_VER
namespace boost {
namespace checks{
-/** Validate the check digit of the number provided with the Luhn algorithm.
- * \tparam Iterator with at least the caracteristics of an input iterator. It represents the beginning or the ending of a sequence of character.
- * \tparam unsigned int which represents a size.
- * \param [in] begin Represents the beginning of the sequence to check.
- * \param [in] end Represents one off the limit of the sequence to check.
- * \param [unsigned int] nbr_digits Represents the number of digits on which the Luhn algorithm will operate. If the size is < 1, the luhn algorithm will validate the check digit with all the digit encountered.
- * \pre begin and end are valid initialized iterators. They represent a sequence of character encoded in big-endian mode in a format compatible with the 7 bits ASCII.
- * \post begin is equal to the position of the check digit plus one if the expression provided is correct, otherwise is equal to end.
- * \returns true is returned if the expression given have a valid check digit and have nbr_digits (or more than 0 digit if nbr_digits is equal to 0).
- */
-template <typename in>
-inline bool check_luhn(in &begin, const in &end, unsigned int nbr_digits)
+template <typename luhn_iter>
+bool check_luhn(luhn_iter &begin, const luhn_iter &end, unsigned int nbr_digits)
{
// If the number of digits isn't given (equal to 0), we count these.
if(!nbr_digits)
{
- in iter = begin;
+ luhn_iter iter = begin;
while(iter != end)
{
if(*iter >= '0' && *iter <= '9')
@@ -56,23 +50,13 @@
return !nbr_digits && !(sum % 10) ;
}
-/** Calculate the check digit of the number provided with the Luhn algorithm.
- * \tparam Iterator with at least the caracteristics of an input iterator. It represents the beginning or the ending of a sequence of character.
- * \tparam unsigned int which represents a size.
- * \param [in] begin Represents the beginning of the sequence to check.
- * \param [in] end Represents one off the limit of the sequence to check.
- * \param [unsigned int] nbr_digits Represents the number of digits on which the Luhn algorithm will operate. If the size is < 1, the luhn algorithm will calculate the check digit with all the digit encountered.
- * \pre begin and end are valid initialized iterators. They represent a sequence of character encoded in big-endian mode in a format compatible with the 7 bits ASCII.
- * \post begin is equal to the position of the last digit encountered plus one if the expression provided is correct, otherwise is equal to end.
- * \returns 0 is returned if the expression given have not nbr_digits (or no digit if nbr_digits is equal to 0). Otherwise the ASCII character of the check digit is returned.
- */
-template <typename out, typename in>
-inline out compute_luhn(in &begin, const in &end, unsigned int nbr_digits)
+template <typename luhn_iter>
+char compute_luhn(luhn_iter &begin, const luhn_iter &end, unsigned int nbr_digits)
{
// If the number of digits isn't given (equal to 0), we count these.
if(!nbr_digits)
{
- in iter = begin;
+ luhn_iter iter = begin;
while(iter != end)
{
if(*iter >= '0' && *iter <= '9')
@@ -88,7 +72,7 @@
}
int sum = 0,v;
/* We start with the leftmost digit and we multiply by two
- * if the total number of digit is even. We alternate the multiplication
+ * if the total number of digit is odd. We alternate the multiplication
* for all the digits. We subtract 9 from the digit greater than 9
* after the multiplication. */
while(nbr_digits > 0 && begin != end)
@@ -97,16 +81,16 @@
sum += (v= (*begin & 15) << (nbr_digits--&1)) - 9 * (v>9);
++begin;
}
- return ((10 - sum % 10) % 10) | '0';
+ return (10 - sum % 10) % 10 | '0';
}
-template <typename in>
-inline char compute_luhn(in &begin, const in &end, unsigned int nbr_digits)
+template <typename out, typename luhn_iter>
+out compute_luhn(luhn_iter &begin, const luhn_iter &end, unsigned int nbr_digits)
{
// If the number of digits isn't given (equal to 0), we count these.
if(!nbr_digits)
{
- in iter = begin;
+ luhn_iter iter = begin;
while(iter != end)
{
if(*iter >= '0' && *iter <= '9')
@@ -122,7 +106,7 @@
}
int sum = 0,v;
/* We start with the leftmost digit and we multiply by two
- * if the total number of digit is odd. We alternate the multiplication
+ * if the total number of digit is even. We alternate the multiplication
* for all the digits. We subtract 9 from the digit greater than 9
* after the multiplication. */
while(nbr_digits > 0 && begin != end)
@@ -131,24 +115,11 @@
sum += (v= (*begin & 15) << (nbr_digits--&1)) - 9 * (v>9);
++begin;
}
- return (10 - sum % 10) % 10 | '0';
+ return ((10 - sum % 10) % 10) | '0';
}
-/** Validate the check digit of the number provided with the modulus 10 algorithm.
- * \tparam Iterator with at least the caracteristics of an input iterator. It represents the beginning or the ending of a sequence of character.
- * \tparam unsigned int[] which represents an array of weight.
- * \tparam unsigned int which represents a size.
- * \param [in] begin Represents the beginning of the sequence to check.
- * \param [in] end Represents one off the limit of the sequence to check.
- * \param [unsigned int\[\]] weight Represents the weight pattern of the sequence starting on the left of the expression. If weight is null, the algorithm will apply a weight of 1 on the sequence.
- * \param [unsigned int] nbr_digits Represents the number of digits on which the modulus 10 algorithm will operate. If the size is < 1, the modulus 10 algorithm will validate the check digit with all the digit encountered.
- * \pre begin and end are valid initialized iterators. They represent a sequence of character encoded in big-endian mode in a format compatible with the 7 bits ASCII.
- * \post begin is equal to the position of the check digit plus one if the expression provided is correct, otherwise is equal to end.
- * \returns true is returned if the expression given have a valid check digit and have nbr_digits (or more than 0 digit if nbr_digits is equal to 0).
- */
-
-template <typename in>
-inline bool check_mod10(in &begin, const in &end, unsigned int weight[], unsigned int nbr_digits)
+template <typename mod10_iter>
+bool check_mod10(mod10_iter &begin, const mod10_iter &end, unsigned int weight[], unsigned int nbr_digits)
{
// If the weight is null or have a size of zero, we apply a weight of 1 on each digit.
if(weight == NULL)
@@ -159,7 +130,7 @@
// If the number of digits isn't given (equal to 0), we count these.
if(!nbr_digits)
{
- in iter = begin;
+ mod10_iter iter = begin;
while(iter != end)
{
if(*iter >= '0' && *iter <= '9')
@@ -187,21 +158,8 @@
return !nbr_digits && !(sum % 10) ;
}
-/** Compute the check digit of the number provided with the modulus 10 algorithm.
- * \tparam Iterator with at least the caracteristics of an input iterator. It represents the beginning or the ending of a sequence of character.
- * \tparam unsigned int[] which represents an array of weight.
- * \tparam unsigned int which represents a size.
- * \param [in] begin Represents the beginning of the sequence to check.
- * \param [in] end Represents one off the limit of the sequence to check.
- * \param [unsigned int\[\]] weight Represents the weight pattern of the sequence starting on the left of the expression. If weight is null, the algorithm will apply a weight of 1 on the sequence.
- * \param [unsigned int] nbr_digits Represents the number of digits on which the modulus 10 algorithm will operate. If the size is < 1, the modulus 10 algorithm will calculate the check digit with all the digit encountered.
- * \pre begin and end are valid initialized iterators. They represent a sequence of character encoded in big-endian mode in a format compatible with the 7 bits ASCII.
- * \post begin is equal to the position of the last digit encountered plus one if the expression provided is correct, otherwise is equal to end.
- * \returns 0 is returned if the expression given have not nbr_digits (or no digit if nbr_digits is equal to 0). Otherwise the ASCII character of the check digit is returned.
- */
-
-template <typename in>
-inline char compute_mod10(in &begin, const in &end, unsigned int weight[], unsigned int nbr_digits)
+template <typename mod10_iter>
+char compute_mod10(mod10_iter &begin, const mod10_iter &end, unsigned int weight[], unsigned int nbr_digits)
{
// If the weight is null we apply a weight of 1 on each digit.
if(weight == NULL)
@@ -212,7 +170,7 @@
// If the number of digits isn't given (equal to 0), we count these.
if(!nbr_digits)
{
- in iter = begin;
+ mod10_iter iter = begin;
while(iter != end)
{
if(*iter >= '0' && *iter <= '9')
@@ -244,21 +202,8 @@
return (10 - sum % 10) % 10 | '0' ;
}
-/** Compute the check digit of the number provided with the modulus 10 algorithm.
- * \tparam Iterator with at least the caracteristics of an input iterator. It represents the beginning or the ending of a sequence of character.
- * \tparam unsigned int[] which represents an array of weight.
- * \tparam unsigned int which represents a size.
- * \param [in] begin Represents the beginning of the sequence to check.
- * \param [in] end Represents one off the limit of the sequence to check.
- * \param [unsigned int\[\]] weight Represents the weight pattern of the sequence starting on the left of the expression. If weight is null, the algorithm will apply a weight of 1 on the sequence.
- * \param [unsigned int] nbr_digits Represents the number of digits on which the modulus 10 algorithm will operate. If the size is < 1, the modulus 10 algorithm will calculate the check digit with all the digit encountered.
- * \pre begin and end are valid initialized iterators. They represent a sequence of character encoded in big-endian mode in a format compatible with the 7 bits ASCII.
- * \post begin is equal to the position of the last digit encountered plus one if the expression provided is correct, otherwise is equal to end.
- * \returns 0 is returned if the expression given have not nbr_digits (or no digit if nbr_digits is equal to 0). Otherwise the ASCII character of the check digit is returned.
- */
-
-template <typename out, typename in>
-inline out compute_mod10(in &begin, const in &end, unsigned int weight[], unsigned int nbr_digits)
+template <typename out, typename mod10_iter>
+out compute_mod10(mod10_iter &begin, const mod10_iter &end, unsigned int weight[], unsigned int nbr_digits)
{
// If the weight is null we apply a weight of 1 on each digit.
if(weight == NULL)
@@ -269,7 +214,7 @@
// If the number of digits isn't given (equal to 0), we count these.
if(!nbr_digits)
{
- in iter = begin;
+ mod10_iter iter = begin;
while(iter != end)
{
if(*iter >= '0' && *iter <= '9')
@@ -301,20 +246,10 @@
return (10 - sum % 10) % 10 | '0' ;
}
-/** Calculate the check digit of the number provided with the modulus 11 algorithm.
- * \tparam Iterator with at least the caracteristics of an input iterator. It represents the beginning or the ending of a sequence of character.
- * \tparam unsigned int which represents a size.
- * \param [in] begin Represents the beginning of the sequence to check.
- * \param [in] end Represents one off the limit of the sequence to check.
- * \param [unsigned int] nbr_digits Represents the number of digits on which the MOD11 algorithm will operate. If the size is < 1, the MOD11 algorithm will calculate the check digit with all the digit encountered.
- * \pre begin and end are valid initialized iterators. They represent a sequence of character encoded in big-endian mode in a format compatible with the 7 bits ASCII.
- * \post begin is equal to the position of the last digit encountered plus one if the expression provided is correct, otherwise is equal to end.
- * \returns 0 is returned if the expression given have not nbr_digits (or no digit if nbr_digits is equal to 0). Otherwise the ASCII character of the check digit is returned.
-*/
-template <typename in>
-inline bool check_mod11(in &begin, const in &end, unsigned int nbr_digits)
+template <typename mod11_iter>
+bool check_mod11(mod11_iter &begin, const mod11_iter &end, unsigned int nbr_digits)
{
- in iter = begin;
+ mod11_iter iter = begin;
// If the number of digits isn't given (equal to 0), we count these.
if(!nbr_digits)
{
@@ -367,20 +302,11 @@
// Return true if the number of digit is equal to the number specified and the sum is valid.
return !nbr_digits && !(sum % 11);
}
-/** Validate the check digit of the number provided with the modulus 11 algorithm.
- * \tparam Iterator with at least the caracteristics of an input iterator. It represents the beginning or the ending of a sequence of character.
- * \tparam unsigned int which represents a size.
- * \param [in] begin Represents the beginning of the sequence to check.
- * \param [in] end Represents one off the limit of the sequence to check.
- * \param [unsigned int] nbr_digits Represents the number of digits on which the Luhn algorithm will operate. If the size is < 1, the luhn algorithm will validate the check digit with all the digit encountered.
- * \pre begin and end are valid initialized iterators. They represent a sequence of character encoded in big-endian mode in a format compatible with the 7 bits ASCII.
- * \post begin is equal to the position of the check digit plus one if the expression provided is correct, otherwise is equal to end.
- * \returns true is returned if the expression given have a valid check digit and have nbr_digits (or more than 0 digit if nbr_digits is equal to 0).
- */
-template <typename out, typename in>
-inline out compute_mod11(in &begin, const in &end, unsigned int nbr_digits)
+
+template <typename mod11_iter>
+char compute_mod11(mod11_iter &begin, const mod11_iter &end, unsigned int nbr_digits)
{
- in iter = begin;
+ mod11_iter iter = begin;
// If the number of digits isn't given (equal to 0), we count these.
if(!nbr_digits)
{
@@ -412,26 +338,16 @@
return 0;
// Compute the check digit.
- int check_digit = (11 - sum % 11) %11;
+ char check_digit = (11 - sum % 11) %11;
if(check_digit == 10)
return 'X';
- return check_digit + '0';
+ return check_digit | '0';
}
-/** Validate the check digit of the number provided with the modulus 11 algorithm.
- * \tparam Iterator with at least the caracteristics of an input iterator. It represents the beginning or the ending of a sequence of character.
- * \tparam unsigned int which represents a size.
- * \param [in] begin Represents the beginning of the sequence to check.
- * \param [in] end Represents one off the limit of the sequence to check.
- * \param [unsigned int] nbr_digits Represents the number of digits on which the Luhn algorithm will operate. If the size is < 1, the luhn algorithm will validate the check digit with all the digit encountered.
- * \pre begin and end are valid initialized iterators. They represent a sequence of character encoded in big-endian mode in a format compatible with the 7 bits ASCII.
- * \post begin is equal to the position of the check digit plus one if the expression provided is correct, otherwise is equal to end.
- * \returns true is returned if the expression given have a valid check digit and have nbr_digits (or more than 0 digit if nbr_digits is equal to 0).
- */
-template <typename in>
-inline char compute_mod11(in &begin, const in &end, unsigned int nbr_digits)
+template <typename out, typename mod11_iter>
+out compute_mod11(mod11_iter &begin, const mod11_iter &end, unsigned int nbr_digits)
{
- in iter = begin;
+ mod11_iter iter = begin;
// If the number of digits isn't given (equal to 0), we count these.
if(!nbr_digits)
{
@@ -463,47 +379,20 @@
return 0;
// Compute the check digit.
- char check_digit = (11 - sum % 11) %11;
+ int check_digit = (11 - sum % 11) %11;
if(check_digit == 10)
return 'X';
- return check_digit + '0';
+ return check_digit | '0';
}
-
-/*!!!
-The modulus 97 algorithm wait for a sequence of numbers only ! and will not do anything else that sum the digits and calculate the modulus of this sum.
-If you need to check an IBAN use the algorithms in iban.hpp */
-
-/** Validate the check digit of the number provided with the modulus 97 algorithm.
- * \tparam Iterator with at least the caracteristics of an input iterator. It represents the beginning or the ending of a sequence of character.
- * \tparam unsigned int which represents a size.
- * \param [in] begin Represents the beginning of the sequence to check.
- * \param [in] end Represents one off the limit of the sequence to check.
- * \param [unsigned int] nbr_digits Represents the number of digits on which the modulus 97 algorithm will operate. If the size is < 1, the modulus 97 algorithm will validate the check digit with all the digit encountered.
- * \pre begin and end are valid initialized iterators. They represent a sequence of character encoded in big-endian mode in a format compatible with the 7 bits ASCII.
- * \post begin is equal to the position of the check digits plus one if the expression provided is correct, otherwise is equal to end.
- * \returns true is returned if the expression given have a valid check digit and have nbr_digits (or more than 0 digit if nbr_digits is equal to 0).
- */
-
-template <typename in>
-inline bool check_mod97(in &begin, const in &end, unsigned int nbr_digit)
+template <typename mod97_iter>
+bool check_mod97(mod97_iter &begin, const mod97_iter &end, unsigned int nbr_digits)
{
return false;
}
-/** Compute the check digit of the number provided with the modulus 97 algorithm.
- * \tparam Iterator with at least the caracteristics of an input iterator. It represents the beginning or the ending of a sequence of character.
- * \tparam unsigned int which represents a size.
- * \param [in] begin Represents the beginning of the sequence to check.
- * \param [in] end Represents one off the limit of the sequence to check.
- * \param [unsigned int] nbr_digits Represents the number of digits on which the modulus 97 algorithm will operate. If the size is < 1, the modulus 97 algorithm will calculate the check digit with all the digit encountered.
- * \pre begin and end are valid initialized iterators. They represent a sequence of character encoded in big-endian mode in a format compatible with the 7 bits ASCII.
- * \post begin is equal to the position of the last digit encountered plus one if the expression provided is correct, otherwise is equal to end.
- * \returns 0 is returned if the expression given have not nbr_digits (or no digit if nbr_digits is equal to 0). Otherwise the ASCII characters of the check digits are returned.
- */
-
-template <typename in>
-inline char compute_mod97(in &begin, const in &end, unsigned int nbr_digit)
+template <typename mod97_iter>
+char compute_mod97(mod97_iter &begin, const mod97_iter &end, unsigned int nbr_digits)
{
return false;
}
@@ -511,5 +400,5 @@
} // namespace checks
} // namespace boost
-#endif // #define BOOST_CHECK_MOD_INCLUDED
+#endif // BOOST_CHECK_MODULUS_HPP
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk