|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r76956 - in sandbox/SOC/2011/checks/boost/checks: . detail
From: pierre.talbot.6114_at_[hidden]
Date: 2012-02-09 06:50:44
Author: trademark
Date: 2012-02-09 06:50:41 EST (Thu, 09 Feb 2012)
New Revision: 76956
URL: http://svn.boost.org/trac/boost/changeset/76956
Log:
The checkdigit_size template parameter of the algorihtm is not considered anymore such a checks characteristic. The compute_checksum function accept now 2 required template parameter : checkdigit_pos and checkdigit_size. It's using the detail/sequence_counter.hpp to use the same core algorithm to compute the checksum
Added:
sandbox/SOC/2011/checks/boost/checks/detail/
sandbox/SOC/2011/checks/boost/checks/detail/sequence_counter.hpp (contents, props changed)
Text files modified:
sandbox/SOC/2011/checks/boost/checks/amex.hpp | 25 ++-----------
sandbox/SOC/2011/checks/boost/checks/basic_check_algorithm.hpp | 1
sandbox/SOC/2011/checks/boost/checks/basic_checks.hpp | 69 ++++++++++++++++++++++++++++-----------
sandbox/SOC/2011/checks/boost/checks/ean.hpp | 25 +++-----------
sandbox/SOC/2011/checks/boost/checks/isbn.hpp | 30 ++++-------------
sandbox/SOC/2011/checks/boost/checks/luhn.hpp | 25 ++++----------
sandbox/SOC/2011/checks/boost/checks/mastercard.hpp | 24 ++-----------
sandbox/SOC/2011/checks/boost/checks/modulus10.hpp | 4 +-
sandbox/SOC/2011/checks/boost/checks/modulus11.hpp | 23 +++++--------
sandbox/SOC/2011/checks/boost/checks/modulus97.hpp | 20 ++++------
sandbox/SOC/2011/checks/boost/checks/upc.hpp | 16 ++------
sandbox/SOC/2011/checks/boost/checks/verhoeff.hpp | 22 +++---------
sandbox/SOC/2011/checks/boost/checks/visa.hpp | 24 ++-----------
sandbox/SOC/2011/checks/boost/checks/weighted_sum.hpp | 6 +-
14 files changed, 114 insertions(+), 200 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-09 06:50:41 EST (Thu, 09 Feb 2012)
@@ -28,10 +28,6 @@
\brief This macro defines the size of a American Express card number (15).
*/
#define AMEX_SIZE 15
-/*!
- \brief This macro defines the size of a American Express card number without its check digit (14).
-*/
-#define AMEX_SIZE_WITHOUT_CHECKDIGIT 14
namespace boost {
namespace checks{
@@ -41,8 +37,8 @@
\tparam checkdigit_size Help functions to provide same behavior on sequence with and without check digits. No "real" value in the sequence will be skipped.
*/
-template <std::size_t checkdigit_size>
-struct amex_algorithm : boost::checks::luhn_algorithm <checkdigit_size>
+
+struct amex_algorithm : boost::checks::luhn_algorithm
{
/*!
\brief Verify that a number matches the Amex pattern.
@@ -57,22 +53,11 @@
template <typename value_type>
static bool require(const value_type &value, std::size_t value_pos)
{
- std::size_t real_pos_from_left = AMEX_SIZE - value_pos - checkdigit_size;
-
- return (real_pos_from_left != 1 || value == '3') && (real_pos_from_left != 2 || value == '4' || value == '7');
+ return (AMEX_SIZE - value_pos != 1 || value == '3') && (AMEX_SIZE - value_pos != 2 || value == '4' || value == '7');
}
};
/*!
- \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.
@@ -88,7 +73,7 @@
template <typename check_range>
bool check_amex (const check_range& check_seq)
{
- return boost::checks::check_sequence<amex_check_algorithm, AMEX_SIZE>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::check_sequence<amex_algorithm, AMEX_SIZE>(boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -108,7 +93,7 @@
template <typename check_range>
typename boost::range_value<check_range>::type compute_amex(const check_range& check_seq)
{
- return boost::checks::compute_checkdigit<amex_compute_algorithm, AMEX_SIZE_WITHOUT_CHECKDIGIT>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::compute_checkdigit<amex_algorithm, AMEX_SIZE, 0, 1>(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-09 06:50:41 EST (Thu, 09 Feb 2012)
@@ -31,7 +31,6 @@
\tparam traversal_direction must meet the iterator_direction concept requirements.
\tparam checkdigit_size Helper functions to provide the same behavior on sequence with and without checkdigits. No "real" value in the sequence will be skipped.
*/
-template <std::size_t checkdigit_size>
struct basic_check_algorithm
{
template <typename value_type>
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-09 06:50:41 EST (Thu, 09 Feb 2012)
@@ -22,6 +22,8 @@
#include <boost/lexical_cast.hpp>
#include <boost/checks/limits.hpp>
+#include <boost/checks/detail/sequence_counter.hpp>
+
namespace boost {
namespace checks{
@@ -41,25 +43,27 @@
\returns The checksum of the sequence calculated with algorithm.
*/
-template <typename algorithm, typename size_contract, typename seq_iterator>
-std::size_t compute_checksum(seq_iterator seq_begin, seq_iterator seq_end)
+template <typename algorithm,
+ typename size_contract,
+ typename seq_iterator,
+ typename counter_type>
+std::size_t compute_checksum(seq_iterator seq_begin, seq_iterator seq_end, counter_type &counter)
{
- std::size_t value_counter = 0;
std::size_t checksum = 0;
bool error = false;
- for(; seq_begin != seq_end && !error && !size_contract::reach_one_past_the_end(value_counter); ++seq_begin)
+ for(; seq_begin != seq_end && !error && !size_contract::reach_one_past_the_end(*counter); ++seq_begin)
{
try
{
if(!algorithm::skip(*seq_begin))
{
- if(!algorithm::require(*seq_begin, value_counter))
+ if(!algorithm::require(*seq_begin, *counter))
error = true;
else
{
std::size_t value = algorithm::convert(*seq_begin);
- checksum = algorithm::process(checksum, value, value_counter);
- ++value_counter;
+ checksum = algorithm::process(checksum, value, *counter);
+ ++counter;
}
}
}
@@ -68,7 +72,7 @@
}
if(error)
throw std::invalid_argument("");
- size_contract::respect_size_contract(value_counter);
+ size_contract::respect_size_contract(*counter);
return checksum;
}
@@ -85,10 +89,12 @@
\returns @c true if the checkdigit is correct, @c false otherwise.
*/
-template <typename algorithm, typename seq_iterator>
+template <typename algorithm,
+ typename seq_iterator>
bool check_sequence(seq_iterator seq_begin, seq_iterator seq_end)
{
- std::size_t checksum = compute_checksum<algorithm, boost::checks::no_null_size_contract<> >(seq_begin, seq_end);
+ boost::checks::detail::simple_counter::type counter = boost::checks::detail::simple_counter()();
+ std::size_t checksum = compute_checksum<algorithm, boost::checks::no_null_size_contract<> >(seq_begin, seq_end, counter);
return algorithm::validate_checksum(checksum);
}
@@ -106,10 +112,13 @@
\returns @c true if the checkdigit is correct, @c false otherwise.
*/
-template <typename algorithm, size_t size_expected, typename seq_iterator>
+template <typename algorithm,
+ std::size_t size_expected,
+ typename seq_iterator>
bool check_sequence(seq_iterator seq_begin, seq_iterator seq_end)
{
- std::size_t checksum = compute_checksum<algorithm, boost::checks::strict_size_contract<size_expected> >(seq_begin, seq_end);
+ boost::checks::detail::simple_counter::type counter = boost::checks::detail::simple_counter()();
+ std::size_t checksum = compute_checksum<algorithm, boost::checks::strict_size_contract<size_expected> >(seq_begin, seq_end, counter);
return algorithm::validate_checksum(checksum);
}
@@ -126,10 +135,14 @@
\returns The check digit of the type of a value in check_seq.
*/
-template <typename algorithm, typename seq_iterator>
+template <typename algorithm,
+ std::size_t checkdigit_pos,
+ std::size_t checkdigit_size,
+ typename seq_iterator>
typename seq_iterator::value_type compute_checkdigit(seq_iterator seq_begin, seq_iterator seq_end)
{
- std::size_t checksum = compute_checksum<algorithm, boost::checks::no_null_size_contract<> >(seq_begin, seq_end);
+ typename boost::checks::detail::skip_counter<checkdigit_pos, checkdigit_size>::type counter = boost::checks::detail::skip_counter<checkdigit_pos, checkdigit_size>()();
+ std::size_t checksum = compute_checksum<algorithm, boost::checks::no_null_size_contract<> >(seq_begin, seq_end, counter);
return algorithm::template compute_checkdigit<typename seq_iterator::value_type>(checksum);
}
@@ -147,10 +160,15 @@
\returns The check digit of the type of a value in check_seq.
*/
-template <typename algorithm, size_t size_expected, typename seq_iterator>
+template <typename algorithm,
+ std::size_t size_expected,
+ std::size_t checkdigit_pos,
+ std::size_t checkdigit_size,
+ typename seq_iterator>
typename seq_iterator::value_type compute_checkdigit(seq_iterator seq_begin, seq_iterator seq_end)
{
- std::size_t checksum = compute_checksum<algorithm, boost::checks::strict_size_contract<size_expected> >(seq_begin, seq_end);
+ typename boost::checks::detail::skip_counter<checkdigit_pos, checkdigit_size>::type counter = boost::checks::detail::skip_counter<checkdigit_pos, checkdigit_size>()();
+ std::size_t checksum = compute_checksum<algorithm, boost::checks::strict_size_contract<size_expected> >(seq_begin, seq_end, counter);
return algorithm::template compute_checkdigit<typename seq_iterator::value_type>(checksum);
}
@@ -170,10 +188,15 @@
\returns An iterator initialized at one pass the end of checkdigits.
*/
-template <typename algorithm, typename seq_iterator, typename checkdigit_iterator>
+template <typename algorithm,
+ std::size_t checkdigit_pos,
+ std::size_t checkdigit_size,
+ typename seq_iterator,
+ typename checkdigit_iterator>
checkdigit_iterator compute_multicheckdigit (seq_iterator seq_begin, seq_iterator seq_end, checkdigit_iterator checkdigits)
{
- std::size_t checksum = compute_checksum<algorithm, boost::checks::no_null_size_contract<> >(seq_begin, seq_end);
+ typename boost::checks::detail::skip_counter<checkdigit_pos, checkdigit_size>::type counter = boost::checks::detail::skip_counter<checkdigit_pos, checkdigit_size>()();
+ std::size_t checksum = compute_checksum<algorithm, boost::checks::no_null_size_contract<> >(seq_begin, seq_end, counter);
return algorithm::compute_multicheckdigit(checksum, checkdigits);
}
@@ -193,10 +216,16 @@
\returns An iterator initialized at one pass the end of checkdigits.
*/
-template <typename algorithm, size_t size_expected, typename seq_iterator, typename checkdigit_iterator>
+template <typename algorithm,
+ std::size_t size_expected,
+ std::size_t checkdigit_pos,
+ std::size_t checkdigit_size,
+ typename seq_iterator,
+ typename checkdigit_iterator>
checkdigit_iterator compute_multicheckdigit (seq_iterator seq_begin, seq_iterator seq_end, checkdigit_iterator checkdigits)
{
- std::size_t checksum = compute_checksum<algorithm, boost::checks::strict_size_contract<size_expected> >(seq_begin, seq_end);
+ typename boost::checks::detail::skip_counter<checkdigit_pos, checkdigit_size>::type counter = boost::checks::detail::skip_counter<checkdigit_pos, checkdigit_size>()();
+ std::size_t checksum = compute_checksum<algorithm, boost::checks::strict_size_contract<size_expected> >(seq_begin, seq_end, counter);
return algorithm::compute_multicheckdigit(checksum, checkdigits);
}
Added: sandbox/SOC/2011/checks/boost/checks/detail/sequence_counter.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2011/checks/boost/checks/detail/sequence_counter.hpp 2012-02-09 06:50:41 EST (Thu, 09 Feb 2012)
@@ -0,0 +1,61 @@
+// Boost checks/sequence_counter.hpp header file
+// (C) Copyright Pierre Talbot 2011 - 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 Counting iterator and skipping iterator.
+*/
+
+#ifndef BOOST_CHECKS_SEQUENCE_COUNTER_HPP
+#define BOOST_CHECKS_SEQUENCE_COUNTER_HPP
+
+#ifdef _MSC_VER
+ #pragma once
+#endif
+
+#include <boost/iterator/counting_iterator.hpp>
+#include <boost/iterator/transform_iterator.hpp>
+#include <functional>
+
+namespace boost{
+ namespace checks{
+
+namespace detail
+{
+
+template <std::size_t skip_at, std::size_t size_to_skip>
+struct skipper : public std::unary_function <std::size_t, std::size_t>
+{
+ std::size_t operator()(std::size_t value_pos) const
+ {
+ return value_pos + size_to_skip * (value_pos >= skip_at);
+ }
+};
+
+struct simple_counter
+{
+ typedef boost::counting_iterator<std::size_t> type;
+ type operator()()
+ {
+ return type(0);
+ }
+};
+
+template <std::size_t skip_at, std::size_t size_to_skip>
+struct skip_counter
+{
+ typedef boost::transform_iterator<skipper<skip_at, size_to_skip>, simple_counter::type> type;
+ type operator()()
+ {
+ simple_counter::type iter = simple_counter()();
+ return type(iter, skipper<skip_at, size_to_skip>());
+ }
+};
+
+}
+}} // namespace boost namespace checks
+
+#endif
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-09 06:50:41 EST (Thu, 09 Feb 2012)
@@ -29,17 +29,9 @@
*/
#define EAN13_SIZE 13
/*!
- \brief This macro defines the size of an EAN-13 without its check digit (12).
-*/
-#define EAN13_SIZE_WITHOUT_CHECKDIGIT 12
-/*!
\brief This macro defines the size of an EAN-8 (8).
*/
#define EAN8_SIZE 8
-/*!
- \brief This macro defines the size of a EAN-8 without its check digit (7).
-*/
-#define EAN8_SIZE_WITHOUT_CHECKDIGIT 7
namespace boost {
namespace checks{
@@ -48,15 +40,10 @@
\brief This is the weight used by EAN system.
*/
typedef boost::checks::weight<1,3> ean_weight ;
-
-/*!
- \brief This is the type of the EAN algorithm for validating a check digit.
-*/
-typedef boost::checks::modulus10_algorithm<ean_weight, 0> ean_check_algorithm;
/*!
- \brief This is the type of the EAN algorithm for computing a check digit.
+ \brief This is the type of the EAN algorithm.
*/
-typedef boost::checks::modulus10_algorithm<ean_weight, 1> ean_compute_algorithm;
+typedef boost::checks::modulus10_algorithm<ean_weight> ean_algorithm;
/*!
\brief Validate a sequence according to the ean_check_algorithm type.
@@ -73,7 +60,7 @@
template <typename check_range>
bool check_ean13(const check_range& check_seq)
{
- return boost::checks::check_sequence<ean_check_algorithm, EAN13_SIZE> (boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::check_sequence<ean_algorithm, EAN13_SIZE> (boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -92,7 +79,7 @@
template <typename check_range>
typename boost::range_value<check_range>::type compute_ean13(const check_range& check_seq)
{
- return boost::checks::compute_checkdigit<ean_compute_algorithm, EAN13_SIZE_WITHOUT_CHECKDIGIT> (boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::compute_checkdigit<ean_algorithm, EAN13_SIZE, 0, 1>(boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -110,7 +97,7 @@
template <typename check_range>
bool check_ean8 (const check_range& check_seq)
{
- return boost::checks::check_sequence<ean_check_algorithm, EAN8_SIZE>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::check_sequence<ean_algorithm, EAN8_SIZE>(boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -129,7 +116,7 @@
template <typename check_range>
typename boost::range_value<check_range>::type compute_ean8(const check_range& check_seq)
{
- return boost::checks::compute_checkdigit<ean_compute_algorithm, EAN8_SIZE_WITHOUT_CHECKDIGIT>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::compute_checkdigit<ean_algorithm, EAN8_SIZE, 0, 1>(boost::rbegin(check_seq), boost::rend(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 2012-02-09 06:50:41 EST (Thu, 09 Feb 2012)
@@ -29,10 +29,6 @@
\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{
@@ -42,8 +38,7 @@
\tparam checkdigit_size Help functions to provide same behavior on sequence with and without check digits. No "real" value in the sequence will be skipped.
*/
-template <std::size_t checkdigit_size>
-struct isbn13_algorithm : boost::checks::modulus10_algorithm<boost::checks::ean_weight, checkdigit_size>
+struct isbn13_algorithm : boost::checks::modulus10_algorithm<boost::checks::ean_weight>
{
/*!
\brief Verify that a number matches the ISBN-13 pattern.
@@ -58,24 +53,13 @@
template <typename value_type>
static bool require(const value_type &value, std::size_t value_pos)
{
- std::size_t real_pos_from_left = EAN13_SIZE - value_pos - checkdigit_size;
-
- return (real_pos_from_left != 1 || value == '9') &&
- (real_pos_from_left != 2 || value == '7') &&
- (real_pos_from_left != 3 || value == '8' || value == '9');
+ return (EAN13_SIZE - value_pos != 1 || value == '9') &&
+ (EAN13_SIZE - value_pos != 2 || value == '7') &&
+ (EAN13_SIZE - value_pos != 3 || value == '8' || value == '9');
}
};
/*!
- \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.
@@ -90,7 +74,7 @@
template <typename check_range>
bool check_isbn13 (const check_range& check_seq)
{
- return boost::checks::check_sequence<isbn13_check_algorithm, EAN13_SIZE>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::check_sequence<isbn13_algorithm, EAN13_SIZE>(boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -109,7 +93,7 @@
template <typename check_range>
typename boost::range_value<check_range>::type compute_isbn13 (const check_range& check_seq)
{
- return boost::checks::compute_checkdigit<isbn13_compute_algorithm, EAN13_SIZE_WITHOUT_CHECKDIGIT>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::compute_checkdigit<isbn13_algorithm, EAN13_SIZE, 0, 1>(boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -146,7 +130,7 @@
template <typename check_range>
typename boost::range_value<check_range>::type compute_isbn10(const check_range& check_seq)
{
- return boost::checks::compute_modulus11<ISBN10_SIZE_WITHOUT_CHECKDIGIT>(check_seq);
+ return boost::checks::compute_modulus11<ISBN10_SIZE>(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-09 06:50:41 EST (Thu, 09 Feb 2012)
@@ -35,8 +35,7 @@
\tparam checkdigit_size Help functions to provide same behavior on sequence with and without check digits. No "real" value in the sequence will be skipped.
*/
-template <std::size_t checkdigit_size>
-struct luhn_algorithm : boost::checks::modulus10_algorithm <luhn_weight, checkdigit_size>
+struct luhn_algorithm : boost::checks::modulus10_algorithm <luhn_weight>
{
/*!
\brief Compute the Luhn algorithm operation on the checksum.
@@ -49,24 +48,14 @@
\remarks This function become obsolete if you don't use luhn_weight. It is using operator "<<" to make internal multiplication.
*/
- static std::size_t process(std::size_t checksum, std::size_t current_valid_value, std::size_t valid_value_counter)
+ static std::size_t process(std::size_t checksum, std::size_t value, std::size_t value_pos)
{
- std::size_t current_weight = luhn_weight::at(valid_value_counter + checkdigit_size);
- std::size_t weighted_value = current_valid_value << (current_weight-1);
+ std::size_t weighted_value = value << (luhn_weight::at(value_pos) -1);
return checksum + weighted_value % 10 + weighted_value / 10;
}
};
/*!
- \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).
@@ -82,7 +71,7 @@
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>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::check_sequence<luhn_algorithm, size_expected>(boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -100,7 +89,7 @@
template <typename check_range>
bool check_luhn (const check_range& check_seq)
{
- return boost::checks::check_sequence<luhn_check_algorithm> (boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::check_sequence<luhn_algorithm> (boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -120,7 +109,7 @@
template <size_t size_expected, typename check_range>
typename boost::range_value<check_range>::type compute_luhn(const check_range& check_seq)
{
- return boost::checks::compute_checkdigit<luhn_compute_algorithm, size_expected>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::compute_checkdigit<luhn_algorithm, size_expected, 0, 1>(boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -139,7 +128,7 @@
template <typename check_range>
typename boost::range_value<check_range>::type compute_luhn (const check_range& check_seq)
{
- return boost::checks::compute_checkdigit<luhn_compute_algorithm>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::compute_checkdigit<luhn_algorithm, 0, 1>(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-09 06:50:41 EST (Thu, 09 Feb 2012)
@@ -26,10 +26,6 @@
\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{
@@ -39,8 +35,7 @@
\tparam checkdigit_size Help functions to provide same behavior on sequence with and without check digits. No "real" value in the sequence will be skipped.
*/
-template <std::size_t checkdigit_size>
-struct mastercard_algorithm : boost::checks::luhn_algorithm <checkdigit_size>
+struct mastercard_algorithm : boost::checks::luhn_algorithm
{
/*!
\brief Verify that a number matches the Mastercard pattern.
@@ -55,22 +50,11 @@
template <typename value_type>
static bool require(const value_type &value, std::size_t value_pos)
{
- std::size_t real_pos_from_left = MASTERCARD_SIZE - value_pos - checkdigit_size;
-
- return (real_pos_from_left != 1 || value == '5') && (real_pos_from_left != 2 || (value >= '1' && value <= '5'));
+ return (MASTERCARD_SIZE - value_pos != 1 || value == '5') && (MASTERCARD_SIZE - value_pos != 2 || (value >= '1' && value <= '5'));
}
};
/*!
- \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.
@@ -86,7 +70,7 @@
template <typename check_range>
bool check_mastercard(const check_range& check_seq)
{
- return boost::checks::check_sequence<mastercard_check_algorithm, MASTERCARD_SIZE>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::check_sequence<mastercard_algorithm, MASTERCARD_SIZE>(boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -106,7 +90,7 @@
template <typename check_range>
typename boost::range_value<check_range>::type compute_mastercard(const check_range& check_seq)
{
- return boost::checks::compute_checkdigit<mastercard_compute_algorithm, MASTERCARD_SIZE_WITHOUT_CHECKDIGIT>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::compute_checkdigit<mastercard_algorithm, MASTERCARD_SIZE, 0, 1>(boost::rbegin(check_seq), boost::rend(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 2012-02-09 06:50:41 EST (Thu, 09 Feb 2012)
@@ -30,8 +30,8 @@
\tparam iteration_sense must meet the iteration_sense concept requirements.
\tparam checkdigit_size 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, std::size_t checkdigit_size>
-struct modulus10_algorithm : boost::checks::weighted_sum_algorithm<mod10_weight, checkdigit_size>
+template <typename mod10_weight>
+struct modulus10_algorithm : boost::checks::weighted_sum_algorithm<mod10_weight>
{
/*!
\brief Validate a checksum with a simple modulus 10.
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-09 06:50:41 EST (Thu, 09 Feb 2012)
@@ -37,8 +37,8 @@
\remarks The range of the check digit is [0..10], the tenth element is translated as the letter 'X'.
*/
-template <typename mod11_weight, std::size_t checkdigit_size>
-struct modulus11_algorithm : boost::checks::weighted_sum_algorithm<mod11_weight, checkdigit_size>
+template <typename mod11_weight>
+struct modulus11_algorithm : boost::checks::weighted_sum_algorithm<mod11_weight>
{
template <typename value_type>
@@ -118,14 +118,9 @@
typedef boost::checks::weight<1,2,3,4,5,6,7,8,9,10> mod11_weight;
/*!
- \brief This is the type of the most common modulus 11 algorithm for validating a check digit.
+ \brief This is the type of the most common modulus 11 algorithm.
*/
-typedef modulus11_algorithm<mod11_weight, 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, 1> mod11_compute_algorithm;
+typedef modulus11_algorithm<mod11_weight> mod11_algorithm;
/*!
\brief Validate a sequence according to the mod11_check_algorithm type.
@@ -143,7 +138,7 @@
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>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::check_sequence<mod11_algorithm, size_expected>(boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -161,7 +156,7 @@
template <typename check_range>
bool check_modulus11(const check_range& check_seq)
{
- return boost::checks::check_sequence<mod11_check_algorithm>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::check_sequence<mod11_algorithm>(boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -178,10 +173,10 @@
\returns The check digit. The check digit is in the range [0..9,X].
*/
-template <size_t size_expected, typename check_range>
+template <std::size_t size_expected, typename check_range>
typename boost::range_value<check_range>::type compute_modulus11(const check_range& check_seq)
{
- return boost::checks::compute_checkdigit<mod11_compute_algorithm, size_expected>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::compute_checkdigit<mod11_algorithm, size_expected, 0, 1>(boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -200,7 +195,7 @@
template <typename check_range>
typename boost::range_value<check_range>::type compute_modulus11(const check_range& check_seq)
{
- return boost::checks::compute_checkdigit<mod11_compute_algorithm>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::compute_checkdigit<mod11_algorithm, 0, 1>(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-09 06:50:41 EST (Thu, 09 Feb 2012)
@@ -37,8 +37,8 @@
\remarks This algorithm use two check digits.
*/
-template <typename mod97_weight, std::size_t checkdigit_size>
-struct modulus97_algorithm : boost::checks::weighted_sum_algorithm<mod97_weight, checkdigit_size>
+template <typename mod97_weight>
+struct modulus97_algorithm : boost::checks::weighted_sum_algorithm<mod97_weight>
{
/*!
\brief Validate a checksum with a simple modulus 97.
@@ -129,13 +129,9 @@
typedef boost::checks::weight<BOOST_PP_ENUM(96, MOD97_weight_maker, ~)> mod97_10_weight;
/*!
- \brief This is the type of the modulus 97-10 algorithm for validating a check digit.
+ \brief This is the type of the modulus 97-10 algorithm.
*/
-typedef modulus97_algorithm<mod97_10_weight, 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, 2> mod97_10_compute_algorithm;
+typedef modulus97_algorithm<mod97_10_weight> mod97_10_algorithm;
/*!
\brief Validate a sequence according to the mod97_10_check_algorithm type.
@@ -153,7 +149,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_check_algorithm, size_expected> (boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::check_sequence<mod97_10_algorithm, size_expected> (boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -171,7 +167,7 @@
template <typename check_range>
bool check_mod97_10(const check_range& check_seq)
{
- return boost::checks::check_sequence<mod97_10_check_algorithm>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::check_sequence<mod97_10_algorithm>(boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -193,7 +189,7 @@
template <size_t size_expected, typename check_range, typename checkdigits_iter>
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>(boost::rbegin(check_seq), boost::rend(check_seq), mod97_checkdigits);
+ return boost::checks::compute_multicheckdigit<mod97_10_algorithm, size_expected, 0, 2>(boost::rbegin(check_seq), boost::rend(check_seq), mod97_checkdigits);
}
/*!
@@ -214,7 +210,7 @@
template <typename check_range, typename checkdigits_iter>
checkdigits_iter compute_mod97_10(const check_range& check_seq, checkdigits_iter mod97_checkdigits)
{
- return boost::checks::compute_multicheckdigit<mod97_10_compute_algorithm>(boost::rbegin(check_seq), boost::rend(check_seq), mod97_checkdigits);
+ return boost::checks::compute_multicheckdigit<mod97_10_algorithm, 0, 2>(boost::rbegin(check_seq), boost::rend(check_seq), mod97_checkdigits);
}
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-09 06:50:41 EST (Thu, 09 Feb 2012)
@@ -28,10 +28,6 @@
\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{
@@ -42,13 +38,9 @@
typedef boost::checks::weight<1,3> upc_weight;
/*!
- \brief This is the type of the UPC algorithm for validating a check digit.
-*/
-typedef boost::checks::modulus10_algorithm<upc_weight, 0> upc_check_algorithm;
-/*!
- \brief This is the type of the UPC algorithm for computing a check digit.
+ \brief This is the type of the UPC algorithm.
*/
-typedef boost::checks::modulus10_algorithm< upc_weight, 1> upc_compute_algorithm;
+typedef boost::checks::modulus10_algorithm<upc_weight> upc_algorithm;
/*!
\brief Validate a sequence according to the upc_check_algorithm type.
@@ -65,7 +57,7 @@
template <typename check_range>
bool check_upca (const check_range& check_seq)
{
- return boost::checks::check_sequence<upc_check_algorithm, UPCA_SIZE>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::check_sequence<upc_algorithm, UPCA_SIZE>(boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -84,7 +76,7 @@
template <typename check_range>
typename boost::range_value<check_range>::type compute_upca(const check_range& check_seq)
{
- return boost::checks::compute_checkdigit<upc_compute_algorithm, UPCA_SIZE_WITHOUT_CHECKDIGIT>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::compute_checkdigit<upc_algorithm, UPCA_SIZE, 0, 1>(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-09 06:50:41 EST (Thu, 09 Feb 2012)
@@ -36,8 +36,7 @@
\tparam checkdigit_size Help functions to provide same behavior on sequence with and without check digits. No "real" value in the sequence will be skipped.
*/
-template <std::size_t checkdigit_size>
-struct verhoeff_algorithm : boost::checks::basic_check_algorithm<checkdigit_size>
+struct verhoeff_algorithm : boost::checks::basic_check_algorithm
{
/*!
\brief Compute the Verhoeff scheme on the checksum with the current valid value.
@@ -78,7 +77,7 @@
{ 7, 0, 4, 6, 9, 1, 3, 2, 5, 8 }
};
- return d[checksum][p[(value_pos + checkdigit_size)% 8][value]];
+ return d[checksum][p[value_pos % 8][value]];
}
/*!
@@ -120,15 +119,6 @@
};
/*!
- \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).
@@ -144,7 +134,7 @@
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>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::check_sequence<verhoeff_algorithm, size_expected>(boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -162,7 +152,7 @@
template <typename check_range>
bool check_verhoeff(const check_range& check_seq)
{
- return boost::checks::check_sequence<verhoeff_check_algorithm>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::check_sequence<verhoeff_algorithm>(boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -182,7 +172,7 @@
template <size_t size_expected, typename check_range>
typename boost::range_value<check_range>::type compute_verhoeff(const check_range& check_seq)
{
- return boost::checks::compute_checkdigit<verhoeff_compute_algorithm, size_expected>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::compute_checkdigit<verhoeff_algorithm, size_expected, 0, 1>(boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -201,7 +191,7 @@
template <typename check_range>
typename boost::range_value<check_range>::type compute_verhoeff(const check_range& check_seq)
{
- return boost::checks::compute_checkdigit<verhoeff_compute_algorithm>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::compute_checkdigit<verhoeff_algorithm, 0, 1>(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-09 06:50:41 EST (Thu, 09 Feb 2012)
@@ -26,10 +26,6 @@
\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{
@@ -39,8 +35,7 @@
\tparam checkdigit_size Helper functions to provide same behavior on a sequence with and without check digits. No "real" value in the sequence will be skipped.
*/
-template <std::size_t checkdigit_size>
-struct visa_algorithm : boost::checks::luhn_algorithm <checkdigit_size>
+struct visa_algorithm : boost::checks::luhn_algorithm
{
/*!
\brief Verify that a number matches the Visa pattern.
@@ -55,22 +50,11 @@
template <typename value_type>
static bool require(const value_type &value, std::size_t value_pos)
{
- std::size_t real_pos_from_left = VISA_SIZE - value_pos - checkdigit_size;
-
- return real_pos_from_left != 1 || value == '4';
+ return VISA_SIZE - value_pos != 1 || value == '4';
}
};
/*!
- \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.
@@ -86,7 +70,7 @@
template <typename check_range>
bool check_visa(const check_range& check_seq)
{
- return boost::checks::check_sequence<visa_check_algorithm, VISA_SIZE>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::check_sequence<visa_algorithm, VISA_SIZE>(boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -106,7 +90,7 @@
template <typename check_range>
typename boost::range_value<check_range>::type compute_visa(const check_range& check_seq)
{
- return boost::checks::compute_checkdigit<visa_compute_algorithm, VISA_SIZE_WITHOUT_CHECKDIGIT>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::compute_checkdigit<visa_algorithm, VISA_SIZE, 0, 1>(boost::rbegin(check_seq), boost::rend(check_seq));
}
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 2012-02-09 06:50:41 EST (Thu, 09 Feb 2012)
@@ -30,8 +30,8 @@
\tparam iteration_sense must meet the iteration_sense concept requirements.
\tparam checkdigit_size Helper function to provide same behavior on sequence with and without checkdigits. No "real" value in the sequence will be skipped.
*/
-template <typename weight, std::size_t checkdigit_size>
-struct weighted_sum_algorithm : boost::checks::basic_check_algorithm<checkdigit_size>
+template <typename weight>
+struct weighted_sum_algorithm : boost::checks::basic_check_algorithm
{
/*!
\brief Compute an operation on the checksum with the current valid value.
@@ -44,7 +44,7 @@
*/
static std::size_t process(std::size_t checksum, std::size_t value, std::size_t value_pos)
{
- return checksum + value * weight::at(value_pos + checkdigit_size);
+ return checksum + value * weight::at(value_pos);
}
};
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