|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r76572 - in sandbox/SOC/2011/checks: boost/checks libs/checks/example libs/checks/test
From: pierre.talbot.6114_at_[hidden]
Date: 2012-01-18 05:29:26
Author: trademark
Date: 2012-01-18 05:29:22 EST (Wed, 18 Jan 2012)
New Revision: 76572
URL: http://svn.boost.org/trac/boost/changeset/76572
Log:
Remove iteration_sense.hpp (useless indirection).
Removed:
sandbox/SOC/2011/checks/boost/checks/iteration_sense.hpp
Text files modified:
sandbox/SOC/2011/checks/boost/checks/amex.hpp | 27 ++-
sandbox/SOC/2011/checks/boost/checks/basic_check_algorithm.hpp | 23 --
sandbox/SOC/2011/checks/boost/checks/basic_checks.hpp | 74 +++------
sandbox/SOC/2011/checks/boost/checks/checks_fwd.hpp | 72 ++++----
sandbox/SOC/2011/checks/boost/checks/ean.hpp | 26 +-
sandbox/SOC/2011/checks/boost/checks/isbn.hpp | 31 ++-
sandbox/SOC/2011/checks/boost/checks/limits.hpp | 12
sandbox/SOC/2011/checks/boost/checks/luhn.hpp | 32 ++--
sandbox/SOC/2011/checks/boost/checks/mastercard.hpp | 39 ++--
sandbox/SOC/2011/checks/boost/checks/modulus10.hpp | 4
sandbox/SOC/2011/checks/boost/checks/modulus11.hpp | 86 +++++-----
sandbox/SOC/2011/checks/boost/checks/modulus97.hpp | 56 +++----
sandbox/SOC/2011/checks/boost/checks/upc.hpp | 18 +-
sandbox/SOC/2011/checks/boost/checks/verhoeff.hpp | 60 +++----
sandbox/SOC/2011/checks/boost/checks/visa.hpp | 37 ++--
sandbox/SOC/2011/checks/boost/checks/weight.hpp | 2
sandbox/SOC/2011/checks/boost/checks/weighted_sum.hpp | 11
sandbox/SOC/2011/checks/libs/checks/example/rtn.hpp | 21 +-
sandbox/SOC/2011/checks/libs/checks/example/vin.hpp | 55 +++---
sandbox/SOC/2011/checks/libs/checks/test/test_checks.cpp | 296 ++++++++++++++++++++--------------------
20 files changed, 465 insertions(+), 517 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 05:29:22 EST (Wed, 18 Jan 2012)
@@ -18,6 +18,9 @@
#include <boost/checks/luhn.hpp>
+#include <boost/range/rbegin.hpp>
+#include <boost/range/rend.hpp>
+
/*!
\brief This macro defines the size of a American Express card number (15).
*/
@@ -36,7 +39,7 @@
\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.
*/
template <unsigned int number_of_virtual_value_skipped = 0>
-struct amex_algorithm : boost::checks::luhn_algorithm < number_of_virtual_value_skipped >
+struct amex_algorithm : boost::checks::luhn_algorithm <number_of_virtual_value_skipped>
{
/*!
\brief Verify that a number matches the Amex pattern.
@@ -48,25 +51,25 @@
\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(const unsigned int current_valid_value, const 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 - number_of_virtual_value_skipped;
- 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!") ;
- else if( real_pos_from_left == 2 && current_valid_value != 4 && current_valid_value != 7 )
- throw std::invalid_argument("The Issuer Identification Number of an American Express should be 34 or 37!" ) ;
+ 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!");
+ else if(real_pos_from_left == 2 && current_valid_value != 4 && current_valid_value != 7)
+ throw std::invalid_argument("The Issuer Identification Number of an American Express should be 34 or 37!");
}
};
/*!
\brief This is the type of the Amex algorithm for validating a check digit.
*/
-typedef amex_algorithm<0> amex_check_algorithm ;
+typedef amex_algorithm<0> amex_check_algorithm;
/*!
\brief This is the type of the Amex algorithm for computing a check digit.
*/
-typedef amex_algorithm<1> amex_compute_algorithm ;
+typedef amex_algorithm<1> amex_compute_algorithm;
/*!
\brief Validate a sequence according to the amex_check_algorithm type.
@@ -84,7 +87,7 @@
template <typename check_range>
bool check_amex (const check_range& check_seq)
{
- return boost::checks::check_sequence<amex_check_algorithm, AMEX_SIZE> ( check_seq ) ;
+ return boost::checks::check_sequence<amex_check_algorithm, AMEX_SIZE>(boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -102,9 +105,9 @@
\returns The check digit. The check digit is in the range [0..9].
*/
template <typename check_range>
-typename boost::checks::amex_compute_algorithm::checkdigit<check_range>::type compute_amex (const check_range& check_seq)
+typename boost::range_value<check_range>::type compute_amex(const check_range& check_seq)
{
- return boost::checks::compute_checkdigit<amex_compute_algorithm, AMEX_SIZE_WITHOUT_CHECKDIGIT> ( check_seq ) ;
+ return boost::checks::compute_checkdigit<amex_compute_algorithm, AMEX_SIZE_WITHOUT_CHECKDIGIT>(boost::rbegin(check_seq), boost::rend(check_seq));
}
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 05:29:22 EST (Wed, 18 Jan 2012)
@@ -32,16 +32,10 @@
\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.
*/
-template <typename traversal_direction, unsigned int number_of_virtual_value_skipped = 0>
+template <unsigned int number_of_virtual_value_skipped = 0>
struct basic_check_algorithm
{
/*!
- \brief This is the sense or direction of the iteration (begins with the right or the leftmost value).
- */
- typedef traversal_direction iterator_direction;
- typedef iterator_direction iteration_sense; // Need to be deleted, just for compatibility...
-
- /*!
\brief translate a value of the sequence into an integer valid value.
\tparam value is the type of a value in the sequence.
@@ -144,21 +138,6 @@
static void filter_valid_value_with_pos(const unsigned int current_valid_value, const unsigned int current_value_position)
{
}
-
- /*!
- \class checkdigit
-
- \brief Template rebinding class used to define the type of the check digit(s) of check_range.
-
- \tparam check_range The type of the sequence to check.
-
- \remarks This function should be overloaded if you want to change the type of the check digit.
- */
- template <typename check_range>
- struct checkdigit
- {
- typedef typename boost::range_value<check_range>::type type;
- };
};
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 05:29:22 EST (Wed, 18 Jan 2012)
@@ -16,9 +16,8 @@
#pragma once
#endif
-#include <boost/checks/limits.hpp>
#include <boost/lexical_cast.hpp>
-
+#include <boost/checks/limits.hpp>
namespace boost {
namespace checks{
@@ -38,8 +37,8 @@
\returns The checksum of the sequence calculated with algorithm.
*/
-template <typename algorithm, typename size_contract, typename iterator>
-int compute_checksum(iterator seq_begin, iterator seq_end)
+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;
int checksum = 0;
@@ -59,31 +58,6 @@
}
/*!
- \brief Create iterators according to the algorithm::iterator policy. And call the iterator overload version of compute_checksum.
-
- \pre check_seq is a valid range.
-
- \tparam algorithm is a set of static methods used to translate, filter and calculate or verify the checkdigit.
- \tparam size_contract is a contract concerning the size of the sequence.
- \tparam check_range is a valid range type.
- \param check_seq is the sequence of value to check.
-
- \throws size_contract::exception_size_failure If the terms of the contract are not respected.
-
- \returns The checksum of the sequence calculated with algorithm.
-*/
-
-template <typename algorithm, typename size_contract, typename check_range>
-int compute_checksum(const check_range &check_seq)
-{
- typedef typename algorithm::iteration_sense::template iterator<check_range>::type iterator;
- iterator begin = algorithm::iteration_sense::begin(check_seq);
- iterator end = algorithm::iteration_sense::end(check_seq);
-
- return compute_checksum<algorithm, size_contract>(begin, end);
-}
-
-/*!
\brief Validate a sequence according to algorithm.
\pre check_seq is a valid range.
@@ -96,10 +70,10 @@
\returns @c true if the checkdigit is correct, @c false otherwise.
*/
-template <typename algorithm, typename check_range>
-bool check_sequence(const check_range& check_seq)
+template <typename algorithm, typename seq_iterator>
+bool check_sequence(seq_iterator seq_begin, seq_iterator seq_end)
{
- int checksum = compute_checksum<algorithm, boost::checks::no_null_size_contract<> >(check_seq);
+ int checksum = compute_checksum<algorithm, boost::checks::no_null_size_contract<> >(seq_begin, seq_end);
return algorithm::validate_checksum(checksum);
}
@@ -117,10 +91,10 @@
\returns @c true if the checkdigit is correct, @c false otherwise.
*/
-template <typename algorithm, size_t size_expected, typename check_range>
-bool check_sequence(const check_range& check_seq)
+template <typename algorithm, size_t size_expected, typename seq_iterator>
+bool check_sequence(seq_iterator seq_begin, seq_iterator seq_end)
{
- int checksum = compute_checksum<algorithm, boost::checks::strict_size_contract<size_expected> >(check_seq);
+ int checksum = compute_checksum<algorithm, boost::checks::strict_size_contract<size_expected> >(seq_begin, seq_end);
return algorithm::validate_checksum(checksum);
}
@@ -137,12 +111,11 @@
\returns The check digit of the type of a value in check_seq.
*/
-template <typename algorithm, typename check_range>
-typename algorithm::template checkdigit<check_range>::type compute_checkdigit(const check_range& check_seq)
+template <typename algorithm, typename seq_iterator>
+typename seq_iterator::value_type compute_checkdigit(seq_iterator seq_begin, seq_iterator seq_end)
{
- typedef typename algorithm::template checkdigit<check_range>::type checkdigit_type;
- int checksum = compute_checksum<algorithm, boost::checks::no_null_size_contract<> >(check_seq);
- return algorithm::template compute_checkdigit<checkdigit_type>(checksum);
+ int checksum = compute_checksum<algorithm, boost::checks::no_null_size_contract<> >(seq_begin, seq_end);
+ return algorithm::template compute_checkdigit<typename seq_iterator::value_type>(checksum);
}
/*!
@@ -159,12 +132,11 @@
\returns The check digit of the type of a value in check_seq.
*/
-template <typename algorithm, size_t size_expected, typename check_range>
-typename algorithm::template checkdigit<check_range>::type compute_checkdigit (const check_range& check_seq)
+template <typename algorithm, size_t size_expected, typename seq_iterator>
+typename seq_iterator::value_type compute_checkdigit(seq_iterator seq_begin, seq_iterator seq_end)
{
- typedef typename algorithm::template checkdigit<check_range>::type checkdigit_type;
- int checksum = compute_checksum<algorithm, boost::checks::strict_size_contract<size_expected> >(check_seq);
- return algorithm::template compute_checkdigit<checkdigit_type>(checksum);
+ int checksum = compute_checksum<algorithm, boost::checks::strict_size_contract<size_expected> >(seq_begin, seq_end);
+ return algorithm::template compute_checkdigit<typename seq_iterator::value_type>(checksum);
}
/*!
@@ -183,10 +155,10 @@
\returns An iterator initialized at one pass the end of checkdigits.
*/
-template <typename algorithm, typename check_range, typename checkdigit_iterator>
-checkdigit_iterator compute_multicheckdigit (const check_range& check_seq, checkdigit_iterator checkdigits)
+template <typename algorithm, typename seq_iterator, typename checkdigit_iterator>
+checkdigit_iterator compute_multicheckdigit (seq_iterator seq_begin, seq_iterator seq_end, checkdigit_iterator checkdigits)
{
- int checksum = compute_checksum<algorithm, boost::checks::no_null_size_contract<> >(check_seq);
+ int checksum = compute_checksum<algorithm, boost::checks::no_null_size_contract<> >(seq_begin, seq_end);
return algorithm::compute_multicheckdigit(checksum, checkdigits);
}
@@ -206,10 +178,10 @@
\returns An iterator initialized at one pass the end of checkdigits.
*/
-template <typename algorithm, size_t size_expected, typename check_range, typename checkdigit_iterator>
-checkdigit_iterator compute_multicheckdigit (const check_range& check_seq, checkdigit_iterator checkdigits)
+template <typename algorithm, size_t size_expected, typename seq_iterator, typename checkdigit_iterator>
+checkdigit_iterator compute_multicheckdigit (seq_iterator seq_begin, seq_iterator seq_end, checkdigit_iterator checkdigits)
{
- int checksum = compute_checksum<algorithm, boost::checks::strict_size_contract<size_expected> >(check_seq) ;
+ int checksum = compute_checksum<algorithm, boost::checks::strict_size_contract<size_expected> >(seq_begin, seq_end);
return algorithm::compute_multicheckdigit(checksum, checkdigits);
}
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-01-18 05:29:22 EST (Wed, 18 Jan 2012)
@@ -1,13 +1,13 @@
// Boost checks/checks_fwd.hpp header file
-// (C) Copyright Pierre Talbot 2011
+// (C)Copyright Pierre Talbot 2011
-// Distributed under the Boost Software License, Version 1.0. (See
+// Distributed under the Boost Software License, Version 1.0.(See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
// See http://www.boost.org for updates, documentation, and revision history.
-// Provides a (perhaps temporary) mainpage for standalone Doxygen.
+// Provides a(perhaps temporary)mainpage for standalone Doxygen.
// This seems a convenient place to put this, but it could go somewhere else?
/*!
@@ -75,119 +75,119 @@
// Luhn
template <size_t size_expected, typename check_range>
-bool check_luhn (const check_range& check_seq) ;
+bool check_luhn(const check_range& check_seq);
template <typename check_range>
-bool check_luhn (const check_range& check_seq) ;
+bool check_luhn(const check_range& check_seq);
template <size_t size_expected, typename check_range>
-typename boost::checks::luhn_compute_algorithm::checkdigit<check_range>::type compute_luhn (const check_range& check_seq) ;
+typename boost::range_value<check_range>::type compute_luhn(const check_range& check_seq);
template <typename check_range>
-typename boost::checks::luhn_compute_algorithm::checkdigit<check_range>::type compute_luhn (const check_range& check_seq) ;
+typename boost::range_value<check_range>::type compute_luhn(const check_range& check_seq);
// Verhoeff
template <size_t size_expected, typename check_range>
-bool check_verhoeff (const check_range& check_seq) ;
+bool check_verhoeff(const check_range& check_seq);
template <typename check_range>
-bool check_verhoeff (const check_range& check_seq) ;
+bool check_verhoeff(const check_range& check_seq);
template <size_t size_expected, typename check_range>
-typename boost::checks::verhoeff_compute_algorithm::checkdigit<check_range>::type compute_verhoeff (const check_range& check_seq) ;
+typename boost::range_value<check_range>::type compute_verhoeff(const check_range& check_seq);
template <typename check_range>
-typename boost::checks::verhoeff_compute_algorithm::checkdigit<check_range>::type compute_verhoeff (const check_range& check_seq) ;
+typename boost::range_value<check_range>::type compute_verhoeff(const check_range& check_seq);
// Modulus 11
template <size_t size_expected, typename check_range>
-bool check_modulus11 (const check_range& check_seq) ;
+bool check_modulus11(const check_range& check_seq);
template <typename check_range>
-bool check_modulus11 (const check_range& check_seq) ;
+bool check_modulus11(const check_range& check_seq);
template <size_t size_expected, typename check_range>
-typename boost::checks::mod11_compute_algorithm::checkdigit<check_range>::type compute_modulus11 (const check_range& check_seq) ;
+typename boost::range_value<check_range>::type compute_modulus11(const check_range& check_seq);
template <typename check_range>
-typename boost::checks::mod11_compute_algorithm::checkdigit<check_range>::type compute_modulus11 (const check_range& check_seq) ;
+typename boost::range_value<check_range>::type compute_modulus11(const check_range& check_seq);
-// Modulus 97-10 (ISO/IEC 7064:2003)
+// Modulus 97-10(ISO/IEC 7064:2003)
template <size_t size_expected, typename check_range>
-bool check_mod97_10 (const check_range& check_seq) ;
+bool check_mod97_10(const check_range& check_seq);
template <typename check_range>
-bool check_mod97_10 (const check_range& check_seq) ;
+bool check_mod97_10(const check_range& check_seq);
template <size_t size_expected, typename check_range, typename checkdigits_iter>
-checkdigits_iter compute_mod97_10 (const check_range& check_seq, checkdigits_iter mod97_checkdigits) ;
+checkdigits_iter compute_mod97_10(const check_range& check_seq, checkdigits_iter mod97_checkdigits);
template <typename check_range, typename checkdigits_iter>
-checkdigits_iter compute_mod97_10 (const check_range& check_seq, checkdigits_iter mod97_checkdigits) ;
+checkdigits_iter compute_mod97_10(const check_range& check_seq, checkdigits_iter mod97_checkdigits);
// EAN-13 and EAN-8
template <typename check_range>
-bool check_ean13 (const check_range& check_seq) ;
+bool check_ean13(const check_range& check_seq);
template <typename check_range>
-typename boost::checks::ean_compute_algorithm::checkdigit<check_range>::type compute_ean13 (const check_range& check_seq) ;
+typename boost::range_value<check_range>::type compute_ean13(const check_range& check_seq);
template <typename check_range>
-bool check_ean8 (const check_range& check_seq) ;
+bool check_ean8(const check_range& check_seq);
template <typename check_range>
-typename boost::checks::ean_compute_algorithm::checkdigit<check_range>::type compute_ean8 (const check_range& check_seq);
+typename boost::range_value<check_range>::type compute_ean8(const check_range& check_seq);
// IBSN-10 and ISBN-13
template <typename check_range>
-bool check_isbn10 (const check_range& check_seq) ;
+bool check_isbn10(const check_range& check_seq);
template <typename check_range>
-typename boost::checks::mod11_compute_algorithm::checkdigit<check_range>::type compute_isbn10 (const check_range& check_seq) ;
+typename boost::range_value<check_range>::type compute_isbn10(const check_range& check_seq);
template <typename check_range>
-bool check_isbn13 (const check_range& check_seq) ;
+bool check_isbn13(const check_range& check_seq);
template <typename check_range>
-typename boost::checks::isbn13_compute_algorithm::checkdigit<check_range>::type compute_isbn13 (const check_range& check_seq) ;
+typename boost::range_value<check_range>::type compute_isbn13(const check_range& check_seq);
// UPC-A
template <typename check_range>
-bool check_upca (const check_range& check_seq) ;
+bool check_upca(const check_range& check_seq);
template <typename check_range>
-typename boost::checks::upc_compute_algorithm::checkdigit<check_range>::type compute_upca (const check_range& check_seq) ;
+typename boost::range_value<check_range>::type compute_upca(const check_range& check_seq);
// American Express
template <typename check_range>
-bool check_amex (const check_range& check_seq) ;
+bool check_amex(const check_range& check_seq);
template <typename check_range>
-typename boost::checks::amex_compute_algorithm::checkdigit<check_range>::type compute_amex (const check_range& check_seq) ;
+typename boost::range_value<check_range>::type compute_amex(const check_range& check_seq);
// VISA
template <typename check_range>
-bool check_visa (const check_range& check_seq) ;
+bool check_visa(const check_range& check_seq);
template <typename check_range>
-typename boost::checks::visa_compute_algorithm::checkdigit<check_range>::type compute_visa (const check_range& check_seq) ;
+typename boost::range_value<check_range>::type compute_visa(const check_range& check_seq);
// Mastercard
template <typename check_range>
-bool check_mastercard (const check_range& check_seq) ;
+bool check_mastercard(const check_range& check_seq);
template <typename check_range>
-typename boost::checks::mastercard_compute_algorithm::checkdigit<check_range>::type compute_mastercard (const check_range& check_seq) ;
+typename boost::range_value<check_range>::type compute_mastercard(const check_range& check_seq);
}} // namespace boost namespace checks
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 05:29:22 EST (Wed, 18 Jan 2012)
@@ -17,10 +17,12 @@
#endif
#include <boost/checks/weight.hpp>
-#include <boost/checks/iteration_sense.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 EAN-13 (13).
*/
@@ -45,19 +47,15 @@
\brief This is the weight used by EAN system.
*/
typedef boost::checks::weight<1,3> ean_weight ;
-/*!
- \brief This is the running sense or direction to check an EAN.
-*/
-typedef boost::checks::rightmost ean_sense ;
/*!
\brief This is the type of the EAN algorithm for validating a check digit.
*/
-typedef boost::checks::modulus10_algorithm< ean_weight, ean_sense, 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, ean_sense, 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.
@@ -72,9 +70,9 @@
\returns @c true if the check digit is correct, @c false otherwise.
*/
template <typename check_range>
-bool check_ean13 (const check_range& check_seq)
+bool check_ean13(const check_range& check_seq)
{
- return boost::checks::check_sequence<ean_check_algorithm, EAN13_SIZE> ( check_seq ) ;
+ return boost::checks::check_sequence<ean_check_algorithm, EAN13_SIZE>(boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -91,9 +89,9 @@
\returns The check digit. The check digit is in the range [0..9].
*/
template <typename check_range>
-typename boost::checks::ean_compute_algorithm::checkdigit<check_range>::type compute_ean13 (const check_range& check_seq)
+typename boost::range_value<check_range>::type compute_ean13(const check_range& check_seq)
{
- return boost::checks::compute_checkdigit<ean_compute_algorithm, EAN13_SIZE_WITHOUT_CHECKDIGIT> ( check_seq ) ;
+ return boost::checks::compute_checkdigit<ean_compute_algorithm, EAN13_SIZE_WITHOUT_CHECKDIGIT> (boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -111,7 +109,7 @@
template <typename check_range>
bool check_ean8 (const check_range& check_seq)
{
- return boost::checks::check_sequence<ean_check_algorithm, EAN8_SIZE> ( check_seq ) ;
+ return boost::checks::check_sequence<ean_check_algorithm, EAN8_SIZE>(boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -128,9 +126,9 @@
\returns The check digit. The check digit is in the range [0..9].
*/
template <typename check_range>
-typename boost::checks::ean_compute_algorithm::checkdigit<check_range>::type compute_ean8 (const check_range& check_seq)
+typename boost::range_value<check_range>::type compute_ean8(const check_range& check_seq)
{
- return boost::checks::compute_checkdigit<ean_compute_algorithm, EAN8_SIZE_WITHOUT_CHECKDIGIT> ( check_seq ) ;
+ return boost::checks::compute_checkdigit<ean_compute_algorithm, EAN8_SIZE_WITHOUT_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-01-18 05:29:22 EST (Wed, 18 Jan 2012)
@@ -21,6 +21,9 @@
#include <boost/checks/ean.hpp>
#include <boost/checks/modulus11.hpp>
+#include <boost/range/rbegin.hpp>
+#include <boost/range/rend.hpp>
+
/*!
\brief This macro defines the size of an ISBN-10.
*/
@@ -39,7 +42,7 @@
\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.
*/
template <unsigned int number_of_virtual_value_skipped = 0>
-struct isbn13_algorithm : boost::checks::modulus10_algorithm < boost::checks::ean_weight, boost::checks::ean_sense, number_of_virtual_value_skipped >
+struct isbn13_algorithm : boost::checks::modulus10_algorithm<boost::checks::ean_weight, number_of_virtual_value_skipped>
{
/*!
\brief Verify that a number matches the ISBN-13 pattern.
@@ -53,25 +56,25 @@
*/
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 = EAN13_SIZE - current_value_position - number_of_virtual_value_skipped ;
+ const unsigned int real_pos_from_left = EAN13_SIZE - current_value_position - number_of_virtual_value_skipped;
if( real_pos_from_left == 1 && current_valid_value != 9)
- throw std::invalid_argument("The first digit should be 9!") ;
+ throw std::invalid_argument("The first digit should be 9!");
else if( real_pos_from_left == 2 && current_valid_value != 7)
- throw std::invalid_argument("The second digit should be 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)
- throw std::invalid_argument("The third digit should be 8 or 9!") ;
+ throw std::invalid_argument("The third digit should be 8 or 9!");
}
};
/*!
\brief This is the type of the ISBN-13 algorithm for validating a check digit.
*/
-typedef boost::checks::isbn13_algorithm<0> isbn13_check_algorithm ;
+typedef boost::checks::isbn13_algorithm<0> isbn13_check_algorithm;
/*!
\brief This is the type of the ISBN-13 algorithm for computing a check digit.
*/
-typedef boost::checks::isbn13_algorithm<1> isbn13_compute_algorithm ;
+typedef boost::checks::isbn13_algorithm<1> isbn13_compute_algorithm;
/*!
\brief Validate a sequence according to the isbn13_check_algorithm type.
@@ -88,7 +91,7 @@
template <typename check_range>
bool check_isbn13 (const check_range& check_seq)
{
- return boost::checks::check_sequence<isbn13_check_algorithm, EAN13_SIZE> ( check_seq ) ;
+ return boost::checks::check_sequence<isbn13_check_algorithm, EAN13_SIZE>(boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -105,9 +108,9 @@
\returns The check digit. The check digit is in the range [0..9].
*/
template <typename check_range>
-typename boost::checks::isbn13_compute_algorithm::checkdigit<check_range>::type compute_isbn13 (const check_range& check_seq)
+typename boost::range_value<check_range>::type compute_isbn13 (const check_range& check_seq)
{
- return boost::checks::compute_checkdigit<isbn13_compute_algorithm, EAN13_SIZE_WITHOUT_CHECKDIGIT> ( check_seq ) ;
+ return boost::checks::compute_checkdigit<isbn13_compute_algorithm, EAN13_SIZE_WITHOUT_CHECKDIGIT>(boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -123,9 +126,9 @@
\returns @c true if the check digit is correct, @c false otherwise.
*/
template <typename check_range>
-bool check_isbn10 (const check_range& check_seq)
+bool check_isbn10(const check_range& check_seq)
{
- return boost::checks::check_modulus11< ISBN10_SIZE >( check_seq );
+ return boost::checks::check_modulus11<ISBN10_SIZE>(check_seq);
}
/*!
@@ -142,9 +145,9 @@
\returns The check digit. The check digit is in the range [0..9,X].
*/
template <typename check_range>
-typename boost::checks::mod11_compute_algorithm::checkdigit<check_range>::type compute_isbn10 (const check_range& check_seq)
+typename boost::range_value<check_range>::type compute_isbn10(const check_range& check_seq)
{
- return boost::checks::compute_modulus11< ISBN10_SIZE_WITHOUT_CHECKDIGIT >( check_seq ) ;
+ return boost::checks::compute_modulus11<ISBN10_SIZE_WITHOUT_CHECKDIGIT>(check_seq);
}
Deleted: sandbox/SOC/2011/checks/boost/checks/iteration_sense.hpp
==============================================================================
--- sandbox/SOC/2011/checks/boost/checks/iteration_sense.hpp 2012-01-18 05:29:22 EST (Wed, 18 Jan 2012)
+++ (empty file)
@@ -1,105 +0,0 @@
-// Boost checks/iteration_sense.hpp header file
-// (C) Copyright Pierre Talbot 2011
-// Distributed under the Boost Software License, Version 1.0. (See
-// accompanying file LICENSE_1_0.txt or copy at
-// http://www.boost.org/LICENSE_1_0.txt
-// See http://www.boost.org for updates, documentation, and revision history.
-
-/*! \file
- \brief Provides two direction of iteration to run through the sequence, either from right to left or left to right.
-*/
-
-
-#ifndef BOOST_CHECK_ITERATION_SENSE_HPP
-#define BOOST_CHECK_ITERATION_SENSE_HPP
-
-#ifdef _MSC_VER
- #pragma once
-#endif
-
-#include <boost/range/reverse_iterator.hpp>
-#include <boost/range/iterator_range.hpp>
-#include <boost/range/const_iterator.hpp>
-#include <boost/range/const_reverse_iterator.hpp>
-
-#include <boost/range/begin.hpp>
-#include <boost/range/end.hpp>
-#include <boost/range/rbegin.hpp>
-#include <boost/range/rend.hpp>
-
-namespace boost{
- namespace checks{
-
-/*! \class rightmost
- \brief Policy class that provides methods to run through a sequence from right to left.
-*/
-struct rightmost
-{
- /*! \class iterator
- \brief Template rebinding class used to define the type of a const reverse iterator for seq_range.
-
- \tparam seq_range The type of the sequence to check.
- */
- template <typename seq_range>
- struct iterator
- {
- typedef typename boost::range_const_reverse_iterator<seq_range>::type type ;
- };
-
- /*! \fn static typename iterator<seq_range>::type begin(seq_range &sequence)
- \brief Get the beginning of the sequence.
-
- \tparam seq_range The type of the sequence to check.
- \returns A reverse iterator representing the beginning of the sequence.
- */
- template <typename seq_range>
- static typename iterator<seq_range>::type begin(seq_range &sequence) { return boost::rbegin(sequence) ; }
-
- /*! \fn static typename iterator<seq_range>::type end(seq_range &sequence)
- \brief Get the ending of the sequence.
-
- \tparam seq_range The type of the sequence to check.
- \returns A reverse iterator represents one past the end of the sequence.
- */
- template <typename seq_range>
- static typename iterator<seq_range>::type end(seq_range &sequence) { return boost::rend(sequence) ; }
-};
-
-/*! \class leftmost
- \brief Policy class that provides methods to run through a sequence from left to right.
-*/
-struct leftmost
-{
- /*! \class iterator
- \brief Template rebinding class used to define the type of a const iterator for seq_range.
-
- \tparam seq_range The type of the sequence to check.
- */
- template <typename seq_range>
- struct iterator
- {
- typedef typename boost::range_const_iterator<seq_range>::type type ;
- };
-
- /*! \fn static typename iterator<seq_range>::type begin(seq_range &sequence)
- \brief Get the beginning of the sequence.
-
- \tparam seq_range The type of the sequence to check.
- \returns An iterator represents the beginning of the sequence.
- */
- template <typename seq_range>
- static typename iterator<seq_range>::type begin(seq_range &sequence) { return boost::begin(sequence) ; }
-
- /*! \fn static typename iterator<seq_range>::type end(seq_range &sequence)
- \brief Get the ending of the sequence.
-
- \tparam seq_range The type of the sequence to check.
- \returns An iterator represents one past the end of the sequence.
- */
- template <typename seq_range>
- static typename iterator<seq_range>::type end(seq_range &sequence) { return boost::end(sequence) ; }
-};
-
-
-}}
-#endif // BOOST_CHECKS_ITERATION_SENSE_HPP
Modified: sandbox/SOC/2011/checks/boost/checks/limits.hpp
==============================================================================
--- sandbox/SOC/2011/checks/boost/checks/limits.hpp (original)
+++ sandbox/SOC/2011/checks/boost/checks/limits.hpp 2012-01-18 05:29:22 EST (Wed, 18 Jan 2012)
@@ -36,7 +36,7 @@
\param valid_value_counter Number of valid values in the sequence.
\throws exception_size_failure If the terms of the contract are not respected. (valid_value_counter != expected_size).
*/
- static void respect_size_contract(const size_t valid_value_counter)
+ static void respect_size_contract(size_t valid_value_counter)
{
BOOST_STATIC_ASSERT_MSG( expected_size > 0 , "The expected size must be greater than 0!" );
if( valid_value_counter != expected_size )
@@ -49,7 +49,7 @@
\param valid_value_counter Number of valid values in the sequence already counted.
\returns true if valid_value_counter is one past the end of the expected size, else false.
*/
- static bool reach_one_past_the_end(const size_t valid_value_counter)
+ static bool reach_one_past_the_end(size_t valid_value_counter)
{
BOOST_STATIC_ASSERT_MSG( expected_size > 0 , "The expected size must be greater than 0!" );
return valid_value_counter > expected_size ;
@@ -70,7 +70,7 @@
\param valid_value_counter Number of valid values in the sequence.
\throws exception_size_failure if the terms of the contract are not respected. (valid_value_counter == 0).
*/
- static void respect_size_contract(const size_t valid_value_counter)
+ static void respect_size_contract(size_t valid_value_counter)
{
if( valid_value_counter == 0 )
throw exception_size_failure("No valid value in this sequence!") ;
@@ -82,13 +82,13 @@
\param valid_value_counter Number of valid values in the sequence already counted.
\returns false.
*/
- static bool reach_one_past_the_end(const size_t /* valid_value_counter */)
+ static bool reach_one_past_the_end(size_t /* valid_value_counter */)
{
- return false ;
+ return false;
}
};
}} // namespace boost namespace checks
-#endif // BOOST_CHECKS_LIMITS_HPP
\ No newline at end of file
+#endif // BOOST_CHECKS_LIMITS_HPP
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 05:29:22 EST (Wed, 18 Jan 2012)
@@ -18,6 +18,9 @@
#include <boost/checks/modulus10.hpp>
+#include <boost/range/rbegin.hpp>
+#include <boost/range/rend.hpp>
+
namespace boost {
namespace checks{
@@ -26,18 +29,13 @@
*/
typedef boost::checks::weight<1,2> luhn_weight;
-/*!
- \brief This is the running sense to check an Luhn number.
-*/
-typedef boost::checks::rightmost luhn_sense;
-
/*! \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.
*/
template <unsigned int number_of_virtual_value_skipped = 0>
-struct luhn_algorithm : boost::checks::modulus10_algorithm < luhn_weight, luhn_sense, number_of_virtual_value_skipped>
+struct luhn_algorithm : boost::checks::modulus10_algorithm <luhn_weight, number_of_virtual_value_skipped>
{
/*!
\brief Compute the Luhn algorithm operation on the checksum.
@@ -50,22 +48,22 @@
\remarks This function become obsolete if you don't use luhn_weight. It is using operator "<<" to make internal multiplication.
*/
- 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(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 + number_of_virtual_value_skipped);
int weighted_value = current_valid_value << (current_weight-1);
- checksum += weighted_value % 10 + weighted_value / 10 ;
+ checksum += weighted_value % 10 + weighted_value / 10;
}
};
/*!
\brief This is the type of the Luhn algorithm for validating a check digit.
*/
-typedef luhn_algorithm<0> luhn_check_algorithm ;
+typedef luhn_algorithm<0> luhn_check_algorithm;
/*!
\brief This is the type of the Luhn algorithm for computing a check digit.
*/
-typedef luhn_algorithm<1> luhn_compute_algorithm ;
+typedef luhn_algorithm<1> luhn_compute_algorithm;
/*!
\brief Validate a sequence according to the luhn_check_algorithm type.
@@ -83,7 +81,7 @@
template <size_t size_expected, typename check_range>
bool check_luhn (const check_range& check_seq)
{
- return boost::checks::check_sequence<luhn_check_algorithm, size_expected>(check_seq);
+ return boost::checks::check_sequence<luhn_check_algorithm, size_expected>(boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -101,7 +99,7 @@
template <typename check_range>
bool check_luhn (const check_range& check_seq)
{
- return boost::checks::check_sequence<luhn_check_algorithm> (check_seq);
+ return boost::checks::check_sequence<luhn_check_algorithm> (boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -119,9 +117,9 @@
\returns The check digit. The check digit is in the range [0..9].
*/
template <size_t size_expected, typename check_range>
-typename boost::checks::luhn_compute_algorithm::checkdigit<check_range>::type compute_luhn (const check_range& check_seq)
+typename boost::range_value<check_range>::type compute_luhn(const check_range& check_seq)
{
- return boost::checks::compute_checkdigit<luhn_compute_algorithm, size_expected> ( check_seq ) ;
+ return boost::checks::compute_checkdigit<luhn_compute_algorithm, size_expected>(boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -138,9 +136,9 @@
\returns The check digit. The check digit is in the range [0..9].
*/
template <typename check_range>
-typename boost::checks::luhn_compute_algorithm::checkdigit<check_range>::type compute_luhn (const check_range& check_seq)
+typename boost::range_value<check_range>::type compute_luhn (const check_range& check_seq)
{
- return boost::checks::compute_checkdigit<luhn_compute_algorithm> ( check_seq ) ;
+ return boost::checks::compute_checkdigit<luhn_compute_algorithm>(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-01-18 05:29:22 EST (Wed, 18 Jan 2012)
@@ -1,6 +1,6 @@
// Boost checks/mastercard.hpp header file
-// (C) Copyright Pierre Talbot 2011
-// Distributed under the Boost Software License, Version 1.0. (See
+// (C)Copyright Pierre Talbot 2011
+// Distributed under the Boost Software License, Version 1.0.(See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
// See http://www.boost.org for updates, documentation, and revision history.
@@ -18,6 +18,9 @@
#include <boost/checks/luhn.hpp>
+#include <boost/range/rbegin.hpp>
+#include <boost/range/rend.hpp>
+
/*!
\brief This macro defines the size of a Mastercard number.
*/
@@ -36,37 +39,37 @@
\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.
*/
template <unsigned int number_of_virtual_value_skipped = 0>
-struct mastercard_algorithm : boost::checks::luhn_algorithm < number_of_virtual_value_skipped >
+struct mastercard_algorithm : boost::checks::luhn_algorithm <number_of_virtual_value_skipped>
{
/*!
\brief Verify that a number matches the Mastercard pattern.
\param current_valid_value is the current valid value analysed.
- \param current_value_position is the number of valid values 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 current_value_position is the number of valid values 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 first character is not equal to 5 or the second is not between 1 and 5. The exception contains a descriptive message of what was expected.
\remarks This function use the macro MASTERCARD_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(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 - number_of_virtual_value_skipped;
- 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) )
- throw std::invalid_argument("The Issuer Identification Number of an Mastercard should be between 51 and 55!" ) ;
+ 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))
+ throw std::invalid_argument("The Issuer Identification Number of an Mastercard should be between 51 and 55!");
}
};
/*!
\brief This is the type of the Mastercard algorithm for validating a check digit.
*/
-typedef mastercard_algorithm<0> mastercard_check_algorithm ;
+typedef mastercard_algorithm<0> mastercard_check_algorithm;
/*!
\brief This is the type of the Mastercard algorithm for computing a check digit.
*/
-typedef mastercard_algorithm<1> mastercard_compute_algorithm ;
+typedef mastercard_algorithm<1> mastercard_compute_algorithm;
/*!
\brief Validate a sequence according to the mastercard_check_algorithm type.
@@ -77,14 +80,14 @@
\param check_seq is the sequence of value to check.
\throws std::invalid_argument if check_seq doesn't contain exactly MASTERCARD_SIZE digits.
- \throws std::invalid_argument if the two first digits (from the leftmost) don't match the Mastercard pattern.
+ \throws std::invalid_argument if the two first digits(from the leftmost)don't match the Mastercard pattern.
\returns True if the check digit is correct, false otherwise.
*/
template <typename check_range>
-bool check_mastercard (const check_range& check_seq)
+bool check_mastercard(const check_range& check_seq)
{
- return boost::checks::check_sequence<mastercard_check_algorithm, MASTERCARD_SIZE> ( check_seq ) ;
+ return boost::checks::check_sequence<mastercard_check_algorithm, MASTERCARD_SIZE>(boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -96,15 +99,15 @@
\param check_seq is the sequence of value to check.
\throws std::invalid_argument if check_seq doesn't contain exactly MASTERCARD_SIZE_WITHOUT_CHECKDIGIT digits.
- \throws std::invalid_argument if the two first digits (from the leftmost) do not match the Mastercard pattern.
+ \throws std::invalid_argument if the two first digits(from the leftmost)do not match the Mastercard pattern.
\throws boost::checks::translation_exception if the check digit cannot be translated into the checkdigit type.
\returns The check digit. The check digit is in the range [0..9].
*/
template <typename check_range>
-typename boost::checks::mastercard_compute_algorithm::checkdigit<check_range>::type compute_mastercard (const check_range& check_seq)
+typename boost::range_value<check_range>::type compute_mastercard(const check_range& check_seq)
{
- return boost::checks::compute_checkdigit<mastercard_compute_algorithm, MASTERCARD_SIZE_WITHOUT_CHECKDIGIT> ( check_seq ) ;
+ return boost::checks::compute_checkdigit<mastercard_compute_algorithm, MASTERCARD_SIZE_WITHOUT_CHECKDIGIT>(boost::rbegin(check_seq), boost::rend(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-01-18 05:29:22 EST (Wed, 18 Jan 2012)
@@ -30,8 +30,8 @@
\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.
*/
-template <typename mod10_weight, typename iteration_sense, unsigned int number_of_virtual_value_skipped = 0>
-struct modulus10_algorithm : boost::checks::weighted_sum_algorithm<mod10_weight, iteration_sense, number_of_virtual_value_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>
{
/*!
\brief Validate a checksum with a simple modulus 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-18 05:29:22 EST (Wed, 18 Jan 2012)
@@ -1,6 +1,6 @@
// Boost checks/modulus11.hpp header file ------------------------------------//
-// (C) Copyright Pierre Talbot 2011
-// Distributed under the Boost Software License, Version 1.0. (See
+// (C)Copyright Pierre Talbot 2011
+// Distributed under the Boost Software License, Version 1.0.(See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
// See http://www.boost.org for updates, documentation, and revision history.
@@ -19,10 +19,13 @@
#include <boost/lexical_cast.hpp>
#include <boost/checks/translation_exception.hpp>
#include <boost/checks/weight.hpp>
-#include <boost/checks/iteration_sense.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{
@@ -35,8 +38,8 @@
\remarks The range of the check digit is [0..10], the tenth element is translated as the letter 'X'.
*/
-template <typename mod11_weight, typename iteration_sense, unsigned int number_of_virtual_value_skipped = 0>
-struct modulus11_algorithm : boost::checks::weighted_sum_algorithm<mod11_weight, iteration_sense, number_of_virtual_value_skipped>
+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>
{
/*!
@@ -44,30 +47,30 @@
\tparam value is the type of a value in the sequence.
\param current_value is the current value analysed in the sequence that must be translated.
- \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 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).
- \throws boost::checks::translation_exception is thrown if the translation of current_value failed.\n The translation will fail if the current value is not a digit (0 <= i < 10), unless it is the rightmost digit, when the value 10 or the 'x' or 'X' character is allowed.
+ \throws boost::checks::translation_exception is thrown if the translation of current_value failed.\n The translation will fail if the current value is not a digit(0 <= i < 10), unless it is the rightmost digit, when the value 10 or the 'x' or 'X' character is allowed.
\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, const unsigned int valid_value_counter )
+ static int translate_to_valid_value(const value ¤t_value, unsigned int valid_value_counter)
{
int valid_value = 0;
try
{
- valid_value = boost::lexical_cast<int>( current_value ) ;
+ valid_value = boost::lexical_cast<int>(current_value);
}
- catch( boost::bad_lexical_cast )
+ catch(boost::bad_lexical_cast)
{
- if( (valid_value_counter + number_of_virtual_value_skipped == 1) && (current_value == 'x' || current_value == 'X') )
- valid_value = 10 ;
+ if((valid_value_counter + number_of_virtual_value_skipped == 1)&&(current_value == 'x' || current_value == 'X'))
+ valid_value = 10;
else
- throw boost::checks::translation_exception() ;
+ 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 ;
+ if(valid_value > 10 ||(valid_value == 10 &&(valid_value_counter + number_of_virtual_value_skipped == 1)))
+ throw boost::checks::translation_exception();
+ return valid_value;
}
/*!
@@ -79,7 +82,7 @@
*/
static bool validate_checksum(int checksum)
{
- return !(checksum % 11) ;
+ return !(checksum % 11);
}
/*!
@@ -93,28 +96,28 @@
\returns The modulus 11 check digit of checksum. 'X' is returned if the check digit value is equal to 10.
*/
template <typename checkdigit>
- static checkdigit compute_checkdigit( int checksum )
+ static checkdigit compute_checkdigit(int checksum)
{
- return translate_checkdigit<checkdigit>((11 - checksum % 11) % 11) ;
+ return translate_checkdigit<checkdigit>((11 - checksum % 11)% 11);
}
protected:
template <typename checkdigit>
- static checkdigit translate_checkdigit( int _checkdigit )
+ static checkdigit translate_checkdigit(int _checkdigit)
{
try
{
- return boost::lexical_cast<checkdigit>(_checkdigit) ;
+ return boost::lexical_cast<checkdigit>(_checkdigit);
}
- catch( boost::bad_lexical_cast )
+ catch(boost::bad_lexical_cast)
{
try
{
- return boost::lexical_cast<checkdigit>('X') ;
+ return boost::lexical_cast<checkdigit>('X');
}
- catch( boost::bad_lexical_cast )
+ catch(boost::bad_lexical_cast)
{
- throw boost::checks::translation_exception() ;
+ throw boost::checks::translation_exception();
}
}
}
@@ -124,25 +127,22 @@
/*!
\brief The most common weight pattern used with a modulus 11 algorithm.
*/
-typedef boost::checks::weight<1,2,3,4,5,6,7,8,9,10> mod11_weight ;
-/*!
- \brief The most common iteration sense or direction used with a modulus 11 algorithm (right to left).
-*/
-typedef boost::checks::rightmost mod11_sense ;
+typedef boost::checks::weight<1,2,3,4,5,6,7,8,9,10> mod11_weight;
/*!
\brief This is the type of the most common modulus 11 algorithm for validating a check digit.
*/
-typedef modulus11_algorithm<mod11_weight, mod11_sense, 0> mod11_check_algorithm ;
+typedef modulus11_algorithm<mod11_weight, 0> mod11_check_algorithm;
+
/*!
\brief This is the type of the most common modulus 11 algorithm for computing a check digit.
*/
-typedef modulus11_algorithm<mod11_weight, mod11_sense, 1> mod11_compute_algorithm ;
+typedef modulus11_algorithm<mod11_weight, 1> mod11_compute_algorithm;
/*!
\brief Validate a sequence according to the mod11_check_algorithm type.
- \pre check_seq is a valid range.\n size_expected > 0 (enforced by static assert).
+ \pre check_seq is a valid range.\n size_expected > 0(enforced by static assert).
\tparam size_expected is the number of valid value expected in the sequence.
\tparam check_range is a valid range type.
@@ -153,9 +153,9 @@
\returns @c true if the check digit is correct, false otherwise.
*/
template <size_t size_expected, typename check_range>
-bool check_modulus11 (const check_range& check_seq)
+bool check_modulus11(const check_range& check_seq)
{
- return boost::checks::check_sequence<mod11_check_algorithm, size_expected> ( check_seq ) ;
+ return boost::checks::check_sequence<mod11_check_algorithm, size_expected>(boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -171,17 +171,17 @@
\returns @c true if the check digit is correct, false otherwise.
*/
template <typename check_range>
-bool check_modulus11 (const check_range& check_seq)
+bool check_modulus11(const check_range& check_seq)
{
- return boost::checks::check_sequence<mod11_check_algorithm> ( check_seq ) ;
+ return boost::checks::check_sequence<mod11_check_algorithm>(boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
\brief Calculate the check digit of a sequence according to the mod11_compute_algorithm type.
- \pre check_seq is a valid range.\n size_expected > 0 (enforced by static assert).
+ \pre check_seq is a valid range.\n size_expected > 0(enforced by static assert).
- \tparam size_expected is the number of valid value expected in the sequence. (So the check digit is not included.)
+ \tparam size_expected is the number of valid value expected in the sequence.(So the check digit is not included.)
\tparam check_range is a valid range type.
\param check_seq is the sequence of value to check.
@@ -191,9 +191,9 @@
\returns The check digit. The check digit is in the range [0..9,X].
*/
template <size_t size_expected, typename check_range>
-typename boost::checks::mod11_compute_algorithm::checkdigit<check_range>::type compute_modulus11 (const check_range& check_seq)
+typename boost::range_value<check_range>::type compute_modulus11(const check_range& check_seq)
{
- return boost::checks::compute_checkdigit<mod11_compute_algorithm, size_expected> ( check_seq ) ;
+ return boost::checks::compute_checkdigit<mod11_compute_algorithm, size_expected>(boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -210,9 +210,9 @@
\returns The check digit. The check digit is in the range [0..9,X].
*/
template <typename check_range>
-typename boost::checks::mod11_compute_algorithm::checkdigit<check_range>::type compute_modulus11 (const check_range& check_seq)
+typename boost::range_value<check_range>::type compute_modulus11(const check_range& check_seq)
{
- return boost::checks::compute_checkdigit<mod11_compute_algorithm> ( check_seq ) ;
+ return boost::checks::compute_checkdigit<mod11_compute_algorithm>(boost::rbegin(check_seq), boost::rend(check_seq));
}
}} // namespace boost namespace checks
Modified: sandbox/SOC/2011/checks/boost/checks/modulus97.hpp
==============================================================================
--- sandbox/SOC/2011/checks/boost/checks/modulus97.hpp (original)
+++ sandbox/SOC/2011/checks/boost/checks/modulus97.hpp 2012-01-18 05:29:22 EST (Wed, 18 Jan 2012)
@@ -21,7 +21,6 @@
#include <boost/lexical_cast.hpp>
#include <boost/checks/translation_exception.hpp>
#include <boost/checks/weight.hpp>
-#include <boost/checks/iteration_sense.hpp>
#include <boost/checks/weighted_sum.hpp>
namespace boost{
@@ -38,8 +37,8 @@
\remarks This algorithm use two check digits.
*/
-template <typename mod97_weight, typename iteration_sense, unsigned int number_of_virtual_value_skipped = 0>
-struct modulus97_algorithm : boost::checks::weighted_sum_algorithm<mod97_weight, iteration_sense, number_of_virtual_value_skipped>
+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>
{
/*!
\brief Validate a checksum with a simple modulus 97.
@@ -50,7 +49,7 @@
*/
static bool validate_checksum(int checksum)
{
- return checksum % 97 == 1 ;
+ return checksum % 97 == 1;
}
/*!
@@ -68,18 +67,19 @@
\returns An iterator initialized at one pass to the end of the two check digits.
*/
template <typename checkdigits_iter>
- static checkdigits_iter compute_multicheckdigit( int checksum, checkdigits_iter checkdigits )
+ static checkdigits_iter compute_multicheckdigit(int checksum, checkdigits_iter checkdigits)
{
- unsigned int mod97_checkdigits = 98 - (checksum % 97) ;
+ unsigned int mod97_checkdigits = 98 - (checksum % 97);
- try{
- *checkdigits = boost::lexical_cast<typename checkdigits_iter::value_type>(mod97_checkdigits / 10) ;
+ try
+ {
+ *checkdigits = boost::lexical_cast<typename checkdigits_iter::value_type>(mod97_checkdigits / 10);
++checkdigits;
- *checkdigits = boost::lexical_cast<typename checkdigits_iter::value_type>(mod97_checkdigits % 10) ;
+ *checkdigits = boost::lexical_cast<typename checkdigits_iter::value_type>(mod97_checkdigits % 10);
++checkdigits;
}
catch( boost::bad_lexical_cast ){
- throw boost::checks::translation_exception() ;
+ throw boost::checks::translation_exception();
}
return checkdigits;
}
@@ -95,8 +95,8 @@
template <unsigned int weight_value>
struct make_mod97_weight
{
- static const unsigned int value = weight_value ;
- typedef make_mod97_weight<weight_value * 10 % 97> next ;
+ static const unsigned int 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.
@@ -104,15 +104,14 @@
template<>
struct make_mod97_weight<68>
{
- static const unsigned int value = 68 ;
- typedef make_mod97_weight type ;
+ 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 ;
-
+typedef make_mod97_weight<1> initial_mod97_weight;
/*!
\brief This macro is used to access the next type.
@@ -127,21 +126,16 @@
/*!
\brief This is weight of the mod97-10 algorithm.
*/
-typedef boost::checks::weight< BOOST_PP_ENUM(96, MOD97_weight_maker, ~) > mod97_10_weight ;
-
-/*!
- \brief The iteration sense or direction of the sequence. From right to left.
-*/
-typedef boost::checks::rightmost mod97_10_sense ;
+typedef boost::checks::weight<BOOST_PP_ENUM(96, MOD97_weight_maker, ~)> mod97_10_weight;
/*!
\brief This is the type of the modulus 97-10 algorithm for validating a check digit.
*/
-typedef modulus97_algorithm< mod97_10_weight, mod97_10_sense, 0 > mod97_10_check_algorithm ;
+typedef modulus97_algorithm<mod97_10_weight, 0> mod97_10_check_algorithm;
/*!
\brief This is the type of the modulus 97-10 algorithm for computing a check digit.
*/
-typedef modulus97_algorithm< mod97_10_weight, mod97_10_sense, 2 > mod97_10_compute_algorithm ;
+typedef modulus97_algorithm<mod97_10_weight, 2> mod97_10_compute_algorithm;
/*!
\brief Validate a sequence according to the mod97_10_check_algorithm type.
@@ -159,7 +153,7 @@
template <size_t size_expected, typename check_range>
bool check_mod97_10 (const check_range& check_seq)
{
- return boost::checks::check_sequence<mod97_10_check_algorithm, size_expected> ( check_seq ) ;
+ return boost::checks::check_sequence<mod97_10_check_algorithm, size_expected> (boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -175,9 +169,9 @@
\returns @c true if the two check digits are correct, @c false otherwise.
*/
template <typename check_range>
-bool check_mod97_10 (const check_range& check_seq)
+bool check_mod97_10(const check_range& check_seq)
{
- return boost::checks::check_sequence<mod97_10_check_algorithm> ( check_seq ) ;
+ return boost::checks::check_sequence<mod97_10_check_algorithm>(boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -197,9 +191,9 @@
\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, typename checkdigits_iter>
-checkdigits_iter compute_mod97_10 (const check_range& check_seq, checkdigits_iter mod97_checkdigits)
+checkdigits_iter compute_mod97_10(const check_range& check_seq, checkdigits_iter mod97_checkdigits)
{
- return boost::checks::compute_multicheckdigit<mod97_10_compute_algorithm, size_expected> ( check_seq, mod97_checkdigits ) ;
+ return boost::checks::compute_multicheckdigit<mod97_10_compute_algorithm, size_expected>(boost::rbegin(check_seq), boost::rend(check_seq), mod97_checkdigits);
}
/*!
@@ -218,9 +212,9 @@
\returns The check digits are stored into mod97_checkdigits. The range of these is [0..9][0..9].
*/
template <typename check_range, typename checkdigits_iter>
-checkdigits_iter compute_mod97_10 (const check_range& check_seq, checkdigits_iter mod97_checkdigits)
+checkdigits_iter compute_mod97_10(const check_range& check_seq, checkdigits_iter mod97_checkdigits)
{
- return boost::checks::compute_multicheckdigit<mod97_10_compute_algorithm> ( check_seq, mod97_checkdigits ) ;
+ return boost::checks::compute_multicheckdigit<mod97_10_compute_algorithm>(boost::rbegin(check_seq), boost::rend(check_seq), mod97_checkdigits);
}
Modified: sandbox/SOC/2011/checks/boost/checks/upc.hpp
==============================================================================
--- sandbox/SOC/2011/checks/boost/checks/upc.hpp (original)
+++ sandbox/SOC/2011/checks/boost/checks/upc.hpp 2012-01-18 05:29:22 EST (Wed, 18 Jan 2012)
@@ -17,10 +17,12 @@
#endif
#include <boost/checks/weight.hpp>
-#include <boost/checks/iteration_sense.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.
*/
@@ -37,19 +39,15 @@
\brief This is the weight used by UPC system.
*/
typedef boost::checks::weight<1,3> upc_weight ;
-/*!
- \brief This is the running sense or direction to check an UPC.
-*/
-typedef boost::checks::rightmost upc_sense ;
/*!
\brief This is the type of the UPC algorithm for validating a check digit.
*/
-typedef boost::checks::modulus10_algorithm< upc_weight, upc_sense, 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, upc_sense, 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.
@@ -66,7 +64,7 @@
template <typename check_range>
bool check_upca (const check_range& check_seq)
{
- return boost::checks::check_sequence<upc_check_algorithm, UPCA_SIZE> ( check_seq ) ;
+ return boost::checks::check_sequence<upc_check_algorithm, UPCA_SIZE>(boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -83,9 +81,9 @@
\returns The check digit. The check digit is in the range [0..9].
*/
template <typename check_range>
-typename boost::checks::upc_compute_algorithm::checkdigit<check_range>::type compute_upca (const check_range& check_seq)
+typename boost::range_value<check_range>::type compute_upca(const check_range& check_seq)
{
- return boost::checks::compute_checkdigit<upc_compute_algorithm, UPCA_SIZE_WITHOUT_CHECKDIGIT> ( check_seq ) ;
+ return boost::checks::compute_checkdigit<upc_compute_algorithm, UPCA_SIZE_WITHOUT_CHECKDIGIT>(boost::rbegin(check_seq), boost::rend(check_seq));
}
}} // namespace boost namespace checks
Modified: sandbox/SOC/2011/checks/boost/checks/verhoeff.hpp
==============================================================================
--- sandbox/SOC/2011/checks/boost/checks/verhoeff.hpp (original)
+++ sandbox/SOC/2011/checks/boost/checks/verhoeff.hpp 2012-01-18 05:29:22 EST (Wed, 18 Jan 2012)
@@ -1,6 +1,6 @@
// Boost checks/verhoeff.hpp header file ------------------------------------//
-// (C) Copyright Pierre Talbot 2011
-// Distributed under the Boost Software License, Version 1.0. (See
+// (C)Copyright Pierre Talbot 2011
+// Distributed under the Boost Software License, Version 1.0.(See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
// See http://www.boost.org for updates, documentation, and revision history.
@@ -20,25 +20,22 @@
#include <boost/lexical_cast.hpp>
#include <boost/checks/translation_exception.hpp>
#include <boost/checks/weight.hpp>
-#include <boost/checks/iteration_sense.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{
-/*!
- \brief This is the sense of the Verhoeff sequence iteration.
-*/
-typedef boost::checks::rightmost verhoeff_iteration_sense ;
-
/*! \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.
*/
template <unsigned int number_of_virtual_value_skipped = 0>
-struct verhoeff_algorithm : boost::checks::basic_check_algorithm<verhoeff_iteration_sense, number_of_virtual_value_skipped>
+struct verhoeff_algorithm : boost::checks::basic_check_algorithm<number_of_virtual_value_skipped>
{
/*!
\brief Compute the Verhoeff scheme on the checksum with the current valid value.
@@ -46,12 +43,12 @@
\post checksum is equal to the new computed checksum.
\param current_valid_value is the current valid value analysed.
- \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 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 use the classic table d and p of the Verhoeff algorithm.
*/
- 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(const int current_valid_value, const unsigned int valid_value_counter, int &checksum)
{
static const unsigned int d[10][10] =
{
@@ -79,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 + number_of_virtual_value_skipped)% 8][current_valid_value]];
}
/*!
@@ -91,7 +88,7 @@
*/
static bool validate_checksum(int checksum)
{
- return !checksum ;
+ return !checksum;
}
/*!
@@ -105,17 +102,17 @@
\returns The Verhoeff check digit of checksum.
*/
template <typename checkdigit>
- static checkdigit compute_checkdigit( int checksum )
+ static checkdigit compute_checkdigit(int checksum)
{
- static const unsigned int inv[] = { 0, 4, 3, 2, 1, 5, 6, 7, 8, 9 } ;
+ static const unsigned int inv[] = {0, 4, 3, 2, 1, 5, 6, 7, 8, 9};
try
{
- return boost::lexical_cast<checkdigit>( inv[checksum] ) ;
+ return boost::lexical_cast<checkdigit>(inv[checksum]);
}
- catch( boost::bad_lexical_cast )
+ catch(boost::bad_lexical_cast)
{
- throw boost::checks::translation_exception() ;
+ throw boost::checks::translation_exception();
}
}
};
@@ -123,16 +120,16 @@
/*!
\brief This is the type of the Verhoeff algorithm for validating a check digit.
*/
-typedef verhoeff_algorithm<0> verhoeff_check_algorithm ;
+typedef verhoeff_algorithm<0> verhoeff_check_algorithm;
/*!
\brief This is the type of the Verhoeff algorithm for computing a check digit.
*/
-typedef verhoeff_algorithm<1> verhoeff_compute_algorithm ;
+typedef verhoeff_algorithm<1> verhoeff_compute_algorithm;
/*!
\brief Validate a sequence according to the verhoeff_check_algorithm type.
- \pre check_seq is a valid range.\n size_expected > 0 (enforced by static assert).
+ \pre check_seq is a valid range.\n size_expected > 0(enforced by static assert).
\tparam size_expected is the number of valid value expected in the sequence.
\tparam check_range is a valid range type.
@@ -143,9 +140,9 @@
\returns @c true if the check digit is correct, @c false otherwise.
*/
template <size_t size_expected, typename check_range>
-bool check_verhoeff (const check_range& check_seq)
+bool check_verhoeff(const check_range& check_seq)
{
- return boost::checks::check_sequence<verhoeff_check_algorithm, size_expected> ( check_seq ) ;
+ return boost::checks::check_sequence<verhoeff_check_algorithm, size_expected>(boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -161,17 +158,17 @@
\returns @c true if the check digit is correct, @c false otherwise.
*/
template <typename check_range>
-bool check_verhoeff (const check_range& check_seq)
+bool check_verhoeff(const check_range& check_seq)
{
- return boost::checks::check_sequence<verhoeff_check_algorithm> ( check_seq ) ;
+ return boost::checks::check_sequence<verhoeff_check_algorithm>(boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
\brief Calculate the check digit of a sequence according to the verhoeff_compute_algorithm type.
- \pre check_seq is a valid range.\n size_expected > 0 (enforced by static assert).
+ \pre check_seq is a valid range.\n size_expected > 0(enforced by static assert).
- \tparam size_expected is the number of valid value expected in the sequence. (So the check digit is not included.)
+ \tparam size_expected is the number of valid value expected in the sequence.(So the check digit is not included.)
\tparam check_range is a valid range type.
\param check_seq is the sequence of value to check.
@@ -181,9 +178,9 @@
\returns The check digit. The check digit is in the range [0..9].
*/
template <size_t size_expected, typename check_range>
-typename boost::checks::verhoeff_compute_algorithm::checkdigit<check_range>::type compute_verhoeff (const check_range& check_seq)
+typename boost::range_value<check_range>::type compute_verhoeff(const check_range& check_seq)
{
- return boost::checks::compute_checkdigit<verhoeff_compute_algorithm, size_expected> ( check_seq ) ;
+ return boost::checks::compute_checkdigit<verhoeff_compute_algorithm, size_expected>(boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -200,11 +197,10 @@
\returns The check digit. The check digit is in the range [0..9].
*/
template <typename check_range>
-typename boost::checks::verhoeff_compute_algorithm::checkdigit<check_range>::type compute_verhoeff (const check_range& check_seq)
+typename boost::range_value<check_range>::type compute_verhoeff(const check_range& check_seq)
{
- return boost::checks::compute_checkdigit<verhoeff_compute_algorithm> ( check_seq ) ;
+ return boost::checks::compute_checkdigit<verhoeff_compute_algorithm>(boost::rbegin(check_seq), boost::rend(check_seq));
}
-
}}
#endif
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 05:29:22 EST (Wed, 18 Jan 2012)
@@ -1,6 +1,6 @@
// Boost checks/visa.hpp header file
-// (C) Copyright Pierre Talbot 2011
-// Distributed under the Boost Software License, Version 1.0. (See
+// (C)Copyright Pierre Talbot 2011
+// Distributed under the Boost Software License, Version 1.0.(See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
// See http://www.boost.org for updates, documentation, and revision history.
@@ -18,12 +18,15 @@
#include <boost/checks/luhn.hpp>
+#include <boost/range/rbegin.hpp>
+#include <boost/range/rend.hpp>
+
/*!
- \brief This macro defines the size of a Visa number (16).
+ \brief This macro defines the size of a Visa number.
*/
#define VISA_SIZE 16
/*!
- \brief This macro defines the size of a Visa number without its check digit (15).
+ \brief This macro defines the size of a Visa number without its check digit.
*/
#define VISA_SIZE_WITHOUT_CHECKDIGIT 15
@@ -42,29 +45,29 @@
\brief Verify that a number matches the Visa 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 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).
\throws std::invalid_argument if the first character is not equal to 4. The exception contains a descriptive message of what was expected.
\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(const unsigned int current_valid_value, const 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 - number_of_virtual_value_skipped;
- 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!") ;
+ 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!");
}
};
/*!
\brief This is the type of the Visa algorithm for validating a check digit.
*/
-typedef visa_algorithm<0> visa_check_algorithm ;
+typedef visa_algorithm<0> visa_check_algorithm;
/*!
\brief This is the type of the Visa algorithm for computing a check digit.
*/
-typedef visa_algorithm<1> visa_compute_algorithm ;
+typedef visa_algorithm<1> visa_compute_algorithm;
/*!
\brief Validate a sequence according to the visa_check_algorithm type.
@@ -75,14 +78,14 @@
\param check_seq is the sequence of value to check.
\throws std::invalid_argument if check_seq doesn't contain exactly VISA_SIZE digits.
- \throws std::invalid_argument if the first digit (from the leftmost) doesn't match the Visa pattern.
+ \throws std::invalid_argument if the first digit(from the leftmost)doesn't match the Visa pattern.
\returns @c true if the check digit is correct, @c false otherwise.
*/
template <typename check_range>
-bool check_visa (const check_range& check_seq)
+bool check_visa(const check_range& check_seq)
{
- return boost::checks::check_sequence<visa_check_algorithm, VISA_SIZE>(check_seq);
+ return boost::checks::check_sequence<visa_check_algorithm, VISA_SIZE>(boost::rbegin(check_seq), boost::rend(check_seq));
}
/*!
@@ -94,15 +97,15 @@
\param check_seq is the sequence of value to check.
\throws std::invalid_argument if check_seq doesn't contain exactly VISA_SIZE_WITHOUT_CHECKDIGIT digits.
- \throws std::invalid_argument if the first digit (from the leftmost) doESn't match the Visa pattern.
+ \throws std::invalid_argument if the first digit(from the leftmost)doESn't match the Visa pattern.
\throws boost::checks::translation_exception if the check digit cannot be translated into the checkdigit type.
\returns The check digit. The check digit is in the range [0..9].
*/
template <typename check_range>
-typename boost::checks::visa_compute_algorithm::checkdigit<check_range>::type compute_visa (const check_range& check_seq)
+typename boost::range_value<check_range>::type compute_visa(const check_range& check_seq)
{
- return boost::checks::compute_checkdigit<visa_compute_algorithm, VISA_SIZE_WITHOUT_CHECKDIGIT>(check_seq);
+ return boost::checks::compute_checkdigit<visa_compute_algorithm, VISA_SIZE_WITHOUT_CHECKDIGIT>(boost::rbegin(check_seq), boost::rend(check_seq));
}
Modified: sandbox/SOC/2011/checks/boost/checks/weight.hpp
==============================================================================
--- sandbox/SOC/2011/checks/boost/checks/weight.hpp (original)
+++ sandbox/SOC/2011/checks/boost/checks/weight.hpp 2012-01-18 05:29:22 EST (Wed, 18 Jan 2012)
@@ -65,4 +65,4 @@
}} // namespace boost namespace checks
-#endif //BOOST_CHECK_WEIGHT_HPP
\ No newline at end of file
+#endif //BOOST_CHECK_WEIGHT_HPP
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-18 05:29:22 EST (Wed, 18 Jan 2012)
@@ -17,7 +17,6 @@
#endif
#include <boost/checks/weight.hpp>
-#include <boost/checks/iteration_sense.hpp>
#include <boost/checks/basic_checks.hpp>
#include <boost/checks/basic_check_algorithm.hpp>
@@ -31,8 +30,8 @@
\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.
*/
-template <typename weight, typename iteration_sense, unsigned int number_of_virtual_value_skipped = 0>
-struct weighted_sum_algorithm : boost::checks::basic_check_algorithm<iteration_sense>
+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>
{
/*!
\brief Compute an operation on the checksum with the current valid value.
@@ -43,10 +42,10 @@
\param valid_value_counter is the number of valid values 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.
*/
- 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(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 ) ;
- checksum += current_valid_value * current_weight ;
+ int current_weight = weight::weight_associated_with_pos(valid_value_counter + number_of_virtual_value_skipped);
+ checksum += current_valid_value * current_weight;
}
};
Modified: sandbox/SOC/2011/checks/libs/checks/example/rtn.hpp
==============================================================================
--- sandbox/SOC/2011/checks/libs/checks/example/rtn.hpp (original)
+++ sandbox/SOC/2011/checks/libs/checks/example/rtn.hpp 2012-01-18 05:29:22 EST (Wed, 18 Jan 2012)
@@ -1,6 +1,6 @@
// rtn.hpp
//! \file
-//! \brief Check and compute the Routing Transit Number (RTN)
+//! \brief Check and compute the Routing Transit Number(RTN)
//! as an example of implementing a new checksum type.
/*! \detail Routing Transit Number
http://en.wikipedia.org/wiki/Routing_transit_number
@@ -10,7 +10,7 @@
// Use, modification and distribution are subject to the
// Boost Software License, Version 1.0.
-// (See accompanying file LICENSE_1_0.txt
+//(See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_CHECKS_RTN_HPP
@@ -19,32 +19,33 @@
//[rtn_include_files
#include <boost/checks/modulus10.hpp>
#include <boost/checks/basic_checks.hpp>
+#include <boost/range/begin.hpp>
+#include <boost/range/end.hpp>
//]
//[rtn_preprocessor_tools
#define RTN_SIZE 9
#define RTN_SIZE_WITHOUT_CHECKDIGIT 8
-typedef boost::checks::weight<3,7,1> rtn_weight ;
-typedef boost::checks::leftmost rtn_direction ;
+typedef boost::checks::weight<3,7,1> rtn_weight;
//]
//[rtn_preprocessor_algorithm
-typedef boost::checks::modulus10_algorithm < rtn_weight, rtn_direction, 0> rtn_check_algorithm ;
-typedef boost::checks::modulus10_algorithm < rtn_weight, rtn_direction, 0> rtn_compute_algorithm ;
+typedef boost::checks::modulus10_algorithm<rtn_weight, 0> rtn_check_algorithm;
+typedef boost::checks::modulus10_algorithm<rtn_weight, 0> rtn_compute_algorithm;
//]
//[rtn_functions
template <typename check_range>
-bool check_rtn (const check_range& check_seq)
+bool check_rtn(const check_range& check_seq)
{
- return boost::checks::check_sequence<rtn_check_algorithm, RTN_SIZE> ( check_seq ) ;
+ return boost::checks::check_sequence<rtn_check_algorithm, RTN_SIZE>(boost::begin(check_seq), boost::end(check_seq));
}
template <typename check_range>
-typename rtn_compute_algorithm::checkdigit<check_range>::type compute_rtn (const check_range& check_seq)
+typename rtn_compute_algorithm::checkdigit<check_range>::type compute_rtn(const check_range& check_seq)
{
- return boost::checks::compute_checkdigit<rtn_compute_algorithm, RTN_SIZE_WITHOUT_CHECKDIGIT> ( check_seq ) ;
+ return boost::checks::compute_checkdigit<rtn_compute_algorithm, RTN_SIZE_WITHOUT_CHECKDIGIT>(boost::begin(check_seq), boost::end(check_seq));
}
//]
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-18 05:29:22 EST (Wed, 18 Jan 2012)
@@ -10,7 +10,7 @@
// Use, modification and distribution are subject to the
// Boost Software License, Version 1.0.
-// (See accompanying file LICENSE_1_0.txt
+//(See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_CHECKS_VIN_HPP
@@ -19,30 +19,31 @@
//[vin_preprocessor_tools
#include <boost/checks/modulus11.hpp>
#include <boost/checks/basic_checks.hpp>
+#include <boost/range/rbegin.hpp>
+#include <boost/range/rend.hpp>
#define VIN_SIZE 17
#define VIN_SIZE_WITHOUT_CHECKDIGIT 16
#define VIN_CHECKDIGIT_POS 8
-typedef boost::checks::weight<2,3,4,5,6,7,8,9,10> vin_weight ;
-typedef boost::checks::rightmost vin_sense ;
+typedef boost::checks::weight<2,3,4,5,6,7,8,9,10> vin_weight;
//]
//[vin_struct_header
template <unsigned int number_of_virtual_value_skipped = 0>
-struct vin_algorithm : boost::checks::modulus11_algorithm<vin_weight, vin_sense, number_of_virtual_value_skipped>
+struct vin_algorithm : boost::checks::modulus11_algorithm<vin_weight, number_of_virtual_value_skipped>
//]
{
//[vin_translation_module
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, unsigned int valid_value_counter)
{
int valid_value = 0;
try
{
- valid_value = boost::lexical_cast<int>( current_value ) ;
+ valid_value = boost::lexical_cast<int>(current_value);
}
- catch( boost::bad_lexical_cast )
+ catch(boost::bad_lexical_cast)
{
// Transform the value to be between 1 and 26.
if(current_value >= 'a' && current_value <= 'z')
@@ -52,19 +53,19 @@
else
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." );
+ if(valid_value == 9 || valid_value == 15 || valid_value == 17)
+ throw std::invalid_argument("The letter I, O and Q are not allowed.");
- if (valid_value_counter == VIN_CHECKDIGIT_POS && number_of_virtual_value_skipped == 0)
+ if(valid_value_counter == VIN_CHECKDIGIT_POS && number_of_virtual_value_skipped == 0)
{
- if (valid_value != 24)
+ if(valid_value != 24)
throw std::invalid_argument("The check digit should be a digit or X or x.");
else
- valid_value = 10 ;
+ valid_value = 10;
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();
@@ -76,43 +77,43 @@
//[vin_operation_module
static void operate_on_valid_value(const int current_valid_value, const unsigned int valid_value_counter, int &checksum)
{
- if( number_of_virtual_value_skipped == 0 && valid_value_counter == VIN_CHECKDIGIT_POS )
- checksum += current_valid_value ;
+ if(number_of_virtual_value_skipped == 0 && valid_value_counter == VIN_CHECKDIGIT_POS)
+ checksum += current_valid_value;
else
{
- unsigned int weight_position = valid_value_counter - (number_of_virtual_value_skipped == 0 && valid_value_counter > VIN_CHECKDIGIT_POS) ;
- int current_weight = vin_weight::weight_associated_with_pos(weight_position) ;
- checksum += current_valid_value * current_weight ;
+ unsigned int weight_position = valid_value_counter - (number_of_virtual_value_skipped == 0 && valid_value_counter > VIN_CHECKDIGIT_POS);
+ int current_weight = vin_weight::weight_associated_with_pos(weight_position);
+ checksum += current_valid_value * current_weight;
}
}
//]
//[vin_compute_checkdigit
template <typename checkdigit>
- static typename checkdigit compute_checkdigit( int checksum )
+ static typename checkdigit compute_checkdigit(int checksum)
{
- typedef typename boost::checks::modulus11_algorithm<vin_weight, vin_sense, number_of_virtual_value_skipped> mod11 ;
- return mod11::translate_checkdigit<checkdigit>(checksum % 11) ;
+ typedef typename boost::checks::modulus11_algorithm<vin_weight, number_of_virtual_value_skipped> mod11;
+ return mod11::translate_checkdigit<checkdigit>(checksum % 11);
}
//]
};
//[vin_preprocessor_algorithm
-typedef vin_algorithm <0> vin_check_algorithm ;
-typedef vin_algorithm <1> vin_compute_algorithm ;
+typedef vin_algorithm <0> vin_check_algorithm;
+typedef vin_algorithm <1> vin_compute_algorithm;
//]
//[vin_functions
template <typename check_range>
-bool check_vin (const check_range& check_seq)
+bool check_vin(const check_range& check_seq)
{
- return boost::checks::check_sequence<vin_check_algorithm, VIN_SIZE> ( check_seq ) ;
+ return boost::checks::check_sequence<vin_check_algorithm, VIN_SIZE>(boost::rbegin(check_seq), boost::rend(check_seq));
}
template <typename check_range>
-typename vin_compute_algorithm::checkdigit<check_range>::type compute_vin (const check_range& check_seq)
+typename vin_compute_algorithm::checkdigit<check_range>::type compute_vin(const check_range& check_seq)
{
- return boost::checks::compute_checkdigit<vin_compute_algorithm, VIN_SIZE_WITHOUT_CHECKDIGIT> ( check_seq ) ;
+ return boost::checks::compute_checkdigit<vin_compute_algorithm, VIN_SIZE_WITHOUT_CHECKDIGIT>(boost::rbegin(check_seq), boost::rend(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-01-18 05:29:22 EST (Wed, 18 Jan 2012)
@@ -4,7 +4,7 @@
// Use, modification and distribution are subject to the
// Boost Software License, Version 1.0.
-// (See accompanying file LICENSE_1_0.txt
+//(See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)
// Boost test of various check 'digit' systems.
@@ -14,7 +14,7 @@
#define BOOST_TEST_MAIN
#define BOOST_TEST_MODULE "Check Test Suite"
#define BOOST_LIB_DIAGNOSTIC "on"// Show library file details.
-// Linking to lib file: libboost_unit_test_framework-vc100-mt-gd-1_47.lib (trunk at 12 Jun 11)
+// Linking to lib file: libboost_unit_test_framework-vc100-mt-gd-1_47.lib (trunk at 12 Jun 11)
#include <iostream>
#include <iomanip>
@@ -37,176 +37,176 @@
#include "transposition_test.hpp"
template <typename functor>
-unsigned int transposition( const functor &compute_checkdigit );
+unsigned int transposition(const functor &compute_checkdigit);
template <typename functor>
-unsigned int alteration( const functor &compute_checkdigit , unsigned int number_of_position_to_test );
+unsigned int alteration(const functor &compute_checkdigit , unsigned int number_of_position_to_test);
-BOOST_AUTO_TEST_SUITE( use_cases_tests )
+BOOST_AUTO_TEST_SUITE(use_cases_tests)
// IIN : Issuer Identification Number.
// MII : Major Industry Identifier.
BOOST_AUTO_TEST_CASE(visa_tests)
{
- std::string visa_valid = "4417 1234 5678 9113" ;
- std::string visa_low_size_failure = "417 1234 5678 9113" ; // A missing digit '4'.
- std::string visa_big_size_failure = "44417 1234 5678 9113" ; // An extra '4' digit.
- std::string visa_mii_failure = "3417 1234 5678 9113" ;
-
- BOOST_CHECK ( boost::checks::check_visa (visa_valid) ) ;
- BOOST_CHECK_THROW ( boost::checks::check_visa (visa_low_size_failure) , std::invalid_argument ) ;
- BOOST_CHECK_THROW ( boost::checks::check_visa (visa_big_size_failure) , std::invalid_argument ) ;
- BOOST_CHECK_THROW ( boost::checks::check_visa (visa_mii_failure) , std::invalid_argument ) ;
+ std::string visa_valid = "4417 1234 5678 9113";
+ std::string visa_low_size_failure = "417 1234 5678 9113"; // A missing digit '4'.
+ std::string visa_big_size_failure = "44417 1234 5678 9113"; // An extra '4' digit.
+ std::string visa_mii_failure = "3417 1234 5678 9113";
+
+ BOOST_CHECK(boost::checks::check_visa(visa_valid));
+ BOOST_CHECK_THROW(boost::checks::check_visa(visa_low_size_failure), std::invalid_argument);
+ BOOST_CHECK_THROW(boost::checks::check_visa(visa_big_size_failure), std::invalid_argument);
+ BOOST_CHECK_THROW(boost::checks::check_visa(visa_mii_failure), std::invalid_argument);
- std::string visa_valid_without_checkdigit = "4417 1234 5678 911" ;
- std::string visa_mii_failure_without_checkdigit = "3417 1234 5678 911" ;
+ std::string visa_valid_without_checkdigit = "4417 1234 5678 911";
+ std::string visa_mii_failure_without_checkdigit = "3417 1234 5678 911";
- BOOST_CHECK_EQUAL ( boost::checks::compute_visa (visa_valid_without_checkdigit) , '3' ) ;
- BOOST_CHECK_THROW ( boost::checks::compute_visa (visa_mii_failure_without_checkdigit) , std::invalid_argument ) ;
+ BOOST_CHECK_EQUAL(boost::checks::compute_visa(visa_valid_without_checkdigit), '3');
+ BOOST_CHECK_THROW(boost::checks::compute_visa(visa_mii_failure_without_checkdigit), std::invalid_argument);
}
BOOST_AUTO_TEST_CASE(amex_tests)
{
- std::string amex_valid = "3782 822463 10005" ;
- std::string amex_low_size_failure = "378 822463 10005" ;
- std::string amex_big_size_failure = "33782 822463 10005" ;
- std::string amex_mii_failure = "4782 822463 10005" ;
- std::string amex_iin_failure = "3882 822463 10005" ;
-
- BOOST_CHECK ( boost::checks::check_amex (amex_valid) ) ;
- BOOST_CHECK_THROW ( boost::checks::check_amex (amex_low_size_failure) , std::invalid_argument ) ;
- BOOST_CHECK_THROW ( boost::checks::check_amex (amex_big_size_failure) , std::invalid_argument ) ;
- BOOST_CHECK_THROW ( boost::checks::check_amex (amex_mii_failure) , std::invalid_argument ) ;
- BOOST_CHECK_THROW ( boost::checks::check_amex (amex_iin_failure) , std::invalid_argument ) ;
-
- std::string amex_valid_without_checkdigit = "3782 822463 1000" ;
- std::string amex_mii_failure_without_checkdigit = "4782 822463 1000" ;
- std::string amex_iin_failure_without_checkdigit = "3682 822463 1000" ;
+ std::string amex_valid = "3782 822463 10005";
+ std::string amex_low_size_failure = "378 822463 10005";
+ std::string amex_big_size_failure = "33782 822463 10005";
+ std::string amex_mii_failure = "4782 822463 10005";
+ std::string amex_iin_failure = "3882 822463 10005";
+
+ BOOST_CHECK(boost::checks::check_amex(amex_valid));
+ BOOST_CHECK_THROW(boost::checks::check_amex(amex_low_size_failure), std::invalid_argument);
+ BOOST_CHECK_THROW(boost::checks::check_amex(amex_big_size_failure), std::invalid_argument);
+ BOOST_CHECK_THROW(boost::checks::check_amex(amex_mii_failure), std::invalid_argument);
+ BOOST_CHECK_THROW(boost::checks::check_amex(amex_iin_failure), std::invalid_argument);
+
+ std::string amex_valid_without_checkdigit = "3782 822463 1000";
+ std::string amex_mii_failure_without_checkdigit = "4782 822463 1000";
+ std::string amex_iin_failure_without_checkdigit = "3682 822463 1000";
- BOOST_CHECK_EQUAL ( boost::checks::compute_amex (amex_valid_without_checkdigit) , '5' ) ;
- BOOST_CHECK_THROW ( boost::checks::compute_amex (amex_mii_failure_without_checkdigit) , std::invalid_argument ) ;
+ BOOST_CHECK_EQUAL(boost::checks::compute_amex(amex_valid_without_checkdigit), '5');
+ BOOST_CHECK_THROW(boost::checks::compute_amex(amex_mii_failure_without_checkdigit), std::invalid_argument);
}
BOOST_AUTO_TEST_CASE(mastercard_tests)
{
- std::string mastercard_valid = "5105 1051 0510 5100" ;
- std::string mastercard_low_size_failure = "515 1051 0510 5100" ;
- std::string mastercard_big_size_failure = "51505 1051 0510 5100" ;
- std::string mastercard_mii_failure = "4105 1051 0510 5100" ;
- std::string mastercard_iin_failure = "5005 1051 0510 5100" ;
-
- BOOST_CHECK ( boost::checks::check_mastercard (mastercard_valid) ) ;
- BOOST_CHECK_THROW ( boost::checks::check_mastercard (mastercard_low_size_failure) , std::invalid_argument ) ;
- BOOST_CHECK_THROW ( boost::checks::check_mastercard (mastercard_big_size_failure) , std::invalid_argument ) ;
- BOOST_CHECK_THROW ( boost::checks::check_mastercard (mastercard_mii_failure) , std::invalid_argument ) ;
- BOOST_CHECK_THROW ( boost::checks::check_mastercard (mastercard_iin_failure) , std::invalid_argument ) ;
-
- std::string mastercard_valid_without_checkdigit = "5105 1051 0510 510" ;
- std::string mastercard_mii_failure_without_checkdigit = "6105 1051 0510 510" ;
- std::string mastercard_iin_failure_without_checkdigit = "5605 1051 0510 510" ;
+ std::string mastercard_valid = "5105 1051 0510 5100";
+ std::string mastercard_low_size_failure = "515 1051 0510 5100";
+ std::string mastercard_big_size_failure = "51505 1051 0510 5100";
+ std::string mastercard_mii_failure = "4105 1051 0510 5100";
+ std::string mastercard_iin_failure = "5005 1051 0510 5100";
+
+ BOOST_CHECK(boost::checks::check_mastercard(mastercard_valid));
+ BOOST_CHECK_THROW(boost::checks::check_mastercard(mastercard_low_size_failure), std::invalid_argument);
+ BOOST_CHECK_THROW(boost::checks::check_mastercard(mastercard_big_size_failure), std::invalid_argument);
+ BOOST_CHECK_THROW(boost::checks::check_mastercard(mastercard_mii_failure), std::invalid_argument);
+ BOOST_CHECK_THROW(boost::checks::check_mastercard(mastercard_iin_failure), std::invalid_argument);
+
+ std::string mastercard_valid_without_checkdigit = "5105 1051 0510 510";
+ std::string mastercard_mii_failure_without_checkdigit = "6105 1051 0510 510";
+ std::string mastercard_iin_failure_without_checkdigit = "5605 1051 0510 510";
- BOOST_CHECK_EQUAL ( boost::checks::compute_mastercard (mastercard_valid_without_checkdigit) , '0' ) ;
- BOOST_CHECK_THROW ( boost::checks::compute_mastercard (mastercard_mii_failure_without_checkdigit) , std::invalid_argument ) ;
+ BOOST_CHECK_EQUAL(boost::checks::compute_mastercard(mastercard_valid_without_checkdigit), '0');
+ BOOST_CHECK_THROW(boost::checks::compute_mastercard(mastercard_mii_failure_without_checkdigit), std::invalid_argument);
}
BOOST_AUTO_TEST_CASE(ean_tests)
{
- std::string ean13_valid = "5 412983 130028" ; // Belgium beer "Bon secours".
- std::string ean13_low_size_failure = "05 412983 130028" ;
- std::string ean13_big_size_failure = "412983 130028" ;
-
- BOOST_CHECK ( boost::checks::check_ean13 (ean13_valid) ) ;
- BOOST_CHECK_THROW ( boost::checks::check_ean13 (ean13_low_size_failure) , std::invalid_argument ) ;
- BOOST_CHECK_THROW ( boost::checks::check_ean13 (ean13_big_size_failure) , std::invalid_argument ) ;
-
- std::string ean13_valid_without_checkdigit = "5 412983 13002" ;
- BOOST_CHECK_EQUAL ( boost::checks::compute_ean13 (ean13_valid_without_checkdigit), '8' ) ;
-
- std::string ean8_valid = "5449 1472" ; // Bottle of Coke.
- std::string ean8_low_size_failure = "5449 472" ;
- std::string ean8_big_size_failure = "05449 1472" ;
-
- BOOST_CHECK ( boost::checks::check_ean8 (ean8_valid) ) ;
- BOOST_CHECK_THROW ( boost::checks::check_ean8 (ean8_low_size_failure) , std::invalid_argument ) ;
- BOOST_CHECK_THROW ( boost::checks::check_ean8 (ean8_big_size_failure) , std::invalid_argument ) ;
+ std::string ean13_valid = "5 412983 130028"; // Belgium beer "Bon secours".
+ std::string ean13_low_size_failure = "05 412983 130028";
+ std::string ean13_big_size_failure = "412983 130028";
+
+ BOOST_CHECK(boost::checks::check_ean13(ean13_valid));
+ BOOST_CHECK_THROW(boost::checks::check_ean13(ean13_low_size_failure), std::invalid_argument);
+ BOOST_CHECK_THROW(boost::checks::check_ean13(ean13_big_size_failure), std::invalid_argument);
+
+ std::string ean13_valid_without_checkdigit = "5 412983 13002";
+ BOOST_CHECK_EQUAL(boost::checks::compute_ean13(ean13_valid_without_checkdigit), '8');
+
+ std::string ean8_valid = "5449 1472"; // Bottle of Coke.
+ std::string ean8_low_size_failure = "5449 472";
+ std::string ean8_big_size_failure = "05449 1472";
+
+ BOOST_CHECK(boost::checks::check_ean8(ean8_valid));
+ BOOST_CHECK_THROW(boost::checks::check_ean8(ean8_low_size_failure), std::invalid_argument);
+ BOOST_CHECK_THROW(boost::checks::check_ean8(ean8_big_size_failure), std::invalid_argument);
- std::string ean8_valid_without_checkdigit = "5449 147" ;
- BOOST_CHECK_EQUAL ( boost::checks::compute_ean8 (ean8_valid_without_checkdigit), '2' ) ;
+ std::string ean8_valid_without_checkdigit = "5449 147";
+ BOOST_CHECK_EQUAL(boost::checks::compute_ean8(ean8_valid_without_checkdigit), '2');
}
BOOST_AUTO_TEST_CASE(upc_tests)
{
- std::string upca_valid = "036000291452" ; // Box of tissues.
- std::string upca_low_size_failure = "36000291452" ;
- std::string upca_big_size_failure = "0036000291452" ;
-
- BOOST_CHECK ( boost::checks::check_upca (upca_valid) ) ;
- BOOST_CHECK_THROW ( boost::checks::check_upca (upca_low_size_failure) , std::invalid_argument ) ;
- BOOST_CHECK_THROW ( boost::checks::check_upca (upca_big_size_failure) , std::invalid_argument ) ;
+ std::string upca_valid = "036000291452"; // Box of tissues.
+ std::string upca_low_size_failure = "36000291452";
+ std::string upca_big_size_failure = "0036000291452";
+
+ BOOST_CHECK(boost::checks::check_upca(upca_valid));
+ BOOST_CHECK_THROW(boost::checks::check_upca(upca_low_size_failure), std::invalid_argument);
+ BOOST_CHECK_THROW(boost::checks::check_upca(upca_big_size_failure), std::invalid_argument);
- std::string upca_valid_without_checkdigit = "03600029145" ;
- BOOST_CHECK_EQUAL ( boost::checks::compute_upca (upca_valid_without_checkdigit), '2' ) ;
+ std::string upca_valid_without_checkdigit = "03600029145";
+ BOOST_CHECK_EQUAL(boost::checks::compute_upca(upca_valid_without_checkdigit), '2');
}
BOOST_AUTO_TEST_CASE(isbn_tests)
{
- std::string isbn13_valid = "978-0-13-235088-4" ; // Clean Code: a handbook of agile software craftsmanship, Robert C. Martin.
- std::string isbn13_not_valid = "979-0-13-235088-4" ;
- std::string isbn13_low_size_failure = "978--13-235088-4" ;
- std::string isbn13_big_size_failure = "978-00-13-235088-4" ;
- std::string isbn13_ean_id_failure = "977-0-13-235088-4" ;
- std::string isbn13_ean_id_failure2 = "988-0-13-235088-4" ;
- std::string isbn13_ean_id_failure3 = "878-0-13-235088-4" ;
-
- BOOST_CHECK ( boost::checks::check_isbn13 (isbn13_valid) ) ;
- BOOST_CHECK ( !boost::checks::check_isbn13 (isbn13_not_valid) ) ;
- BOOST_CHECK_THROW ( boost::checks::check_isbn13 (isbn13_low_size_failure) , std::invalid_argument ) ;
- BOOST_CHECK_THROW ( boost::checks::check_isbn13 (isbn13_big_size_failure) , std::invalid_argument ) ;
- BOOST_CHECK_THROW ( boost::checks::check_isbn13 (isbn13_ean_id_failure) , std::invalid_argument ) ;
- BOOST_CHECK_THROW ( boost::checks::check_isbn13 (isbn13_ean_id_failure2) , std::invalid_argument ) ;
- BOOST_CHECK_THROW ( boost::checks::check_isbn13 (isbn13_ean_id_failure3) , std::invalid_argument ) ;
-
- std::string isbn13_valid_without_checkdigit = "978-0-13-235088-" ;
- std::string isbn13_not_valid_without_checkdigit = "979-0-13-235088-" ;
- BOOST_CHECK_EQUAL ( boost::checks::compute_isbn13 (isbn13_valid_without_checkdigit), '4' ) ;
- BOOST_CHECK_NE ( boost::checks::compute_isbn13 (isbn13_not_valid_without_checkdigit), '4' ) ;
-
- std::string isbn10_valid = "0-201-70073-5" ; // The C++ Programming Language, Special Edition, Bjarne Stroustrup.
- std::string isbn10_low_size_failure = "00-201-70073-5" ;
- std::string isbn10_big_size_failure = "-201-70073-5" ;
-
- BOOST_CHECK ( boost::checks::check_isbn10 (isbn10_valid) ) ;
- BOOST_CHECK_THROW ( boost::checks::check_isbn10 (isbn10_low_size_failure) , std::invalid_argument ) ;
- BOOST_CHECK_THROW ( boost::checks::check_isbn10 (isbn10_big_size_failure) , std::invalid_argument ) ;
+ std::string isbn13_valid = "978-0-13-235088-4"; // Clean Code: a handbook of agile software craftsmanship, Robert C. Martin.
+ std::string isbn13_not_valid = "979-0-13-235088-4";
+ std::string isbn13_low_size_failure = "978--13-235088-4";
+ std::string isbn13_big_size_failure = "978-00-13-235088-4";
+ std::string isbn13_ean_id_failure = "977-0-13-235088-4";
+ std::string isbn13_ean_id_failure2 = "988-0-13-235088-4";
+ std::string isbn13_ean_id_failure3 = "878-0-13-235088-4";
+
+ BOOST_CHECK(boost::checks::check_isbn13(isbn13_valid));
+ BOOST_CHECK(!boost::checks::check_isbn13(isbn13_not_valid));
+ BOOST_CHECK_THROW(boost::checks::check_isbn13(isbn13_low_size_failure), std::invalid_argument);
+ BOOST_CHECK_THROW(boost::checks::check_isbn13(isbn13_big_size_failure), std::invalid_argument);
+ BOOST_CHECK_THROW(boost::checks::check_isbn13(isbn13_ean_id_failure), std::invalid_argument);
+ BOOST_CHECK_THROW(boost::checks::check_isbn13(isbn13_ean_id_failure2), std::invalid_argument);
+ BOOST_CHECK_THROW(boost::checks::check_isbn13(isbn13_ean_id_failure3), std::invalid_argument);
+
+ std::string isbn13_valid_without_checkdigit = "978-0-13-235088-";
+ std::string isbn13_not_valid_without_checkdigit = "979-0-13-235088-";
+ BOOST_CHECK_EQUAL(boost::checks::compute_isbn13(isbn13_valid_without_checkdigit), '4');
+ BOOST_CHECK_NE(boost::checks::compute_isbn13(isbn13_not_valid_without_checkdigit), '4');
+
+ std::string isbn10_valid = "0-201-70073-5"; // The C++ Programming Language, Special Edition, Bjarne Stroustrup.
+ std::string isbn10_low_size_failure = "00-201-70073-5";
+ std::string isbn10_big_size_failure = "-201-70073-5";
+
+ BOOST_CHECK(boost::checks::check_isbn10(isbn10_valid));
+ BOOST_CHECK_THROW(boost::checks::check_isbn10(isbn10_low_size_failure), std::invalid_argument);
+ BOOST_CHECK_THROW(boost::checks::check_isbn10(isbn10_big_size_failure), std::invalid_argument);
- std::string isbn10_valid_without_checkdigit = "0-201-70073-" ;
- BOOST_CHECK_EQUAL ( boost::checks::compute_isbn10 (isbn10_valid_without_checkdigit), '5' ) ;
+ std::string isbn10_valid_without_checkdigit = "0-201-70073-";
+ BOOST_CHECK_EQUAL(boost::checks::compute_isbn10(isbn10_valid_without_checkdigit), '5');
}
BOOST_AUTO_TEST_CASE(mod97_10_tests)
{
- std::string mod97_10_valid = "510007547061111462" ; // From a Belgium IBAN
- std::string mod97_10_not_valid = "511007547061111462" ;
- std::string mod97_10_low_size_failure = "51007547061111462" ;
- std::string mod97_10_big_size_failure = "5100007547061111462" ;
-
- BOOST_CHECK ( boost::checks::check_mod97_10 (mod97_10_valid) ) ;
- BOOST_CHECK ( !boost::checks::check_mod97_10 (mod97_10_not_valid) ) ;
- BOOST_CHECK ( !boost::checks::check_mod97_10 (mod97_10_low_size_failure)) ;
- BOOST_CHECK ( !boost::checks::check_mod97_10 (mod97_10_big_size_failure)) ;
-
- std::string mod97_10_valid_without_checkdigits = "5100075470611114" ;
- std::string mod97_10_not_valid_without_checkdigits = "5110075470611114" ;
-
- std::string valid_check_digits = "00" ;
- boost::checks::compute_mod97_10 (mod97_10_valid_without_checkdigits, valid_check_digits.begin() );
- BOOST_CHECK_EQUAL ( valid_check_digits, "62" ) ;
+ std::string mod97_10_valid = "510007547061111462"; // From a Belgium IBAN
+ std::string mod97_10_not_valid = "511007547061111462";
+ std::string mod97_10_low_size_failure = "51007547061111462";
+ std::string mod97_10_big_size_failure = "5100007547061111462";
+
+ BOOST_CHECK(boost::checks::check_mod97_10(mod97_10_valid));
+ BOOST_CHECK(!boost::checks::check_mod97_10(mod97_10_not_valid));
+ BOOST_CHECK(!boost::checks::check_mod97_10(mod97_10_low_size_failure));
+ BOOST_CHECK(!boost::checks::check_mod97_10(mod97_10_big_size_failure));
+
+ std::string mod97_10_valid_without_checkdigits = "5100075470611114";
+ std::string mod97_10_not_valid_without_checkdigits = "5110075470611114";
+
+ std::string valid_check_digits = "00";
+ boost::checks::compute_mod97_10(mod97_10_valid_without_checkdigits, valid_check_digits.begin());
+ BOOST_CHECK_EQUAL(valid_check_digits, "62");
std::string invalid_check_digits = "00";
- boost::checks::compute_mod97_10 (mod97_10_not_valid_without_checkdigits, invalid_check_digits.begin() );
- BOOST_CHECK_NE ( invalid_check_digits, "62" ) ;
+ boost::checks::compute_mod97_10(mod97_10_not_valid_without_checkdigits, invalid_check_digits.begin());
+ BOOST_CHECK_NE(invalid_check_digits, "62");
}
BOOST_AUTO_TEST_SUITE_END()
@@ -214,60 +214,60 @@
-BOOST_AUTO_TEST_SUITE( technical_tests )
+BOOST_AUTO_TEST_SUITE(technical_tests)
struct luhn_functor
{
template <typename range>
- typename boost::checks::luhn_compute_algorithm::checkdigit<range>::type operator ()( const range &check_range ) const
+ typename boost::range_value<range>::type operator()(const range &check_range)const
{
- return boost::checks::compute_luhn( check_range ) ;
+ return boost::checks::compute_luhn(check_range);
}
};
struct verhoeff_functor
{
template <typename range>
- typename boost::checks::verhoeff_compute_algorithm::checkdigit<range>::type operator ()( const range &check_range ) const
+ typename boost::range_value<range>::type operator()(const range &check_range)const
{
- return boost::checks::compute_verhoeff( check_range ) ;
+ return boost::checks::compute_verhoeff(check_range);
}
};
struct modulus11_functor
{
template <typename range>
- typename boost::checks::mod11_compute_algorithm::checkdigit<range>::type operator ()( const range &check_range ) const
+ typename boost::range_value<range>::type operator()(const range &check_range)const
{
- return boost::checks::compute_modulus11( check_range ) ;
+ return boost::checks::compute_modulus11(check_range);
}
};
BOOST_AUTO_TEST_CASE(luhn_test)
{
- unsigned int transpositions_failures = transposition( luhn_functor() ) ;
- BOOST_CHECK_MESSAGE( transpositions_failures == 2, "" << (90-transpositions_failures) << " caught on 90.") ;
+ unsigned int transpositions_failures = transposition(luhn_functor());
+ BOOST_CHECK_MESSAGE(transpositions_failures == 2, "" <<(90-transpositions_failures)<< " caught on 90.");
- unsigned int alterations_failures = alteration( luhn_functor() , 2) ;
- BOOST_CHECK_MESSAGE( alterations_failures == 0, "" << (18-alterations_failures) << " caught on 18.") ;
+ unsigned int alterations_failures = alteration(luhn_functor(), 2);
+ BOOST_CHECK_MESSAGE(alterations_failures == 0, "" <<(18-alterations_failures)<< " caught on 18.");
}
BOOST_AUTO_TEST_CASE(verhoeff_test)
{
- unsigned int transpositions_failures = transposition( verhoeff_functor() ) ;
- BOOST_CHECK_MESSAGE( transpositions_failures == 0, "" << (90-transpositions_failures) << " caught on 90.") ;
+ unsigned int transpositions_failures = transposition(verhoeff_functor());
+ BOOST_CHECK_MESSAGE(transpositions_failures == 0, "" <<(90-transpositions_failures)<< " caught on 90.");
- unsigned int alterations_failures = alteration( verhoeff_functor() , 20) ;
- BOOST_CHECK_MESSAGE( alterations_failures == 0, "" << (180-alterations_failures) << " caught on 180.") ;
+ unsigned int alterations_failures = alteration(verhoeff_functor(), 20);
+ BOOST_CHECK_MESSAGE(alterations_failures == 0, "" <<(180-alterations_failures)<< " caught on 180.");
}
BOOST_AUTO_TEST_CASE(modulus11_test)
{
- unsigned int transpositions_failures = transposition( modulus11_functor() ) ;
- BOOST_CHECK_MESSAGE( transpositions_failures == 0, "" << (90-transpositions_failures) << " caught on 90.") ;
+ unsigned int transpositions_failures = transposition(modulus11_functor());
+ BOOST_CHECK_MESSAGE(transpositions_failures == 0, "" <<(90-transpositions_failures)<< " caught on 90.");
- unsigned int alterations_failures = alteration( modulus11_functor() , 10) ;
- BOOST_CHECK_MESSAGE( alterations_failures == 0, "" << (90-alterations_failures) << " caught on 90.") ;
+ unsigned int alterations_failures = alteration(modulus11_functor(), 10);
+ BOOST_CHECK_MESSAGE(alterations_failures == 0, "" <<(90-alterations_failures)<< " caught on 90.");
}
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