$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r76574 - sandbox/SOC/2011/checks/boost/checks
From: pierre.talbot.6114_at_[hidden]
Date: 2012-01-18 08:32:27
Author: trademark
Date: 2012-01-18 08:32:25 EST (Wed, 18 Jan 2012)
New Revision: 76574
URL: http://svn.boost.org/trac/boost/changeset/76574
Log:
Translation only depend on the value, not anymore on the position (responsability left to the function filter_value_with_pos). Correct inclusion error of iteration_sense.hpp
Text files modified: 
   sandbox/SOC/2011/checks/boost/checks/amex.hpp                  |     1 +                                       
   sandbox/SOC/2011/checks/boost/checks/basic_check_algorithm.hpp |    15 +++++++--------                         
   sandbox/SOC/2011/checks/boost/checks/basic_checks.hpp          |     7 ++++---                                 
   sandbox/SOC/2011/checks/boost/checks/ean.hpp                   |     1 +                                       
   sandbox/SOC/2011/checks/boost/checks/isbn.hpp                  |     1 +                                       
   sandbox/SOC/2011/checks/boost/checks/luhn.hpp                  |     1 +                                       
   sandbox/SOC/2011/checks/boost/checks/mastercard.hpp            |     5 +++--                                   
   sandbox/SOC/2011/checks/boost/checks/modulus11.hpp             |    20 ++++++++++++--------                    
   sandbox/SOC/2011/checks/boost/checks/upc.hpp                   |     7 ++++---                                 
   sandbox/SOC/2011/checks/boost/checks/verhoeff.hpp              |     8 ++++----                                
   sandbox/SOC/2011/checks/boost/checks/visa.hpp                  |     5 +++--                                   
   11 files changed, 41 insertions(+), 30 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-01-18 08:32:25 EST (Wed, 18 Jan 2012)
@@ -20,6 +20,7 @@
 
 #include <boost/range/rbegin.hpp>
 #include <boost/range/rend.hpp>
+#include <boost/range/iterator_range.hpp>
 
 /*!
   \brief This macro defines the size of a American Express card number (15).
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-01-18 08:32:25 EST (Wed, 18 Jan 2012)
@@ -21,7 +21,6 @@
 
 #include <boost/lexical_cast.hpp>
 #include <boost/checks/translation_exception.hpp>
-#include <boost/checks/iteration_sense.hpp>
 
 namespace boost{
   namespace checks{
@@ -47,17 +46,17 @@
     \returns the translation of the current value in the range [0..9].
 */
   template <typename value>
-  static int translate_to_valid_value(const value ¤t_value, const unsigned int valid_value_counter)
+  static int translate_to_valid_value(const value ¤t_value)
   {
     int valid_value = 0;
     try{
-      valid_value = boost::lexical_cast<int>( current_value ) ;
-      if( valid_value > 9)
-        throw boost::checks::translation_exception() ;
-    }catch( boost::bad_lexical_cast ){
-      throw boost::checks::translation_exception() ;
+      valid_value = boost::lexical_cast<int>(current_value);
+      if(valid_value > 9)
+        throw boost::checks::translation_exception();
+    }catch(boost::bad_lexical_cast){
+      throw boost::checks::translation_exception();
     }
-    return valid_value ;
+    return valid_value;
   }
 
   /*!
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-01-18 08:32:25 EST (Wed, 18 Jan 2012)
@@ -44,11 +44,12 @@
   int checksum = 0;
   for(; seq_begin != seq_end && !size_contract::reach_one_past_the_end(valid_value_counter); ++seq_begin)
   {
-    try{
-      int current_valid_value = algorithm::translate_to_valid_value(*seq_begin, valid_value_counter);
+    try
+    {
+      int current_valid_value = algorithm::translate_to_valid_value(*seq_begin);
       algorithm::filter_valid_value_with_pos(current_valid_value, valid_value_counter);
       algorithm::operate_on_valid_value(current_valid_value, valid_value_counter, checksum);
-      ++valid_value_counter ;
+      ++valid_value_counter;
     }
     catch(boost::checks::translation_exception){
     }
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-01-18 08:32:25 EST (Wed, 18 Jan 2012)
@@ -22,6 +22,7 @@
 
 #include <boost/range/rbegin.hpp>
 #include <boost/range/rend.hpp>
+#include <boost/range/iterator_range.hpp>
 
 /*!
   \brief This macro defines the size of an EAN-13 (13).
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-01-18 08:32:25 EST (Wed, 18 Jan 2012)
@@ -23,6 +23,7 @@
 
 #include <boost/range/rbegin.hpp>
 #include <boost/range/rend.hpp>
+#include <boost/range/iterator_range.hpp>
 
 /*!
   \brief This macro defines the size of an ISBN-10.
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-01-18 08:32:25 EST (Wed, 18 Jan 2012)
@@ -20,6 +20,7 @@
 
 #include <boost/range/rbegin.hpp>
 #include <boost/range/rend.hpp>
+#include <boost/range/iterator_range.hpp>
 
 namespace boost {
     namespace checks{
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-01-18 08:32:25 EST (Wed, 18 Jan 2012)
@@ -16,10 +16,11 @@
     #pragma once
 #endif
 
-#include <boost/checks/luhn.hpp>
-
 #include <boost/range/rbegin.hpp>
 #include <boost/range/rend.hpp>
+#include <boost/range/iterator_range.hpp>
+
+#include <boost/checks/luhn.hpp>
 
 /*!
   \brief This macro defines the size of a Mastercard number.
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-01-18 08:32:25 EST (Wed, 18 Jan 2012)
@@ -16,16 +16,15 @@
     #pragma once
 #endif
 
+#include <boost/range/rbegin.hpp>
+#include <boost/range/rend.hpp>
+#include <boost/range/iterator_range.hpp>
 #include <boost/lexical_cast.hpp>
 #include <boost/checks/translation_exception.hpp>
 #include <boost/checks/weight.hpp>
 #include <boost/checks/basic_checks.hpp>
 #include <boost/checks/weighted_sum.hpp>
 
-#include <boost/range/rbegin.hpp>
-#include <boost/range/rend.hpp>
-
-
 namespace boost{
   namespace checks{
 
@@ -54,7 +53,7 @@
     \returns the translation of the current value in the range [0..10].
 */
   template <typename value>
-  static int translate_to_valid_value(const value ¤t_value, unsigned int valid_value_counter)
+  static int translate_to_valid_value(const value ¤t_value)
   {
     int valid_value = 0;
     try
@@ -63,15 +62,20 @@
     }
     catch(boost::bad_lexical_cast)
     {
-      if((valid_value_counter + number_of_virtual_value_skipped == 1)&&(current_value == 'x' || current_value == 'X'))
+      if(current_value == 'x' || current_value == 'X')
         valid_value = 10;
       else
         throw boost::checks::translation_exception();
     }
-    if(valid_value > 10 ||(valid_value == 10 &&(valid_value_counter + number_of_virtual_value_skipped == 1)))
-      throw boost::checks::translation_exception();
     return valid_value;
   }
+/* pre: value must be valid */
+  static void filter_valid_value_with_pos(unsigned int value, unsigned int value_position)
+  {
+    // Must be the last digit if the value == 10. (reverse traversal).
+    if(value > 10 || (value == 10 && (value_position + number_of_virtual_value_skipped > 0)))
+      throw std::invalid_argument("The character X must be the last");
+  }
 
   /*!
     \brief Validate a checksum with a simple modulus 11.
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-01-18 08:32:25 EST (Wed, 18 Jan 2012)
@@ -16,13 +16,14 @@
     #pragma once
 #endif
 
+#include <boost/range/rbegin.hpp>
+#include <boost/range/rend.hpp>
+#include <boost/range/iterator_range.hpp>
+
 #include <boost/checks/weight.hpp>
 #include <boost/checks/basic_checks.hpp>
 #include <boost/checks/modulus10.hpp>
 
-#include <boost/range/rbegin.hpp>
-#include <boost/range/rend.hpp>
-
 /*!
   \brief This macro defines the size of an UPC-A.
 */
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-01-18 08:32:25 EST (Wed, 18 Jan 2012)
@@ -17,15 +17,15 @@
     #pragma once
 #endif
 
-#include <boost/lexical_cast.hpp>
+#include <boost/range/rbegin.hpp>
+#include <boost/range/rend.hpp>
+#include <boost/range/iterator_range.hpp>
+
 #include <boost/checks/translation_exception.hpp>
 #include <boost/checks/weight.hpp>
 #include <boost/checks/basic_checks.hpp>
 #include <boost/checks/basic_check_algorithm.hpp>
 
-#include <boost/range/rbegin.hpp>
-#include <boost/range/rend.hpp>
-
 namespace boost {
     namespace checks{
 
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-01-18 08:32:25 EST (Wed, 18 Jan 2012)
@@ -16,10 +16,11 @@
     #pragma once
 #endif
 
-#include <boost/checks/luhn.hpp>
-
 #include <boost/range/rbegin.hpp>
 #include <boost/range/rend.hpp>
+#include <boost/range/iterator_range.hpp>
+
+#include <boost/checks/luhn.hpp>
 
 /*!
   \brief This macro defines the size of a Visa number.