Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r76601 - in sandbox/SOC/2011/checks: boost/checks libs/checks/example
From: pierre.talbot.6114_at_[hidden]
Date: 2012-01-20 19:06:51


Author: trademark
Date: 2012-01-20 19:06:49 EST (Fri, 20 Jan 2012)
New Revision: 76601
URL: http://svn.boost.org/trac/boost/changeset/76601

Log:
Remove lexical_cast responsibility, prepare to extract and separate the different part of the core algorithm.
Text files modified:
   sandbox/SOC/2011/checks/boost/checks/amex.hpp | 10 +++---
   sandbox/SOC/2011/checks/boost/checks/basic_check_algorithm.hpp | 24 ++++++----------
   sandbox/SOC/2011/checks/boost/checks/basic_checks.hpp | 32 +++++++++++++++++-----
   sandbox/SOC/2011/checks/boost/checks/ean.hpp | 6 ++--
   sandbox/SOC/2011/checks/boost/checks/isbn.hpp | 20 +++++++-------
   sandbox/SOC/2011/checks/boost/checks/luhn.hpp | 8 ++--
   sandbox/SOC/2011/checks/boost/checks/mastercard.hpp | 10 +++---
   sandbox/SOC/2011/checks/boost/checks/modulus10.hpp | 13 ++------
   sandbox/SOC/2011/checks/boost/checks/modulus11.hpp | 56 +++++++++++++++------------------------
   sandbox/SOC/2011/checks/boost/checks/modulus97.hpp | 6 ++--
   sandbox/SOC/2011/checks/boost/checks/upc.hpp | 6 ++--
   sandbox/SOC/2011/checks/boost/checks/verhoeff.hpp | 8 ++--
   sandbox/SOC/2011/checks/boost/checks/visa.hpp | 10 +++---
   sandbox/SOC/2011/checks/boost/checks/weighted_sum.hpp | 8 ++--
   sandbox/SOC/2011/checks/libs/checks/example/vin.hpp | 15 ++++++++--
   15 files changed, 118 insertions(+), 114 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-20 19:06:49 EST (Fri, 20 Jan 2012)
@@ -37,10 +37,10 @@
 /*! \class amex_algorithm
     \brief This class can be used to compute or validate checksum with the Luhn algorithm, but filter following the Amex pattern.
 
- \tparam number_of_virtual_value_skipped Help functions to provide same behavior on sequence with and without check digits. No "real" value in the sequence will be skipped.
+ \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 <unsigned int number_of_virtual_value_skipped = 0>
-struct amex_algorithm : boost::checks::luhn_algorithm <number_of_virtual_value_skipped>
+template <std::size_t checkdigit_size = 0>
+struct amex_algorithm : boost::checks::luhn_algorithm <checkdigit_size>
 {
   /*!
     \brief Verify that a number matches the Amex pattern.
@@ -52,9 +52,9 @@
 
     \remarks This function use the macro AMEX_SIZE to find the real position from left to right.
   */
- static void filter_valid_value_with_pos(const unsigned int current_valid_value, const unsigned int current_value_position)
+ static void filter_valid_value_with_pos(unsigned int current_valid_value, unsigned int current_value_position)
   {
- const unsigned int real_pos_from_left = AMEX_SIZE - current_value_position - number_of_virtual_value_skipped;
+ const unsigned int real_pos_from_left = AMEX_SIZE - current_value_position - checkdigit_size;
 
     if(real_pos_from_left == 1 && current_valid_value != 3)
       throw std::invalid_argument("The Major Industry Identifier of an American Express should be 3!");

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-20 19:06:49 EST (Fri, 20 Jan 2012)
@@ -18,7 +18,7 @@
     #pragma once
 #endif
 
-
+#include <cstddef> // std::size_t
 #include <boost/lexical_cast.hpp>
 #include <boost/checks/translation_exception.hpp>
 
@@ -29,9 +29,9 @@
     \brief The main check algorithm class that provides every static function that can be overloaded.\n Most of the functions must be re-implemented to have the desired behavior.
 
     \tparam traversal_direction must meet the iterator_direction concept requirements.
- \tparam number_of_virtual_value_skipped Helper functions to provide the same behavior on sequence with and without checkdigits. No "real" value in the sequence will be skipped.
+ \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 <unsigned int number_of_virtual_value_skipped = 0>
+template <std::size_t checkdigit_size = 0>
 struct basic_check_algorithm
 {
   /*!
@@ -45,18 +45,12 @@
 
     \returns the translation of the current value in the range [0..9].
 */
- template <typename value>
- static int translate_to_valid_value(const value &current_value)
+ template <typename value_type>
+ static int translate_to_valid_value(const value_type &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){
+ if(value > 9)
       throw boost::checks::translation_exception();
- }
- return valid_value;
+ return value;
   }
 
   /*!
@@ -120,7 +114,7 @@
 
     \remarks This function should be overloaded if you want to calculate the checksum of a sequence.
   */
- static void operate_on_valid_value(const int current_valid_value, const unsigned int valid_value_counter, int &checksum)
+ static void operate_on_valid_value(int current_valid_value, unsigned int valid_value_counter, int &checksum)
   {
   }
 
@@ -134,7 +128,7 @@
 
     \remarks This function should be overloaded if you want to filter the values with their positions.
   */
- static void filter_valid_value_with_pos(const unsigned int current_valid_value, const unsigned int current_value_position)
+ static void filter_valid_value_with_pos(unsigned int current_valid_value, unsigned int current_value_position)
   {
   }
 };

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-20 19:06:49 EST (Fri, 20 Jan 2012)
@@ -16,12 +16,29 @@
     #pragma once
 #endif
 
+#include <boost/checks/translation_exception.hpp>
 #include <boost/lexical_cast.hpp>
 #include <boost/checks/limits.hpp>
 
 namespace boost {
   namespace checks{
 
+
+namespace detail
+{
+ template <typename value_type>
+ int lexical_cast(value_type x)
+ {
+ // If it's a character, transform digit to int (for example: '1' to 1).
+ try
+ {
+ return boost::lexical_cast<int>(x);
+ }
+ catch(boost::bad_lexical_cast){}
+ return static_cast<int>(x);
+ }
+}
+
 /*!
     \brief Run through a sequence and calculate the checksum with the algorithm policy class.
 
@@ -40,21 +57,22 @@
 template <typename algorithm, typename size_contract, typename seq_iterator>
 int compute_checksum(seq_iterator seq_begin, seq_iterator seq_end)
 {
- unsigned int valid_value_counter = 0;
+ unsigned int value_counter = 0;
   int checksum = 0;
- for(; seq_begin != seq_end && !size_contract::reach_one_past_the_end(valid_value_counter); ++seq_begin)
+ for(; seq_begin != seq_end && !size_contract::reach_one_past_the_end(value_counter); ++seq_begin)
   {
     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;
+ int value = boost::checks::detail::lexical_cast(*seq_begin);
+ value = algorithm::translate_to_valid_value(value);
+ algorithm::filter_valid_value_with_pos(value, value_counter);
+ algorithm::operate_on_valid_value(value, value_counter, checksum);
+ ++value_counter;
     }
     catch(boost::checks::translation_exception){
     }
   }
- size_contract::respect_size_contract(valid_value_counter);
+ size_contract::respect_size_contract(value_counter);
   return 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-01-20 19:06:49 EST (Fri, 20 Jan 2012)
@@ -52,11 +52,11 @@
 /*!
   \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;
+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.
 */
-typedef boost::checks::modulus10_algorithm<ean_weight, 1>ean_compute_algorithm;
+typedef boost::checks::modulus10_algorithm<ean_weight, 1> ean_compute_algorithm;
 
 /*!
     \brief Validate a sequence according to the ean_check_algorithm type.
@@ -73,7 +73,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_check_algorithm, EAN13_SIZE> (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-01-20 19:06:49 EST (Fri, 20 Jan 2012)
@@ -40,30 +40,30 @@
 /*! \class isbn13_algorithm
     \brief This class can be used to compute or validate checksum with a basic modulus 10 but using a custom filter for the ISBN-13 prefix.
 
- \tparam number_of_virtual_value_skipped Help functions to provide same behavior on sequence with and without check digits. No "real" value in the sequence will be skipped.
+ \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 <unsigned int number_of_virtual_value_skipped = 0>
-struct isbn13_algorithm : boost::checks::modulus10_algorithm<boost::checks::ean_weight, number_of_virtual_value_skipped>
+template <std::size_t checkdigit_size = 0>
+struct isbn13_algorithm : boost::checks::modulus10_algorithm<boost::checks::ean_weight, checkdigit_size>
 {
   /*!
     \brief Verify that a number matches the ISBN-13 pattern.
 
- \param current_valid_value is the current valid value analysed.
- \param current_value_position 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 value is the current valid value analysed.
+ \param value_position 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).
 
     \throws std::invalid_argument if the three first character are not equal to 978 or 979. The exception contains a descriptive message of what was expected.
 
     \remarks This function use the macro EAN13_SIZE to find the real position from left to right.
   */
- static void filter_valid_value_with_pos(const unsigned int current_valid_value, const unsigned int current_value_position )
+ static void filter_valid_value_with_pos(unsigned int value, unsigned int value_position)
   {
- const unsigned int real_pos_from_left = EAN13_SIZE - current_value_position - number_of_virtual_value_skipped;
+ unsigned int real_pos_from_left = EAN13_SIZE - value_position - checkdigit_size;
 
- if( real_pos_from_left == 1 && current_valid_value != 9)
+ if(real_pos_from_left == 1 && value != 9)
       throw std::invalid_argument("The first digit should be 9!");
- else if( real_pos_from_left == 2 && current_valid_value != 7)
+ else if(real_pos_from_left == 2 && value != 7)
       throw std::invalid_argument("The second digit should be 7!");
- else if( real_pos_from_left == 3 && current_valid_value != 8 && current_valid_value != 9)
+ else if(real_pos_from_left == 3 && value != 8 && value != 9)
       throw std::invalid_argument("The third digit should be 8 or 9!");
   }
 };

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-20 19:06:49 EST (Fri, 20 Jan 2012)
@@ -33,10 +33,10 @@
 /*! \class luhn_algorithm
     \brief This class can be used to compute or validate checksum with the Luhn algorithm.
 
- \tparam number_of_virtual_value_skipped Help functions to provide same behavior on sequence with and without check digits. No "real" value in the sequence will be skipped.
+ \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 <unsigned int number_of_virtual_value_skipped = 0>
-struct luhn_algorithm : boost::checks::modulus10_algorithm <luhn_weight, number_of_virtual_value_skipped>
+template <std::size_t checkdigit_size = 0>
+struct luhn_algorithm : boost::checks::modulus10_algorithm <luhn_weight, checkdigit_size>
 {
   /*!
     \brief Compute the Luhn algorithm operation on the checksum.
@@ -51,7 +51,7 @@
   */
   static void operate_on_valid_value(const int current_valid_value, const unsigned int valid_value_counter, int &checksum)
   {
- int current_weight = luhn_weight::weight_associated_with_pos(valid_value_counter + number_of_virtual_value_skipped);
+ int current_weight = luhn_weight::weight_associated_with_pos(valid_value_counter + checkdigit_size);
     int weighted_value = current_valid_value << (current_weight-1);
     checksum += weighted_value % 10 + weighted_value / 10;
   }

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-20 19:06:49 EST (Fri, 20 Jan 2012)
@@ -37,10 +37,10 @@
 /*! \class mastercard_algorithm
     \brief This class can be used to compute or validate checksum with the Luhn algorithm, but filter following the Mastercard pattern.
 
- \tparam number_of_virtual_value_skipped Help functions to provide same behavior on sequence with and without check digits. No "real" value in the sequence will be skipped.
+ \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 <unsigned int number_of_virtual_value_skipped = 0>
-struct mastercard_algorithm : boost::checks::luhn_algorithm <number_of_virtual_value_skipped>
+template <std::size_t checkdigit_size = 0>
+struct mastercard_algorithm : boost::checks::luhn_algorithm <checkdigit_size>
 {
   /*!
     \brief Verify that a number matches the Mastercard pattern.
@@ -54,11 +54,11 @@
   */
   static void filter_valid_value_with_pos(const unsigned int current_valid_value, const unsigned int current_value_position)
   {
- const unsigned int real_pos_from_left = MASTERCARD_SIZE - current_value_position - number_of_virtual_value_skipped;
+ const unsigned int real_pos_from_left = MASTERCARD_SIZE - current_value_position - checkdigit_size;
 
     if(real_pos_from_left == 1 && current_valid_value != 5)
       throw std::invalid_argument("The Major Industry Identifier of a Mastercard should be 5!");
- else if(real_pos_from_left == 2 &&(current_valid_value == 0 || current_valid_value > 5))
+ else if(real_pos_from_left == 2 && (current_valid_value == 0 || current_valid_value > 5))
       throw std::invalid_argument("The Issuer Identification Number of an Mastercard should be between 51 and 55!");
   }
 };

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-01-20 19:06:49 EST (Fri, 20 Jan 2012)
@@ -17,7 +17,6 @@
 #endif
 
 #include <boost/lexical_cast.hpp>
-#include <boost/checks/translation_exception.hpp>
 #include <boost/checks/weighted_sum.hpp>
 
 namespace boost{
@@ -28,10 +27,10 @@
 
     \tparam mod10_weight must meet the weight concept requirements.
     \tparam iteration_sense must meet the iteration_sense concept requirements.
- \tparam number_of_virtual_value_skipped Help functions to provide same behavior on sequence with and without check digits. No "real" value in the sequence will be skipped.
+ \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, unsigned int number_of_virtual_value_skipped = 0>
-struct modulus10_algorithm : boost::checks::weighted_sum_algorithm<mod10_weight, number_of_virtual_value_skipped>
+template <typename mod10_weight, std::size_t checkdigit_size = 0>
+struct modulus10_algorithm : boost::checks::weighted_sum_algorithm<mod10_weight, checkdigit_size>
 {
   /*!
     \brief Validate a checksum with a simple modulus 10.
@@ -58,11 +57,7 @@
   template <typename checkdigit>
   static checkdigit compute_checkdigit(int checksum)
   {
- try{
- return boost::lexical_cast<checkdigit>((10 - checksum % 10) % 10);
- }catch(boost::bad_lexical_cast){
- throw boost::checks::translation_exception();
- }
+ return boost::lexical_cast<checkdigit>((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-01-20 19:06:49 EST (Fri, 20 Jan 2012)
@@ -33,12 +33,12 @@
 
     \tparam mod11_weight must meet the weight concept requirements.
     \tparam iteration_sense must meet the iteration_sense concept requirements.
- \tparam number_of_virtual_value_skipped Help functions to provide same behavior on sequence with and without check digits. No "real" value in the sequence will be skipped.
+ \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.
 
     \remarks The range of the check digit is [0..10], the tenth element is translated as the letter 'X'.
 */
-template <typename mod11_weight, unsigned int number_of_virtual_value_skipped = 0>
-struct modulus11_algorithm : boost::checks::weighted_sum_algorithm<mod11_weight, number_of_virtual_value_skipped>
+template <typename mod11_weight, std::size_t checkdigit_size = 0>
+struct modulus11_algorithm : boost::checks::weighted_sum_algorithm<mod11_weight, checkdigit_size>
 {
 
   /*!
@@ -52,29 +52,29 @@
 
     \returns the translation of the current value in the range [0..10].
 */
- template <typename value>
- static int translate_to_valid_value(const value &current_value)
+ template <typename value_type>
+ static int translate_to_valid_value(const value_type &value)
   {
- int valid_value = 0;
- try
- {
- valid_value = boost::lexical_cast<int>(current_value);
- }
- catch(boost::bad_lexical_cast)
- {
- if(current_value == 'x' || current_value == 'X')
- valid_value = 10;
- else
- throw boost::checks::translation_exception();
- }
+ int valid_value = value;
+ if(value == 'x' || value == 'X')
+ valid_value = 10;
+ else if(value > 9)
+ 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)))
+ // Must be the first digit if the value == 'X'. (reverse traversal).
+ if(value == 'X' || value == 'x')
+ {
+ if(value_position + checkdigit_size > 0)
+ throw std::invalid_argument("The character X must be the last");
+ }
+ else if(value > 10)
       throw std::invalid_argument("The character X must be the last");
+
   }
 
   /*!
@@ -109,21 +109,9 @@
   template <typename checkdigit>
   static checkdigit translate_checkdigit(int _checkdigit)
   {
- try
- {
- return boost::lexical_cast<checkdigit>(_checkdigit);
- }
- catch(boost::bad_lexical_cast)
- {
- try
- {
- return boost::lexical_cast<checkdigit>('X');
- }
- catch(boost::bad_lexical_cast)
- {
- throw boost::checks::translation_exception();
- }
- }
+ if(_checkdigit == 10)
+ return static_cast<checkdigit>('X');
+ return boost::lexical_cast<checkdigit>(_checkdigit);
   }
 
 };

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-01-20 19:06:49 EST (Fri, 20 Jan 2012)
@@ -33,12 +33,12 @@
 
     \tparam mod97_weight must meet the weight concept requirements.
     \tparam iteration_sense must meet the iteration_sense concept requirements.
- \tparam number_of_virtual_value_skipped Help functions to provide same behavior on sequence with and without check digits. No "real" value in the sequence will be skipped.
+ \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.
 
     \remarks This algorithm use two check digits.
 */
-template <typename mod97_weight, unsigned int number_of_virtual_value_skipped = 0>
-struct modulus97_algorithm : boost::checks::weighted_sum_algorithm<mod97_weight, number_of_virtual_value_skipped>
+template <typename mod97_weight, std::size_t checkdigit_size = 0>
+struct modulus97_algorithm : boost::checks::weighted_sum_algorithm<mod97_weight, checkdigit_size>
 {
   /*!
     \brief Validate a checksum with a simple modulus 97.

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-20 19:06:49 EST (Fri, 20 Jan 2012)
@@ -39,16 +39,16 @@
 /*!
   \brief This is the weight used by UPC system.
 */
-typedef boost::checks::weight<1,3> upc_weight ;
+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 ;
+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.
 */
-typedef boost::checks::modulus10_algorithm< upc_weight, 1> upc_compute_algorithm ;
+typedef boost::checks::modulus10_algorithm< upc_weight, 1> upc_compute_algorithm;
 
 /*!
     \brief Validate a sequence according to the upc_check_algorithm type.

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-20 19:06:49 EST (Fri, 20 Jan 2012)
@@ -32,10 +32,10 @@
 /*! \class verhoeff_algorithm
     \brief This class can be used to compute or validate checksum with the Verhoeff algorithm.
 
- \tparam number_of_virtual_value_skipped Help functions to provide same behavior on sequence with and without check digits. No "real" value in the sequence will be skipped.
+ \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 <unsigned int number_of_virtual_value_skipped = 0>
-struct verhoeff_algorithm : boost::checks::basic_check_algorithm<number_of_virtual_value_skipped>
+template <std::size_t checkdigit_size = 0>
+struct verhoeff_algorithm : boost::checks::basic_check_algorithm<checkdigit_size>
 {
   /*!
     \brief Compute the Verhoeff scheme on the checksum with the current valid value.
@@ -76,7 +76,7 @@
       { 7, 0, 4, 6, 9, 1, 3, 2, 5, 8 }
     };
 
- checksum = d[checksum][p[(valid_value_counter + number_of_virtual_value_skipped)% 8][current_valid_value]];
+ checksum = d[checksum][p[(valid_value_counter + checkdigit_size)% 8][current_valid_value]];
   }
 
   /*!

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-20 19:06:49 EST (Fri, 20 Jan 2012)
@@ -37,10 +37,10 @@
 /*! \class visa_algorithm
     \brief This class can be used to compute or validate checksum with the Luhn algorithm, but filter following the Visa pattern.
 
- \tparam number_of_virtual_value_skipped Helper functions to provide same behavior on a sequence with and without check digits. No "real" value in the sequence will be skipped.
+ \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 <unsigned int number_of_virtual_value_skipped = 0>
-struct visa_algorithm : boost::checks::luhn_algorithm <number_of_virtual_value_skipped>
+template <std::size_t checkdigit_size = 0>
+struct visa_algorithm : boost::checks::luhn_algorithm <checkdigit_size>
 {
   /*!
     \brief Verify that a number matches the Visa pattern.
@@ -52,9 +52,9 @@
 
     \remarks This function use the macro VISA_SIZE to find the real position from left to right.
   */
- static void filter_valid_value_with_pos(const unsigned int current_valid_value, const unsigned int current_value_position)
+ static void filter_valid_value_with_pos(unsigned int current_valid_value, unsigned int current_value_position)
   {
- const unsigned int real_pos_from_left = VISA_SIZE - current_value_position - number_of_virtual_value_skipped;
+ const unsigned int real_pos_from_left = VISA_SIZE - current_value_position - checkdigit_size;
 
     if(real_pos_from_left == 1 && current_valid_value != 4)
       throw std::invalid_argument("The Major Industry Identifier of a VISA credit card should be 4!");

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-01-20 19:06:49 EST (Fri, 20 Jan 2012)
@@ -28,10 +28,10 @@
 
     \tparam weight must meet the weight concept requirements.
     \tparam iteration_sense must meet the iteration_sense concept requirements.
- \tparam number_of_virtual_value_skipped Helper function to provide same behavior on sequence with and without checkdigits. No "real" value in the sequence will be skipped.
+ \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, unsigned int number_of_virtual_value_skipped = 0>
-struct weighted_sum_algorithm : boost::checks::basic_check_algorithm<number_of_virtual_value_skipped>
+template <typename weight, std::size_t checkdigit_size = 0>
+struct weighted_sum_algorithm : boost::checks::basic_check_algorithm<checkdigit_size>
 {
   /*!
     \brief Compute an operation on the checksum with the current valid value.
@@ -44,7 +44,7 @@
   */
   static void operate_on_valid_value(const int current_valid_value, const unsigned int valid_value_counter, int &checksum)
   {
- int current_weight = weight::weight_associated_with_pos(valid_value_counter + number_of_virtual_value_skipped);
+ int current_weight = weight::weight_associated_with_pos(valid_value_counter + checkdigit_size);
     checksum += current_valid_value * current_weight;
   }
 };

Modified: sandbox/SOC/2011/checks/libs/checks/example/vin.hpp
==============================================================================
--- sandbox/SOC/2011/checks/libs/checks/example/vin.hpp (original)
+++ sandbox/SOC/2011/checks/libs/checks/example/vin.hpp 2012-01-20 19:06:49 EST (Fri, 20 Jan 2012)
@@ -36,7 +36,7 @@
 {
   //[vin_translation_module
   template <typename value>
- static int translate_to_valid_value(const value &current_value, unsigned int valid_value_counter)
+ static int translate_to_valid_value(const value &current_value)
   {
     int valid_value = 0;
     try
@@ -54,7 +54,7 @@
         throw boost::checks::translation_exception();
 
       if(valid_value == 9 || valid_value == 15 || valid_value == 17)
- throw std::invalid_argument("The letter I, O and Q are not allowed.");
+ throw std::invalid_argument("The letters I, O and Q are not allowed.");
 
       if(valid_value_counter == VIN_CHECKDIGIT_POS && number_of_virtual_value_skipped == 0)
       {
@@ -65,13 +65,22 @@
         valid_value = 11 - valid_value;
       }
       else
- valid_value = valid_value % 10 + valid_value / 10 +(valid_value > 18);
+ valid_value = valid_value % 10 + valid_value / 10 + (valid_value > 18);
     }
     if(valid_value > 10)
       throw boost::checks::translation_exception();
 
     return valid_value;
   }
+
+ static void filter_valid_value_with_pos(unsigned int current_valid_value, unsigned int current_value_position)
+ {
+ if(valid_value_counter == VIN_CHECKDIGIT_POS && number_of_virtual_value_skipped == 0)
+ {
+ if(valid_value != 24)
+ throw std::invalid_argument("The check digit should be a digit or X or x.");
+ }
+ }
   //]
 
   //[vin_operation_module


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