Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r82700 - in sandbox/SOC/2011/checks: boost/checks libs/checks/doc libs/checks/example libs/checks/test
From: pierre.talbot.6114_at_[hidden]
Date: 2013-02-06 20:24:33


Author: trademark
Date: 2013-02-03 06:40:32 EST (Sun, 03 Feb 2013)
New Revision: 82700
URL: http://svn.boost.org/trac/boost/changeset/82700

Log:
Finish checkdigit structure
Update documentation
Update example

Added:
   sandbox/SOC/2011/checks/boost/checks/modulus.hpp (contents, props changed)
   sandbox/SOC/2011/checks/boost/checks/type_adaptor.hpp (contents, props changed)
   sandbox/SOC/2011/checks/libs/checks/test/core_test.cpp (contents, props changed)
Text files modified:
   sandbox/SOC/2011/checks/boost/checks/checkdigit.hpp | 74 +++++++++++++++--
   sandbox/SOC/2011/checks/boost/checks/modulus10.hpp | 26 +----
   sandbox/SOC/2011/checks/boost/checks/modulus11.hpp | 145 ++---------------------------------
   sandbox/SOC/2011/checks/boost/checks/modulus97.hpp | 164 ++-------------------------------------
   sandbox/SOC/2011/checks/libs/checks/doc/extending_library.qbk | 6
   sandbox/SOC/2011/checks/libs/checks/doc/reference.qbk | 6 +
   sandbox/SOC/2011/checks/libs/checks/example/rtn.hpp | 6 -
   sandbox/SOC/2011/checks/libs/checks/example/vin.hpp | 7
   sandbox/SOC/2011/checks/libs/checks/test/jamfile.v2 | 5
   sandbox/SOC/2011/checks/libs/checks/test/test_checks.cpp | 2
   10 files changed, 108 insertions(+), 333 deletions(-)

Modified: sandbox/SOC/2011/checks/boost/checks/checkdigit.hpp
==============================================================================
--- sandbox/SOC/2011/checks/boost/checks/checkdigit.hpp (original)
+++ sandbox/SOC/2011/checks/boost/checks/checkdigit.hpp 2013-02-03 06:40:32 EST (Sun, 03 Feb 2013)
@@ -5,10 +5,6 @@
 // http://www.boost.org/LICENSE_1_0.txt
 // See http://www.boost.org for updates, documentation, and revision history.
 
-/*! \file
- \brief Provides a type "checkdigit"
-*/
-
 #ifndef BOOST_CHECK_CHECKDIGIT_HPP
 #define BOOST_CHECK_CHECKDIGIT_HPP
 
@@ -17,21 +13,77 @@
 #endif
 
 #include <cstddef> // size_t
+#include <boost/lexical_cast.hpp>
 
 namespace boost{
   namespace checks{
 
-template <size_t checkdigit_pos,
- size_t checkdigit_size>
-struct checkdigit
+template <typename Result=char>
+struct checkdigit_encoder
+{
+ typedef Result result_type;
+ typedef size_t argument_type;
+
+ result_type operator()(argument_type checksum)
+ {
+ return boost::lexical_cast<result_type>(checksum);
+ }
+};
+
+struct checkdigitx_encoder
 {
- static const size_t pos = checkdigit_pos;
- static const size_t size = checkdigit_size;
+ typedef char result_type;
+ typedef size_t argument_type;
+
+ result_type operator()(argument_type checksum)
+ {
+ if(checksum == 10)
+ return 'X';
+ else
+ return checkdigit_encoder<result_type>()(checksum);
+ }
 };
 
-// A checkdigit at the end of the number for reverse traversal.
-typedef checkdigit<0, 1> basic_checkdigit;
+template
+<
+ typename Processor,
+ typename Encoder,
+ size_t position = 0,
+ size_t size = 1
+>
+struct checkdigit
+{
+ typedef Processor processor_type;
+ typedef Encoder encoder_type;
+ static const size_t position_value;
+ static const size_t size_value;
+
+ typedef typename Encoder::result_type result_type;
+ typedef typename Processor::argument_type argument_type;
+
+ result_type operator()(argument_type value)
+ {
+ return Encoder()(Processor()(value));
+ }
+};
 
+template
+<
+ typename Processor,
+ typename Encoder,
+ size_t position,
+ size_t size
+>
+const size_t checkdigit<Processor, Encoder, position, size>::position_value = position;
+
+template
+<
+ typename Processor,
+ typename Encoder,
+ size_t position,
+ size_t size
+>
+const size_t checkdigit<Processor, Encoder, position, size>::size_value = size;
 
 }} // namespace boost namespace checks
 

Added: sandbox/SOC/2011/checks/boost/checks/modulus.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2011/checks/boost/checks/modulus.hpp 2013-02-03 06:40:32 EST (Sun, 03 Feb 2013)
@@ -0,0 +1,50 @@
+// Boost checks/modulus.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.
+
+#ifndef BOOST_CHECKS_MODULUS_HPP
+#define BOOST_CHECKS_MODULUS_HPP
+
+#ifdef _MSC_VER
+ #pragma once
+#endif
+
+#include <cstddef>
+
+namespace boost{
+ namespace checks{
+
+template <size_t mod>
+struct modulus
+{
+ typedef size_t result_type;
+ typedef size_t argument_type;
+
+ static const size_t modulus_value = mod;
+
+ result_type operator()(argument_type value)
+ {
+ return value % mod;
+ }
+};
+
+template <size_t mod>
+struct modulus_inv
+{
+ typedef size_t result_type;
+ typedef size_t argument_type;
+
+ static const size_t modulus_value = mod;
+
+ result_type operator()(argument_type value)
+ {
+ return (mod - (value % mod)) % mod;
+ }
+};
+
+}} // namespace boost namespace checks
+
+#endif //BOOST_CHECKS_MODULUS_HPP

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 2013-02-03 06:40:32 EST (Sun, 03 Feb 2013)
@@ -5,10 +5,6 @@
 // http://www.boost.org/LICENSE_1_0.txt
 // See http://www.boost.org for updates, documentation, and revision history.
 
-/*! \file
- \brief This file provides tools to compute and validate classic modulus 10 checksum.
-*/
-
 #ifndef BOOST_CHECKS_MOD10_HPP
 #define BOOST_CHECKS_MOD10_HPP
 
@@ -17,26 +13,18 @@
 #endif
 
 #include <cstddef>
+#include <boost/checks/checkdigit.hpp>
+#include <boost/checks/modulus.hpp>
 
 namespace boost{
   namespace checks{
 
-struct mod10_inv_checkdigit
-{
- char operator()(size_t checksum)
- {
- return ((10 - checksum % 10) % 10) + '0';
- }
-};
-
-struct mod10_checkdigit
-{
- char operator()(size_t checksum)
- {
- return checksum % 10 + '0';
- }
-};
+typedef modulus<10> mod10_basic;
+typedef modulus_inv<10> mod10_inv_basic;
+typedef checkdigit_encoder<> mod10_basic_encoder;
 
+typedef checkdigit<mod10_basic, mod10_basic_encoder> mod10_basic_checkdigit;
+typedef checkdigit<mod10_inv_basic, mod10_basic_encoder> mod10_inv_checkdigit;
 
 }} // namespace boost namespace checks
 

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 2013-02-03 06:40:32 EST (Sun, 03 Feb 2013)
@@ -5,10 +5,6 @@
 // http://www.boost.org/LICENSE_1_0.txt
 // See http://www.boost.org for updates, documentation, and revision history.
 
-/*! \file
- \brief This file provides tools to compute and validate classic modulus 11 checksum.
-*/
-
 #ifndef BOOST_CHECKS_MOD11_HPP
 #define BOOST_CHECKS_MOD11_HPP
 
@@ -16,144 +12,21 @@
     #pragma once
 #endif
 
-#include <boost/range/rbegin.hpp>
-#include <boost/range/rend.hpp>
-#include <boost/range/iterator_range.hpp>
-#include <boost/checks/checksum.hpp>
-
 #include <boost/checks/weight.hpp>
-#include <boost/checks/basic_checks.hpp>
-#include <boost/checks/weighted_sum.hpp>
+#include <boost/checks/modulus.hpp>
+#include <boost/checks/checkdigit.hpp>
 
 namespace boost{
   namespace checks{
 
-struct mod11_checkdigit
-{
- char operator()(size_t checksum)
- {
- checksum %= 11;
- if(checksum == 10)
- return 'X';
- else
- return checksum + '0';
- }
-};
- /*!
- \brief Compute the check digit with a simple modulus 11.
-
- \tparam checkdigit is the type of the check digit desired.
- \param checksum is the checksum used to extract the check digit.
-
- \throws boost::checks::translation_exception if the check digit cannot be translated into the checkdigit type.
-
- \returns The modulus 11 check digit of checksum. 'X' is returned if the check digit value is equal to 10.
- */
-struct mod11_checkdigit
-{
- char operator()(size_t checksum)
- {
- checksum = ((11 - checksum % 11)% 11);
- if(checksum == 10)
- return 'X';
- else
- return checksum + '0';
- }
-};
-
-/*!
- \brief The most common weight pattern used with a modulus 11 algorithm.
-*/
-typedef weight<1,2,3,4,5,6,7,8,9,10> mod11_weight;
+typedef modulus<11> mod11_basic;
+typedef modulus_inv<11> mod11_inv_basic;
+typedef checkdigitx_encoder mod11_basic_encoder;
 
-/*!
- \brief This is the type of the most common modulus 11 algorithm.
-*/
-typedef weighted_sum<mod11_weight> mod11_processor;
-
-typedef checksum
-<
- mod11_processor,
- mod11_validation,
- mod11_checkdigit
-> mod11;
-
-/*!
- \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).
-
- \tparam size_expected is the number of valid value expected in the sequence.
- \tparam check_range is a valid range type.
- \param check_seq is the sequence of value to check.
-
- \throws std::invalid_argument if check_seq doesn't contain size_expected valid values.
-
- \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)
-{
- return boost::checks::check_sequence<features<mod11, size_expected> >(check_seq);
-}
-
-/*!
- \brief Validate a sequence according to the mod11_check_algorithm type.
-
- \pre check_seq is a valid range.
-
- \tparam check_range is a valid range type.
- \param check_seq is the sequence of value to check.
-
- \throws std::invalid_argument if check_seq contains no valid value.
-
- \returns @c true if the check digit is correct, false otherwise.
-*/
-template <typename check_range>
-bool check_modulus11(const check_range& check_seq)
-{
- return check_sequence<features<mod11> >(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).
-
- \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.
-
- \throws std::invalid_argument if check_seq doesn't contain size_expected valid values.
- \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,X].
-*/
-template <size_t size_expected, typename check_range>
-size_t compute_modulus11(const check_range& check_seq)
-{
- return compute_checkdigit<features<mod11,
- size_expected> >(check_seq);
-}
-
-/*!
- \brief Calculate the check digit of a sequence according to the mod11_compute_algorithm type.
-
- \pre check_seq is a valid range.
-
- \tparam check_range is a valid range type.
- \param check_seq is the sequence of value to check.
-
- \throws std::invalid_argument if check_seq contains no valid value.
- \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,X].
-*/
-template <typename check_range>
-size_t compute_modulus11(const check_range& check_seq)
-{
- return compute_checkdigit<features<mod11> >(check_seq);
-}
+typedef checkdigit<mod11_basic, mod11_basic_encoder> mod11_basic_checkdigit;
+typedef checkdigit<mod11_inv_basic, mod11_basic_encoder> mod11_inv_checkdigit;
+
+typedef weight<1,2,3,4,5,6,7,8,9,10> mod11_weight;
 
 }} // 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 2013-02-03 06:40:32 EST (Sun, 03 Feb 2013)
@@ -17,62 +17,27 @@
     #pragma once
 #endif
 
-#include <boost/preprocessor/repetition.hpp>
 #include <boost/checks/weight.hpp>
-#include <boost/checks/weighted_sum.hpp>
-#include <boost/checks/checksum.hpp>
+#include <boost/checks/checkdigit.hpp>
 
 namespace boost{
   namespace checks{
 
-/*! \class modulus97_algorithm
- \brief This class can be used to compute or validate a checksum with a basic modulus 97.
-
- \details The mod97-10 algorithm (ISO/IEC 7064:2003 Information technology -- Security techniques -- Check character systems) uses two check digits.
-
- \tparam mod97_weight must meet the weight concept requirements.
- \tparam iteration_sense must meet the iteration_sense concept requirements.
- \tparam checkdigit_size Help functions to provide same behavior on sequence with and without check digits. No "real" value in the sequence will be skipped.
-
- \remarks This algorithm use two check digits.
-*/
- /*!
- \brief Validate a checksum with a simple modulus 97.
-
- \param checksum is the checksum to validate.
-
- \returns @c true if the checksum is correct, @c false otherwise.
- */
-struct mod97_validation
+struct mod97
 {
- bool operator()(size_t checksum)
- {
- return checksum % 97 == 1;
- }
-};
- /*!
- \brief Compute the two check digits with a simple modulus 97.
-
- \pre checkdigits should have enough reserved place to store the two check digits.
- \post The two check digits are stored into checkdigits.
+ typedef size_t result_type;
+ typedef size_t argument_type;
 
- \tparam checkdigits_iter must meet the OutputIterator requirements.
- \param checksum is the checksum used to extract the check digit.
- \param checkdigits is the output iterator in which the two check digits will be written.
+ static const size_t modulus_value = 97;
 
- \throws translation_exception if the check digits cannot be translated into the check digits_iter type.
-
- \returns An iterator initialized at one pass to the end of the two check digits.
- */
-struct mod97_checkdigit
-{
- size_t operator()(size_t checksum)
+ result_type operator()(argument_type value)
   {
- return 98 - (checksum % 97);
+ return 98 - (value % 97);
   }
 };
 
-typedef checkdigit<0, 2> mod97_10_checkdigit;
+typedef checkdigit_encoder<std::string> mod97_basic_encoder;
+typedef checkdigit<mod97, mod97_basic_encoder, 0, 2> mod97_10_checkdigit;
 
 struct mod97_10_processor
 {
@@ -92,117 +57,6 @@
   }
 };
 
-typedef checksum
-<
- mod97_10_processor,
- mod97_validation,
- mod97_checkdigit,
- mod97_10_checkdigit
-> mod97_10;
-
-/*!
- \brief Validate a sequence according to the mod97_10_check_algorithm type.
-
- \pre x 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.
- \param x is the sequence of value to check.
-
- \throws std::invalid_argument if x doesn't contain size_expected valid values.
-
- \returns True if the two check digits are correct, false otherwise.
-*/
-template <size_t size_expected, typename check_range>
-bool check_mod97_10 (const check_range& x)
-{
- return check_sequence<features<mod97_10, size_expected> >(x);
-}
-
-template <size_t size_expected>
-bool check_mod97_10 (const std::string& x)
-{
- return check_sequence<features<mod97_10, size_expected> >(make_precheck<digit>(x));
-}
-
-/*!
- \brief Validate a sequence according to the mod97_10_check_algorithm type.
-
- \pre x is a valid range.
-
- \tparam check_range is a valid range type.
- \param x is the sequence of value to check.
-
- \throws std::invalid_argument if x contains no valid value.
-
- \returns @c true if the two check digits are correct, @c false otherwise.
-*/
-template <typename check_range>
-bool check_mod97_10(const check_range& x)
-{
- return check_sequence<features<mod97_10> >(x);
-}
-
-bool check_mod97_10(const std::string& x)
-{
- return check_sequence<features<mod97_10> >(make_precheck<digit>(x));
-}
-
-/*!
- \brief Calculate the check digits of a sequence according to the mod97_10_compute_algorithm type.
-
- \pre x is a valid range.\n size_expected > 0 (enforced by static assert).\n mod97_checkdigits should have enough reserved place to store the two check digits.
-
- \tparam size_expected is the number of valid value expected in the sequence. (So the check digits are not included.)
- \tparam check_range is a valid range type.
- \tparam checkdigits_iter must meet the OutputIterator requirements.
- \param x is the sequence of value to check.
- \param mod97_checkdigits is the OutputIterator in which the two check digits will be stored.
-
- \throws std::invalid_argument if x doesn't contain size_expected valid values.
- \throws translation_exception if the check digits cannot be translated into the checkdigits_iter type.
-
- \returns The check digits are stored into mod97_checkdigits. The range of these is [0..9][0..9].
-*/
-template <size_t size_expected, typename check_range>
-size_t compute_mod97_10(const check_range& x)
-{
- return compute_checkdigit<features<mod97_10, size_expected> >(x);
-}
-
-template <size_t size_expected>
-size_t compute_mod97_10(const std::string& x)
-{
- return compute_checkdigit<features<mod97_10, size_expected> >(make_precheck<digit>(x));
-}
-
-/*!
- \brief Calculate the check digits of a sequence according to the mod97_10_compute_algorithm type.
-
- \pre x is a valid range.\n mod97_checkdigits should have enough reserved place to store the two check digits.
-
- \tparam check_range is a valid range type.
- \tparam checkdigits_iter must meet the OutputIterator requirements.
- \param x is the sequence of value to check.
- \param mod97_checkdigits is the OutputIterator in which the two check digits will be stored.
-
- \throws std::invalid_argument if x contains no valid value.
- \throws translation_exception if the check digits cannot be translated into the checkdigits_iter type.
-
- \returns The check digits are stored into mod97_checkdigits. The range of these is [0..9][0..9].
-*/
-template <typename check_range>
-size_t compute_mod97_10(const check_range& x)
-{
- return compute_checkdigit<features<mod97_10> >(x);
-}
-
-size_t compute_mod97_10(const std::string& x)
-{
- return compute_checkdigit<features<mod97_10> >(make_precheck<digit>(x));
-}
-
-
 }} // namespace boost namespace checks
 
 #endif //BOOST_CHECKS_MOD97_HPP

Added: sandbox/SOC/2011/checks/boost/checks/type_adaptor.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2011/checks/boost/checks/type_adaptor.hpp 2013-02-03 06:40:32 EST (Sun, 03 Feb 2013)
@@ -0,0 +1,60 @@
+// Boost checks/checksum.hpp header file
+// (C) Copyright Pierre Talbot 2013
+// 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.
+
+#ifndef BOOST_CHECK_TYPE_ADAPTOR_HPP
+#define BOOST_CHECK_TYPE_ADAPTOR_HPP
+
+#ifdef _MSC_VER
+ #pragma once
+#endif
+
+#include <boost/mpl/size_t.hpp>
+#include <boost/checks/checkdigit.hpp>
+
+namespace boost {
+ namespace checks{
+
+// Some tags.
+struct checkdigit_pos_tag{};
+struct checkdigit_size_tag{};
+struct checkdigit_encoder_tag{};
+struct checkdigit_processor_tag{};
+
+// The type adaptor structure with specialization on the tag.
+
+template <class CurrentType, class tag, class NewType>
+struct type_adaptor
+{};
+
+template <class P, class E, size_t p, size_t s, size_t newPos>
+struct type_adaptor<checkdigit<P,E,p,s>, checkdigit_pos_tag, boost::mpl::size_t<newPos> >
+{
+ typedef checkdigit<P,E,newPos,s> type;
+};
+
+template <class P, class E, size_t p, size_t s, size_t newSize>
+struct type_adaptor<checkdigit<P,E,p,s>, checkdigit_size_tag, boost::mpl::size_t<newSize> >
+{
+ typedef checkdigit<P,E,p,newSize> type;
+};
+
+template <class P, class E, size_t p, size_t s, class NewEncoder>
+struct type_adaptor<checkdigit<P,E,p,s>, checkdigit_encoder_tag, NewEncoder>
+{
+ typedef checkdigit<P,NewEncoder,p,s> type;
+};
+
+template <class P, class E, size_t p, size_t s, class NewProcessor>
+struct type_adaptor<checkdigit<P,E,p,s>, checkdigit_processor_tag, NewProcessor>
+{
+ typedef checkdigit<NewProcessor,E,p,s> type;
+};
+
+} // namespace checks
+} // namespace boost
+
+#endif // BOOST_CHECK_CHECKSUM_HPP

Modified: sandbox/SOC/2011/checks/libs/checks/doc/extending_library.qbk
==============================================================================
--- sandbox/SOC/2011/checks/libs/checks/doc/extending_library.qbk (original)
+++ sandbox/SOC/2011/checks/libs/checks/doc/extending_library.qbk 2013-02-03 06:40:32 EST (Sun, 03 Feb 2013)
@@ -22,7 +22,7 @@
 
 [section:implement_rtn Implement the RTN algorithm]
 
-We begin with the implementation of the __RTN__ algorithm. We follow the __DESCRIPTION__ given earlier to find similar point with it and our algorithm.
+We begin with the implementation of the __RTN__ algorithm. We follow the __DESCRIPTION__ given earlier to find similitude with it and our algorithm.
 
 [h4]Filter[/h4]
 
@@ -79,7 +79,9 @@
 
 Furthermore, the function that compute the check digit is a classic mod11 calculation. The VIN use a simple `checksum % 11`.
 
-Now we can compose the check digit structure of VIN. Here the sample of code doing this task.
+The library already have a basic mod11 checkdigit structure, the only things which change is the position of the checkdigit.
+We can use a type adaptor which permit to change a single template parameter without taking care of the other defaults.
+Here the sample of code doing this task.
 
 [vin_checkdigit]
 

Modified: sandbox/SOC/2011/checks/libs/checks/doc/reference.qbk
==============================================================================
--- sandbox/SOC/2011/checks/libs/checks/doc/reference.qbk (original)
+++ sandbox/SOC/2011/checks/libs/checks/doc/reference.qbk 2013-02-03 06:40:32 EST (Sun, 03 Feb 2013)
@@ -9,4 +9,10 @@
 
 [section:reference Reference]
 
+[section:checkdigit Checkdigit]
+
+
+
+[endsect][/section:checkdigit Checkdigit]
+
 [endsect][/section:reference Reference]
\ No newline at end of file

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 2013-02-03 06:40:32 EST (Sun, 03 Feb 2013)
@@ -26,11 +26,7 @@
 namespace checks{
 
 //[rtn_checkdigit
-typedef checkdigit
-<
- mod10_checkdigit
->
-rtn_checkdigit;
+typedef mod10_basic_checkdigit rtn_checkdigit;
 //]
 
 //[rtn_checksum

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 2013-02-03 06:40:32 EST (Sun, 03 Feb 2013)
@@ -32,11 +32,12 @@
 #define VIN_CHECKDIGIT_POS 8
 #define VIN_CHECKDIGIT_SIZE 1
 
-typedef checkdigit
+typedef type_adaptor
 <
- mod11_checkdigit,
+ mod11_basic_checkdigit,
+ checkdigit_pos,
   VIN_CHECKDIGIT_POS
->
+>::type
 vin_checkdigit;
 //]
 

Added: sandbox/SOC/2011/checks/libs/checks/test/core_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2011/checks/libs/checks/test/core_test.cpp 2013-02-03 06:40:32 EST (Sun, 03 Feb 2013)
@@ -0,0 +1,112 @@
+// Copyright Pierre Talbot 2013.
+
+// Use, modification and distribution are subject to 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/doc/libs/1_46_1/libs/test/doc/html/utf/testing-tools/reference.html
+
+#define BOOST_TEST_MAIN
+#define BOOST_TEST_MODULE "Check Test Suite"
+#define BOOST_LIB_DIAGNOSTIC "on"// Show library file details.
+
+#include <boost/test/unit_test.hpp> // Enhanced for unit_test framework autolink
+#include <boost/test/included/unit_test.hpp>
+
+#include <boost/type_traits.hpp>
+#include <boost/mpl/assert.hpp>
+
+#include <boost/checks/checkdigit.hpp>
+#include <boost/checks/modulus10.hpp>
+#include <boost/checks/modulus11.hpp>
+#include <boost/checks/modulus97.hpp>
+#include <boost/checks/type_adaptor.hpp>
+
+BOOST_AUTO_TEST_SUITE(core_tests)
+
+BOOST_AUTO_TEST_CASE(mod10_checkdigit_test)
+{
+ using namespace boost::checks;
+ mod10_basic_checkdigit c;
+
+ char results_expected[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
+
+ for(size_t checksum=0; checksum < 30; ++checksum)
+ {
+ BOOST_CHECK_EQUAL(c(checksum), results_expected[checksum%10]);
+ }
+}
+
+BOOST_AUTO_TEST_CASE(mod10_inv_checkdigit_test)
+{
+ using namespace boost::checks;
+ mod10_inv_checkdigit c;
+
+ char results_expected[] = {'0', '9', '8', '7', '6', '5', '4', '3', '2', '1'};
+
+ for(size_t checksum=0; checksum < 30; ++checksum)
+ {
+ BOOST_CHECK_EQUAL(c(checksum), results_expected[checksum%10]);
+ }
+}
+
+BOOST_AUTO_TEST_CASE(mod11_checkdigit_test)
+{
+ using namespace boost::checks;
+ mod11_basic_checkdigit c;
+
+ char results_expected[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'X'};
+
+ for(size_t checksum=0; checksum < 33; ++checksum)
+ {
+ BOOST_CHECK_EQUAL(c(checksum), results_expected[checksum%11]);
+ }
+}
+
+BOOST_AUTO_TEST_CASE(mod11_inv_checkdigit_test)
+{
+ using namespace boost::checks;
+ mod11_inv_checkdigit c;
+
+ char results_expected[] = {'0', 'X', '9', '8', '7', '6', '5', '4', '3', '2', '1'};
+
+ for(size_t checksum=0; checksum < 33; ++checksum)
+ {
+ BOOST_CHECK_EQUAL(c(checksum), results_expected[checksum%11]);
+ }
+}
+
+BOOST_AUTO_TEST_CASE(mod97_10_checkdigit_test)
+{
+ using namespace boost::checks;
+ mod97_10_checkdigit c;
+
+ for(size_t checksum=0, res = 98; checksum < 100; ++checksum, --res)
+ {
+ if(res < 2) res = 98;
+ std::string result_expected = boost::lexical_cast<std::string>(res);
+ BOOST_CHECK_EQUAL(c(checksum), result_expected);
+ }
+}
+
+BOOST_AUTO_TEST_CASE(type_adaptor_test)
+{
+ using namespace boost::checks;
+ BOOST_CHECK_EQUAL(mod11_basic_checkdigit::position_value, size_t(0));
+ BOOST_CHECK_EQUAL(mod11_basic_checkdigit::size_value, size_t(1));
+
+ typedef type_adaptor<mod11_basic_checkdigit, checkdigit_pos_tag, boost::mpl::size_t<10> >::type mod11_pos_10;
+ typedef type_adaptor<mod11_basic_checkdigit, checkdigit_size_tag, boost::mpl::size_t<3> >::type mod11_size_3;
+
+ BOOST_CHECK_EQUAL(mod11_pos_10::position_value, size_t(10));
+ BOOST_CHECK_EQUAL(mod11_size_3::size_value, size_t(3));
+
+ typedef type_adaptor<mod11_basic_checkdigit, checkdigit_encoder_tag, mod10_basic_encoder>::type mod11_mod10_encoder;
+ typedef type_adaptor<mod11_basic_checkdigit, checkdigit_processor_tag, mod11_inv_basic>::type mod11_inv_type;
+
+ BOOST_MPL_ASSERT((boost::is_same<mod11_mod10_encoder::encoder_type, mod10_basic_encoder>));
+ BOOST_MPL_ASSERT((boost::is_same<mod11_inv_type::processor_type, mod11_inv_basic>));
+}
+
+BOOST_AUTO_TEST_SUITE_END()
\ No newline at end of file

Modified: sandbox/SOC/2011/checks/libs/checks/test/jamfile.v2
==============================================================================
--- sandbox/SOC/2011/checks/libs/checks/test/jamfile.v2 (original)
+++ sandbox/SOC/2011/checks/libs/checks/test/jamfile.v2 2013-02-03 06:40:32 EST (Sun, 03 Feb 2013)
@@ -58,6 +58,7 @@
     ;
 
 test-suite "Checks"
- : [ run test_checks.cpp boost_unit_test ]
- [ run test_checks_tools.cpp boost_unit_test ]
+ : #[ run test_checks.cpp boost_unit_test ]
+ #[ run test_checks_tools.cpp boost_unit_test ]
+ [ run core_test.cpp boost_unit_test ]
     ;

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 2013-02-03 06:40:32 EST (Sun, 03 Feb 2013)
@@ -49,6 +49,8 @@
 template <typename functor>
 unsigned int alteration(const functor &compute_checkdigit , unsigned int number_of_position_to_test);
 
+
+
 BOOST_AUTO_TEST_SUITE(use_cases_tests)
 
 BOOST_AUTO_TEST_CASE(visa_tests)


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