Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r77354 - in sandbox/SOC/2011/checks: boost/checks libs/checks/test
From: pierre.talbot.6114_at_[hidden]
Date: 2012-03-17 06:06:56


Author: trademark
Date: 2012-03-17 06:06:54 EDT (Sat, 17 Mar 2012)
New Revision: 77354
URL: http://svn.boost.org/trac/boost/changeset/77354

Log:
Unify multi and single checkdigit. Remove algorithm structure and replace with Unary[Function | Predicate] corresponding to validate and compute checkdigit.
Text files modified:
   sandbox/SOC/2011/checks/boost/checks/amex.hpp | 9 --
   sandbox/SOC/2011/checks/boost/checks/basic_checks.hpp | 109 ++++++---------------------------------
   sandbox/SOC/2011/checks/boost/checks/checks_fwd.hpp | 4
   sandbox/SOC/2011/checks/boost/checks/ean.hpp | 20 ++----
   sandbox/SOC/2011/checks/boost/checks/luhn.hpp | 21 +++----
   sandbox/SOC/2011/checks/boost/checks/mastercard.hpp | 9 --
   sandbox/SOC/2011/checks/boost/checks/modulus10.hpp | 12 ++-
   sandbox/SOC/2011/checks/boost/checks/modulus11.hpp | 32 +++++-----
   sandbox/SOC/2011/checks/boost/checks/modulus97.hpp | 105 ++++++++++----------------------------
   sandbox/SOC/2011/checks/boost/checks/upc.hpp | 17 ++----
   sandbox/SOC/2011/checks/boost/checks/verhoeff.hpp | 33 ++++++-----
   sandbox/SOC/2011/checks/boost/checks/visa.hpp | 9 --
   sandbox/SOC/2011/checks/libs/checks/test/test_checks.cpp | 14 ++--
   13 files changed, 124 insertions(+), 270 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-03-17 06:06:54 EDT (Sat, 17 Mar 2012)
@@ -51,9 +51,7 @@
 template <typename check_range>
 bool check_amex (const check_range& check_seq)
 {
- return boost::checks::check_sequence<luhn_algorithm,
- luhn_processor,
- AMEX_SIZE>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return check_luhn<AMEX_SIZE>(check_seq);
 }
 
 /*!
@@ -73,10 +71,7 @@
 template <typename check_range>
 std::size_t compute_amex(const check_range& check_seq)
 {
- return boost::checks::compute_checkdigit<luhn_algorithm,
- luhn_processor,
- AMEX_SIZE,
- basic_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return compute_luhn<AMEX_SIZE>(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-03-17 06:06:54 EDT (Sat, 17 Mar 2012)
@@ -56,8 +56,7 @@
   }
 };
 
-template <typename algorithm,
- template <class> class processor,
+template <template <class> class processor,
           std::size_t size_expected,
           typename seq_iterator,
           typename counter_iter>
@@ -75,8 +74,7 @@
   return checksum;
 }
 
-template <typename algorithm,
- template <class> class processor,
+template <template <class> class processor,
           typename seq_iterator,
           typename counter_iter>
 std::size_t compute_checksum(seq_iterator seq_begin, seq_iterator seq_end, counter_iter &counter)
@@ -103,18 +101,17 @@
 
     \returns @c true if the checkdigit is correct, @c false otherwise.
 */
-template <typename algorithm,
- template <class> class processor,
+template <template <class> class processor,
+ typename UnaryPredicate,
           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()();
  
- std::size_t checksum = compute_checksum<algorithm,
- processor>(seq_begin,
+ std::size_t checksum = compute_checksum<processor>(seq_begin,
                                                      seq_end,
                                                      counter);
- return algorithm::validate_checksum(checksum);
+ return UnaryPredicate()(checksum);
 }
 
 /*!
@@ -131,9 +128,8 @@
 
     \returns @c true if the checkdigit is correct, @c false otherwise.
 */
-template <typename algorithm,
- template <class> class processor,
-// typename prechecksum_type,
+template <template <class> class processor,
+ typename UnaryPredicate,
           std::size_t size_expected,
           typename seq_iterator>
 bool check_sequence(seq_iterator seq_begin, seq_iterator seq_end)
@@ -141,13 +137,12 @@
   boost::checks::detail::simple_counter::type counter = boost::checks::detail::simple_counter()();
   
  // prechecksum_type prechecksum;
- std::size_t checksum = compute_checksum<algorithm,
- processor,
+ std::size_t checksum = compute_checksum<processor,
                                           size_expected>(seq_begin,//prechecksum(seq_begin, seq_end),
                                                          seq_end, //prechecksum(seq_end, seq_end),
                                                          counter);
   if(checksum != bad_sequence)
- return algorithm::validate_checksum(checksum);
+ return UnaryPredicate()(checksum);
   return false;
 }
 
@@ -164,19 +159,18 @@
 
     \returns The check digit of the type of a value in check_seq.
 */
-template <typename algorithm,
- template <class> class processor,
+template <template <class> class processor,
+ typename UnaryFunction,
           typename checkdigit,
           typename seq_iterator>
 std::size_t compute_checkdigit(seq_iterator seq_begin, seq_iterator seq_end)
 {
   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,
- processor>(seq_begin,
+ std::size_t checksum = compute_checksum<processor>(seq_begin,
                                                      seq_end,
                                                      counter);
- return algorithm::compute_checkdigit(checksum);
+ return UnaryFunction()(checksum);
 }
 
 /*!
@@ -193,8 +187,8 @@
 
     \returns The check digit of the type of a value in check_seq.
 */
-template <typename algorithm,
- template <class> class processor,
+template <template <class> class processor,
+ typename UnaryFunction,
           std::size_t size_expected,
           typename checkdigit,
           typename seq_iterator>
@@ -202,82 +196,15 @@
 {
   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,
- processor,
+ std::size_t checksum = compute_checksum<processor,
                                           size_expected>(seq_begin,
                                                          seq_end,
                                                          counter);
   if(checksum != bad_sequence)
- return algorithm::compute_checkdigit(checksum);
+ return UnaryFunction()(checksum);
   return bad_sequence;
 }
 
-/*!
-
- \brief Calculate the checkdigits of a sequence according to algorithm.
-
- \pre check_seq is a valid range.\n checkdigits is a valid initialized iterator and have enough reserved place to store the check digits.
-
- \tparam algorithm is a set of static methods used to translate, filter and calculate or verify the checkdigits.
- \tparam check_range is a valid range type.
- \tparam checkdigit_iterator must meet the OutputIterator requirements.
- \param check_seq is the sequence of value to check.
- \param checkdigits is the output iterator in which the check digits will be written.
-
- \throws std::invalid_argument if check_seq contains no valid value.
-
- \returns An iterator initialized at one pass the end of checkdigits.
-*/
-template <typename algorithm,
- template <class> class processor,
- typename checkdigit,
- typename seq_iterator>
-std::pair<std::size_t, std::size_t> compute_multicheckdigit (seq_iterator seq_begin, seq_iterator seq_end)
-{
- 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,
- processor>(seq_begin,
- seq_end,
- counter);
- return algorithm::compute_multicheckdigit(checksum);
-}
-
-/*!
- \brief Calculate the checkdigits of a sequence according to algorithm.
-
- \pre check_seq is a valid range.\n checkdigits is a valid initialized iterator and have enough reserved place to store the check digits.\n size_expected > 0 (enforced by static assert).
-
- \tparam algorithm is a set of static method use to translate, filter and calculate or verify the checkdigits.
- \tparam size_expected is the number of valid value expected in the sequence.
- \tparam check_range is a valid range type.
- \tparam checkdigit_iterator must meet the OutputIterator requirements.
- \param check_seq is the sequence of value to check.
- \param checkdigits is the output iterator in which the check digits will be written.
-
- \throws std::invalid_argument if check_seq doesn't contain size_expected valid values.
-
- \returns An iterator initialized at one pass the end of checkdigits.
-*/
-template <typename algorithm,
- template <class> class processor,
- 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 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,
- processor,
- size_expected>(seq_begin,
- seq_end,
- counter);
- if(checksum != bad_sequence)
- return algorithm::compute_multicheckdigit(checksum);
- return std::pair<std::size_t, std::size_t>(bad_sequence, bad_sequence);
-}
-
 } // namespace checks
 } // namespace boost
 

Modified: sandbox/SOC/2011/checks/boost/checks/checks_fwd.hpp
==============================================================================
--- sandbox/SOC/2011/checks/boost/checks/checks_fwd.hpp (original)
+++ sandbox/SOC/2011/checks/boost/checks/checks_fwd.hpp 2012-03-17 06:06:54 EDT (Sat, 17 Mar 2012)
@@ -123,10 +123,10 @@
 bool check_mod97_10(const check_range& check_seq);
 
 template <size_t size_expected, typename check_range>
-std::pair<std::size_t, std::size_t> compute_mod97_10(const check_range& check_seq);
+std::size_t compute_mod97_10(const check_range& check_seq);
 
 template <typename check_range>
-std::pair<std::size_t, std::size_t> compute_mod97_10(const check_range& check_seq);
+std::size_t compute_mod97_10(const check_range& check_seq);
 
 // EAN-13 and EAN-8
 

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-03-17 06:06:54 EDT (Sat, 17 Mar 2012)
@@ -42,10 +42,6 @@
   \brief This is the weight used by EAN system.
 */
 typedef weighted_sum<weight<1,3> > ean_processor;
-/*!
- \brief This is the type of the EAN algorithm.
-*/
-typedef modulus10_algorithm ean_algorithm;
 
 /*!
     \brief Validate a sequence according to the ean_check_algorithm type.
@@ -62,8 +58,8 @@
 template <typename check_range>
 bool check_ean13(const check_range& check_seq)
 {
- return boost::checks::check_sequence<ean_algorithm,
- ean_processor::processor,
+ return boost::checks::check_sequence<ean_processor::processor,
+ mod10_validation,
                                        EAN13_SIZE> (boost::rbegin(check_seq), boost::rend(check_seq));
 }
 
@@ -83,8 +79,8 @@
 template <typename check_range>
 std::size_t compute_ean13(const check_range& check_seq)
 {
- return boost::checks::compute_checkdigit<ean_algorithm,
- ean_processor::processor,
+ return boost::checks::compute_checkdigit<ean_processor::processor,
+ mod10_checkdigit,
                                            EAN13_SIZE,
                                            basic_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq));
 }
@@ -104,8 +100,8 @@
 template <typename check_range>
 bool check_ean8 (const check_range& check_seq)
 {
- return boost::checks::check_sequence<ean_algorithm,
- ean_processor::processor,
+ return boost::checks::check_sequence<ean_processor::processor,
+ mod10_validation,
                                        EAN8_SIZE>(boost::rbegin(check_seq), boost::rend(check_seq));
 }
 
@@ -125,8 +121,8 @@
 template <typename check_range>
 std::size_t compute_ean8(const check_range& check_seq)
 {
- return boost::checks::compute_checkdigit<ean_algorithm,
- ean_processor::processor,
+ return boost::checks::compute_checkdigit<ean_processor::processor,
+ mod10_checkdigit,
                                            EAN8_SIZE,
                                            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-03-17 06:06:54 EDT (Sat, 17 Mar 2012)
@@ -26,8 +26,6 @@
 namespace boost {
     namespace checks{
 
-typedef modulus10_algorithm luhn_algorithm;
-
 /*!
   \brief Compute the Luhn algorithm operation on the checksum.
 
@@ -37,7 +35,6 @@
   \param valid_value_counter is the number of valid value already counted (the current value is not included).\n This is also the position (above the valid values) of the current value analysed (0 <= valid_value_counter < n).
   \param checksum is the current checksum.
 
- \remarks This function become obsolete if you don't use luhn_weight. It is using operator "<<" to make internal multiplication.
 */
 template <typename Function>
 struct luhn_processor
@@ -69,8 +66,8 @@
 template <size_t size_expected, typename check_range>
 bool check_luhn (const check_range& check_seq)
 {
- return boost::checks::check_sequence<luhn_algorithm,
- luhn_processor,
+ return boost::checks::check_sequence<luhn_processor,
+ mod10_validation,
                                        size_expected>(boost::rbegin(check_seq), boost::rend(check_seq));
 }
 
@@ -89,9 +86,9 @@
 template <typename check_range>
 bool check_luhn (const check_range& check_seq)
 {
- return boost::checks::check_sequence<luhn_algorithm,
- luhn_processor
- >(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::check_sequence<luhn_processor,
+ mod10_validation>
+ (boost::rbegin(check_seq), boost::rend(check_seq));
 }
 
 /*!
@@ -111,8 +108,8 @@
 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,
- luhn_processor,
+ return boost::checks::compute_checkdigit<luhn_processor,
+ mod10_checkdigit,
                                            size_expected,
                                            basic_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq));
 }
@@ -133,8 +130,8 @@
 template <typename check_range>
 std::size_t compute_luhn (const check_range& check_seq)
 {
- return boost::checks::compute_checkdigit<luhn_algorithm,
- luhn_processor,
+ return boost::checks::compute_checkdigit<luhn_processor,
+ mod10_checkdigit,
                                            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-03-17 06:06:54 EDT (Sat, 17 Mar 2012)
@@ -47,9 +47,7 @@
 template <typename check_range>
 bool check_mastercard(const check_range& check_seq)
 {
- return check_sequence<luhn_algorithm,
- luhn_processor,
- MASTERCARD_SIZE>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return check_luhn<MASTERCARD_SIZE>(check_seq);
 }
 
 /*!
@@ -69,10 +67,7 @@
 template <typename check_range>
 std::size_t compute_mastercard(const check_range& check_seq)
 {
- return compute_checkdigit<luhn_algorithm,
- luhn_processor,
- MASTERCARD_SIZE,
- basic_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return compute_luhn<MASTERCARD_SIZE>(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-03-17 06:06:54 EDT (Sat, 17 Mar 2012)
@@ -29,8 +29,6 @@
     \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.
 */
-struct modulus10_algorithm
-{
   /*!
     \brief Validate a checksum with a simple modulus 10.
 
@@ -38,11 +36,13 @@
 
     \returns @c true if the checksum is correct, @c false otherwise.
   */
- static bool validate_checksum(std::size_t checksum)
+struct mod10_validation
+{
+ bool operator()(std::size_t checksum)
   {
     return !(checksum % 10);
   }
-
+};
   /*!
     \brief Compute the check digit with a simple modulus 10.
 
@@ -53,7 +53,9 @@
 
     \returns The modulus 10 check digit of checksum.
   */
- static std::size_t compute_checkdigit(std::size_t checksum)
+struct mod10_checkdigit
+{
+ std::size_t operator()(std::size_t checksum)
   {
     return ((10 - checksum % 10) % 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-03-17 06:06:54 EDT (Sat, 17 Mar 2012)
@@ -37,8 +37,6 @@
     \remarks The range of the check digit is [0..10], the tenth element is translated as the letter 'X'.
 */
 
-struct modulus11_algorithm
-{
   /*!
     \brief Validate a checksum with a simple modulus 11.
 
@@ -46,11 +44,13 @@
 
     \returns true if the checksum is correct, false otherwise.
   */
- static bool validate_checksum(std::size_t checksum)
+struct mod11_validation
+{
+ bool operator()(std::size_t checksum)
   {
     return !(checksum % 11);
   }
-
+};
   /*!
     \brief Compute the check digit with a simple modulus 11.
 
@@ -61,7 +61,9 @@
 
     \returns The modulus 11 check digit of checksum. 'X' is returned if the check digit value is equal to 10.
   */
- static std::size_t compute_checkdigit(std::size_t checksum)
+struct mod11_checkdigit
+{
+ std::size_t operator()(std::size_t checksum)
   {
      return ((11 - checksum % 11)% 11);
   }
@@ -75,8 +77,6 @@
 /*!
   \brief This is the type of the most common modulus 11 algorithm.
 */
-typedef modulus11_algorithm mod11_algorithm;
-
 typedef weighted_sum<mod11_weight> mod11_processor;
 
 /*!
@@ -95,8 +95,8 @@
 template <size_t size_expected, typename check_range>
 bool check_modulus11(const check_range& check_seq)
 {
- return boost::checks::check_sequence<mod11_algorithm,
- mod11_processor::processor,
+ return boost::checks::check_sequence<mod11_processor::processor,
+ mod11_validation,
                                        size_expected>(boost::rbegin(check_seq), boost::rend(check_seq));
 }
 
@@ -115,9 +115,9 @@
 template <typename check_range>
 bool check_modulus11(const check_range& check_seq)
 {
- return boost::checks::check_sequence<mod11_algorithm,
- mod11_processor::processor
- >(boost::rbegin(check_seq), boost::rend(check_seq));
+ return check_sequence<mod11_processor::processor,
+ mod11_validation>
+ (boost::rbegin(check_seq), boost::rend(check_seq));
 }
 
 /*!
@@ -137,8 +137,8 @@
 template <std::size_t size_expected, typename check_range>
 std::size_t compute_modulus11(const check_range& check_seq)
 {
- return compute_checkdigit<mod11_algorithm,
- mod11_processor::processor,
+ return compute_checkdigit<mod11_processor::processor,
+ mod11_checkdigit,
                             size_expected,
                             basic_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq));
 }
@@ -159,8 +159,8 @@
 template <typename check_range>
 std::size_t compute_modulus11(const check_range& check_seq)
 {
- return compute_checkdigit<mod11_algorithm,
- mod11_processor::processor,
+ return compute_checkdigit<mod11_processor::processor,
+ mod11_checkdigit,
                             basic_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq));
 }
 

Modified: sandbox/SOC/2011/checks/boost/checks/modulus97.hpp
==============================================================================
--- sandbox/SOC/2011/checks/boost/checks/modulus97.hpp (original)
+++ sandbox/SOC/2011/checks/boost/checks/modulus97.hpp 2012-03-17 06:06:54 EDT (Sat, 17 Mar 2012)
@@ -35,9 +35,6 @@
 
     \remarks This algorithm use two check digits.
 */
-
-struct modulus97_algorithm
-{
   /*!
     \brief Validate a checksum with a simple modulus 97.
 
@@ -45,11 +42,13 @@
 
     \returns @c true if the checksum is correct, @c false otherwise.
   */
- static bool validate_checksum(std::size_t checksum)
+struct mod97_validation
+{
+ bool operator()(std::size_t checksum)
   {
     return checksum % 97 == 1;
   }
-
+};
   /*!
     \brief Compute the two check digits with a simple modulus 97.
 
@@ -64,80 +63,32 @@
 
     \returns An iterator initialized at one pass to the end of the two check digits.
   */
- static std::pair<std::size_t, std::size_t> compute_multicheckdigit(std::size_t checksum)
+struct mod97_checkdigit
+{
+ std::size_t operator()(std::size_t checksum)
   {
- std::size_t mod97_checkdigits = 98 - (checksum % 97);
-
- return std::pair<std::size_t, std::size_t>(mod97_checkdigits / 10, mod97_checkdigits % 10);
+ return 98 - (checksum % 97);
   }
 };
 
-/*! \class make_mod97_weight
- \brief This class is used to pre-compute the weight of the mod97-10 algorithm (a = 1; a = a * 10 % 97 ;).
-
- \tparam weight_value is the weight value stored by make_mod97_weight.
-
- \remarks The last value is 68, so we specialize make_mod97_weight to terminate the template recursion.
-*/
-template <std::size_t weight_value>
-struct make_mod97_weight
-{
- static const std::size_t value = weight_value;
- typedef make_mod97_weight<weight_value * 10 % 97> next;
-};
-/*! \class make_mod97_weight
- \brief This class is the terminal specialisation of make_mod97_weight, so the recursion can finish.
-*/
-template<>
-struct make_mod97_weight<68>
-{
- static const unsigned int value = 68;
- typedef make_mod97_weight type;
-};
-
-/*!
- \brief This is the initial weight for the mod97-10 weights series.
-*/
-typedef make_mod97_weight<1> initial_mod97_weight;
-
-/*!
- \brief This macro is used to access the next type.
-*/
-#define NEXT(z,n,unused) next::
-
-/*!
- \brief This macro is used to access to n-th value of initial_mod97_weight. (By using make_mod97_weight).
-*/
-#define MOD97_weight_maker(z, n ,unused) initial_mod97_weight::BOOST_PP_REPEAT(n, NEXT, ~)value
-
-/*!
- \brief This is weight of the mod97-10 algorithm.
-*/
-typedef weight<BOOST_PP_ENUM(96, MOD97_weight_maker, ~)> mod97_10_weight;
-
-/*!
- \brief This is the type of the modulus 97-10 algorithm.
-*/
-typedef modulus97_algorithm mod97_10_algorithm;
-
-// typedef weighted_sum<mod97_10_weight> mod97_10_processor;
-
 typedef checkdigit<0, 2> mod97_10_checkdigit;
 
-typedef weighted_sum<mod97_10_weight> mod97_10_processor;
-/*
 template <typename Function>
 struct mod97_10_processor
 {
   unsigned char weight;
- mod97_10_processor(Function counter) : weight(68) { }
+ mod97_10_processor(Function counter) : weight(68)
+ {
+ if(counter() != 0)
+ weight = 10;
+ }
 
   std::size_t operator()(std::size_t checksum, std::size_t value)
   {
     weight = weight * 10 % 97;
     return checksum + value * weight;
   }
-};*/
+};
 
 /*!
     \brief Validate a sequence according to the mod97_10_check_algorithm type.
@@ -155,8 +106,8 @@
 template <size_t size_expected, typename check_range>
 bool check_mod97_10 (const check_range& check_seq)
 {
- return check_sequence<mod97_10_algorithm,
- mod97_10_processor::processor,
+ return check_sequence<mod97_10_processor,
+ mod97_validation,
                         size_expected>(boost::rbegin(check_seq), boost::rend(check_seq));
 }
 
@@ -175,9 +126,9 @@
 template <typename check_range>
 bool check_mod97_10(const check_range& check_seq)
 {
- return check_sequence<mod97_10_algorithm,
- mod97_10_processor::processor
- >(boost::rbegin(check_seq), boost::rend(check_seq));
+ return check_sequence<mod97_10_processor,
+ mod97_validation>
+ (boost::rbegin(check_seq), boost::rend(check_seq));
 }
 
 /*!
@@ -197,12 +148,12 @@
     \returns The check digits are stored into mod97_checkdigits. The range of these is [0..9][0..9].
 */
 template <size_t size_expected, typename check_range>
-std::pair<std::size_t, std::size_t> compute_mod97_10(const check_range& check_seq)
+std::size_t compute_mod97_10(const check_range& check_seq)
 {
- return compute_multicheckdigit<mod97_10_algorithm,
- mod97_10_processor::processor,
- mod97_10_checkdigit,
- size_expected>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return compute_checkdigit<mod97_10_processor,
+ mod97_checkdigit,
+ mod97_10_checkdigit,
+ size_expected>(boost::rbegin(check_seq), boost::rend(check_seq));
 }
 
 /*!
@@ -221,11 +172,11 @@
     \returns The check digits are stored into mod97_checkdigits. The range of these is [0..9][0..9].
 */
 template <typename check_range>
-std::pair<std::size_t, std::size_t> compute_mod97_10(const check_range& check_seq)
+std::size_t compute_mod97_10(const check_range& check_seq)
 {
- return compute_multicheckdigit<mod97_10_algorithm,
- mod97_10_processor::processor,
- mod97_10_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return compute_checkdigit<mod97_10_processor,
+ mod97_checkdigit,
+ mod97_10_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq));
 }
 
 

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-03-17 06:06:54 EDT (Sat, 17 Mar 2012)
@@ -36,12 +36,7 @@
 /*!
   \brief This is the weight used by UPC system.
 */
-typedef boost::checks::weight<1,3> upc_weight;
-
-/*!
- \brief This is the type of the UPC algorithm.
-*/
-typedef modulus10_algorithm upc_algorithm;
+typedef weight<1,3> upc_weight;
 
 typedef weighted_sum<upc_weight> upc_processor;
 
@@ -60,9 +55,9 @@
 template <typename check_range>
 bool check_upca (const check_range& check_seq)
 {
- return boost::checks::check_sequence<upc_algorithm,
- upc_processor::processor,
- UPCA_SIZE>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return check_sequence<upc_processor::processor,
+ mod10_validation,
+ UPCA_SIZE>(boost::rbegin(check_seq), boost::rend(check_seq));
 }
 
 /*!
@@ -81,8 +76,8 @@
 template <typename check_range>
 std::size_t compute_upca(const check_range& check_seq)
 {
- return boost::checks::compute_checkdigit<upc_algorithm,
- upc_processor::processor,
+ return boost::checks::compute_checkdigit<upc_processor::processor,
+ mod10_checkdigit,
                                            UPCA_SIZE,
                                            basic_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq));
 }

Modified: sandbox/SOC/2011/checks/boost/checks/verhoeff.hpp
==============================================================================
--- sandbox/SOC/2011/checks/boost/checks/verhoeff.hpp (original)
+++ sandbox/SOC/2011/checks/boost/checks/verhoeff.hpp 2012-03-17 06:06:54 EDT (Sat, 17 Mar 2012)
@@ -36,8 +36,6 @@
 
     \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.
 */
-struct verhoeff_algorithm
-{
   /*!
     \brief Validate the Verhoeff checksum.
 
@@ -45,11 +43,13 @@
 
     \returns @c true if the checksum is correct, @c false otherwise.
   */
- static bool validate_checksum(std::size_t checksum)
+struct verhoeff_validation
+{
+ bool operator()(std::size_t checksum)
   {
     return !checksum;
   }
-
+};
   /*!
     \brief Compute the check digit with the Verhoeff inverse table.
 
@@ -60,13 +60,16 @@
 
     \returns The Verhoeff check digit of checksum.
   */
- static std::size_t compute_checkdigit(std::size_t checksum)
+struct verhoeff_checkdigit
+{
+ static const unsigned char inv[10];
+
+ std::size_t operator()(std::size_t checksum)
   {
- static const unsigned char inv[] = {0, 4, 3, 2, 1, 5, 6, 7, 8, 9};
-
     return inv[checksum];
   }
 };
+const unsigned char verhoeff_checkdigit::inv[10] = {0, 4, 3, 2, 1, 5, 6, 7, 8, 9};
 
 /*!
   \brief Compute the Verhoeff scheme on the checksum with the current valid value.
@@ -138,8 +141,8 @@
 template <size_t size_expected, typename check_range>
 bool check_verhoeff(const check_range& check_seq)
 {
- return boost::checks::check_sequence<verhoeff_algorithm,
- verhoeff_processor,
+ return boost::checks::check_sequence<verhoeff_processor,
+ verhoeff_validation,
                                        size_expected>(boost::rbegin(check_seq), boost::rend(check_seq));
 }
 
@@ -158,8 +161,8 @@
 template <typename check_range>
 bool check_verhoeff(const check_range& check_seq)
 {
- return boost::checks::check_sequence<verhoeff_algorithm,
- verhoeff_processor>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return boost::checks::check_sequence<verhoeff_processor,
+ verhoeff_validation>(boost::rbegin(check_seq), boost::rend(check_seq));
 }
 
 /*!
@@ -179,8 +182,8 @@
 template <size_t size_expected, typename check_range>
 std::size_t compute_verhoeff(const check_range& check_seq)
 {
- return compute_checkdigit<verhoeff_algorithm,
- verhoeff_processor,
+ return compute_checkdigit<verhoeff_processor,
+ verhoeff_checkdigit,
                             size_expected,
                             basic_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq));
 }
@@ -201,8 +204,8 @@
 template <typename check_range>
 std::size_t compute_verhoeff(const check_range& check_seq)
 {
- return compute_checkdigit<verhoeff_algorithm,
- verhoeff_processor,
+ return compute_checkdigit<verhoeff_processor,
+ verhoeff_checkdigit,
                             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-03-17 06:06:54 EDT (Sat, 17 Mar 2012)
@@ -47,9 +47,7 @@
 template <typename check_range>
 bool check_visa(const check_range& check_seq)
 {
- return check_sequence<luhn_algorithm,
- luhn_processor,
- VISA_SIZE>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return check_luhn<VISA_SIZE>(check_seq);
 }
 
 /*!
@@ -69,10 +67,7 @@
 template <typename check_range>
 std::size_t compute_visa(const check_range& check_seq)
 {
- return compute_checkdigit<luhn_algorithm,
- luhn_processor,
- VISA_SIZE,
- basic_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return compute_luhn<VISA_SIZE>(check_seq);
 }
 
 

Modified: sandbox/SOC/2011/checks/libs/checks/test/test_checks.cpp
==============================================================================
--- sandbox/SOC/2011/checks/libs/checks/test/test_checks.cpp (original)
+++ sandbox/SOC/2011/checks/libs/checks/test/test_checks.cpp 2012-03-17 06:06:54 EDT (Sat, 17 Mar 2012)
@@ -192,14 +192,12 @@
   std::string mod97_10_valid_without_checkdigits = "5100075470611114";
   std::string mod97_10_not_valid_without_checkdigits = "5110075470611114";
 
- std::pair<std::size_t, std::size_t> checkdigits(6, 2);
- std::pair<std::size_t, std::size_t> valid_check_digits = compute_mod97_10(make_prechecksum<digit_prechecksum>(mod97_10_valid_without_checkdigits));
- BOOST_CHECK_EQUAL(valid_check_digits.first, checkdigits.first);
- BOOST_CHECK_EQUAL(valid_check_digits.second, checkdigits.second);
-
- std::pair<std::size_t, std::size_t> invalid_check_digits = compute_mod97_10(make_prechecksum<digit_prechecksum>(mod97_10_not_valid_without_checkdigits));
- BOOST_CHECK_NE(invalid_check_digits.first, checkdigits.first);
- BOOST_CHECK_NE(invalid_check_digits.second, checkdigits.second);
+ std::size_t checkdigits = 62;
+ std::size_t valid_check_digits = compute_mod97_10(make_prechecksum<digit_prechecksum>(mod97_10_valid_without_checkdigits));
+ BOOST_CHECK_EQUAL(valid_check_digits, checkdigits);
+
+ std::size_t invalid_check_digits = compute_mod97_10(make_prechecksum<digit_prechecksum>(mod97_10_not_valid_without_checkdigits));
+ BOOST_CHECK_NE(invalid_check_digits, checkdigits);
 }
 
 BOOST_AUTO_TEST_SUITE_END()


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