Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r73885 - sandbox/SOC/2011/checks/boost/checks
From: pierre.talbot.6114_at_[hidden]
Date: 2011-08-18 08:26:50


Author: trademark
Date: 2011-08-18 08:26:49 EDT (Thu, 18 Aug 2011)
New Revision: 73885
URL: http://svn.boost.org/trac/boost/changeset/73885

Log:
Add check and compute function of the VISA check digit verification.
Text files modified:
   sandbox/SOC/2011/checks/boost/checks/visa.hpp | 41 ++++++++++++++++++++++++++++++++++-----
   1 files changed, 35 insertions(+), 6 deletions(-)

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 2011-08-18 08:26:49 EDT (Thu, 18 Aug 2011)
@@ -5,16 +5,45 @@
 // http://www.boost.org/LICENSE_1_0.txt
 // See http://www.boost.org for updates, documentation, and revision history.
 
-#ifndef BOOST_VISA_INCLUDED
-#define BOOST_VISA_INCLUDED
+#ifndef BOOST_CHECKS_VISA_HPP
+#define BOOST_CHECKS_VISA_HPP
 
+#include <boost/checks/luhn.hpp>
+
+#define VISA_SIZE 16
+#define VISA_SIZE_WITHOUT_CHECKDIGIT 15
 
 namespace boost {
     namespace checks{
 
-/* visa : use luhn algorithm */
 
-} // namespace checks
-} // namespace boost
+template <unsigned int number_of_virtual_value_skipped = 0>
+struct visa_algorithm : boost::checks::luhn_algorithm < number_of_virtual_value_skipped >
+{
+ 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 ;
+
+ 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.") ;
+ }
+};
+
+typedef visa_algorithm<0> visa_check_algorithm ;
+typedef visa_algorithm<1> visa_compute_algorithm ;
+
+template <typename check_range>
+bool check_visa (const check_range& check_seq)
+{
+ return boost::checks::check_sequence<visa_check_algorithm, VISA_SIZE> ( check_seq ) ;
+}
+
+template <typename check_range>
+typename boost::checks::visa_compute_algorithm::checkdigit<check_range>::type compute_visa (const check_range& check_seq)
+{
+ return boost::checks::compute_checkdigit<visa_compute_algorithm, VISA_SIZE_WITHOUT_CHECKDIGIT> ( check_seq ) ;
+}
+
 
-#endif
+}}
+#endif // BOOST_CHECKS_VISA_HPP


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