Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r82451 - sandbox/SOC/2011/checks/libs/checks/example
From: pierre.talbot.6114_at_[hidden]
Date: 2013-01-11 16:58:25


Author: trademark
Date: 2013-01-11 16:58:23 EST (Fri, 11 Jan 2013)
New Revision: 82451
URL: http://svn.boost.org/trac/boost/changeset/82451

Log:
Update the examples with the new code.
Format the examples with more standard layout.

Desactivate the check_tutorials run until it's not fixed.

Text files modified:
   sandbox/SOC/2011/checks/libs/checks/example/checks_examples.cpp | 82 +++++++++++++++++----------------------
   sandbox/SOC/2011/checks/libs/checks/example/jamfile.v2 | 2
   2 files changed, 37 insertions(+), 47 deletions(-)

Modified: sandbox/SOC/2011/checks/libs/checks/example/checks_examples.cpp
==============================================================================
--- sandbox/SOC/2011/checks/libs/checks/example/checks_examples.cpp (original)
+++ sandbox/SOC/2011/checks/libs/checks/example/checks_examples.cpp 2013-01-11 16:58:23 EST (Fri, 11 Jan 2013)
@@ -19,6 +19,7 @@
 #include <string>
 #include <exception>
 #include <iterator>
+#include <boost/lexical_cast.hpp>
 
 //[credit_cards_include_files
 #include <boost/checks/visa.hpp>
@@ -43,71 +44,60 @@
 int main()
 {
   //[checks_example_1
-
- std::string visa_credit_card_number = "4000 0807 0620 0007" ;
- if( boost::checks::check_visa( visa_credit_card_number ) )
- std::cout << "The VISA credit card number : " << visa_credit_card_number << " is valid." << std::endl ;
-
- std::string amex_credit_card_number = "3458 2531 9273 09" ;
- char amex_checkdigit = boost::checks::compute_amex( amex_credit_card_number ) ;
- std::cout << "The check digit of the American Express number : " << amex_credit_card_number << " is " << amex_checkdigit << "." << std::endl ;
-
- std::string mastercard_credit_card_number = "5320 1274 8562 157" ;
- mastercard_credit_card_number += boost::checks::compute_mastercard( mastercard_credit_card_number );
- std::cout << "This is a valid Mastercard number : " << mastercard_credit_card_number << std::endl ;
+ using namespace boost::checks;
+ std::string visa = "4000 0807 0620 0007";
+ if(check_visa(visa))
+ std::cout << "The VISA credit card number : " << visa << " is valid." << std::endl;
+
+ std::string amex = "3458 2531 9273 09";
+ size_t amex_checkdigit = compute_amex(amex);
+ std::cout << "The check digit of the American Express number \"" << amex << "\" is \'" << amex_checkdigit << "\'." << std::endl;
+
+ std::string mastercard = "5320 1274 8562 157";
+ mastercard += boost::lexical_cast<std::string>(compute_mastercard(mastercard));
+ std::cout << "\"" << mastercard << "\" is a valid mastercard number." << std::endl;
 
   //] [/checks_example_1]
 
- std::cout << std::endl ;
+ std::cout << std::endl;
 
   //[checks_example_2
 
- std::string mod97_10_number = "1234567890123456789" ;
- std::string mod97_10_checkdigits = " " ;
- boost::checks::compute_mod97_10 ( mod97_10_number , mod97_10_checkdigits.begin() ) ;
- std::cout << "The number : " << mod97_10_number << " have the check digits : " << mod97_10_checkdigits << "." << std::endl ;
-
- mod97_10_number = "85212547851652 " ;
- boost::checks::compute_mod97_10 ( mod97_10_number , mod97_10_number.end() - 2);
- std::cout << "A complete mod97-10 number : " << mod97_10_number << std::endl ;
+ std::string mod97_10 = "1234567890123456789";
+ size_t mod97_10_checkdigits = compute_mod97_10(mod97_10);
+ std::cout << "The number \"" << mod97_10 << "\" has the check digits \"" << mod97_10_checkdigits << "\"." << std::endl;
+
+ mod97_10 = "85212547851652";
+ mod97_10 += boost::lexical_cast<std::string>(compute_mod97_10(mod97_10));
+ std::cout << "A complete mod97-10 number is \"" << mod97_10 << "\"." << std::endl;
 
   //] [/checks_example_2]
 
- std::cout << std::endl ;
+ std::cout << std::endl;
 
   //[checks_example_3
 
- std::string ean13_number = "540011301748" ; // Incorrect size.
- try
- {
- boost::checks::check_ean13 ( ean13_number ) ;
- }
- catch ( std::invalid_argument e )
- {
- std::cout << e.what() << std::endl ;
- }
-
- std::string isbn13_number = "977-0321227256" ; // Third digit altered.
- try
- {
- boost::checks::check_isbn13( isbn13_number );
- }
- catch ( std::invalid_argument e )
- {
- std::cout << e.what() << std::endl ;
- }
+ std::string ean13 = "540011301748"; // Incorrect size.
+ if(!check_ean13(ean13))
+ std::cout << "The EAN \"" << ean13 << "\" is not valid." << std::endl;
+
+
+ std::string isbn13 = "977-0321227256"; // Third digit altered.
+ if(!check_isbn13(isbn13))
+ std::cout << "The ISBN-13 \"" << isbn13 << "\" is not valid." << std::endl;
+
 
   //] [/checks_example_3]
 
- std::cout << std::endl ;
+ std::cout << std::endl;
 
   //[checks_example_4
 
- std::string isbn10_number = "020163371" ; // More Effective C++: 35 New Ways to Improve Your Programs and Designs, Scott Meyers.
- int isbn10_integer_number[] = {0,2,0,1,6,3,3,7,1} ;
+ std::string isbn10 = "020163371"; // More Effective C++: 35 New Ways to Improve Your Programs and Designs, Scott Meyers.
+ int isbn10_int_array[] = {0,2,0,1,6,3,3,7,1};
 
- std::cout << "ISBN10 : " << isbn10_number << ". Check digit : " << boost::checks::compute_isbn10( isbn10_number ) << std::endl ;
- std::cout << "ISBN10 integer version. Check digit : " << boost::checks::compute_isbn10( isbn10_integer_number ) << std::endl ;
+ std::cout << "ISBN10 : " << isbn10 << ". Check digit : " << compute_isbn10(isbn10) << std::endl;
+ std::cout << "ISBN10 integer version. Check digit : " << compute_isbn10(isbn10_int_array) << std::endl;
 
   //] [/checks_example_4]
 

Modified: sandbox/SOC/2011/checks/libs/checks/example/jamfile.v2
==============================================================================
--- sandbox/SOC/2011/checks/libs/checks/example/jamfile.v2 (original)
+++ sandbox/SOC/2011/checks/libs/checks/example/jamfile.v2 2013-01-11 16:58:23 EST (Fri, 11 Jan 2013)
@@ -29,5 +29,5 @@
     ;
 
 run checks_examples.cpp ; # Example of some function in Boost.Checks.
-run checks_tutorial.cpp ; # Examples for the "Extending the library" section of the tutorial.
+#run checks_tutorial.cpp ; # Examples for the "Extending the library" section of the tutorial.
 


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