|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r73920 - sandbox/SOC/2011/checks/boost/checks
From: pierre.talbot.6114_at_[hidden]
Date: 2011-08-19 11:43:54
Author: trademark
Date: 2011-08-19 11:43:50 EDT (Fri, 19 Aug 2011)
New Revision: 73920
URL: http://svn.boost.org/trac/boost/changeset/73920
Log:
Adding the doxygen doc.
Adding MSC guard #pragma once.
Text files modified:
sandbox/SOC/2011/checks/boost/checks/amex.hpp | 62 ++++++++++++++++++
sandbox/SOC/2011/checks/boost/checks/basic_check_algorithm.hpp | 8 +
sandbox/SOC/2011/checks/boost/checks/basic_checks.hpp | 8 +-
sandbox/SOC/2011/checks/boost/checks/checks_fwd.hpp | 13 ---
sandbox/SOC/2011/checks/boost/checks/ean.hpp | 82 ++++++++++++++++++++++++
sandbox/SOC/2011/checks/boost/checks/isbn.hpp | 87 +++++++++++++++++++++++++
sandbox/SOC/2011/checks/boost/checks/iteration_sense.hpp | 4 +
sandbox/SOC/2011/checks/boost/checks/limits.hpp | 4 +
sandbox/SOC/2011/checks/boost/checks/luhn.hpp | 91 +++++++++++++++++++++++++++
sandbox/SOC/2011/checks/boost/checks/mastercard.hpp | 65 ++++++++++++++++++
sandbox/SOC/2011/checks/boost/checks/modulus10.hpp | 32 +++++++++
sandbox/SOC/2011/checks/boost/checks/modulus11.hpp | 110 +++++++++++++++++++++++++++++++++
sandbox/SOC/2011/checks/boost/checks/modulus97.hpp | 133 +++++++++++++++++++++++++++++++++++++++
sandbox/SOC/2011/checks/boost/checks/translation_exception.hpp | 12 +++
sandbox/SOC/2011/checks/boost/checks/upc.hpp | 51 +++++++++++++++
sandbox/SOC/2011/checks/boost/checks/verhoeff.hpp | 108 +++++++++++++++++++++++++++++++-
sandbox/SOC/2011/checks/boost/checks/visa.hpp | 63 ++++++++++++++++++
sandbox/SOC/2011/checks/boost/checks/weight.hpp | 4 +
sandbox/SOC/2011/checks/boost/checks/weighted_sum.hpp | 26 +++++++
19 files changed, 926 insertions(+), 37 deletions(-)
Modified: sandbox/SOC/2011/checks/boost/checks/amex.hpp
==============================================================================
--- sandbox/SOC/2011/checks/boost/checks/amex.hpp (original)
+++ sandbox/SOC/2011/checks/boost/checks/amex.hpp 2011-08-19 11:43:50 EDT (Fri, 19 Aug 2011)
@@ -5,22 +5,49 @@
// http://www.boost.org/LICENSE_1_0.txt
// See http://www.boost.org for updates, documentation, and revision history.
-// American express.
+/*! \file amex.hpp
+ \brief This file provides tools to compute and validate an American Express credit card number.
+*/
#ifndef BOOST_CHECKS_AMEX_HPP
#define BOOST_CHECKS_AMEX_HPP
+#ifdef _MSC_VER
+ #pragma once
+#endif
+
#include <boost/checks/luhn.hpp>
+/*!
+ \brief This macro defines the size of a American Express number.
+*/
#define AMEX_SIZE 15
+/*!
+ \brief This macro defines the size of a American Express number without its check digit.
+*/
#define AMEX_SIZE_WITHOUT_CHECKDIGIT 14
namespace boost {
namespace checks{
+/*! \class amex_algorithm
+ \brief This class can be used to compute or validate checksum with the Luhn algorithm but filter following the amex pattern.
+
+ \tparam number_of_virtual_value_skipped Help functions to provide same behavior on sequence with and without check digits. No "real" value in the sequence will be skipped.
+*/
template <unsigned int number_of_virtual_value_skipped = 0>
struct amex_algorithm : boost::checks::luhn_algorithm < number_of_virtual_value_skipped >
{
+ /*!
+ \brief Verify that a number matches the amex pattern.
+
+ \param current_valid_value is the current valid value analysed.
+ \param valid_value_counter is the number of valid value already counted (the current value is not included).\n This is also the position (above the valid values) of the current value analysed (0 <= valid_value_counter < n).
+
+ \throws std::invalid_argument if the first character is not equal to 3 or the second is not equal to 4 or 7. The exception contains a descriptive message of what was expected.
+
+ \remarks This function use the macro AMEX_SIZE to find the real position from left to right.
+ */
static void filter_valid_value_with_pos(const unsigned int current_valid_value, const unsigned int current_value_position )
{
const unsigned int real_pos_from_left = AMEX_SIZE - current_value_position - number_of_virtual_value_skipped ;
@@ -32,15 +59,48 @@
}
};
+/*!
+ \brief This is the type of the Amex algorithm for validating a check digit.
+*/
typedef amex_algorithm<0> amex_check_algorithm ;
+/*!
+ \brief This is the type of the Amex algorithm for computing a check digit.
+*/
typedef amex_algorithm<1> amex_compute_algorithm ;
+/*!
+ \brief Validate a sequence according to the amex_check_algorithm type.
+
+ \pre check_seq is a valid range.
+
+ \tparam check_range is a valid range type.
+ \param check_seq is the sequence of value to check.
+
+ \throws std::invalid_argument if check_seq doesn't contain exactly AMEX_SIZE digits.
+ \throws std::invalid_argument if the two first digits (from the leftmost) don't match the amex pattern.
+
+ \returns True if the check digit is correct, false otherwise.
+*/
template <typename check_range>
bool check_amex (const check_range& check_seq)
{
return boost::checks::check_sequence<amex_check_algorithm, AMEX_SIZE> ( check_seq ) ;
}
+/*!
+ \brief Calculate the check digit of a sequence according to the amex_compute_algorithm type.
+
+ \pre check_seq is a valid range.
+
+ \tparam check_range is a valid range type.
+ \param check_seq is the sequence of value to check.
+
+ \throws std::invalid_argument if check_seq doesn't contain exactly AMEX_SIZE_WITHOUT_CHECKDIGIT digits.
+ \throws std::invalid_argument if the two first digits (from the leftmost) don't match the amex pattern.
+ \throws boost::checks::translation_exception if the check digit cannot be translated into the checkdigit type.
+
+ \returns The check digit. The check digit is in the range [0..9].
+*/
template <typename check_range>
typename boost::checks::amex_compute_algorithm::checkdigit<check_range>::type compute_amex (const check_range& check_seq)
{
Modified: sandbox/SOC/2011/checks/boost/checks/basic_check_algorithm.hpp
==============================================================================
--- sandbox/SOC/2011/checks/boost/checks/basic_check_algorithm.hpp (original)
+++ sandbox/SOC/2011/checks/boost/checks/basic_check_algorithm.hpp 2011-08-19 11:43:50 EDT (Fri, 19 Aug 2011)
@@ -14,6 +14,11 @@
#ifndef BOOST_CHECKS_BASIC_CHECK_ALGO_HPP
#define BOOST_CHECKS_BASIC_CHECK_ALGO_HPP
+#ifdef _MSC_VER
+ #pragma once
+#endif
+
+
#include <boost/lexical_cast.hpp>
#include <boost/checks/translation_exception.hpp>
#include <boost/checks/iteration_sense.hpp>
@@ -110,8 +115,7 @@
}
/*!
- \brief Compute an operation on the current valid value an the checksum.
-
+ \brief Compute an operation on the checksum with the current valid value
\post Do nothing. The checksum is inchanged.
\param current_valid_value is the current valid value analysed.
Modified: sandbox/SOC/2011/checks/boost/checks/basic_checks.hpp
==============================================================================
--- sandbox/SOC/2011/checks/boost/checks/basic_checks.hpp (original)
+++ sandbox/SOC/2011/checks/boost/checks/basic_checks.hpp 2011-08-19 11:43:50 EDT (Fri, 19 Aug 2011)
@@ -5,7 +5,7 @@
// http://www.boost.org/LICENSE_1_0.txt
// See http://www.boost.org for updates, documentation, and revision history.
-/*! \file basic_check.hpp
+/*! \file basic_checks.hpp
\brief This file provides a set of basic functions used to compute and validate check digit(s) and checksum.
*/
@@ -14,7 +14,7 @@
#ifdef _MSC_VER
#pragma once
-#endif // _MSC_VER
+#endif
#include <boost/checks/limits.hpp>
#include <boost/lexical_cast.hpp>
@@ -125,7 +125,7 @@
}
/*!
- \brief Calculate the checkdigit of a sequence according to algorithm.
+ \brief Calculate the check digit of a sequence according to algorithm.
\pre check_seq is a valid range.
@@ -145,7 +145,7 @@
}
/*!
- \brief Calculate the checkdigit of a sequence according to algorithm.
+ \brief Calculate the check digit of a sequence according to algorithm.
\pre check_seq is a valid range.\n size_expected > 0 (enforced by static assert).
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-08-19 11:43:50 EDT (Fri, 19 Aug 2011)
@@ -56,18 +56,7 @@
#ifdef _MSC_VER
#pragma once
-#endif // _MSC_VER
-
-#include <boost/checks/luhn.hpp>
-#include <boost/checks/verhoeff.hpp>
-#include <boost/checks/modulus11.hpp>
-#include <boost/checks/modulus97.hpp>
-#include <boost/checks/ean.hpp>
-#include <boost/checks/isbn.hpp>
-#include <boost/checks/upc.hpp>
-#include <boost/checks/amex.hpp>
-#include <boost/checks/visa.hpp>
-#include <boost/checks/mastercard.hpp>
+#endif
namespace boost{
namespace checks{
Modified: sandbox/SOC/2011/checks/boost/checks/ean.hpp
==============================================================================
--- sandbox/SOC/2011/checks/boost/checks/ean.hpp (original)
+++ sandbox/SOC/2011/checks/boost/checks/ean.hpp 2011-08-19 11:43:50 EDT (Fri, 19 Aug 2011)
@@ -5,48 +5,128 @@
// http://www.boost.org/LICENSE_1_0.txt
// See http://www.boost.org for updates, documentation, and revision history.
-// European Article Numbering 13 and 8.
+/*! \file ean.hpp
+ \brief This file provides tools to compute and validate an European Article Numbering of size 8 or 13.
+*/
#ifndef BOOST_CHECKS_EAN_HPP
#define BOOST_CHECKS_EAN_HPP
+#ifdef _MSC_VER
+ #pragma once
+#endif
+
#include <boost/checks/weight.hpp>
#include <boost/checks/iteration_sense.hpp>
#include <boost/checks/basic_checks.hpp>
#include <boost/checks/modulus10.hpp>
+/*!
+ \brief This macro defines the size of an EAN-13.
+*/
#define EAN13_SIZE 13
+/*!
+ \brief This macro defines the size of an EAN-13 without its check digit.
+*/
#define EAN13_SIZE_WITHOUT_CHECKDIGIT 12
+/*!
+ \brief This macro defines the size of an EAN-8.
+*/
#define EAN8_SIZE 8
+/*!
+ \brief This macro defines the size of a EAN-8 without its check digit.
+*/
#define EAN8_SIZE_WITHOUT_CHECKDIGIT 7
namespace boost {
namespace checks{
+/*!
+ \brief This is the weight used by EAN system.
+*/
typedef boost::checks::weight<1,3> ean_weight ;
+/*!
+ \brief This is the running sense to check an EAN.
+*/
typedef boost::checks::rightmost ean_sense ;
+/*!
+ \brief This is the type of the EAN algorithm for validating a check digit.
+*/
typedef boost::checks::modulus10_algorithm< ean_weight, ean_sense, 0> ean_check_algorithm ;
+/*!
+ \brief This is the type of the EAN algorithm for computing a check digit.
+*/
typedef boost::checks::modulus10_algorithm< ean_weight, ean_sense, 1> ean_compute_algorithm ;
+/*!
+ \brief Validate a sequence according to the ean_check_algorithm type.
+
+ \pre check_seq is a valid range.
+
+ \tparam check_range is a valid range type.
+ \param check_seq is the sequence of value to check.
+
+ \throws std::invalid_argument if check_seq doesn't contain exactly EAN13_SIZE digits.
+
+ \returns True if the check digit is correct, false otherwise.
+*/
template <typename check_range>
bool check_ean13 (const check_range& check_seq)
{
return boost::checks::check_sequence<ean_check_algorithm, EAN13_SIZE> ( check_seq ) ;
}
+/*!
+ \brief Calculate the check digit of a sequence according to the ean_compute_algorithm type.
+
+ \pre check_seq is a valid range.
+
+ \tparam check_range is a valid range type.
+ \param check_seq is the sequence of value to check.
+
+ \throws std::invalid_argument if check_seq doesn't contain exactly EAN13_SIZE_WITHOUT_CHECKDIGIT digits.
+ \throws boost::checks::translation_exception if the check digit cannot be translated into the checkdigit type.
+
+ \returns The check digit. The check digit is in the range [0..9].
+*/
template <typename check_range>
typename boost::checks::ean_compute_algorithm::checkdigit<check_range>::type compute_ean13 (const check_range& check_seq)
{
return boost::checks::compute_checkdigit<ean_compute_algorithm, EAN13_SIZE_WITHOUT_CHECKDIGIT> ( check_seq ) ;
}
+/*!
+ \brief Validate a sequence according to the ean_check_algorithm type.
+
+ \pre check_seq is a valid range.
+
+ \tparam check_range is a valid range type.
+ \param check_seq is the sequence of value to check.
+
+ \throws std::invalid_argument if check_seq doesn't contain exactly EAN8_SIZE digits.
+
+ \returns True if the check digit is correct, false otherwise.
+*/
template <typename check_range>
bool check_ean8 (const check_range& check_seq)
{
return boost::checks::check_sequence<ean_check_algorithm, EAN8_SIZE> ( check_seq ) ;
}
+/*!
+ \brief Calculate the check digit of a sequence according to the ean_compute_algorithm type.
+
+ \pre check_seq is a valid range.
+
+ \tparam check_range is a valid range type.
+ \param check_seq is the sequence of value to check.
+
+ \throws std::invalid_argument if check_seq doesn't contain exactly EAN8_SIZE_WITHOUT_CHECKDIGIT digits.
+ \throws boost::checks::translation_exception if the check digit cannot be translated into the checkdigit type.
+
+ \returns The check digit. The check digit is in the range [0..9].
+*/
template <typename check_range>
typename boost::checks::ean_compute_algorithm::checkdigit<check_range>::type compute_ean8 (const check_range& check_seq)
{
Modified: sandbox/SOC/2011/checks/boost/checks/isbn.hpp
==============================================================================
--- sandbox/SOC/2011/checks/boost/checks/isbn.hpp (original)
+++ sandbox/SOC/2011/checks/boost/checks/isbn.hpp 2011-08-19 11:43:50 EDT (Fri, 19 Aug 2011)
@@ -5,24 +5,52 @@
// http://www.boost.org/LICENSE_1_0.txt
// See http://www.boost.org for updates, documentation, and revision history.
+/*! \file isbn.hpp
+ \brief This file provides tools to compute and validate an International Standard Book Number of size 10 or 13.
+
+ \remarks The ISBN-13 is derived from the EAN number, so EAN macro or type are used.
+*/
#ifndef BOOST_CHECKS_ISBN_HPP
#define BOOST_CHECKS_ISBN_HPP
+#ifdef _MSC_VER
+ #pragma once
+#endif
+
#include <boost/checks/ean.hpp>
#include <boost/checks/modulus11.hpp>
+/*!
+ \brief This macro defines the size of an ISBN-10.
+*/
#define ISBN10_SIZE 10
+/*!
+ \brief This macro defines the size of an ISBN-10 without its check digit.
+*/
#define ISBN10_SIZE_WITHOUT_CHECKDIGIT 9
namespace boost {
namespace checks{
-// ISBN-13
+/*! \class isbn13_algorithm
+ \brief This class can be used to compute or validate checksum with a basic modulus 10 but using a custom filter for the ISBN-13 prefix.
+ \tparam number_of_virtual_value_skipped Help functions to provide same behavior on sequence with and without check digits. No "real" value in the sequence will be skipped.
+*/
template <unsigned int number_of_virtual_value_skipped = 0>
struct isbn13_algorithm : boost::checks::modulus10_algorithm < boost::checks::ean_weight, boost::checks::ean_sense, number_of_virtual_value_skipped >
{
+ /*!
+ \brief Verify that a number matches the ISBN-13 pattern.
+
+ \param current_valid_value is the current valid value analysed.
+ \param valid_value_counter is the number of valid value already counted (the current value is not included).\n This is also the position (above the valid values) of the current value analysed (0 <= valid_value_counter < n).
+
+ \throws std::invalid_argument if the three first character are not equal to 978 or 979. The exception contains a descriptive message of what was expected.
+
+ \remarks This function use the macro EAN13_SIZE to find the real position from left to right.
+ */
static void filter_valid_value_with_pos(const unsigned int current_valid_value, const unsigned int current_value_position )
{
const unsigned int real_pos_from_left = EAN13_SIZE - current_value_position - number_of_virtual_value_skipped ;
@@ -36,34 +64,87 @@
}
};
+/*!
+ \brief This is the type of the ISBN-13 algorithm for validating a check digit.
+*/
typedef boost::checks::isbn13_algorithm<0> isbn13_check_algorithm ;
+/*!
+ \brief This is the type of the ISBN-13 algorithm for computing a check digit.
+*/
typedef boost::checks::isbn13_algorithm<1> isbn13_compute_algorithm ;
+/*!
+ \brief Validate a sequence according to the isbn13_check_algorithm type.
+
+ \pre check_seq is a valid range.
+
+ \tparam check_range is a valid range type.
+ \param check_seq is the sequence of value to check.
+
+ \throws std::invalid_argument if check_seq doesn't contain exactly EAN13_SIZE digits.
+
+ \returns True if the check digit is correct, false otherwise.
+*/
template <typename check_range>
bool check_isbn13 (const check_range& check_seq)
{
return boost::checks::check_sequence<isbn13_check_algorithm, EAN13_SIZE> ( check_seq ) ;
}
+/*!
+ \brief Calculate the check digit of a sequence according to the isbn13_compute_algorithm type.
+
+ \pre check_seq is a valid range.
+
+ \tparam check_range is a valid range type.
+ \param check_seq is the sequence of value to check.
+
+ \throws std::invalid_argument if check_seq doesn't contain exactly EAN13_SIZE_WITHOUT_CHECKDIGIT digits.
+ \throws boost::checks::translation_exception if the check digit cannot be translated into the checkdigit type.
+
+ \returns The check digit. The check digit is in the range [0..9].
+*/
template <typename check_range>
typename boost::checks::isbn13_compute_algorithm::checkdigit<check_range>::type compute_isbn13 (const check_range& check_seq)
{
return boost::checks::compute_checkdigit<isbn13_compute_algorithm, EAN13_SIZE_WITHOUT_CHECKDIGIT> ( check_seq ) ;
}
+/*!
+ \brief Validate a sequence according to the mod11_check_algorithm type.
+
+ \pre check_seq is a valid range.
-// ISBN-10
+ \tparam check_range is a valid range type.
+ \param check_seq is the sequence of value to check.
+ \throws std::invalid_argument if check_seq doesn't contain exactly ISBN10_SIZE digits.
+
+ \returns True if the check digit is correct, false otherwise.
+*/
template <typename check_range>
bool check_isbn10 (const check_range& check_seq)
{
return boost::checks::check_modulus11< ISBN10_SIZE >( check_seq );
}
+/*!
+ \brief Calculate the check digit of a sequence according to the mod11_compute_algorithm type.
+
+ \pre check_seq is a valid range.
+
+ \tparam check_range is a valid range type.
+ \param check_seq is the sequence of value to check.
+
+ \throws std::invalid_argument if check_seq doesn't contain exactly ISBN10_SIZE_WITHOUT_CHECKDIGIT digits.
+ \throws boost::checks::translation_exception if the check digit cannot be translated into the checkdigit type.
+
+ \returns The check digit. The check digit is in the range [0..9,X].
+*/
template <typename check_range>
typename boost::checks::mod11_compute_algorithm::checkdigit<check_range>::type compute_isbn10 (const check_range& check_seq)
{
- return boost::checks::compute_checkdigit<boost::checks::mod11_compute_algorithm, ISBN10_SIZE_WITHOUT_CHECKDIGIT> ( check_seq ) ;
+ return boost::checks::compute_modulus11< ISBN10_SIZE_WITHOUT_CHECKDIGIT >( check_seq ) ;
}
Modified: sandbox/SOC/2011/checks/boost/checks/iteration_sense.hpp
==============================================================================
--- sandbox/SOC/2011/checks/boost/checks/iteration_sense.hpp (original)
+++ sandbox/SOC/2011/checks/boost/checks/iteration_sense.hpp 2011-08-19 11:43:50 EDT (Fri, 19 Aug 2011)
@@ -13,6 +13,10 @@
#ifndef BOOST_CHECK_ITERATION_SENSE_HPP
#define BOOST_CHECK_ITERATION_SENSE_HPP
+#ifdef _MSC_VER
+ #pragma once
+#endif
+
#include <boost/range/reverse_iterator.hpp>
#include <boost/range/iterator_range.hpp>
#include <boost/range/const_iterator.hpp>
Modified: sandbox/SOC/2011/checks/boost/checks/limits.hpp
==============================================================================
--- sandbox/SOC/2011/checks/boost/checks/limits.hpp (original)
+++ sandbox/SOC/2011/checks/boost/checks/limits.hpp 2011-08-19 11:43:50 EDT (Fri, 19 Aug 2011)
@@ -12,6 +12,10 @@
#ifndef BOOST_CHECK_LIMITS_HPP
#define BOOST_CHECK_LIMITS_HPP
+#ifdef _MSC_VER
+ #pragma once
+#endif
+
#include <boost/static_assert.hpp>
namespace boost{
Modified: sandbox/SOC/2011/checks/boost/checks/luhn.hpp
==============================================================================
--- sandbox/SOC/2011/checks/boost/checks/luhn.hpp (original)
+++ sandbox/SOC/2011/checks/boost/checks/luhn.hpp 2011-08-19 11:43:50 EDT (Fri, 19 Aug 2011)
@@ -5,20 +5,51 @@
// http://www.boost.org/LICENSE_1_0.txt
// See http://www.boost.org for updates, documentation, and revision history.
+/*! \file luhn.hpp
+ \brief This file provides tools to compute and validate sequence with the Luhn algorithm.
+*/
+
#ifndef BOOST_CHECKS_LUHN_INCLUDED
#define BOOST_CHECKS_LUHN_INCLUDED
+#ifdef _MSC_VER
+ #pragma once
+#endif
+
#include <boost/checks/modulus10.hpp>
namespace boost {
namespace checks{
+/*!
+ \brief This is the weight used by the Luhn algorithm.
+*/
typedef boost::checks::weight<1,2> luhn_weight ;
+
+/*!
+ \brief This is the running sense to check an Luhn number.
+*/
typedef boost::checks::rightmost luhn_sense ;
+/*! \class luhn_algorithm
+ \brief This class can be used to compute or validate checksum with the Luhn algorithm.
+
+ \tparam number_of_virtual_value_skipped Help functions to provide same behavior on sequence with and without check digits. No "real" value in the sequence will be skipped.
+*/
template <unsigned int number_of_virtual_value_skipped = 0>
struct luhn_algorithm : boost::checks::modulus10_algorithm < luhn_weight, luhn_sense, number_of_virtual_value_skipped>
-{
+{
+ /*!
+ \brief Compute the Luhn algorithm operation on the checksum.
+
+ \post checksum is equal to the new computed checksum.
+
+ \param current_valid_value is the current valid value analysed.
+ \param valid_value_counter is the number of valid value already counted (the current value is not included).\n This is also the position (above the valid values) of the current value analysed (0 <= valid_value_counter < n).
+ \param checksum is the current checksum.
+
+ \remarks This function become obsolete if you don't use luhn_weight. It's using operator "<<" to make internal multiplication.
+ */
static void operate_on_valid_value( const int current_valid_value, const unsigned int valid_value_counter, int &checksum )
{
int current_weight = luhn_weight::weight_associated_with_pos( valid_value_counter + number_of_virtual_value_skipped ) ;
@@ -26,27 +57,85 @@
}
};
+/*!
+ \brief This is the type of the Luhn algorithm for validating a check digit.
+*/
typedef luhn_algorithm<0> luhn_check_algorithm ;
+/*!
+ \brief This is the type of the Luhn algorithm for computing a check digit.
+*/
typedef luhn_algorithm<1> luhn_compute_algorithm ;
+/*!
+ \brief Validate a sequence according to the luhn_check_algorithm type.
+
+ \pre check_seq is a valid range.\n size_expected > 0 (enforced by static assert).
+
+ \tparam size_expected is the number of valid value expected in the sequence.
+ \tparam check_range is a valid range type.
+ \param check_seq is the sequence of value to check.
+
+ \throws std::invalid_argument if check_seq doesn't contain size_expected valid values.
+
+ \returns True if the check digit is correct, false otherwise.
+*/
template <size_t size_expected, typename check_range>
bool check_luhn (const check_range& check_seq)
{
return boost::checks::check_sequence<luhn_check_algorithm, size_expected> ( check_seq ) ;
}
+/*!
+ \brief Validate a sequence according to the luhn_check_algorithm type.
+
+ \pre check_seq is a valid range.
+
+ \tparam check_range is a valid range type.
+ \param check_seq is the sequence of value to check.
+
+ \throws std::invalid_argument if check_seq contains no valid value.
+
+ \returns True if the check digit is correct, false otherwise.
+*/
template <typename check_range>
bool check_luhn (const check_range& check_seq)
{
return boost::checks::check_sequence<luhn_check_algorithm> ( check_seq ) ;
}
+/*!
+ \brief Calculate the check digit of a sequence according to the luhn_compute_algorithm type.
+
+ \pre check_seq is a valid range.\n size_expected > 0 (enforced by static assert).
+
+ \tparam size_expected is the number of valid value expected in the sequence. (So the check digit is not included.)
+ \tparam check_range is a valid range type.
+ \param check_seq is the sequence of value to check.
+
+ \throws std::invalid_argument if check_seq doesn't contain size_expected valid values.
+ \throws boost::checks::translation_exception if the check digit cannot be translated into the checkdigit type.
+
+ \returns The check digit. The check digit is in the range [0..9].
+*/
template <size_t size_expected, typename check_range>
typename boost::checks::luhn_compute_algorithm::checkdigit<check_range>::type compute_luhn (const check_range& check_seq)
{
return boost::checks::compute_checkdigit<luhn_compute_algorithm, size_expected> ( check_seq ) ;
}
+/*!
+ \brief Calculate the check digit of a sequence according to the luhn_compute_algorithm type.
+
+ \pre check_seq is a valid range.
+
+ \tparam check_range is a valid range type.
+ \param check_seq is the sequence of value to check.
+
+ \throws std::invalid_argument if check_seq contains no valid value.
+ \throws boost::checks::translation_exception if the check digit cannot be translated into the checkdigit type.
+
+ \returns The check digit. The check digit is in the range [0..9].
+*/
template <typename check_range>
typename boost::checks::luhn_compute_algorithm::checkdigit<check_range>::type compute_luhn (const check_range& check_seq)
{
Modified: sandbox/SOC/2011/checks/boost/checks/mastercard.hpp
==============================================================================
--- sandbox/SOC/2011/checks/boost/checks/mastercard.hpp (original)
+++ sandbox/SOC/2011/checks/boost/checks/mastercard.hpp 2011-08-19 11:43:50 EDT (Fri, 19 Aug 2011)
@@ -5,21 +5,49 @@
// http://www.boost.org/LICENSE_1_0.txt
// See http://www.boost.org for updates, documentation, and revision history.
+/*! \file mastercard.hpp
+ \brief This file provides tools to compute and validate a Mastercard credit card number.
+*/
+
#ifndef BOOST_CHECKS_MASTERCARD_HPP
#define BOOST_CHECKS_MASTERCARD_HPP
+#ifdef _MSC_VER
+ #pragma once
+#endif
+
#include <boost/checks/luhn.hpp>
+/*!
+ \brief This macro defines the size of a Mastercard number.
+*/
#define MASTERCARD_SIZE 16
+/*!
+ \brief This macro defines the size of a Mastercard number without its check digit.
+*/
#define MASTERCARD_SIZE_WITHOUT_CHECKDIGIT 15
namespace boost {
namespace checks{
+/*! \class mastercard_algorithm
+ \brief This class can be used to compute or validate checksum with the Luhn algorithm but filter following the Mastercard pattern.
+ \tparam number_of_virtual_value_skipped Help functions to provide same behavior on sequence with and without check digits. No "real" value in the sequence will be skipped.
+*/
template <unsigned int number_of_virtual_value_skipped = 0>
struct mastercard_algorithm : boost::checks::luhn_algorithm < number_of_virtual_value_skipped >
-{
+{
+ /*!
+ \brief Verify that a number matches the Mastercard pattern.
+
+ \param current_valid_value is the current valid value analysed.
+ \param valid_value_counter is the number of valid value already counted (the current value is not included).\n This is also the position (above the valid values) of the current value analysed (0 <= valid_value_counter < n).
+
+ \throws std::invalid_argument if the first character is not equal to 5 or the second is not between 1 and 5. The exception contains a descriptive message of what was expected.
+
+ \remarks This function use the macro MASTERCARD_SIZE to find the real position from left to right.
+ */
static void filter_valid_value_with_pos(const unsigned int current_valid_value, const unsigned int current_value_position )
{
const unsigned int real_pos_from_left = MASTERCARD_SIZE - current_value_position - number_of_virtual_value_skipped ;
@@ -27,19 +55,52 @@
if( real_pos_from_left == 1 && current_valid_value != 5)
throw std::invalid_argument("The Major Industry Identifier of a Mastercard should be 5.") ;
else if( real_pos_from_left == 2 && (current_valid_value == 0 || current_valid_value > 5) )
- throw std::invalid_argument("The Issuer Identification Number of an American Express should be between 51 and 55." ) ;
+ throw std::invalid_argument("The Issuer Identification Number of an Mastercard should be between 51 and 55." ) ;
}
};
+/*!
+ \brief This is the type of the Mastercard algorithm for validating a check digit.
+*/
typedef mastercard_algorithm<0> mastercard_check_algorithm ;
+/*!
+ \brief This is the type of the Mastercard algorithm for computing a check digit.
+*/
typedef mastercard_algorithm<1> mastercard_compute_algorithm ;
+/*!
+ \brief Validate a sequence according to the mastercard_check_algorithm type.
+
+ \pre check_seq is a valid range.
+
+ \tparam check_range is a valid range type.
+ \param check_seq is the sequence of value to check.
+
+ \throws std::invalid_argument if check_seq doesn't contain exactly MASTERCARD_SIZE digits.
+ \throws std::invalid_argument if the two first digits (from the leftmost) don't match the mastercard pattern.
+
+ \returns True if the check digit is correct, false otherwise.
+*/
template <typename check_range>
bool check_mastercard (const check_range& check_seq)
{
return boost::checks::check_sequence<mastercard_check_algorithm, MASTERCARD_SIZE> ( check_seq ) ;
}
+/*!
+ \brief Calculate the check digit of a sequence according to the mastercard_compute_algorithm type.
+
+ \pre check_seq is a valid range.
+
+ \tparam check_range is a valid range type.
+ \param check_seq is the sequence of value to check.
+
+ \throws std::invalid_argument if check_seq doesn't contain exactly MASTERCARD_SIZE_WITHOUT_CHECKDIGIT digits.
+ \throws std::invalid_argument if the two first digits (from the leftmost) don't match the mastercard pattern.
+ \throws boost::checks::translation_exception if the check digit cannot be translated into the checkdigit type.
+
+ \returns The check digit. The check digit is in the range [0..9].
+*/
template <typename check_range>
typename boost::checks::mastercard_compute_algorithm::checkdigit<check_range>::type compute_mastercard (const check_range& check_seq)
{
Modified: sandbox/SOC/2011/checks/boost/checks/modulus10.hpp
==============================================================================
--- sandbox/SOC/2011/checks/boost/checks/modulus10.hpp (original)
+++ sandbox/SOC/2011/checks/boost/checks/modulus10.hpp 2011-08-19 11:43:50 EDT (Fri, 19 Aug 2011)
@@ -5,9 +5,17 @@
// http://www.boost.org/LICENSE_1_0.txt
// See http://www.boost.org for updates, documentation, and revision history.
+/*! \file modulus10.hpp
+ \brief This file provides tools to compute and validate classic modulus 10 checksum.
+*/
+
#ifndef BOOST_CHECKS_MOD10_HPP
#define BOOST_CHECKS_MOD10_HPP
+#ifdef _MSC_VER
+ #pragma once
+#endif
+
#include <boost/lexical_cast.hpp>
#include <boost/checks/translation_exception.hpp>
#include <boost/checks/weight.hpp>
@@ -17,14 +25,38 @@
namespace boost{
namespace checks{
+/*! \class modulus10_algorithm
+ \brief This class can be used to compute or validate checksum with a basic modulus 10.
+
+ \tparam mod10_weight must meet the weight concept requirements.
+ \tparam iteration_sense must meet the iteration_sense concept requirements.
+ \tparam number_of_virtual_value_skipped Help functions to provide same behavior on sequence with and without check digits. No "real" value in the sequence will be skipped.
+*/
template <typename mod10_weight, typename iteration_sense, unsigned int number_of_virtual_value_skipped = 0>
struct modulus10_algorithm : boost::checks::weighted_sum_algorithm<mod10_weight, iteration_sense, number_of_virtual_value_skipped>
{
+ /*!
+ \brief Validate a checksum with a simple modulus 10.
+
+ \param checksum is the checksum to validate.
+
+ \returns true if the checksum is correct, false otherwise.
+ */
static bool validate_checksum(int checksum)
{
return !(checksum % 10) ;
}
+ /*!
+ \brief Compute the check digit with a simple modulus 10.
+
+ \tparam checkdigit is the type of the check digit desired.
+ \param checksum is the checksum used to extract the check digit.
+
+ \throws boost::checks::translation_exception if the check digit cannot be translated into the checkdigit type.
+
+ \returns The modulus 10 check digit of checksum.
+ */
template <typename checkdigit>
static typename checkdigit compute_checkdigit( int checksum )
{
Modified: sandbox/SOC/2011/checks/boost/checks/modulus11.hpp
==============================================================================
--- sandbox/SOC/2011/checks/boost/checks/modulus11.hpp (original)
+++ sandbox/SOC/2011/checks/boost/checks/modulus11.hpp 2011-08-19 11:43:50 EDT (Fri, 19 Aug 2011)
@@ -5,9 +5,17 @@
// http://www.boost.org/LICENSE_1_0.txt
// See http://www.boost.org for updates, documentation, and revision history.
+/*! \file modulus11.hpp
+ \brief This file provides tools to compute and validate classic modulus 11 checksum.
+*/
+
#ifndef BOOST_CHECKS_MOD11_HPP
#define BOOST_CHECKS_MOD11_HPP
+#ifdef _MSC_VER
+ #pragma once
+#endif
+
#include <boost/lexical_cast.hpp>
#include <boost/checks/translation_exception.hpp>
#include <boost/checks/weight.hpp>
@@ -18,9 +26,30 @@
namespace boost{
namespace checks{
+/*! \class modulus11_algorithm
+ \brief This class can be used to compute or validate checksum with a basic modulus 11.
+
+ \tparam mod11_weight must meet the weight concept requirements.
+ \tparam iteration_sense must meet the iteration_sense concept requirements.
+ \tparam number_of_virtual_value_skipped Help functions to provide same behavior on sequence with and without check digits. No "real" value in the sequence will be skipped.
+
+ \remarks The range of the check digit is [0..10], the tenth element is translated as the letter 'X'.
+*/
template <typename mod11_weight, typename iteration_sense, unsigned int number_of_virtual_value_skipped = 0>
struct modulus11_algorithm : boost::checks::weighted_sum_algorithm<mod11_weight, iteration_sense, number_of_virtual_value_skipped>
{
+
+ /*!
+ \brief translate the current value into an integer valid value.
+
+ \tparam value is the type of a value in the sequence.
+ \param current_value is the current value analysed in the sequence that must be translated.
+ \param valid_value_counter is the number of valid value already counted (the current value is not included).\n This is also the position (above the valid values) of the current value analysed (0 <= valid_value_counter < n).
+
+ \throws boost::checks::translation_exception is throwed if the translation of current_value failed.\n The translation will fail if the current value is not a digit or the 'x' or 'X' character.
+
+ \returns the translation of the current value. 10 is returned if the current value was 'X' or 'x'.
+*/
template <typename value>
static int translate_to_valid_value(const value ¤t_value, const unsigned int valid_value_counter )
{
@@ -39,11 +68,28 @@
return valid_value ;
}
+ /*!
+ \brief Validate a checksum with a simple modulus 11.
+
+ \param checksum is the checksum to validate.
+
+ \returns true if the checksum is correct, false otherwise.
+ */
static bool validate_checksum(int checksum)
{
return !(checksum % 11) ;
}
+ /*!
+ \brief Compute the check digit with a simple modulus 11.
+
+ \tparam checkdigit is the type of the check digit desired.
+ \param checksum is the checksum used to extract the check digit.
+
+ \throws boost::checks::translation_exception if the check digit cannot be translated into the checkdigit type.
+
+ \returns The modulus 11 check digit of checksum. 'X' is returned if the check digit is equal to 10.
+ */
template <typename checkdigit>
static typename checkdigit compute_checkdigit( int checksum )
{
@@ -65,30 +111,94 @@
}
};
+/*!
+ \brief The most common weight pattern used with a modulus 11 algorithm.
+*/
typedef boost::checks::weight<1,2,3,4,5,6,7,8,9,10> mod11_weight ;
+/*!
+ \brief The most common iteration sense used with a modulus 11 algorithm.
+*/
typedef boost::checks::rightmost mod11_sense ;
+/*!
+ \brief This is the type of the most common modulus 11 algorithm for validating a check digit.
+*/
typedef modulus11_algorithm<mod11_weight, mod11_sense, 0> mod11_check_algorithm ;
+/*!
+ \brief This is the type of the most common modulus 11 algorithm for computing a check digit.
+*/
typedef modulus11_algorithm<mod11_weight, mod11_sense, 1> mod11_compute_algorithm ;
+/*!
+ \brief Validate a sequence according to the mod11_check_algorithm type.
+
+ \pre check_seq is a valid range.\n size_expected > 0 (enforced by static assert).
+
+ \tparam size_expected is the number of valid value expected in the sequence.
+ \tparam check_range is a valid range type.
+ \param check_seq is the sequence of value to check.
+
+ \throws std::invalid_argument if check_seq doesn't contain size_expected valid values.
+
+ \returns True if the check digit is correct, false otherwise.
+*/
template <size_t size_expected, typename check_range>
bool check_modulus11 (const check_range& check_seq)
{
return boost::checks::check_sequence<mod11_check_algorithm, size_expected> ( check_seq ) ;
}
+/*!
+ \brief Validate a sequence according to the mod11_check_algorithm type.
+
+ \pre check_seq is a valid range.
+
+ \tparam check_range is a valid range type.
+ \param check_seq is the sequence of value to check.
+
+ \throws std::invalid_argument if check_seq contains no valid value.
+
+ \returns True if the check digit is correct, false otherwise.
+*/
template <typename check_range>
bool check_modulus11 (const check_range& check_seq)
{
return boost::checks::check_sequence<mod11_check_algorithm> ( check_seq ) ;
}
+/*!
+ \brief Calculate the check digit of a sequence according to the mod11_compute_algorithm type.
+
+ \pre check_seq is a valid range.\n size_expected > 0 (enforced by static assert).
+
+ \tparam size_expected is the number of valid value expected in the sequence. (So the check digit is not included.)
+ \tparam check_range is a valid range type.
+ \param check_seq is the sequence of value to check.
+
+ \throws std::invalid_argument if check_seq doesn't contain size_expected valid values.
+ \throws boost::checks::translation_exception if the check digit cannot be translated into the checkdigit type.
+
+ \returns The check digit. The check digit is in the range [0..9,X].
+*/
template <size_t size_expected, typename check_range>
typename boost::checks::mod11_compute_algorithm::checkdigit<check_range>::type compute_modulus11 (const check_range& check_seq)
{
return boost::checks::compute_checkdigit<mod11_compute_algorithm, size_expected> ( check_seq ) ;
}
+/*!
+ \brief Calculate the check digit of a sequence according to the mod11_compute_algorithm type.
+
+ \pre check_seq is a valid range.
+
+ \tparam check_range is a valid range type.
+ \param check_seq is the sequence of value to check.
+
+ \throws std::invalid_argument if check_seq contains no valid value.
+ \throws boost::checks::translation_exception if the check digit cannot be translated into the checkdigit type.
+
+ \returns The check digit. The check digit is in the range [0..9,X].
+*/
template <typename check_range>
typename boost::checks::mod11_compute_algorithm::checkdigit<check_range>::type compute_modulus11 (const check_range& check_seq)
{
Modified: sandbox/SOC/2011/checks/boost/checks/modulus97.hpp
==============================================================================
--- sandbox/SOC/2011/checks/boost/checks/modulus97.hpp (original)
+++ sandbox/SOC/2011/checks/boost/checks/modulus97.hpp 2011-08-19 11:43:50 EDT (Fri, 19 Aug 2011)
@@ -5,9 +5,17 @@
// http://www.boost.org/LICENSE_1_0.txt
// See http://www.boost.org for updates, documentation, and revision history.
+/*! \file modulus97.hpp
+ \brief This file provides tools to compute and validate classic modulus 97 checksum. It provides function for convenience with the mod97-10 algorithm (ISO/IEC 7064:2003).
+*/
+
#ifndef BOOST_CHECKS_MOD97_HPP
#define BOOST_CHECKS_MOD97_HPP
+#ifdef _MSC_VER
+ #pragma once
+#endif
+
#include <boost/preprocessor/repetition.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/checks/translation_exception.hpp>
@@ -18,14 +26,44 @@
namespace boost{
namespace checks{
+/*! \class modulus97_algorithm
+ \brief This class can be used to compute or validate checksum with a basic modulus 97.
+
+ \tparam mod97_weight must meet the weight concept requirements.
+ \tparam iteration_sense must meet the iteration_sense concept requirements.
+ \tparam number_of_virtual_value_skipped Help functions to provide same behavior on sequence with and without check digits. No "real" value in the sequence will be skipped.
+
+ \remarks This algorithm use two check digits.
+*/
template <typename mod97_weight, typename iteration_sense, unsigned int number_of_virtual_value_skipped = 0>
struct modulus97_algorithm : boost::checks::weighted_sum_algorithm<mod97_weight, iteration_sense, number_of_virtual_value_skipped>
{
+ /*!
+ \brief Validate a checksum with a simple modulus 97.
+
+ \param checksum is the checksum to validate.
+
+ \returns true if the checksum is correct, false otherwise.
+ */
static bool validate_checksum(int checksum)
{
return checksum % 97 == 1 ;
}
+ /*!
+ \brief Compute the two check digits with a simple modulus 97.
+
+ \pre checkdigits should have enough reserved place to store the two check digits.
+ \post The two check digits are stored into checkdigits.
+
+ \tparam checkdigits_iter must meet the OutputIterator requirements.
+ \param checksum is the checksum used to extract the check digit.
+ \param checkdigits is the output iterator in which the two check digits will be written.
+
+ \throws boost::checks::translation_exception if the check digits cannot be translated into the check digits_iter type.
+
+ \returns An iterator initialized at one pass the end of the two check digits.
+ */
template <typename checkdigits_iter>
static typename checkdigits_iter compute_multicheckdigit( int checksum, checkdigits_iter checkdigits )
{
@@ -44,7 +82,13 @@
}
};
-// cf. ISO/IEC 7064:2003 for the mod97-10 algorithm.
+/*! \class make_mod97_weight
+ \brief This class is used to pre-computed the weight of the mod97-10 algorithm (a = 1; a = a * 10 % 97 ;).
+
+ \tparam weight_value is the weight value stored by make_mod97_weight.
+
+ \remarks The last value is 68, so we specialize make_mod97_weight to terminate the template recursion.
+*/
template <unsigned int weight_value>
struct make_mod97_weight
{
@@ -57,33 +101,116 @@
static const unsigned int value = 68 ;
typedef make_mod97_weight type ;
};
+
+/*!
+ \brief This is the initial weight for the mod97-10 weights serie.
+*/
+typedef make_mod97_weight<1> initial_mod97_weight ;
+
+
+/*!
+ \brief This macro is used to access the next type.
+*/
#define NEXT(z,n,unused) next::
-#define MOD97_make_weight(z, n ,unused) make_mod97_weight<1>::BOOST_PP_REPEAT(n, NEXT, ~)value
-typedef boost::checks::weight< BOOST_PP_ENUM(96, MOD97_make_weight, ~) > mod97_10_weight ;
+/*!
+ \brief This macro is used to access to n-th value of initial_mod97_weight. (By using make_mod97_weight).
+*/
+#define MOD97_weight_maker(z, n ,unused) initial_mod97_weight::BOOST_PP_REPEAT(n, NEXT, ~)value
+
+/*!
+ \brief This is weight of the mod97-10 algorithm.
+*/
+typedef boost::checks::weight< BOOST_PP_ENUM(96, MOD97_weight_maker, ~) > mod97_10_weight ;
+
+/*!
+ \brief The iteration sense of the sequence. From right to left.
+*/
typedef boost::checks::rightmost mod97_10_sense ;
+/*!
+ \brief This is the type of the modulus 97-10 algorithm for validating a check digit.
+*/
typedef modulus97_algorithm< mod97_10_weight, mod97_10_sense, 0 > mod97_10_check_algorithm ;
+/*!
+ \brief This is the type of the modulus 97-10 algorithm for computing a check digit.
+*/
typedef modulus97_algorithm< mod97_10_weight, mod97_10_sense, 2 > mod97_10_compute_algorithm ;
+/*!
+ \brief Validate a sequence according to the mod97_10_check_algorithm type.
+
+ \pre check_seq is a valid range.\n size_expected > 0 (enforced by static assert).
+
+ \tparam size_expected is the number of valid value expected in the sequence.
+ \tparam check_range is a valid range type.
+ \param check_seq is the sequence of value to check.
+
+ \throws std::invalid_argument if check_seq doesn't contain size_expected valid values.
+
+ \returns True if the two check digits are correct, false otherwise.
+*/
template <size_t size_expected, typename check_range>
bool check_mod97_10 (const check_range& check_seq)
{
return boost::checks::check_sequence<mod97_10_check_algorithm, size_expected> ( check_seq ) ;
}
+/*!
+ \brief Validate a sequence according to the mod97_10_check_algorithm type.
+
+ \pre check_seq is a valid range.
+
+ \tparam check_range is a valid range type.
+ \param check_seq is the sequence of value to check.
+
+ \throws std::invalid_argument if check_seq contains no valid value.
+
+ \returns True if the two check digits are correct, false otherwise.
+*/
template <typename check_range>
bool check_mod97_10 (const check_range& check_seq)
{
return boost::checks::check_sequence<mod97_10_check_algorithm> ( check_seq ) ;
}
+/*!
+ \brief Calculate the check digits of a sequence according to the mod97_10_compute_algorithm type.
+
+ \pre check_seq is a valid range.\n size_expected > 0 (enforced by static assert).\n mod97_checkdigits should have enough reserved place to store the two check digits.
+
+ \tparam size_expected is the number of valid value expected in the sequence. (So the check digits are not included.)
+ \tparam check_range is a valid range type.
+ \tparam checkdigits_iter must meet the OutputIterator requirements.
+ \param check_seq is the sequence of value to check.
+ \param mod97_checkdigits is the OutputIterator in which the two check digits will be stored.
+
+ \throws std::invalid_argument if check_seq doesn't contain size_expected valid values.
+ \throws boost::checks::translation_exception if the check digits cannot be translated into the checkdigits_iter type.
+
+ \returns The check digits are stored into mod97_checkdigits. The range of these is [0..9][0..9].
+*/
template <size_t size_expected, typename check_range, typename checkdigits_iter>
typename checkdigits_iter compute_mod97_10 (const check_range& check_seq, checkdigits_iter mod97_checkdigits)
{
return boost::checks::compute_multicheckdigit<mod97_10_compute_algorithm, size_expected> ( check_seq, mod97_checkdigits ) ;
}
+/*!
+ \brief Calculate the check digits of a sequence according to the mod97_10_compute_algorithm type.
+
+ \pre check_seq is a valid range.\n mod97_checkdigits should have enough reserved place to store the two check digits.
+
+ \tparam check_range is a valid range type.
+ \tparam checkdigits_iter must meet the OutputIterator requirements.
+ \param check_seq is the sequence of value to check.
+ \param mod97_checkdigits is the OutputIterator in which the two check digits will be stored.
+
+ \throws std::invalid_argument if check_seq contains no valid value.
+ \throws boost::checks::translation_exception if the check digits cannot be translated into the checkdigits_iter type.
+
+ \returns The check digits are stored into mod97_checkdigits. The range of these is [0..9][0..9].
+*/
template <typename check_range, typename checkdigits_iter>
typename checkdigits_iter compute_mod97_10 (const check_range& check_seq, checkdigits_iter mod97_checkdigits)
{
Modified: sandbox/SOC/2011/checks/boost/checks/translation_exception.hpp
==============================================================================
--- sandbox/SOC/2011/checks/boost/checks/translation_exception.hpp (original)
+++ sandbox/SOC/2011/checks/boost/checks/translation_exception.hpp 2011-08-19 11:43:50 EDT (Fri, 19 Aug 2011)
@@ -5,14 +5,24 @@
// http://www.boost.org/LICENSE_1_0.txt
// See http://www.boost.org for updates, documentation, and revision history.
+/*! \file translation_exception.hpp
+ \brief This file provides an exception class used when the translation of a value failed.
+*/
+
#ifndef BOOST_CHECKS_translation_EXCEPTION_HPP
#define BOOST_CHECKS_translation_EXCEPTION_HPP
+#ifdef _MSC_VER
+ #pragma once
+#endif
+
#include <exception>
namespace boost{
namespace checks{
-
+/*! \class translation_exception
+ \brief This class provides support for translation failure. For example, sequence value into integer, or integer into check digit type.
+*/
class translation_exception : public std::exception
{
};
Modified: sandbox/SOC/2011/checks/boost/checks/upc.hpp
==============================================================================
--- sandbox/SOC/2011/checks/boost/checks/upc.hpp (original)
+++ sandbox/SOC/2011/checks/boost/checks/upc.hpp 2011-08-19 11:43:50 EDT (Fri, 19 Aug 2011)
@@ -5,34 +5,83 @@
// http://www.boost.org/LICENSE_1_0.txt
// See http://www.boost.org for updates, documentation, and revision history.
-// European Article Numbering 13 and 8.
+/*! \file upc.hpp
+ \brief This file provides tools to compute and validate an Universal Product Code.
+*/
#ifndef BOOST_CHECKS_UPC_HPP
#define BOOST_CHECKS_UPC_HPP
+#ifdef _MSC_VER
+ #pragma once
+#endif
+
#include <boost/checks/weight.hpp>
#include <boost/checks/iteration_sense.hpp>
#include <boost/checks/basic_checks.hpp>
#include <boost/checks/modulus10.hpp>
+/*!
+ \brief This macro defines the size of an UPC-A.
+*/
#define UPCA_SIZE 12
+/*!
+ \brief This macro defines the size of an UPC-A without its check digit.
+*/
#define UPCA_SIZE_WITHOUT_CHECKDIGIT 11
namespace boost {
namespace checks{
+/*!
+ \brief This is the weight used by UPC system.
+*/
typedef boost::checks::weight<1,3> upc_weight ;
+/*!
+ \brief This is the running sense to check an UPC.
+*/
typedef boost::checks::rightmost upc_sense ;
+/*!
+ \brief This is the type of the UPC algorithm for validating a check digit.
+*/
typedef boost::checks::modulus10_algorithm< upc_weight, upc_sense, 0> upc_check_algorithm ;
+/*!
+ \brief This is the type of the UPC algorithm for computing a check digit.
+*/
typedef boost::checks::modulus10_algorithm< upc_weight, upc_sense, 1> upc_compute_algorithm ;
+/*!
+ \brief Validate a sequence according to the upc_check_algorithm type.
+
+ \pre check_seq is a valid range.
+
+ \tparam check_range is a valid range type.
+ \param check_seq is the sequence of value to check.
+
+ \throws std::invalid_argument if check_seq doesn't contain exactly UPCA_SIZE digits.
+
+ \returns True if the check digit is correct, false otherwise.
+*/
template <typename check_range>
bool check_upca (const check_range& check_seq)
{
return boost::checks::check_sequence<upc_check_algorithm, UPCA_SIZE> ( check_seq ) ;
}
+/*!
+ \brief Calculate the check digit of a sequence according to the upc_compute_algorithm type.
+
+ \pre check_seq is a valid range.
+
+ \tparam check_range is a valid range type.
+ \param check_seq is the sequence of value to check.
+
+ \throws std::invalid_argument if check_seq doesn't contain exactly UPCA_SIZE_WITHOUT_CHECKDIGIT digits.
+ \throws boost::checks::translation_exception if the check digit cannot be translated into the checkdigit type.
+
+ \returns The check digit. The check digit is in the range [0..9].
+*/
template <typename check_range>
typename boost::checks::upc_compute_algorithm::checkdigit<check_range>::type compute_upca (const check_range& check_seq)
{
Modified: sandbox/SOC/2011/checks/boost/checks/verhoeff.hpp
==============================================================================
--- sandbox/SOC/2011/checks/boost/checks/verhoeff.hpp (original)
+++ sandbox/SOC/2011/checks/boost/checks/verhoeff.hpp 2011-08-19 11:43:50 EDT (Fri, 19 Aug 2011)
@@ -5,9 +5,17 @@
// http://www.boost.org/LICENSE_1_0.txt
// See http://www.boost.org for updates, documentation, and revision history.
+/*! \file verhoeff.hpp
+ \brief This file provides tools to compute a Verhoeff checksum.
+*/
+
#ifndef BOOST_VERHOEFF_INCLUDED
#define BOOST_VERHOEFF_INCLUDED
+#ifdef _MSC_VER
+ #pragma once
+#endif
+
#include <boost/lexical_cast.hpp>
#include <boost/checks/translation_exception.hpp>
#include <boost/checks/weight.hpp>
@@ -18,11 +26,30 @@
namespace boost {
namespace checks{
+/*!
+ \brief This is the sense of the Verhoeff sequence iteration.
+*/
typedef boost::checks::rightmost verhoeff_iteration_sense ;
+/*! \class verhoeff_algorithm
+ \brief This class can be used to compute or validate checksum with the Verhoeff algorithm.
+
+ \tparam number_of_virtual_value_skipped Help functions to provide same behavior on sequence with and without check digits. No "real" value in the sequence will be skipped.
+*/
template <unsigned int number_of_virtual_value_skipped = 0>
struct verhoeff_algorithm : boost::checks::basic_check_algorithm<verhoeff_iteration_sense, number_of_virtual_value_skipped>
-{
+{
+ /*!
+ \brief Compute the Verhoeff scheme on the checksum with the current valid value.
+
+ \post checksum is equal to the new computed checksum.
+
+ \param current_valid_value is the current valid value analysed.
+ \param valid_value_counter is the number of valid value already counted (the current value is not included).\n This is also the position (above the valid values) of the current value analysed (0 <= valid_value_counter < n).
+ \param checksum is the current checksum.
+
+ \remarks This function use the classic table d and p of the Verhoeff algorithm.
+ */
static void operate_on_valid_value( const int current_valid_value, const unsigned int valid_value_counter, int &checksum )
{
static const unsigned int d[10][10] =
@@ -54,11 +81,28 @@
checksum = d[ checksum ][ p[ (valid_value_counter + number_of_virtual_value_skipped) % 8 ][ current_valid_value ] ] ;
}
+ /*!
+ \brief Validate the Verhoeff checksum.
+
+ \param checksum is the checksum to validate.
+
+ \returns true if the checksum is correct, false otherwise.
+ */
static bool validate_checksum(int checksum)
{
return !checksum ;
}
+ /*!
+ \brief Compute the check digit with the Verhoeff inverse table.
+
+ \tparam checkdigit is the type of the check digit desired.
+ \param checksum is the checksum used to extract the check digit.
+
+ \throws boost::checks::translation_exception if the check digit cannot be translated into the checkdigit type.
+
+ \returns The Verhoeff check digit of checksum.
+ */
template <typename checkdigit>
static typename checkdigit compute_checkdigit( int checksum )
{
@@ -75,35 +119,91 @@
}
};
-
+/*!
+ \brief This is the type of the Verhoeff algorithm for validating a check digit.
+*/
typedef verhoeff_algorithm<0> verhoeff_check_algorithm ;
+/*!
+ \brief This is the type of the Verhoeff algorithm for computing a check digit.
+*/
typedef verhoeff_algorithm<1> verhoeff_compute_algorithm ;
+/*!
+ \brief Validate a sequence according to the verhoeff_check_algorithm type.
+
+ \pre check_seq is a valid range.\n size_expected > 0 (enforced by static assert).
+
+ \tparam size_expected is the number of valid value expected in the sequence.
+ \tparam check_range is a valid range type.
+ \param check_seq is the sequence of value to check.
+
+ \throws std::invalid_argument if check_seq doesn't contain size_expected valid values.
+
+ \returns True if the check digit is correct, false otherwise.
+*/
template <size_t size_expected, typename check_range>
bool check_verhoeff (const check_range& check_seq)
{
return boost::checks::check_sequence<verhoeff_check_algorithm, size_expected> ( check_seq ) ;
}
+/*!
+ \brief Validate a sequence according to the verhoeff_check_algorithm type.
+
+ \pre check_seq is a valid range.
+
+ \tparam check_range is a valid range type.
+ \param check_seq is the sequence of value to check.
+
+ \throws std::invalid_argument if check_seq contains no valid value.
+
+ \returns True if the check digit is correct, false otherwise.
+*/
template <typename check_range>
bool check_verhoeff (const check_range& check_seq)
{
return boost::checks::check_sequence<verhoeff_check_algorithm> ( check_seq ) ;
}
+/*!
+ \brief Calculate the check digit of a sequence according to the verhoeff_compute_algorithm type.
+
+ \pre check_seq is a valid range.\n size_expected > 0 (enforced by static assert).
+
+ \tparam size_expected is the number of valid value expected in the sequence. (So the check digit is not included.)
+ \tparam check_range is a valid range type.
+ \param check_seq is the sequence of value to check.
+
+ \throws std::invalid_argument if check_seq doesn't contain size_expected valid values.
+ \throws boost::checks::translation_exception if the check digit cannot be translated into the checkdigit type.
+
+ \returns The check digit. The check digit is in the range [0..9].
+*/
template <size_t size_expected, typename check_range>
typename boost::checks::verhoeff_compute_algorithm::checkdigit<check_range>::type compute_verhoeff (const check_range& check_seq)
{
return boost::checks::compute_checkdigit<verhoeff_compute_algorithm, size_expected> ( check_seq ) ;
}
+/*!
+ \brief Calculate the check digit of a sequence according to the verhoeff_compute_algorithm type.
+
+ \pre check_seq is a valid range.
+
+ \tparam check_range is a valid range type.
+ \param check_seq is the sequence of value to check.
+
+ \throws std::invalid_argument if check_seq contains no valid value.
+ \throws boost::checks::translation_exception if the check digit cannot be translated into the checkdigit type.
+
+ \returns The check digit. The check digit is in the range [0..9].
+*/
template <typename check_range>
typename boost::checks::verhoeff_compute_algorithm::checkdigit<check_range>::type compute_verhoeff (const check_range& check_seq)
{
return boost::checks::compute_checkdigit<verhoeff_compute_algorithm> ( check_seq ) ;
}
-} // namespace checks
-} // namespace boost
+}}
#endif
Modified: sandbox/SOC/2011/checks/boost/checks/visa.hpp
==============================================================================
--- sandbox/SOC/2011/checks/boost/checks/visa.hpp (original)
+++ sandbox/SOC/2011/checks/boost/checks/visa.hpp 2011-08-19 11:43:50 EDT (Fri, 19 Aug 2011)
@@ -5,21 +5,49 @@
// http://www.boost.org/LICENSE_1_0.txt
// See http://www.boost.org for updates, documentation, and revision history.
+/*! \file visa.hpp
+ \brief This file provides tools to compute and validate a Visa credit card number.
+*/
+
#ifndef BOOST_CHECKS_VISA_HPP
#define BOOST_CHECKS_VISA_HPP
+#ifdef _MSC_VER
+ #pragma once
+#endif
+
#include <boost/checks/luhn.hpp>
+/*!
+ \brief This macro defines the size of a Visa number.
+*/
#define VISA_SIZE 16
+/*!
+ \brief This macro defines the size of a Visa number without its check digit.
+*/
#define VISA_SIZE_WITHOUT_CHECKDIGIT 15
namespace boost {
namespace checks{
+/*! \class visa_algorithm
+ \brief This class can be used to compute or validate checksum with the Luhn algorithm but filter following the Visa pattern.
+ \tparam number_of_virtual_value_skipped Help functions to provide same behavior on sequence with and without check digits. No "real" value in the sequence will be skipped.
+*/
template <unsigned int number_of_virtual_value_skipped = 0>
struct visa_algorithm : boost::checks::luhn_algorithm < number_of_virtual_value_skipped >
-{
+{
+ /*!
+ \brief Verify that a number matches the Visa pattern.
+
+ \param current_valid_value is the current valid value analysed.
+ \param valid_value_counter is the number of valid value already counted (the current value is not included).\n This is also the position (above the valid values) of the current value analysed (0 <= valid_value_counter < n).
+
+ \throws std::invalid_argument if the first character is not equal to 4. The exception contains a descriptive message of what was expected.
+
+ \remarks This function use the macro VISA_SIZE to find the real position from left to right.
+ */
static void filter_valid_value_with_pos(const unsigned int current_valid_value, const unsigned int current_value_position )
{
const unsigned int real_pos_from_left = VISA_SIZE - current_value_position - number_of_virtual_value_skipped ;
@@ -29,15 +57,48 @@
}
};
+/*!
+ \brief This is the type of the Visa algorithm for validating a check digit.
+*/
typedef visa_algorithm<0> visa_check_algorithm ;
+/*!
+ \brief This is the type of the Visa algorithm for computing a check digit.
+*/
typedef visa_algorithm<1> visa_compute_algorithm ;
+/*!
+ \brief Validate a sequence according to the visa_check_algorithm type.
+
+ \pre check_seq is a valid range.
+
+ \tparam check_range is a valid range type.
+ \param check_seq is the sequence of value to check.
+
+ \throws std::invalid_argument if check_seq doesn't contain exactly VISA_SIZE digits.
+ \throws std::invalid_argument if the first digit (from the leftmost) doesn't match the Visa pattern.
+
+ \returns True if the check digit is correct, false otherwise.
+*/
template <typename check_range>
bool check_visa (const check_range& check_seq)
{
return boost::checks::check_sequence<visa_check_algorithm, VISA_SIZE> ( check_seq ) ;
}
+/*!
+ \brief Calculate the check digit of a sequence according to the visa_compute_algorithm type.
+
+ \pre check_seq is a valid range.
+
+ \tparam check_range is a valid range type.
+ \param check_seq is the sequence of value to check.
+
+ \throws std::invalid_argument if check_seq doesn't contain exactly VISA_SIZE_WITHOUT_CHECKDIGIT digits.
+ \throws std::invalid_argument if the first digit (from the leftmost) doESn't match the Visa pattern.
+ \throws boost::checks::translation_exception if the check digit cannot be translated into the checkdigit type.
+
+ \returns The check digit. The check digit is in the range [0..9].
+*/
template <typename check_range>
typename boost::checks::visa_compute_algorithm::checkdigit<check_range>::type compute_visa (const check_range& check_seq)
{
Modified: sandbox/SOC/2011/checks/boost/checks/weight.hpp
==============================================================================
--- sandbox/SOC/2011/checks/boost/checks/weight.hpp (original)
+++ sandbox/SOC/2011/checks/boost/checks/weight.hpp 2011-08-19 11:43:50 EDT (Fri, 19 Aug 2011)
@@ -12,6 +12,10 @@
#ifndef BOOST_CHECK_WEIGHT_HPP
#define BOOST_CHECK_WEIGHT_HPP
+#ifdef _MSC_VER
+ #pragma once
+#endif
+
#include <boost/preprocessor/repetition.hpp>
#include <boost/preprocessor/facilities/intercept.hpp>
Modified: sandbox/SOC/2011/checks/boost/checks/weighted_sum.hpp
==============================================================================
--- sandbox/SOC/2011/checks/boost/checks/weighted_sum.hpp (original)
+++ sandbox/SOC/2011/checks/boost/checks/weighted_sum.hpp 2011-08-19 11:43:50 EDT (Fri, 19 Aug 2011)
@@ -5,9 +5,17 @@
// http://www.boost.org/LICENSE_1_0.txt
// See http://www.boost.org for updates, documentation, and revision history.
+/*! \file weighted_sum.hpp
+ \brief This file provides tools to compute weighted sum.
+*/
+
#ifndef BOOST_CHECKS_WEIGHTED_SUM_HPP
#define BOOST_CHECKS_WEIGHTED_SUM_HPP
+#ifdef _MSC_VER
+ #pragma once
+#endif
+
#include <boost/checks/weight.hpp>
#include <boost/checks/iteration_sense.hpp>
#include <boost/checks/basic_check_algorithm.hpp>
@@ -15,9 +23,25 @@
namespace boost{
namespace checks{
+/*! \class weighted_sum_algorithm
+ \brief This class permit to add to the current checksum the weight multiply by the current value.
+
+ \tparam weight must meet the weight concept requirements.
+ \tparam iteration_sense must meet the iteration_sense concept requirements.
+ \tparam number_of_virtual_value_skipped Help functions to provide same behavior on sequence with and without checkdigits. No "real" value in the sequence will be skipped.
+*/
template <typename weight, typename iteration_sense, unsigned int number_of_virtual_value_skipped = 0>
struct weighted_sum_algorithm : boost::checks::basic_check_algorithm< iteration_sense >
-{
+{
+ /*!
+ \brief Compute an operation on the checksum with the current valid value.
+
+ \post The current weight multiply by the current value is added to the checksum.
+
+ \param current_valid_value is the current valid value analysed.
+ \param valid_value_counter is the number of valid value already counted (the current value is not included).\n This is also the position (above the valid values) of the current value analysed (0 <= valid_value_counter < n).
+ \param checksum is the current checksum.
+ */
static void operate_on_valid_value( const int current_valid_value, const unsigned int valid_value_counter, int &checksum )
{
int current_weight = weight::weight_associated_with_pos( valid_value_counter + number_of_virtual_value_skipped ) ;
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