Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r77300 - sandbox/SOC/2011/checks/boost/checks
From: pierre.talbot.6114_at_[hidden]
Date: 2012-03-10 21:21:00


Author: trademark
Date: 2012-03-10 21:20:59 EST (Sat, 10 Mar 2012)
New Revision: 77300
URL: http://svn.boost.org/trac/boost/changeset/77300

Log:
Externalisation of the pre-treatment, implemented with transform and filter iterator in prechecksum.hpp. Add usage function make_prechecksum. Adaptation of the test suite.
Text files modified:
   sandbox/SOC/2011/checks/boost/checks/amex.hpp | 2 -
   sandbox/SOC/2011/checks/boost/checks/basic_checks.hpp | 43 ++++++++++++++-------------------------
   sandbox/SOC/2011/checks/boost/checks/ean.hpp | 4 ---
   sandbox/SOC/2011/checks/boost/checks/isbn.hpp | 4 +-
   sandbox/SOC/2011/checks/boost/checks/luhn.hpp | 7 +----
   sandbox/SOC/2011/checks/boost/checks/mastercard.hpp | 2 -
   sandbox/SOC/2011/checks/boost/checks/modulus11.hpp | 7 +----
   sandbox/SOC/2011/checks/boost/checks/modulus97.hpp | 35 ++++++++++++++-----------------
   sandbox/SOC/2011/checks/boost/checks/prechecksum.hpp | 38 ++++++++++++++++++++++++++++++++--
   sandbox/SOC/2011/checks/boost/checks/upc.hpp | 2 -
   sandbox/SOC/2011/checks/boost/checks/verhoeff.hpp | 6 ----
   sandbox/SOC/2011/checks/boost/checks/visa.hpp | 2 -
   12 files changed, 74 insertions(+), 78 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-10 21:20:59 EST (Sat, 10 Mar 2012)
@@ -53,7 +53,6 @@
 {
   return boost::checks::check_sequence<luhn_algorithm,
                                        luhn_processor,
- digit_prechecksum,
                                        AMEX_SIZE>(boost::rbegin(check_seq), boost::rend(check_seq));
 }
 
@@ -76,7 +75,6 @@
 {
   return boost::checks::compute_checkdigit<luhn_algorithm,
                                            luhn_processor,
- digit_prechecksum,
                                            AMEX_SIZE,
                                            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-03-10 21:20:59 EST (Sat, 10 Mar 2012)
@@ -44,7 +44,6 @@
     \returns The checksum of the sequence calculated with algorithm.
   */
 
-// Use bind and boost::ref instead ? But how to deduce type ?
 template <typename Iterator>
 struct deref
 {
@@ -64,7 +63,7 @@
           typename counter_iter>
 std::size_t compute_checksum(seq_iterator seq_begin, seq_iterator seq_end, counter_iter &counter)
 {
- typedef typename processor<deref<counter_iter> > counter_processor;
+ typedef processor<deref<counter_iter> > counter_processor;
   counter_processor process = counter_processor(deref<counter_iter>(counter));
 
   std::size_t checksum = 0;
@@ -82,7 +81,7 @@
           typename counter_iter>
 std::size_t compute_checksum(seq_iterator seq_begin, seq_iterator seq_end, counter_iter &counter)
 {
- typedef typename processor<deref<counter_iter> > counter_processor;
+ typedef processor<deref<counter_iter> > counter_processor;
   counter_processor process = counter_processor(deref<counter_iter>(counter));
   
   std::size_t checksum = 0;
@@ -106,16 +105,14 @@
 */
 template <typename algorithm,
           template <class> class processor,
- typename prechecksum_type,
           typename seq_iterator>
 bool check_sequence(seq_iterator seq_begin, seq_iterator seq_end)
 {
   boost::checks::detail::simple_counter::type counter = boost::checks::detail::simple_counter()();
  
- prechecksum_type prechecksum;
   std::size_t checksum = compute_checksum<algorithm,
- processor>(prechecksum(seq_begin, seq_end),
- prechecksum(seq_end, seq_end),
+ processor>(seq_begin,
+ seq_end,
                                                      counter);
   return algorithm::validate_checksum(checksum);
 }
@@ -136,18 +133,18 @@
 */
 template <typename algorithm,
           template <class> class processor,
- typename prechecksum_type,
+// typename prechecksum_type,
           std::size_t size_expected,
           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()();
   
- prechecksum_type prechecksum;
+ // prechecksum_type prechecksum;
   std::size_t checksum = compute_checksum<algorithm,
                                           processor,
- size_expected>(prechecksum(seq_begin, seq_end),
- prechecksum(seq_end, seq_end),
+ 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);
@@ -169,17 +166,15 @@
 */
 template <typename algorithm,
           template <class> class processor,
- typename prechecksum_type,
           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()();
- prechecksum_type prechecksum;
   std::size_t checksum = compute_checksum<algorithm,
- processor>(prechecksum(seq_begin, seq_end),
- prechecksum(seq_end, seq_end),
+ processor>(seq_begin,
+ seq_end,
                                                      counter);
   return algorithm::compute_checkdigit(checksum);
 }
@@ -200,7 +195,6 @@
 */
 template <typename algorithm,
           template <class> class processor,
- typename prechecksum_type,
           std::size_t size_expected,
           typename checkdigit,
           typename seq_iterator>
@@ -208,11 +202,10 @@
 {
   typedef typename boost::checks::detail::skip_counter<checkdigit::pos, checkdigit::size> counter_type;
   typename counter_type::type counter = counter_type()();
- prechecksum_type prechecksum;
   std::size_t checksum = compute_checksum<algorithm,
                                           processor,
- size_expected>(prechecksum(seq_begin, seq_end),
- prechecksum(seq_end, seq_end),
+ size_expected>(seq_begin,
+ seq_end,
                                                          counter);
   if(checksum != bad_sequence)
     return algorithm::compute_checkdigit(checksum);
@@ -237,17 +230,15 @@
 */
 template <typename algorithm,
           template <class> class processor,
- typename prechecksum_type,
           typename checkdigit,
           typename seq_iterator>
 std::pair<std::size_t, std::size_t> compute_multicheckdigit (seq_iterator seq_begin, seq_iterator seq_end)
 {
   typedef typename boost::checks::detail::skip_counter<checkdigit::pos, checkdigit::size> counter_type;
   typename counter_type::type counter = counter_type()();
- prechecksum_type prechecksum;
   std::size_t checksum = compute_checksum<algorithm,
- processor>(prechecksum(seq_begin, seq_end),
- prechecksum(seq_end, seq_end),
+ processor>(seq_begin,
+ seq_end,
                                                      counter);
   return algorithm::compute_multicheckdigit(checksum);
 }
@@ -270,7 +261,6 @@
 */
 template <typename algorithm,
           template <class> class processor,
- typename prechecksum_type,
           std::size_t size_expected,
           typename checkdigit,
           typename seq_iterator>
@@ -278,11 +268,10 @@
 {
   typedef typename boost::checks::detail::skip_counter<checkdigit::pos, checkdigit::size> counter_type;
   typename counter_type::type counter = counter_type()();
- prechecksum_type prechecksum;
   std::size_t checksum = compute_checksum<algorithm,
                                           processor,
- size_expected>(prechecksum(seq_begin, seq_end),
- prechecksum(seq_end, seq_end),
+ size_expected>(seq_begin,
+ seq_end,
                                                          counter);
   if(checksum != bad_sequence)
     return algorithm::compute_multicheckdigit(checksum);

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-10 21:20:59 EST (Sat, 10 Mar 2012)
@@ -64,7 +64,6 @@
 {
   return boost::checks::check_sequence<ean_algorithm,
                                        ean_processor::processor,
- digit_prechecksum,
                                        EAN13_SIZE> (boost::rbegin(check_seq), boost::rend(check_seq));
 }
 
@@ -86,7 +85,6 @@
 {
   return boost::checks::compute_checkdigit<ean_algorithm,
                                            ean_processor::processor,
- digit_prechecksum,
                                            EAN13_SIZE,
                                            basic_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq));
 }
@@ -108,7 +106,6 @@
 {
   return boost::checks::check_sequence<ean_algorithm,
                                        ean_processor::processor,
- digit_prechecksum,
                                        EAN8_SIZE>(boost::rbegin(check_seq), boost::rend(check_seq));
 }
 
@@ -130,7 +127,6 @@
 {
   return boost::checks::compute_checkdigit<ean_algorithm,
                                            ean_processor::processor,
- digit_prechecksum,
                                            EAN8_SIZE,
                                            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-03-10 21:20:59 EST (Sat, 10 Mar 2012)
@@ -86,7 +86,7 @@
 template <typename check_range>
 bool check_isbn10(const check_range& check_seq)
 {
- return boost::checks::check_modulus11<ISBN10_SIZE>(check_seq);
+ return check_modulus11<ISBN10_SIZE>(check_seq);
 }
 
 /*!
@@ -105,7 +105,7 @@
 template <typename check_range>
 std::size_t compute_isbn10(const check_range& check_seq)
 {
- return boost::checks::compute_modulus11<ISBN10_SIZE>(check_seq);
+ return 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-03-10 21:20:59 EST (Sat, 10 Mar 2012)
@@ -71,7 +71,6 @@
 {
   return boost::checks::check_sequence<luhn_algorithm,
                                        luhn_processor,
- digit_prechecksum,
                                        size_expected>(boost::rbegin(check_seq), boost::rend(check_seq));
 }
 
@@ -91,8 +90,8 @@
 bool check_luhn (const check_range& check_seq)
 {
   return boost::checks::check_sequence<luhn_algorithm,
- luhn_processor,
- digit_prechecksum>(boost::rbegin(check_seq), boost::rend(check_seq));
+ luhn_processor
+ >(boost::rbegin(check_seq), boost::rend(check_seq));
 }
 
 /*!
@@ -114,7 +113,6 @@
 {
   return boost::checks::compute_checkdigit<luhn_algorithm,
                                            luhn_processor,
- digit_prechecksum,
                                            size_expected,
                                            basic_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq));
 }
@@ -137,7 +135,6 @@
 {
   return boost::checks::compute_checkdigit<luhn_algorithm,
                                            luhn_processor,
- digit_prechecksum,
                                            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-10 21:20:59 EST (Sat, 10 Mar 2012)
@@ -49,7 +49,6 @@
 {
   return check_sequence<luhn_algorithm,
                         luhn_processor,
- digit_prechecksum,
                         MASTERCARD_SIZE>(boost::rbegin(check_seq), boost::rend(check_seq));
 }
 
@@ -72,7 +71,6 @@
 {
   return compute_checkdigit<luhn_algorithm,
                             luhn_processor,
- digit_prechecksum,
                             MASTERCARD_SIZE,
                             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-03-10 21:20:59 EST (Sat, 10 Mar 2012)
@@ -97,7 +97,6 @@
 {
   return boost::checks::check_sequence<mod11_algorithm,
                                        mod11_processor::processor,
- digitx_prechecksum,
                                        size_expected>(boost::rbegin(check_seq), boost::rend(check_seq));
 }
 
@@ -117,8 +116,8 @@
 bool check_modulus11(const check_range& check_seq)
 {
   return boost::checks::check_sequence<mod11_algorithm,
- mod11_processor::processor,
- digitx_prechecksum>(boost::rbegin(check_seq), boost::rend(check_seq));
+ mod11_processor::processor
+ >(boost::rbegin(check_seq), boost::rend(check_seq));
 }
 
 /*!
@@ -140,7 +139,6 @@
 {
   return compute_checkdigit<mod11_algorithm,
                             mod11_processor::processor,
- digitx_prechecksum,
                             size_expected,
                             basic_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq));
 }
@@ -163,7 +161,6 @@
 {
   return compute_checkdigit<mod11_algorithm,
                             mod11_processor::processor,
- digitx_prechecksum,
                             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-10 21:20:59 EST (Sat, 10 Mar 2012)
@@ -60,7 +60,7 @@
     \param checksum is the checksum used to extract the check digit.
     \param checkdigits is the output iterator in which the two check digits will be written.
 
- \throws boost::checks::translation_exception if the check digits cannot be translated into the check digits_iter type.
+ \throws translation_exception if the check digits cannot be translated into the check digits_iter type.
 
     \returns An iterator initialized at one pass to the end of the two check digits.
   */
@@ -155,10 +155,9 @@
 template <size_t size_expected, typename check_range>
 bool check_mod97_10 (const check_range& check_seq)
 {
- return boost::checks::check_sequence<mod97_10_algorithm,
- mod97_10_processor::processor,
- digit_prechecksum,
- size_expected>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return check_sequence<mod97_10_algorithm,
+ mod97_10_processor::processor,
+ size_expected>(boost::rbegin(check_seq), boost::rend(check_seq));
 }
 
 /*!
@@ -176,9 +175,9 @@
 template <typename check_range>
 bool check_mod97_10(const check_range& check_seq)
 {
- return boost::checks::check_sequence<mod97_10_algorithm,
- mod97_10_processor::processor,
- digit_prechecksum>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return check_sequence<mod97_10_algorithm,
+ mod97_10_processor::processor
+ >(boost::rbegin(check_seq), boost::rend(check_seq));
 }
 
 /*!
@@ -193,18 +192,17 @@
     \param mod97_checkdigits is the OutputIterator in which the two check digits will be stored.
 
     \throws std::invalid_argument if check_seq doesn't contain size_expected valid values.
- \throws boost::checks::translation_exception if the check digits cannot be translated into the checkdigits_iter type.
+ \throws translation_exception if the check digits cannot be translated into the checkdigits_iter type.
 
     \returns The check digits are stored into mod97_checkdigits. The range of these is [0..9][0..9].
 */
 template <size_t size_expected, typename check_range>
 std::pair<std::size_t, std::size_t> compute_mod97_10(const check_range& check_seq)
 {
- return boost::checks::compute_multicheckdigit<mod97_10_algorithm,
- mod97_10_processor::processor,
- digit_prechecksum,
- mod97_10_checkdigit,
- size_expected>(boost::rbegin(check_seq), boost::rend(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));
 }
 
 /*!
@@ -218,17 +216,16 @@
     \param mod97_checkdigits is the OutputIterator in which the two check digits will be stored.
 
     \throws std::invalid_argument if check_seq contains no valid value.
- \throws boost::checks::translation_exception if the check digits cannot be translated into the checkdigits_iter type.
+ \throws translation_exception if the check digits cannot be translated into the checkdigits_iter type.
 
     \returns The check digits are stored into mod97_checkdigits. The range of these is [0..9][0..9].
 */
 template <typename check_range>
 std::pair<std::size_t, std::size_t> compute_mod97_10(const check_range& check_seq)
 {
- return boost::checks::compute_multicheckdigit<mod97_10_algorithm,
- mod97_10_processor::processor,
- digit_prechecksum,
- mod97_10_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq));
+ return compute_multicheckdigit<mod97_10_algorithm,
+ mod97_10_processor::processor,
+ mod97_10_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq));
 }
 
 

Modified: sandbox/SOC/2011/checks/boost/checks/prechecksum.hpp
==============================================================================
--- sandbox/SOC/2011/checks/boost/checks/prechecksum.hpp (original)
+++ sandbox/SOC/2011/checks/boost/checks/prechecksum.hpp 2012-03-10 21:20:59 EST (Sat, 10 Mar 2012)
@@ -9,19 +9,51 @@
     \brief
 */
 
-#ifndef BOOST_PRECHECKSUM_HPP
-#define BOOST_PRECHECKSUM_HPP
+#ifndef BOOST_CHECK_PRECHECKSUM_HPP
+#define BOOST_CHECK_PRECHECKSUM_HPP
 
 #ifdef _MSC_VER
     #pragma once
 #endif
 
+#include <utility>
+#include <boost/range.hpp>
 #include <boost/iterator/filter_iterator.hpp>
 #include <boost/iterator/transform_iterator.hpp>
 
 namespace boost {
   namespace checks{
 
+template <
+ typename Prechecksum,
+ typename Iterator
+ >
+std::pair
+<
+ typename Prechecksum::template iterator<Iterator>::type,
+ typename Prechecksum::template iterator<Iterator>::type
+>
+make_prechecksum(Iterator begin, Iterator end)
+{
+ typedef typename Prechecksum::template iterator<Iterator>::type iter;
+ Prechecksum prechecksum;
+ return std::make_pair<iter, iter>(prechecksum(begin, end), prechecksum(end, end));
+}
+
+template <
+ typename Prechecksum,
+ typename T
+ >
+std::pair
+<
+ typename Prechecksum::template iterator<typename range_iterator<T>::type>::type,
+ typename Prechecksum::template iterator<typename range_iterator<T>::type>::type
+>
+make_prechecksum(T &sequence)
+{
+ return make_prechecksum<Prechecksum>(boost::begin(sequence), boost::end(sequence));
+}
+
 struct no_filter_tag {};
 struct no_conversion_tag {};
 
@@ -96,4 +128,4 @@
 } // namespace checks
 } // namespace boost
 
-#endif // BOOST_PRECHECKSUM_HPP
+#endif // BOOST_CHECK_PRECHECKSUM_HPP

Modified: sandbox/SOC/2011/checks/boost/checks/upc.hpp
==============================================================================
--- sandbox/SOC/2011/checks/boost/checks/upc.hpp (original)
+++ sandbox/SOC/2011/checks/boost/checks/upc.hpp 2012-03-10 21:20:59 EST (Sat, 10 Mar 2012)
@@ -62,7 +62,6 @@
 {
   return boost::checks::check_sequence<upc_algorithm,
                                        upc_processor::processor,
- digit_prechecksum,
                                        UPCA_SIZE>(boost::rbegin(check_seq), boost::rend(check_seq));
 }
 
@@ -84,7 +83,6 @@
 {
   return boost::checks::compute_checkdigit<upc_algorithm,
                                            upc_processor::processor,
- digit_prechecksum,
                                            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-10 21:20:59 EST (Sat, 10 Mar 2012)
@@ -140,7 +140,6 @@
 {
   return boost::checks::check_sequence<verhoeff_algorithm,
                                        verhoeff_processor,
- digit_prechecksum,
                                        size_expected>(boost::rbegin(check_seq), boost::rend(check_seq));
 }
 
@@ -160,8 +159,7 @@
 bool check_verhoeff(const check_range& check_seq)
 {
   return boost::checks::check_sequence<verhoeff_algorithm,
- verhoeff_processor,
- digit_prechecksum >(boost::rbegin(check_seq), boost::rend(check_seq));
+ verhoeff_processor>(boost::rbegin(check_seq), boost::rend(check_seq));
 }
 
 /*!
@@ -183,7 +181,6 @@
 {
   return compute_checkdigit<verhoeff_algorithm,
                             verhoeff_processor,
- digit_prechecksum,
                             size_expected,
                             basic_checkdigit>(boost::rbegin(check_seq), boost::rend(check_seq));
 }
@@ -206,7 +203,6 @@
 {
   return compute_checkdigit<verhoeff_algorithm,
                             verhoeff_processor,
- digit_prechecksum,
                             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-10 21:20:59 EST (Sat, 10 Mar 2012)
@@ -49,7 +49,6 @@
 {
   return check_sequence<luhn_algorithm,
                         luhn_processor,
- digit_prechecksum,
                         VISA_SIZE>(boost::rbegin(check_seq), boost::rend(check_seq));
 }
 
@@ -72,7 +71,6 @@
 {
   return compute_checkdigit<luhn_algorithm,
                             luhn_processor,
- digit_prechecksum,
                             VISA_SIZE,
                             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