Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r76934 - sandbox/SOC/2011/checks/boost/checks
From: pierre.talbot.6114_at_[hidden]
Date: 2012-02-07 09:52:25


Author: trademark
Date: 2012-02-07 09:52:23 EST (Tue, 07 Feb 2012)
New Revision: 76934
URL: http://svn.boost.org/trac/boost/changeset/76934

Log:
Change translate_to_valid_value to std::size_t convert(const value_type& value)
Text files modified:
   sandbox/SOC/2011/checks/boost/checks/basic_check_algorithm.hpp | 8 +++-----
   sandbox/SOC/2011/checks/boost/checks/basic_checks.hpp | 18 +-----------------
   sandbox/SOC/2011/checks/boost/checks/modulus11.hpp | 9 +++------
   3 files changed, 7 insertions(+), 28 deletions(-)

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-02-07 09:52:23 EST (Tue, 07 Feb 2012)
@@ -47,16 +47,14 @@
     \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(s) already counted (the current value is not included).\n This is also the position (beyond 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 This will automatically throw if the value is not a digit (0 <= i < 11).
+ \throws boost::checks::translation_exception is thrown if the translation of current_value failed.\n This will automatically throw if the value is not a digit (0 <= i < 10).
 
     \returns the translation of the current value in the range [0..9].
 */
   template <typename value_type>
- static std::size_t translate_to_valid_value(const value_type &value)
+ static std::size_t convert(const value_type &value)
   {
- if(value > 9)
- throw boost::checks::translation_exception();
- return value;
+ return value - '0';
   }
 
   /*!

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-02-07 09:52:23 EST (Tue, 07 Feb 2012)
@@ -26,21 +26,6 @@
   namespace checks{
 
 
-namespace detail
-{
- template <typename value_type>
- std::size_t lexical_cast(value_type x)
- {
- // If it's a character, transform digit to int (for example: '1' to 1).
- try
- {
- return boost::lexical_cast<std::size_t>(x);
- }
- catch(boost::bad_lexical_cast){}
- return static_cast<std::size_t>(x);
- }
-}
-
 /*!
     \brief Run through a sequence and calculate the checksum with the algorithm policy class.
 
@@ -72,8 +57,7 @@
           error = true;
         else
         {
- std::size_t value = boost::checks::detail::lexical_cast(*seq_begin);
- value = algorithm::translate_to_valid_value(value);
+ std::size_t value = algorithm::convert(*seq_begin);
           checksum = algorithm::process(checksum, value, value_counter);
           ++value_counter;
         }

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-02-07 09:52:23 EST (Tue, 07 Feb 2012)
@@ -59,14 +59,11 @@
     \returns the translation of the current value in the range [0..10].
 */
   template <typename value_type>
- static std::size_t translate_to_valid_value(const value_type &value)
+ static std::size_t convert(const value_type &value)
   {
- int valid_value = value;
     if(value == 'x' || value == 'X')
- valid_value = 10;
- else if(value > 9)
- throw boost::checks::translation_exception();
- return valid_value;
+ return 10;
+ return value - '0';
   }
 
 /* pre: value must be valid */


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