|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r77014 - sandbox/SOC/2011/checks/boost/checks
From: pierre.talbot.6114_at_[hidden]
Date: 2012-02-14 03:16:46
Author: trademark
Date: 2012-02-14 03:16:44 EST (Tue, 14 Feb 2012)
New Revision: 77014
URL: http://svn.boost.org/trac/boost/changeset/77014
Log:
Prechecksum struct (filtering bad character and convert it to readable digit for the checksum).
Added:
sandbox/SOC/2011/checks/boost/checks/conversion.hpp (contents, props changed)
sandbox/SOC/2011/checks/boost/checks/prechecksum.hpp (contents, props changed)
Text files modified:
sandbox/SOC/2011/checks/boost/checks/amex.hpp | 8 ++-
sandbox/SOC/2011/checks/boost/checks/basic_check_algorithm.hpp | 37 +++++++++++---------
sandbox/SOC/2011/checks/boost/checks/basic_checks.hpp | 70 ++++++++++++++++++---------------------
sandbox/SOC/2011/checks/boost/checks/ean.hpp | 8 ++--
sandbox/SOC/2011/checks/boost/checks/filter.hpp | 11 +++--
sandbox/SOC/2011/checks/boost/checks/isbn.hpp | 4 +-
sandbox/SOC/2011/checks/boost/checks/luhn.hpp | 8 ++--
sandbox/SOC/2011/checks/boost/checks/mastercard.hpp | 4 +-
sandbox/SOC/2011/checks/boost/checks/modulus11.hpp | 34 ++-----------------
sandbox/SOC/2011/checks/boost/checks/modulus97.hpp | 8 ++--
sandbox/SOC/2011/checks/boost/checks/upc.hpp | 4 +-
sandbox/SOC/2011/checks/boost/checks/verhoeff.hpp | 15 ++++++--
sandbox/SOC/2011/checks/boost/checks/visa.hpp | 4 +-
13 files changed, 98 insertions(+), 117 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 2012-02-14 03:16:44 EST (Tue, 14 Feb 2012)
@@ -17,7 +17,9 @@
#endif
#include <cstddef> // std::size_t
-
+#include <boost/checks/prechecksum.hpp>
+#include <boost/checks/conversion.hpp>
+#include <boost/checks/filter.hpp>
#include <boost/checks/checkdigit.hpp>
#include <boost/checks/luhn.hpp>
@@ -49,7 +51,7 @@
template <typename check_range>
bool check_amex (const check_range& check_seq)
{
- return boost::checks::check_sequence<luhn_algorithm, digit_filter, AMEX_SIZE>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::check_sequence<luhn_algorithm, typename digit_prechecksum<typename boost::range_reverse_iterator<check_range>::type>::type, AMEX_SIZE>(boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -69,7 +71,7 @@
template <typename check_range>
std::size_t compute_amex(const check_range& check_seq)
{
- return boost::checks::compute_checkdigit<luhn_algorithm, digit_filter, AMEX_SIZE, boost::checks::basic_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::compute_checkdigit<luhn_algorithm, typename digit_prechecksum<typename boost::range_reverse_iterator<check_range>::type>::type, AMEX_SIZE, basic_checkdigit>(boost::rbegin(check_seq), boost::rend(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 2012-02-14 03:16:44 EST (Tue, 14 Feb 2012)
@@ -20,9 +20,29 @@
#include <cstddef> // std::size_t
#include <boost/checks/filter.hpp>
+#include <boost/checks/conversion.hpp>
+#include <boost/checks/prechecksum.hpp>
+#include <boost/range.hpp>
namespace boost{
namespace checks{
+
+
+template <typename Iterator>
+struct digit_prechecksum
+{
+ typedef prechecksum<digit_filter<typename Iterator::value_type>,
+ chartodigit<typename Iterator::value_type>,
+ Iterator> type;
+};
+
+template <typename Iterator>
+struct digitx_prechecksum
+{
+ typedef prechecksum<digitx_filter<typename Iterator::value_type>,
+ chartodigitx<typename Iterator::value_type>,
+ Iterator> type;
+};
/*! \class basic_check_algorithm
\brief The main check algorithm class that provides every static function that can be overloaded.\n Most of the functions must be re-implemented to have the desired behavior.
@@ -33,23 +53,6 @@
struct basic_check_algorithm
{
/*!
- \brief translate a value of the sequence 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(s) already counted (the current value is not included).\n This is also the position (beyond the valid values) of the current value analysed (0 <= valid_value_counter < n).
-
- \throws boost::checks::translation_exception is thrown if the translation of current_value failed.\n This will automatically throw if the value is not a digit (0 <= i < 10).
-
- \returns the translation of the current value in the range [0..9].
-*/
- template <typename value_type>
- static std::size_t convert(const value_type &value)
- {
- return value - '0';
- }
-
- /*!
\brief Validate the checksum.
\param checksum is the checksum to validate.
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 2012-02-14 03:16:44 EST (Tue, 14 Feb 2012)
@@ -21,9 +21,12 @@
#include <boost/checks/detail/sequence_counter.hpp>
#include <boost/iterator/filter_iterator.hpp>
+
namespace boost {
namespace checks{
+struct no_prechecksum_tag {};
+
static const std::size_t bad_sequence = -1;
/*!
@@ -50,8 +53,7 @@
std::size_t checksum = 0;
for(; seq_begin != seq_end && *counter < size_expected; ++seq_begin)
{
- std::size_t value = algorithm::convert(*seq_begin);
- checksum = algorithm::process(checksum, value, *counter);
+ checksum = algorithm::process(checksum, *seq_begin, *counter);
++counter;
}
if(*counter != size_expected || seq_begin != seq_end)
@@ -64,11 +66,10 @@
typename counter_type>
std::size_t compute_checksum(seq_iterator seq_begin, seq_iterator seq_end, counter_type &counter)
{
- std::size_t checksum = 0;
+ std::size_t checksum = 0;
for(; seq_begin != seq_end; ++seq_begin)
{
- std::size_t value = algorithm::convert(*seq_begin);
- checksum = algorithm::process(checksum, value, *counter);
+ checksum = algorithm::process(checksum, *seq_begin, *counter);
++counter;
}
return checksum;
@@ -88,15 +89,15 @@
\returns @c true if the checkdigit is correct, @c false otherwise.
*/
template <typename algorithm,
- typename UnaryPredicate,
+ typename prechecksum_type,
typename seq_iterator>
bool check_sequence(seq_iterator seq_begin, seq_iterator seq_end)
{
boost::checks::detail::simple_counter::type counter = boost::checks::detail::simple_counter()();
- typedef boost::filter_iterator<UnaryPredicate, seq_iterator> skip_iterator;
- UnaryPredicate predicate;
- std::size_t checksum = compute_checksum<algorithm>(skip_iterator(predicate, seq_begin, seq_end),
- skip_iterator(predicate, seq_end, seq_end),
+
+ prechecksum_type prechecksum;
+ std::size_t checksum = compute_checksum<algorithm>(prechecksum(seq_begin, seq_end),
+ prechecksum(seq_end, seq_end),
counter);
return algorithm::validate_checksum(checksum);
}
@@ -116,16 +117,16 @@
\returns @c true if the checkdigit is correct, @c false otherwise.
*/
template <typename algorithm,
- typename UnaryPredicate,
+ typename prechecksum_type,
std::size_t size_expected,
typename seq_iterator>
bool check_sequence(seq_iterator seq_begin, seq_iterator seq_end)
{
- typedef boost::filter_iterator<UnaryPredicate, seq_iterator> skip_iterator;
- UnaryPredicate predicate;
boost::checks::detail::simple_counter::type counter = boost::checks::detail::simple_counter()();
- std::size_t checksum = compute_checksum<algorithm, size_expected>(skip_iterator(predicate, seq_begin, seq_end),
- skip_iterator(predicate, seq_end, seq_end),
+
+ prechecksum_type prechecksum;
+ std::size_t checksum = compute_checksum<algorithm, size_expected>(prechecksum(seq_begin, seq_end),
+ prechecksum(seq_end, seq_end),
counter);
if(checksum != bad_sequence)
return algorithm::validate_checksum(checksum);
@@ -146,17 +147,16 @@
\returns The check digit of the type of a value in check_seq.
*/
template <typename algorithm,
- typename UnaryPredicate,
+ typename prechecksum_type,
typename checkdigit,
typename seq_iterator>
std::size_t compute_checkdigit(seq_iterator seq_begin, seq_iterator seq_end)
{
- typedef boost::filter_iterator<UnaryPredicate, seq_iterator> skip_iterator;
- UnaryPredicate predicate;
typedef typename boost::checks::detail::skip_counter<checkdigit::pos, checkdigit::size> counter_type;
typename counter_type::type counter = counter_type()();
- std::size_t checksum = compute_checksum<algorithm>(skip_iterator(predicate, seq_begin, seq_end),
- skip_iterator(predicate, seq_end, seq_end),
+ prechecksum_type prechecksum;
+ std::size_t checksum = compute_checksum<algorithm>(prechecksum(seq_begin, seq_end),
+ prechecksum(seq_end, seq_end),
counter);
return algorithm::compute_checkdigit(checksum);
}
@@ -176,19 +176,17 @@
\returns The check digit of the type of a value in check_seq.
*/
template <typename algorithm,
- typename UnaryPredicate,
+ typename prechecksum_type,
std::size_t size_expected,
typename checkdigit,
typename seq_iterator>
std::size_t compute_checkdigit(seq_iterator seq_begin, seq_iterator seq_end)
{
- typedef boost::filter_iterator<UnaryPredicate, seq_iterator> skip_iterator;
- UnaryPredicate predicate;
-
typedef typename boost::checks::detail::skip_counter<checkdigit::pos, checkdigit::size> counter_type;
typename counter_type::type counter = counter_type()();
- std::size_t checksum = compute_checksum<algorithm, size_expected>(skip_iterator(predicate, seq_begin, seq_end),
- skip_iterator(predicate, seq_end, seq_end),
+ prechecksum_type prechecksum;
+ std::size_t checksum = compute_checksum<algorithm, size_expected>(prechecksum(seq_begin, seq_end),
+ prechecksum(seq_end, seq_end),
counter);
if(checksum != size_expected)
return algorithm::compute_checkdigit(checksum);
@@ -212,18 +210,16 @@
\returns An iterator initialized at one pass the end of checkdigits.
*/
template <typename algorithm,
- typename UnaryPredicate,
+ typename prechecksum_type,
typename checkdigit,
typename seq_iterator>
std::pair<std::size_t, std::size_t> compute_multicheckdigit (seq_iterator seq_begin, seq_iterator seq_end)
{
- typedef boost::filter_iterator<UnaryPredicate, seq_iterator> skip_iterator;
- UnaryPredicate predicate;
-
typedef typename boost::checks::detail::skip_counter<checkdigit::pos, checkdigit::size> counter_type;
typename counter_type::type counter = counter_type()();
- std::size_t checksum = compute_checksum<algorithm>(skip_iterator(predicate, seq_begin, seq_end),
- skip_iterator(predicate, seq_end, seq_end),
+ prechecksum_type prechecksum;
+ std::size_t checksum = compute_checksum<algorithm>(prechecksum(seq_begin, seq_end),
+ prechecksum(seq_end, seq_end),
counter);
return algorithm::compute_multicheckdigit(checksum);
}
@@ -245,19 +241,17 @@
\returns An iterator initialized at one pass the end of checkdigits.
*/
template <typename algorithm,
- typename UnaryPredicate,
+ typename prechecksum_type,
std::size_t size_expected,
typename checkdigit,
typename seq_iterator>
std::pair<std::size_t, std::size_t> compute_multicheckdigit(seq_iterator seq_begin, seq_iterator seq_end)
{
- typedef boost::filter_iterator<UnaryPredicate, seq_iterator> skip_iterator;
- UnaryPredicate predicate;
-
typedef typename boost::checks::detail::skip_counter<checkdigit::pos, checkdigit::size> counter_type;
typename counter_type::type counter = counter_type()();
- std::size_t checksum = compute_checksum<algorithm, size_expected>(skip_iterator(predicate, seq_begin, seq_end),
- skip_iterator(predicate, seq_end, seq_end),
+ prechecksum_type prechecksum;
+ std::size_t checksum = compute_checksum<algorithm, size_expected>(prechecksum(seq_begin, seq_end),
+ prechecksum(seq_end, seq_end),
counter);
if(checksum != bad_sequence)
return algorithm::compute_multicheckdigit(checksum);
Added: sandbox/SOC/2011/checks/boost/checks/conversion.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2011/checks/boost/checks/conversion.hpp 2012-02-14 03:16:44 EST (Tue, 14 Feb 2012)
@@ -0,0 +1,47 @@
+// Boost checks/conversion.hpp header file
+// (C) Copyright Pierre Talbot 2012
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt
+// See http://www.boost.org for updates, documentation, and revision history.
+
+/*! \file
+ \brief
+*/
+
+#ifndef BOOST_CHECK_CONVERSION_HPP
+#define BOOST_CHECK_CONVERSION_HPP
+
+#ifdef _MSC_VER
+ #pragma once
+#endif
+
+#include <cstddef> // std::size_t
+#include <cctype>
+#include <functional>
+
+
+namespace boost{
+ namespace checks{
+
+template <typename value_type>
+struct chartodigit : public std::unary_function<value_type, std::size_t>
+{
+ std::size_t operator()(const value_type &value) const
+ {
+ return value - '0';
+ }
+};
+
+template <typename value_type>
+struct chartodigitx : public std::unary_function<value_type, std::size_t>
+{
+ std::size_t operator()(const value_type &value) const
+ {
+ return value <= '9' ? (value - '0') : 10;
+ }
+};
+
+}} // namespace boost namespace checks
+
+#endif //BOOST_CHECK_CONVERSION_HPP
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 2012-02-14 03:16:44 EST (Tue, 14 Feb 2012)
@@ -61,7 +61,7 @@
template <typename check_range>
bool check_ean13(const check_range& check_seq)
{
- return boost::checks::check_sequence<ean_algorithm, digit_filter, EAN13_SIZE> (boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::check_sequence<ean_algorithm, typename digit_prechecksum<typename boost::range_reverse_iterator<check_range>::type>::type, EAN13_SIZE> (boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -80,7 +80,7 @@
template <typename check_range>
std::size_t compute_ean13(const check_range& check_seq)
{
- return boost::checks::compute_checkdigit<ean_algorithm, digit_filter, EAN13_SIZE, boost::checks::basic_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::compute_checkdigit<ean_algorithm, typename digit_prechecksum<typename boost::range_reverse_iterator<check_range>::type>::type, EAN13_SIZE, basic_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -98,7 +98,7 @@
template <typename check_range>
bool check_ean8 (const check_range& check_seq)
{
- return boost::checks::check_sequence<ean_algorithm, digit_filter, EAN8_SIZE>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::check_sequence<ean_algorithm, typename digit_prechecksum<typename boost::range_reverse_iterator<check_range>::type>::type, EAN8_SIZE>(boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -117,7 +117,7 @@
template <typename check_range>
std::size_t compute_ean8(const check_range& check_seq)
{
- return boost::checks::compute_checkdigit<ean_algorithm, digit_filter, EAN8_SIZE, boost::checks::basic_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::compute_checkdigit<ean_algorithm, typename digit_prechecksum<typename boost::range_reverse_iterator<check_range>::type>::type, EAN8_SIZE, boost::checks::basic_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq));
}
Modified: sandbox/SOC/2011/checks/boost/checks/filter.hpp
==============================================================================
--- sandbox/SOC/2011/checks/boost/checks/filter.hpp (original)
+++ sandbox/SOC/2011/checks/boost/checks/filter.hpp 2012-02-14 03:16:44 EST (Tue, 14 Feb 2012)
@@ -18,23 +18,24 @@
#include <cstddef> // std::size_t
#include <cctype>
+#include <functional>
namespace boost{
namespace checks{
-struct digit_filter
+template <typename value_type>
+struct digit_filter : public std::unary_function<value_type, bool>
{
- template <typename value_type>
bool operator()(const value_type &value)
{
return std::isdigit(static_cast<int>(value));
}
};
-struct digitx_filter
+template <typename value_type>
+struct digitx_filter : public std::unary_function<value_type, bool>
{
- template <typename value_type>
- bool operator()(const value_type &value)
+ bool operator()(const value_type &value)
{
return std::isdigit(static_cast<int>(value)) || std::tolower(static_cast<int>(value)) == 'x';
}
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 2012-02-14 03:16:44 EST (Tue, 14 Feb 2012)
@@ -56,7 +56,7 @@
template <typename check_range>
bool check_isbn13 (const check_range& check_seq)
{
- return boost::checks::check_sequence<isbn13_algorithm, digit_filter, EAN13_SIZE>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::check_sequence<isbn13_algorithm, typename digit_prechecksum<typename boost::range_reverse_iterator<check_range>::type>::type, EAN13_SIZE>(boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -75,7 +75,7 @@
template <typename check_range>
std::size_t compute_isbn13 (const check_range& check_seq)
{
- return boost::checks::compute_checkdigit<isbn13_algorithm, digit_filter, EAN13_SIZE, boost::checks::basic_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::compute_checkdigit<isbn13_algorithm, typename digit_prechecksum<typename boost::range_reverse_iterator<check_range>::type>::type, EAN13_SIZE, boost::checks::basic_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
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 2012-02-14 03:16:44 EST (Tue, 14 Feb 2012)
@@ -90,7 +90,7 @@
template <size_t size_expected, typename check_range>
bool check_luhn (const check_range& check_seq)
{
- return boost::checks::check_sequence<luhn_algorithm, digit_filter, size_expected>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::check_sequence<luhn_algorithm, typename digit_prechecksum<typename boost::range_reverse_iterator<check_range>::type>::type, size_expected>(boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -108,7 +108,7 @@
template <typename check_range>
bool check_luhn (const check_range& check_seq)
{
- return boost::checks::check_sequence<luhn_algorithm, digit_filter> (boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::check_sequence<luhn_algorithm, typename digit_prechecksum<typename boost::range_reverse_iterator<check_range>::type>::type> (boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -128,7 +128,7 @@
template <size_t size_expected, typename check_range>
std::size_t compute_luhn(const check_range& check_seq)
{
- return boost::checks::compute_checkdigit<luhn_algorithm, digit_filter, size_expected, boost::checks::basic_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::compute_checkdigit<luhn_algorithm, typename digit_prechecksum<typename boost::range_reverse_iterator<check_range>::type>::type, size_expected, boost::checks::basic_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -147,7 +147,7 @@
template <typename check_range>
std::size_t compute_luhn (const check_range& check_seq)
{
- return boost::checks::compute_checkdigit<luhn_algorithm, digit_filter, boost::checks::basic_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::compute_checkdigit<luhn_algorithm, typename digit_prechecksum<typename boost::range_reverse_iterator<check_range>::type>::type, boost::checks::basic_checkdigit>(boost::rbegin(check_seq), boost::rend(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 2012-02-14 03:16:44 EST (Tue, 14 Feb 2012)
@@ -47,7 +47,7 @@
template <typename check_range>
bool check_mastercard(const check_range& check_seq)
{
- return boost::checks::check_sequence<luhn_algorithm, digit_filter, MASTERCARD_SIZE>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::check_sequence<luhn_algorithm, typename digit_prechecksum<typename boost::range_reverse_iterator<check_range>::type>, MASTERCARD_SIZE>(boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -67,7 +67,7 @@
template <typename check_range>
std::size_t compute_mastercard(const check_range& check_seq)
{
- return boost::checks::compute_checkdigit<luhn_algorithm, digit_filter, MASTERCARD_SIZE, boost::checks::basic_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::compute_checkdigit<luhn_algorithm, typename digit_prechecksum<typename boost::range_reverse_iterator<check_range>::type>, MASTERCARD_SIZE, boost::checks::basic_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq));
}
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 2012-02-14 03:16:44 EST (Tue, 14 Feb 2012)
@@ -40,32 +40,6 @@
struct modulus11_algorithm : boost::checks::weighted_sum_algorithm<mod11_weight>
{
/*!
- \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 thrown if the translation of current_value failed.\n The translation will fail if the current value is not a digit(0 <= i < 10), unless it is the rightmost digit, when the value 10 or the 'x' or 'X' character is allowed.
-
- \returns the translation of the current value in the range [0..10].
-*/
- template <typename value_type>
- static std::size_t convert(const value_type &value)
- {
- if(value == 'x' || value == 'X')
- return 10;
- return value - '0';
- }
-
-/* pre: value must be valid */
- template <typename value_type>
- static bool require(const value_type &value, std::size_t value_pos)
- {
- return value_pos == 0 || (value != 'X' && value != 'x');
- }
-
- /*!
\brief Validate a checksum with a simple modulus 11.
\param checksum is the checksum to validate.
@@ -119,7 +93,7 @@
template <size_t size_expected, typename check_range>
bool check_modulus11(const check_range& check_seq)
{
- return boost::checks::check_sequence<mod11_algorithm, digitx_filter, size_expected>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::check_sequence<mod11_algorithm, typename digitx_prechecksum<typename boost::range_reverse_iterator<check_range>::type>::type, size_expected>(boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -137,7 +111,7 @@
template <typename check_range>
bool check_modulus11(const check_range& check_seq)
{
- return boost::checks::check_sequence<mod11_algorithm, digitx_filter>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::check_sequence<mod11_algorithm, typename digitx_prechecksum<typename boost::range_reverse_iterator<check_range>::type>::type>(boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -157,7 +131,7 @@
template <std::size_t size_expected, typename check_range>
std::size_t compute_modulus11(const check_range& check_seq)
{
- return boost::checks::compute_checkdigit<mod11_algorithm, digitx_filter, size_expected, boost::checks::basic_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::compute_checkdigit<mod11_algorithm, typename digitx_prechecksum<typename boost::range_reverse_iterator<check_range>::type>::type, size_expected, boost::checks::basic_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -176,7 +150,7 @@
template <typename check_range>
std::size_t compute_modulus11(const check_range& check_seq)
{
- return boost::checks::compute_checkdigit<mod11_algorithm, digitx_filter, boost::checks::basic_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::compute_checkdigit<mod11_algorithm, typename digitx_prechecksum<typename boost::range_reverse_iterator<check_range>::type>::type, boost::checks::basic_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq));
}
}} // namespace boost namespace checks
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 2012-02-14 03:16:44 EST (Tue, 14 Feb 2012)
@@ -138,7 +138,7 @@
template <size_t size_expected, typename check_range>
bool check_mod97_10 (const check_range& check_seq)
{
- return boost::checks::check_sequence<mod97_10_algorithm, digit_filter, size_expected> (boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::check_sequence<mod97_10_algorithm, typename digit_prechecksum<typename boost::range_reverse_iterator<check_range>::type>, size_expected> (boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -156,7 +156,7 @@
template <typename check_range>
bool check_mod97_10(const check_range& check_seq)
{
- return boost::checks::check_sequence<mod97_10_algorithm, digit_filter>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::check_sequence<mod97_10_algorithm, typename digit_prechecksum<typename boost::range_reverse_iterator<check_range>::type> >(boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -178,7 +178,7 @@
template <size_t size_expected, typename check_range>
std::pair<std::size_t, std::size_t> compute_mod97_10(const check_range& check_seq)
{
- return boost::checks::compute_multicheckdigit<mod97_10_algorithm, digit_filter, mod97_10_checkdigit, size_expected>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::compute_multicheckdigit<mod97_10_algorithm, typename digit_prechecksum<typename boost::range_reverse_iterator<check_range>::type>, mod97_10_checkdigit, size_expected>(boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -199,7 +199,7 @@
template <typename check_range>
std::pair<std::size_t, std::size_t> compute_mod97_10(const check_range& check_seq)
{
- return boost::checks::compute_multicheckdigit<mod97_10_algorithm, digit_filter, mod97_10_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::compute_multicheckdigit<mod97_10_algorithm, typename digit_prechecksum<typename boost::range_reverse_iterator<check_range>::type>, mod97_10_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq));
}
Added: sandbox/SOC/2011/checks/boost/checks/prechecksum.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2011/checks/boost/checks/prechecksum.hpp 2012-02-14 03:16:44 EST (Tue, 14 Feb 2012)
@@ -0,0 +1,83 @@
+// Boost checks/prechecksum.hpp header file
+// (C) Copyright Pierre Talbot 2012
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt
+// See http://www.boost.org for updates, documentation, and revision history.
+
+/*! \file
+ \brief
+*/
+
+#ifndef BOOST_PRECHECKSUM_HPP
+#define BOOST_PRECHECKSUM_HPP
+
+#ifdef _MSC_VER
+ #pragma once
+#endif
+
+#include <boost/iterator/filter_iterator.hpp>
+#include <boost/iterator/transform_iterator.hpp>
+
+namespace boost {
+ namespace checks{
+
+struct no_filter_tag {};
+struct no_conversion_tag {};
+
+template <typename UnaryPredicate,
+ typename UnaryFunction,
+ typename BaseIterator>
+struct prechecksum
+{
+ typedef UnaryPredicate FilterPredicate;
+ typedef UnaryFunction ConversionFunction;
+
+ typedef typename boost::filter_iterator<FilterPredicate, BaseIterator> filter_iterator;
+
+ typedef typename boost::transform_iterator<ConversionFunction, filter_iterator> iterator;
+
+ FilterPredicate filter;
+ ConversionFunction converter;
+
+ iterator operator()(BaseIterator b, BaseIterator e)
+ {
+ return iterator(filter_iterator(filter, b, e), converter);
+ }
+};
+
+template <typename UnaryFunction,
+ typename BaseIterator>
+struct prechecksum<no_filter_tag, UnaryFunction, BaseIterator>
+{
+ typedef UnaryFunction ConversionFunction;
+
+ typedef typename boost::transform_iterator<ConversionFunction, BaseIterator> iterator;
+
+ ConversionFunction converter;
+ iterator operator()(BaseIterator b, BaseIterator e)
+ {
+ return iterator(b, converter);
+ }
+};
+
+template <typename UnaryPredicate,
+ typename BaseIterator>
+struct prechecksum<UnaryPredicate, no_conversion_tag, BaseIterator>
+{
+ typedef UnaryPredicate FilterPredicate;
+
+ typedef typename boost::filter_iterator<FilterPredicate, BaseIterator> iterator;
+
+ FilterPredicate filter;
+ iterator operator()(BaseIterator b, BaseIterator e)
+ {
+ return iterator(filter, b, e);
+ }
+};
+
+
+} // namespace checks
+} // namespace boost
+
+#endif // BOOST_PRECHECKSUM_HPP
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 2012-02-14 03:16:44 EST (Tue, 14 Feb 2012)
@@ -57,7 +57,7 @@
template <typename check_range>
bool check_upca (const check_range& check_seq)
{
- return boost::checks::check_sequence<upc_algorithm, digit_filter, UPCA_SIZE>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::check_sequence<upc_algorithm, typename digit_prechecksum<typename boost::range_reverse_iterator<check_range>::type>, UPCA_SIZE>(boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -76,7 +76,7 @@
template <typename check_range>
std::size_t compute_upca(const check_range& check_seq)
{
- return boost::checks::compute_checkdigit<upc_algorithm, digit_filter, UPCA_SIZE, boost::checks::basic_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::compute_checkdigit<upc_algorithm, typename digit_prechecksum<typename boost::range_reverse_iterator<check_range>::type>, UPCA_SIZE, boost::checks::basic_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq));
}
}} // namespace boost namespace checks
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 2012-02-14 03:16:44 EST (Tue, 14 Feb 2012)
@@ -126,7 +126,7 @@
template <size_t size_expected, typename check_range>
bool check_verhoeff(const check_range& check_seq)
{
- return boost::checks::check_sequence<verhoeff_algorithm, digit_filter, size_expected>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::check_sequence<verhoeff_algorithm, typename digit_prechecksum<typename boost::range_reverse_iterator<check_range>::type>, size_expected>(boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -144,7 +144,7 @@
template <typename check_range>
bool check_verhoeff(const check_range& check_seq)
{
- return boost::checks::check_sequence<verhoeff_algorithm, digit_filter>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::check_sequence<verhoeff_algorithm, typename digit_prechecksum<typename boost::range_reverse_iterator<check_range>::type> >(boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -164,7 +164,11 @@
template <size_t size_expected, typename check_range>
std::size_t compute_verhoeff(const check_range& check_seq)
{
- return boost::checks::compute_checkdigit<verhoeff_algorithm, digit_filter, size_expected, boost::checks::basic_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::compute_checkdigit<verhoeff_algorithm,
+ typename digit_prechecksum<typename boost::range_reverse_iterator<check_range>::type>,
+ size_expected,
+ basic_checkdigit>
+ (boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -183,7 +187,10 @@
template <typename check_range>
std::size_t compute_verhoeff(const check_range& check_seq)
{
- return boost::checks::compute_checkdigit<verhoeff_algorithm, digit_filter, boost::checks::basic_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::compute_checkdigit<verhoeff_algorithm,
+ typename digit_prechecksum<typename boost::range_reverse_iterator<check_range>::type>,
+ basic_checkdigit>
+ (boost::rbegin(check_seq), boost::rend(check_seq));
}
}}
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 2012-02-14 03:16:44 EST (Tue, 14 Feb 2012)
@@ -47,7 +47,7 @@
template <typename check_range>
bool check_visa(const check_range& check_seq)
{
- return boost::checks::check_sequence<luhn_algorithm, digit_filter, VISA_SIZE>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::check_sequence<luhn_algorithm, typename digit_prechecksum<typename boost::range_reverse_iterator<check_range>::type>, VISA_SIZE>(boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -67,7 +67,7 @@
template <typename check_range>
std::size_t compute_visa(const check_range& check_seq)
{
- return boost::checks::compute_checkdigit<luhn_algorithm, digit_filter, VISA_SIZE, boost::checks::basic_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::compute_checkdigit<luhn_algorithm, typename digit_prechecksum<typename boost::range_reverse_iterator<check_range>::type>, VISA_SIZE, boost::checks::basic_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq));
}
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