Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r82848 - in sandbox/SOC/2011/checks: boost/checks libs/checks/doc libs/checks/example
From: pierre.talbot.6114_at_[hidden]
Date: 2013-02-13 08:19:07


Author: trademark
Date: 2013-02-13 08:19:05 EST (Wed, 13 Feb 2013)
New Revision: 82848
URL: http://svn.boost.org/trac/boost/changeset/82848

Log:
Add an exemple of a mod 12 checkdigit.
Add documentation on the check digit concepts and encoder.

Added:
   sandbox/SOC/2011/checks/libs/checks/example/checkdigit_mod12_example.hpp (contents, props changed)
Text files modified:
   sandbox/SOC/2011/checks/boost/checks/checkdigit.hpp | 11 +-
   sandbox/SOC/2011/checks/libs/checks/doc/checks.qbk | 16 ++++
   sandbox/SOC/2011/checks/libs/checks/doc/import.qbk | 3
   sandbox/SOC/2011/checks/libs/checks/doc/reference.qbk | 144 +++++++++++++++++++++++++++++++++++++++
   sandbox/SOC/2011/checks/libs/checks/example/amex_example.cpp | 13 +++
   5 files changed, 177 insertions(+), 10 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-13 08:19:05 EST (Wed, 13 Feb 2013)
@@ -22,20 +22,21 @@
 struct checkdigit_encoder
 {
   typedef Result result_type;
- typedef size_t argument_type;
 
- result_type operator()(argument_type checksum)
+ template <typename T>
+ result_type operator()(T checksum)
   {
     return boost::lexical_cast<result_type>(checksum);
   }
 };
 
+template <typename Result=char>
 struct checkdigitx_encoder
 {
- typedef char result_type;
- typedef size_t argument_type;
+ typedef Result result_type;
 
- result_type operator()(argument_type checksum)
+ template <typename T>
+ result_type operator()(T checksum)
   {
     if(checksum == 10)
       return 'X';

Modified: sandbox/SOC/2011/checks/libs/checks/doc/checks.qbk
==============================================================================
--- sandbox/SOC/2011/checks/libs/checks/doc/checks.qbk (original)
+++ sandbox/SOC/2011/checks/libs/checks/doc/checks.qbk 2013-02-13 08:19:05 EST (Wed, 13 Feb 2013)
@@ -35,8 +35,9 @@
 [def __EAN [@http://en.wikipedia.org/wiki/European_Article_Number International Article Number (EAN)]]
 
 [/ Links to C++ reference.]
-[def __BOOST_REGEX__ [@http://www.boost.org/doc/libs/1_52_0/libs/regex/doc/html/index.html Boost regex]]
+[def __BOOST_REGEX__ [@http://www.boost.org/doc/libs/1_53_0/libs/regex/doc/html/index.html Boost.Regex]]
 [def __STD_REGEX__ [@http://en.cppreference.com/w/cpp/regex Standard regex]]
+[def __BOOST_LEXICAL_CAST__ [@http://www.boost.org/doc/libs/1_53_0/doc/html/boost_lexical_cast.html Boost.Lexical_Cast]]
 
 [/ Links to different check description]
 [def __VIN__ [@http://en.wikipedia.org/wiki/Vehicle_identification_number Vehicle Identification Number (VIN)]]
@@ -51,7 +52,20 @@
 [def __EXTENDING_LIBRARY__ [link checks.checks.extending_the_library Extending the library]]
 [def __INTERNATIONALIZATION__ [link checks.checks.internationalization Internationalization]]
 [def __REFERENCE__ [link checks.checks.reference Reference]]
+
+[/ Links to reference section]
 [def __TYPE_ADAPTOR__ [link checks.checks.reference.type_adaptor Type adaptor]]
+[def __MOD10_CHECKDIGIT__ [link checks.checks.reference.checkdigit.mod10_checkdigit Mod10 Check digit]]
+[def __MOD11_CHECKDIGIT__ [link checks.checks.reference.checkdigit.mod11_checkdigit Mod11 Check digit]]
+[def __MOD97_CHECKDIGIT__ [link checks.checks.reference.checkdigit.mod97_checkdigit Mod97 Check digit]]
+[def __MODULUS_CHECKDIGIT__ [link checks.checks.reference.checkdigit.mod_checkdigit modulus]]
+[def __MODULUS_INV_CHECKDIGIT__ [link checks.checks.reference.checkdigit.mod_inv_checkdigit modulus_inv]]
+[def __CHECKDIGIT_PROCESSOR_CONCEPT__ [link checks.checks.reference.checkdigit.checkdigit_processor_concept Check digit Processor concept]]
+[def __CHECKDIGIT_ENCODER_CONCEPT__ [link checks.checks.reference.checkdigit.checkdigit_encoder_concept Check digit Encoder concept]]
+[def __CHECKDIGIT_ENCODER__ [link checks.checks.reference.checkdigit.checkdigit_encoder checkdigit_encoder]]
+[def __CHECKDIGITX_ENCODER__ [link checks.checks.reference.checkdigit.checkdigitx_encoder checkdigitx_encoder]]
+
+[def __TRAVERSAL_TYPE__ [link checks.checks.reference.traversal_type Traversal type]]
 
 [def __overview [link checks.checks.preface Preface]]
 

Modified: sandbox/SOC/2011/checks/libs/checks/doc/import.qbk
==============================================================================
--- sandbox/SOC/2011/checks/libs/checks/doc/import.qbk (original)
+++ sandbox/SOC/2011/checks/libs/checks/doc/import.qbk 2013-02-13 08:19:05 EST (Wed, 13 Feb 2013)
@@ -3,4 +3,5 @@
 [import ../example/rtn.hpp]
 [import ../example/vin.hpp]
 [import ../example/filter_example.cpp]
-[import ../example/amex_example.cpp]
\ No newline at end of file
+[import ../example/amex_example.cpp]
+[import ../example/checkdigit_mod12_example.hpp]
\ No newline at end of file

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-13 08:19:05 EST (Wed, 13 Feb 2013)
@@ -9,15 +9,153 @@
 
 [section:reference Reference]
 
-[section:checkdigit Checkdigit]
+[section:checkdigit Check digit]
 
+[section:checkdigit_processor_concept Check Digit Processor Concept]
 
+[h1 Description]
+The check digit processor concept defines a structure used to compute a non-encoded check digit from the checksum.
 
-[endsect][/section:checkdigit Checkdigit]
-[section:type_adaptor Type adaptor]
+The structure must expose:
+``
+/*unspecified*/ operator(size_t);
+``
+
+[h1 Example]
+
+Example given in __MODULUS_CHECKDIGIT__.
+
+[h1 See also]
+__MODULUS_CHECKDIGIT__, __MODULUS_INV_CHECKDIGIT__, __MOD10_CHECKDIGIT__, __MOD11_CHECKDIGIT__, __MOD97_CHECKDIGIT__, __CHECKDIGIT_ENCODER_CONCEPT__.
+
+[endsect][/section:checkdigit_processor_concept Check Digit Processor Concept]
+
+[section:checkdigit_encoder_concept Check Digit Encoder Concept]
+[h1 Description]
+The check digit encoder concept defines a structure used to encode a check digit into a readable character.
+
+The structure must expose:
+``
+template <typename T>
+/*unspecified*/ operator(T);
+``
+
+`T` is equal to `CheckDigitProcessor::result_type`. Note that by default, all check digit processor returns a ['size_t].
+
+[h1 Examples]
+
+Example given in __CHECKDIGIT_ENCODER__ and __CHECKDIGITX_ENCODER__.
+
+[h1 See also]
+__CHECKDIGIT_ENCODER__, __CHECKDIGITX_ENCODER__, __MODULUS_CHECKDIGIT__, __MOD10_CHECKDIGIT__, __MOD11_CHECKDIGIT__, __MOD97_CHECKDIGIT__.
+
+[endsect][/section:checkdigit_encoder_concept Check digit Encoder concept]
+
+[section:checkdigitref checkdigit]
+
+[h1 Synopsis]
+``
+template
+<
+ typename Processor,
+ typename Encoder,
+ size_t position = 0,
+ size_t size = 1
+>
+struct checkdigit
+{
+ // ...
+};
+``
+[h1 Description]
+Structure describing a check digit.
+[h1 Header]
+``
+#include <boost/checks/checkdigit.hpp>
+``
+[h1 Template parameters]
+
+* [*Processor] is used to compute a non-encoded check digit from the checksum. Must meet the __CHECKDIGIT_PROCESSOR_CONCEPT__ requirements.
+* [*Encoder] is used to encode the check digit obtained from the Processor. Must meet the __CHECKDIGIT_ENCODER_CONCEPT__ requirements.
+* [*position] is the position of the check digit in the sequence. This position ['must depends] on the __TRAVERSAL_TYPE__. [*Default] to 0 (because the default traversal is from right to left).
+* [*size] is the size of the check digit. [*Default] to 1.
+
+[h1 Example]
+The example shows how to make a check digit that is computed with a modulus 12 and where the encoding is [0..9, X, Y].
+
+[checkdigit_mod12_example]
+
+[h1 See also]
+
+__MOD10_CHECKDIGIT__, __MOD11_CHECKDIGIT__, __MOD97_CHECKDIGIT__, __CHECKDIGIT_PROCESSOR_CONCEPT__, __CHECKDIGIT_ENCODER_CONCEPT__.
+
+[endsect][/section:checkdigitref checkdigit]
 
+[section:checkdigit_encoder checkdigit_encoder]
+[h1 Synopsis]
+``
+template <typename Result=char>
+struct checkdigit_encoder
+{
+ typedef Result result_type;
 
+ template <typename T>
+ result_type operator()(T checksum);
+};
+``
+[h1 Description]
 
+The checkdigit_encoder structure encodes a checksum (possibly already processed by a check digit processor) to a 7-bits ASCII encoding.
+
+[h1 Header]
+``
+#include <boost/checks/checkdigit.hpp>
+``
+[h1 Template parameters]
+
+* [*Result] is the type in which the checksum will be encoded.
+* [*T] is the type of the checksum.
+
+[h1 Parameters]
+
+* [*checksum] is the checksum received from a check digit processor.
+
+[h1 Exception]
+
+This code can launch exception under the condition of the __BOOST_LEXICAL_CAST__ library. That is, if the return type cannot contains the encoded version of the check digit.
+
+[note An exception here is a programming error. No exception should be launched.]
+
+[h1 See also]
+
+__BOOST_LEXICAL_CAST__, __CHECKDIGITX_ENCODER__, __CHECKDIGIT_ENCODER_CONCEPT__.
+
+[endsect][/section:checkdigit_encoder checkdigit_encoder]
+
+[section:checkdigitx_encoder checkdigitx_encoder]
+[endsect][/section:checkdigitx_encoder checkdigitx_encoder]
+
+[section:mod_checkdigit modulus]
+[endsect][/section:mod_checkdigit modulus]
+
+[section:mod_inv_checkdigit modulus_inv]
+[endsect][/section:mod_inv_checkdigit modulus_inv]
+
+[section:mod10_checkdigit Mod10 check digit]
+[endsect][/section:mod10_checkdigit Mod10 check digit]
+
+[section:mod11_checkdigit Mod11 check digit]
+[endsect][/section:mod11_checkdigit Mod11 check digit]
+
+[section:mod97_checkdigit Mod97 check digit]
+[endsect][/section:mod97_checkdigit Mod97 check digit]
+
+[endsect][/section:checkdigit Check digit]
+
+[section:traversal_type Traversal type]
+[endsect][/section:traversal_type Traversal type]
+
+[section:type_adaptor Type adaptor]
 [endsect][/section:type_adaptor Type adaptor]
 
 [endsect][/section:reference Reference]
\ No newline at end of file

Modified: sandbox/SOC/2011/checks/libs/checks/example/amex_example.cpp
==============================================================================
--- sandbox/SOC/2011/checks/libs/checks/example/amex_example.cpp (original)
+++ sandbox/SOC/2011/checks/libs/checks/example/amex_example.cpp 2013-02-13 08:19:05 EST (Wed, 13 Feb 2013)
@@ -1,3 +1,16 @@
+// 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)
+
+// This file is written to be included from a Quickbook .qbk document.
+// It can be compiled by the C++ compiler, and run. Any output can
+// also be added here as comment or included or pasted in elsewhere.
+// Caution: this file contains Quickbook markup as well as code
+// and comments: don't change any of the special comment markups!
+
 //[amex_example
 #include <string>
 #include <boost/checks/amex.hpp>

Added: sandbox/SOC/2011/checks/libs/checks/example/checkdigit_mod12_example.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2011/checks/libs/checks/example/checkdigit_mod12_example.hpp 2013-02-13 08:19:05 EST (Wed, 13 Feb 2013)
@@ -0,0 +1,40 @@
+// 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)
+
+// This file is written to be included from a Quickbook .qbk document.
+// It can be compiled by the C++ compiler, and run. Any output can
+// also be added here as comment or included or pasted in elsewhere.
+// Caution: this file contains Quickbook markup as well as code
+// and comments: don't change any of the special comment markups!
+
+//[checkdigit_mod12_example
+#include <boost/checks/modulus.hpp>
+#include <boost/checks/checkdigit.hpp>
+
+using namespace boost::checks;
+
+// The check digit processor.
+typedef modulus<12> mod12_basic;
+
+// The check digit encoder.
+struct checkdigit_12_encoder
+{
+ typedef char result_type;
+ typedef size_t argument_type;
+
+ result_type operator()(argument_type checksum)
+ {
+ if(checksum == 11)
+ return 'Y';
+ else
+ return checkdigitx_encoder<result_type>()(checksum);
+ }
+};
+
+// The check digit type.
+typedef checkdigit<mod12_basic, checkdigit_12_encoder> mod12_basic_checkdigit;
+//]
\ No newline at end of file


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