|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r76992 - sandbox/SOC/2011/checks/boost/checks
From: pierre.talbot.6114_at_[hidden]
Date: 2012-02-12 09:57:46
Author: trademark
Date: 2012-02-12 09:57:45 EST (Sun, 12 Feb 2012)
New Revision: 76992
URL: http://svn.boost.org/trac/boost/changeset/76992
Log:
Add the type checkdigit, prepare for changes.
Added:
sandbox/SOC/2011/checks/boost/checks/checkdigit.hpp (contents, props changed)
Text files modified:
sandbox/SOC/2011/checks/boost/checks/amex.hpp | 3 ++-
sandbox/SOC/2011/checks/boost/checks/basic_checks.hpp | 24 ++++++++++++------------
sandbox/SOC/2011/checks/boost/checks/ean.hpp | 7 ++++---
sandbox/SOC/2011/checks/boost/checks/isbn.hpp | 3 ++-
sandbox/SOC/2011/checks/boost/checks/luhn.hpp | 23 +++++++++++++++++++++--
sandbox/SOC/2011/checks/boost/checks/mastercard.hpp | 3 ++-
sandbox/SOC/2011/checks/boost/checks/modulus11.hpp | 4 ++--
sandbox/SOC/2011/checks/boost/checks/modulus97.hpp | 6 ++++--
sandbox/SOC/2011/checks/boost/checks/upc.hpp | 2 +-
sandbox/SOC/2011/checks/boost/checks/verhoeff.hpp | 5 +++--
sandbox/SOC/2011/checks/boost/checks/visa.hpp | 4 ++--
11 files changed, 55 insertions(+), 29 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-12 09:57:45 EST (Sun, 12 Feb 2012)
@@ -18,6 +18,7 @@
#include <cstddef> // std::size_t
+#include <boost/checks/checkdigit.hpp>
#include <boost/checks/luhn.hpp>
#include <boost/range/rbegin.hpp>
@@ -69,7 +70,7 @@
template <typename check_range>
typename boost::range_value<check_range>::type compute_amex(const check_range& check_seq)
{
- return boost::checks::compute_checkdigit<luhn_algorithm, AMEX_SIZE, 0, 1>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::compute_checkdigit<luhn_algorithm, AMEX_SIZE, boost::checks::basic_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq));
}
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-12 09:57:45 EST (Sun, 12 Feb 2012)
@@ -123,12 +123,12 @@
\returns The check digit of the type of a value in check_seq.
*/
template <typename algorithm,
- std::size_t checkdigit_pos,
- std::size_t checkdigit_size,
+ typename checkdigit,
typename seq_iterator>
typename seq_iterator::value_type compute_checkdigit(seq_iterator seq_begin, seq_iterator seq_end)
{
- typename boost::checks::detail::skip_counter<checkdigit_pos, checkdigit_size>::type counter = boost::checks::detail::skip_counter<checkdigit_pos, checkdigit_size>()();
+ 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, boost::checks::no_null_size_contract<> >(seq_begin, seq_end, counter);
return algorithm::template compute_checkdigit<typename seq_iterator::value_type>(checksum);
}
@@ -149,12 +149,12 @@
*/
template <typename algorithm,
std::size_t size_expected,
- std::size_t checkdigit_pos,
- std::size_t checkdigit_size,
+ typename checkdigit,
typename seq_iterator>
typename seq_iterator::value_type compute_checkdigit(seq_iterator seq_begin, seq_iterator seq_end)
{
- typename boost::checks::detail::skip_counter<checkdigit_pos, checkdigit_size>::type counter = boost::checks::detail::skip_counter<checkdigit_pos, checkdigit_size>()();
+ 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, boost::checks::strict_size_contract<size_expected> >(seq_begin, seq_end, counter);
return algorithm::template compute_checkdigit<typename seq_iterator::value_type>(checksum);
}
@@ -176,13 +176,13 @@
\returns An iterator initialized at one pass the end of checkdigits.
*/
template <typename algorithm,
- std::size_t checkdigit_pos,
- std::size_t checkdigit_size,
+ typename checkdigit,
typename seq_iterator,
typename checkdigit_iterator>
checkdigit_iterator compute_multicheckdigit (seq_iterator seq_begin, seq_iterator seq_end, checkdigit_iterator checkdigits)
{
- typename boost::checks::detail::skip_counter<checkdigit_pos, checkdigit_size>::type counter = boost::checks::detail::skip_counter<checkdigit_pos, checkdigit_size>()();
+ 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, boost::checks::no_null_size_contract<> >(seq_begin, seq_end, counter);
return algorithm::compute_multicheckdigit(checksum, checkdigits);
}
@@ -205,13 +205,13 @@
*/
template <typename algorithm,
std::size_t size_expected,
- std::size_t checkdigit_pos,
- std::size_t checkdigit_size,
+ typename checkdigit,
typename seq_iterator,
typename checkdigit_iterator>
checkdigit_iterator compute_multicheckdigit (seq_iterator seq_begin, seq_iterator seq_end, checkdigit_iterator checkdigits)
{
- typename boost::checks::detail::skip_counter<checkdigit_pos, checkdigit_size>::type counter = boost::checks::detail::skip_counter<checkdigit_pos, checkdigit_size>()();
+ 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, 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/checkdigit.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2011/checks/boost/checks/checkdigit.hpp 2012-02-12 09:57:45 EST (Sun, 12 Feb 2012)
@@ -0,0 +1,38 @@
+// Boost checks/checkdigit.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 Provides a type "checkdigit"
+*/
+
+#ifndef BOOST_CHECK_CHECKDIGIT_HPP
+#define BOOST_CHECK_CHECKDIGIT_HPP
+
+#ifdef _MSC_VER
+ #pragma once
+#endif
+
+#include <cstddef> // std::size_t
+
+namespace boost{
+ namespace checks{
+
+template <std::size_t checkdigit_pos,
+ std::size_t checkdigit_size>
+struct checkdigit
+{
+ static const std::size_t pos = checkdigit_pos;
+ static const std::size_t size = checkdigit_size;
+};
+
+// A checkdigit at the end of the number for reverse traversal.
+typedef checkdigit<0, 1> basic_checkdigit;
+
+
+}} // namespace boost namespace checks
+
+#endif //BOOST_CHECK_CHECKDIGIT_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-12 09:57:45 EST (Sun, 12 Feb 2012)
@@ -17,6 +17,7 @@
#endif
#include <boost/checks/weight.hpp>
+#include <boost/checks/checkdigit.hpp>
#include <boost/checks/basic_checks.hpp>
#include <boost/checks/modulus10.hpp>
@@ -39,7 +40,7 @@
/*!
\brief This is the weight used by EAN system.
*/
-typedef boost::checks::weight<1,3> ean_weight ;
+typedef boost::checks::weight<1,3> ean_weight;
/*!
\brief This is the type of the EAN algorithm.
*/
@@ -79,7 +80,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_algorithm, EAN13_SIZE, 0, 1>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::compute_checkdigit<ean_algorithm, EAN13_SIZE, boost::checks::basic_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -116,7 +117,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_algorithm, EAN8_SIZE, 0, 1>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::compute_checkdigit<ean_algorithm, EAN8_SIZE, boost::checks::basic_checkdigit>(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-12 09:57:45 EST (Sun, 12 Feb 2012)
@@ -20,6 +20,7 @@
#include <boost/checks/ean.hpp>
#include <boost/checks/modulus11.hpp>
+#include <boost/checks/checkdigit.hpp>
#include <boost/range/rbegin.hpp>
#include <boost/range/rend.hpp>
@@ -74,7 +75,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_algorithm, EAN13_SIZE, 0, 1>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::compute_checkdigit<isbn13_algorithm, 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-12 09:57:45 EST (Sun, 12 Feb 2012)
@@ -17,6 +17,7 @@
#endif
#include <boost/checks/modulus10.hpp>
+#include <boost/checks/checkdigit.hpp>
#include <boost/range/rbegin.hpp>
#include <boost/range/rend.hpp>
@@ -53,6 +54,24 @@
std::size_t weighted_value = value << (luhn_weight::at(value_pos) -1);
return checksum + weighted_value % 10 + weighted_value / 10;
}
+ /*
+ template <typename Function>
+ struct processor
+ {
+ Function counter;
+ bool weight;
+ processor(Function counter) : counter(counter), weight(!(counter()&1)) { }
+
+ std::size_t operator()(std::size_t checksum, std::size_t value)
+ {
+ return checksum + value << weight % 10 + value << weight / 10;
+ }
+ };
+
+ validate_checksum <UnaryPredicate : for the checkdigit validation
+ compute_checksum <UnaryFunction : for the computation of the checkdigit
+
+*/
};
/*!
@@ -109,7 +128,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_algorithm, size_expected, 0, 1>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::compute_checkdigit<luhn_algorithm, size_expected, boost::checks::basic_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -128,7 +147,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_algorithm, 0, 1>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::compute_checkdigit<luhn_algorithm, 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-12 09:57:45 EST (Sun, 12 Feb 2012)
@@ -21,6 +21,7 @@
#include <boost/range/iterator_range.hpp>
#include <boost/checks/luhn.hpp>
+#include <boost/checks/checkdigit.hpp>
/*!
\brief This macro defines the size of a Mastercard number.
@@ -66,7 +67,7 @@
template <typename check_range>
typename boost::range_value<check_range>::type compute_mastercard(const check_range& check_seq)
{
- return boost::checks::compute_checkdigit<luhn_algorithm, MASTERCARD_SIZE, 0, 1>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::compute_checkdigit<luhn_algorithm, 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-12 09:57:45 EST (Sun, 12 Feb 2012)
@@ -176,7 +176,7 @@
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_algorithm, size_expected, 0, 1>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::compute_checkdigit<mod11_algorithm, size_expected, boost::checks::basic_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -195,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_algorithm, 0, 1>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::compute_checkdigit<mod11_algorithm, 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-12 09:57:45 EST (Sun, 12 Feb 2012)
@@ -133,6 +133,8 @@
*/
typedef modulus97_algorithm<mod97_10_weight> mod97_10_algorithm;
+typedef checkdigit<0, 2> mod97_10_checkdigit;
+
/*!
\brief Validate a sequence according to the mod97_10_check_algorithm type.
@@ -189,7 +191,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_algorithm, size_expected, 0, 2>(boost::rbegin(check_seq), boost::rend(check_seq), mod97_checkdigits);
+ return boost::checks::compute_multicheckdigit<mod97_10_algorithm, size_expected, mod97_10_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq), mod97_checkdigits);
}
/*!
@@ -210,7 +212,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_algorithm, 0, 2>(boost::rbegin(check_seq), boost::rend(check_seq), mod97_checkdigits);
+ return boost::checks::compute_multicheckdigit<mod97_10_algorithm, mod97_10_checkdigit>(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-12 09:57:45 EST (Sun, 12 Feb 2012)
@@ -76,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_algorithm, UPCA_SIZE, 0, 1>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::compute_checkdigit<upc_algorithm, 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-12 09:57:45 EST (Sun, 12 Feb 2012)
@@ -25,6 +25,7 @@
#include <boost/checks/translation_exception.hpp>
#include <boost/checks/weight.hpp>
+#include <boost/checks/checkdigit.hpp>
#include <boost/checks/basic_checks.hpp>
#include <boost/checks/basic_check_algorithm.hpp>
@@ -172,7 +173,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_algorithm, size_expected, 0, 1>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::compute_checkdigit<verhoeff_algorithm, size_expected, boost::checks::basic_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -191,7 +192,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_algorithm, 0, 1>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::compute_checkdigit<verhoeff_algorithm, boost::checks::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-12 09:57:45 EST (Sun, 12 Feb 2012)
@@ -21,7 +21,7 @@
#include <boost/range/iterator_range.hpp>
#include <boost/checks/luhn.hpp>
-
+#include <boost/checks/checkdigit.hpp>
/*!
\brief This macro defines the size of a Visa number.
*/
@@ -67,7 +67,7 @@
template <typename check_range>
typename boost::range_value<check_range>::type compute_visa(const check_range& check_seq)
{
- return boost::checks::compute_checkdigit<luhn_algorithm, VISA_SIZE, 0, 1>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::compute_checkdigit<luhn_algorithm, 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