Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r53146 - in branches/release: boost/test/impl boost/test/utils/runtime/file libs/accumulators/example libs/iostreams/src libs/iostreams/test
From: jewillco_at_[hidden]
Date: 2009-05-20 19:35:09


Author: jewillco
Date: 2009-05-20 19:35:08 EDT (Wed, 20 May 2009)
New Revision: 53146
URL: http://svn.boost.org/trac/boost/changeset/53146

Log:
Fixed broken merges from last commit; kept boost::next and boost::prior changes to BGL that went in by accident in that commit, though
Text files modified:
   branches/release/boost/test/impl/unit_test_parameters.ipp | 445 ++++++++++---------------
   branches/release/boost/test/utils/runtime/file/config_file_iterator.cpp | 7
   branches/release/libs/accumulators/example/main.cpp | 2
   branches/release/libs/iostreams/src/mapped_file.cpp | 695 +++++++++++++++++++--------------------
   branches/release/libs/iostreams/test/mapped_file_test.cpp | 172 ++-------
   5 files changed, 558 insertions(+), 763 deletions(-)

Modified: branches/release/boost/test/impl/unit_test_parameters.ipp
==============================================================================
--- branches/release/boost/test/impl/unit_test_parameters.ipp (original)
+++ branches/release/boost/test/impl/unit_test_parameters.ipp 2009-05-20 19:35:08 EDT (Wed, 20 May 2009)
@@ -25,22 +25,6 @@
 #include <boost/test/utils/basic_cstring/io.hpp>
 #include <boost/test/utils/fixed_mapping.hpp>
 #include <boost/test/debug.hpp>
-#include <boost/test/framework.hpp>
-
-// Boost.Runtime.Param
-#include <boost/test/utils/runtime/cla/dual_name_parameter.hpp>
-#include <boost/test/utils/runtime/cla/parser.hpp>
-
-namespace rt = boost::runtime;
-namespace cla = rt::cla;
-
-
-#ifndef UNDER_CE
-#include <boost/test/utils/runtime/env/variable.hpp>
-
-namespace env = rt::env;
-#endif
-
 
 // Boost
 #include <boost/config.hpp>
@@ -51,7 +35,6 @@
 // STL
 #include <map>
 #include <cstdlib>
-#include <iostream>
 
 #include <boost/test/detail/suppress_warnings.hpp>
 
@@ -65,14 +48,130 @@
 
 namespace unit_test {
 
+namespace {
+
+// framework parameters and there corresponding command-line arguments
+literal_string LOG_LEVEL = "BOOST_TEST_LOG_LEVEL";
+literal_string NO_RESULT_CODE = "BOOST_TEST_RESULT_CODE";
+literal_string REPORT_LEVEL = "BOOST_TEST_REPORT_LEVEL";
+literal_string TESTS_TO_RUN = "BOOST_TESTS_TO_RUN";
+literal_string SAVE_TEST_PATTERN = "BOOST_TEST_SAVE_PATTERN";
+literal_string BUILD_INFO = "BOOST_TEST_BUILD_INFO";
+literal_string SHOW_PROGRESS = "BOOST_TEST_SHOW_PROGRESS";
+literal_string CATCH_SYS_ERRORS = "BOOST_TEST_CATCH_SYSTEM_ERRORS";
+literal_string AUTO_START_DBG = "BOOST_TEST_AUTO_START_DBG";
+literal_string USE_ALT_STACK = "BOOST_TEST_USE_ALT_STACK";
+literal_string DETECT_FP_EXCEPT = "BOOST_TEST_DETECT_FP_EXCEPTIONS";
+literal_string REPORT_FORMAT = "BOOST_TEST_REPORT_FORMAT";
+literal_string LOG_FORMAT = "BOOST_TEST_LOG_FORMAT";
+literal_string OUTPUT_FORMAT = "BOOST_TEST_OUTPUT_FORMAT";
+literal_string DETECT_MEM_LEAK = "BOOST_TEST_DETECT_MEMORY_LEAK";
+literal_string RANDOM_SEED = "BOOST_TEST_RANDOM";
+literal_string BREAK_EXEC_PATH = "BOOST_TEST_BREAK_EXEC_PATH";
+
+unit_test::log_level s_log_level;
+bool s_no_result_code;
+unit_test::report_level s_report_level;
+const_string s_tests_to_run;
+const_string s_exec_path_to_break;
+bool s_save_pattern;
+bool s_show_build_info;
+bool s_show_progress;
+bool s_catch_sys_errors;
+bool s_auto_start_dbg;
+bool s_use_alt_stack;
+bool s_detect_fp_except;
+output_format s_report_format;
+output_format s_log_format;
+long s_detect_mem_leaks;
+unsigned int s_random_seed;
+
 // ************************************************************************** //
-// ************** input operations for unit_test's enums ************** //
+// ************** runtime_config ************** //
 // ************************************************************************** //
 
-std::istream&
-operator>>( std::istream& in, unit_test::log_level& ll )
+const_string
+retrieve_framework_parameter( const_string parameter_name, int* argc, char** argv )
 {
- static fixed_mapping<const_string,unit_test::log_level,case_ins_less<char const> > log_level_name(
+ static fixed_mapping<const_string,const_string> parameter_2_cla_name_map(
+ LOG_LEVEL , "--log_level",
+ NO_RESULT_CODE , "--result_code",
+ REPORT_LEVEL , "--report_level",
+ TESTS_TO_RUN , "--run_test",
+ SAVE_TEST_PATTERN , "--save_pattern",
+ BUILD_INFO , "--build_info",
+ SHOW_PROGRESS , "--show_progress",
+ CATCH_SYS_ERRORS , "--catch_system_errors",
+ AUTO_START_DBG , "--auto_start_dbg",
+ USE_ALT_STACK , "--use_alt_stack",
+ DETECT_FP_EXCEPT , "--detect_fp_exceptions",
+ REPORT_FORMAT , "--report_format",
+ LOG_FORMAT , "--log_format",
+ OUTPUT_FORMAT , "--output_format",
+ DETECT_MEM_LEAK , "--detect_memory_leaks",
+ RANDOM_SEED , "--random",
+ BREAK_EXEC_PATH , "--break_exec_path",
+
+ ""
+ );
+
+ // first try to find parameter among command line arguments if present
+ if( argc ) {
+ // locate corresponding cla name
+ const_string cla_name = parameter_2_cla_name_map[parameter_name];
+
+ if( !cla_name.is_empty() ) {
+ for( int i = 1; i < *argc; ++i ) {
+ if( cla_name == const_string( argv[i], cla_name.size() ) && argv[i][cla_name.size()] == '=' ) {
+ const_string result = argv[i] + cla_name.size() + 1;
+
+ for( int j = i; j < *argc; ++j ) {
+ argv[j] = argv[j+1];
+ }
+ --(*argc);
+
+ return result;
+ }
+ }
+ }
+ }
+
+ return std::getenv( parameter_name.begin() );
+}
+
+long interpret_long( const_string from )
+{
+ bool negative = false;
+ long res = 0;
+
+ if( first_char( from ) == '-' ) {
+ negative = true;
+ from.trim_left( 1 );
+ }
+
+ const_string::iterator it = from.begin();
+ for( ;it != from.end(); ++it ) {
+ int d = *it - '0';
+
+ res = 10 * res + d;
+ }
+
+ if( negative )
+ res = -res;
+
+ return res;
+}
+
+} // local namespace
+
+//____________________________________________________________________________//
+
+namespace runtime_config {
+
+void
+init( int* argc, char** argv )
+{
+ fixed_mapping<const_string,unit_test::log_level,case_ins_less<char const> > log_level_name(
         "all" , log_successful_tests,
         "success" , log_successful_tests,
         "test_suite" , log_test_units,
@@ -86,22 +185,8 @@
         "nothing" , log_nothing,
 
         invalid_log_level
- );
-
- std::string val;
- in >> val;
-
- ll = log_level_name[val];
- BOOST_TEST_SETUP_ASSERT( ll != unit_test::invalid_log_level, "invalid log level " + val );
-
- return in;
-}
+ );
 
-//____________________________________________________________________________//
-
-std::istream&
-operator>>( std::istream& in, unit_test::report_level& rl )
-{
     fixed_mapping<const_string,unit_test::report_level,case_ins_less<char const> > report_level_name (
         "confirm", CONFIRMATION_REPORT,
         "short", SHORT_REPORT,
@@ -109,215 +194,57 @@
         "no", NO_REPORT,
 
         INV_REPORT_LEVEL
- );
-
- std::string val;
- in >> val;
-
- rl = report_level_name[val];
- BOOST_TEST_SETUP_ASSERT( rl != INV_REPORT_LEVEL, "invalid report level " + val );
+ );
 
- return in;
-}
-
-//____________________________________________________________________________//
-
-std::istream&
-operator>>( std::istream& in, unit_test::output_format& of )
-{
- fixed_mapping<const_string,unit_test::output_format,case_ins_less<char const> > output_format_name (
- "HRF", unit_test::CLF,
- "CLF", unit_test::CLF,
- "XML", unit_test::XML,
-
- unit_test::INV_OF
- );
-
- std::string val;
- in >> val;
-
- of = output_format_name[val];
- BOOST_TEST_SETUP_ASSERT( of != unit_test::INV_OF, "invalid output format " + val );
-
- return in;
-}
-
-//____________________________________________________________________________//
-
-// ************************************************************************** //
-// ************** runtime_config ************** //
-// ************************************************************************** //
-
-namespace runtime_config {
-
-namespace {
-
-// framework parameters and corresponding command-line arguments
-std::string AUTO_START_DBG = "auto_start_dbg";
-std::string BREAK_EXEC_PATH = "break_exec_path";
-std::string BUILD_INFO = "build_info";
-std::string CATCH_SYS_ERRORS = "catch_system_errors";
-std::string DETECT_FP_EXCEPT = "detect_fp_exceptions";
-std::string DETECT_MEM_LEAKS = "detect_memory_leaks";
-std::string LOG_FORMAT = "log_format";
-std::string LOG_LEVEL = "log_level";
-std::string OUTPUT_FORMAT = "output_format";
-std::string RANDOM_SEED = "random";
-std::string REPORT_FORMAT = "report_format";
-std::string REPORT_LEVEL = "report_level";
-std::string RESULT_CODE = "result_code";
-std::string TESTS_TO_RUN = "run_test";
-std::string SAVE_TEST_PATTERN = "save_pattern";
-std::string SHOW_PROGRESS = "show_progress";
-std::string USE_ALT_STACK = "use_alt_stack";
-
-fixed_mapping<const_string,const_string> parameter_2_env_var(
- AUTO_START_DBG , "BOOST_TEST_AUTO_START_DBG",
- BREAK_EXEC_PATH , "BOOST_TEST_BREAK_EXEC_PATH",
- BUILD_INFO , "BOOST_TEST_BUILD_INFO",
- CATCH_SYS_ERRORS , "BOOST_TEST_CATCH_SYSTEM_ERRORS",
- DETECT_FP_EXCEPT , "BOOST_TEST_DETECT_FP_EXCEPTIONS",
- DETECT_MEM_LEAKS , "BOOST_TEST_DETECT_MEMORY_LEAK",
- LOG_FORMAT , "BOOST_TEST_LOG_FORMAT",
- LOG_LEVEL , "BOOST_TEST_LOG_LEVEL",
- OUTPUT_FORMAT , "BOOST_TEST_OUTPUT_FORMAT",
- RANDOM_SEED , "BOOST_TEST_RANDOM",
- REPORT_FORMAT , "BOOST_TEST_REPORT_FORMAT",
- REPORT_LEVEL , "BOOST_TEST_REPORT_LEVEL",
- RESULT_CODE , "BOOST_TEST_RESULT_CODE",
- TESTS_TO_RUN , "BOOST_TESTS_TO_RUN",
- SAVE_TEST_PATTERN , "BOOST_TEST_SAVE_PATTERN",
- SHOW_PROGRESS , "BOOST_TEST_SHOW_PROGRESS",
- USE_ALT_STACK , "BOOST_TEST_USE_ALT_STACK",
-
- ""
-);
-
-//____________________________________________________________________________//
-
-// storage for the CLAs
-cla::parser s_cla_parser;
-std::string s_empty;
-
-output_format s_report_format;
-output_format s_log_format;
-
-//____________________________________________________________________________//
-
-template<typename T>
-T
-retrieve_parameter( const_string parameter_name, cla::parser const& s_cla_parser, T const& default_value = T(), T const& optional_value = T() )
-{
- rt::const_argument_ptr arg = s_cla_parser[parameter_name];
- if( arg ) {
- if( rtti::type_id<T>() == rtti::type_id<bool>() ||
- !static_cast<cla::parameter const&>( arg->p_formal_parameter.get() ).p_optional_value )
- return s_cla_parser.get<T>( parameter_name );
-
- optional<T> val = s_cla_parser.get<optional<T> >( parameter_name );
- return val ? *val : optional_value;
+ fixed_mapping<const_string,output_format,case_ins_less<char const> > output_format_name (
+ "HRF", CLF,
+ "CLF", CLF,
+ "XML", XML,
+
+ CLF
+ );
+
+ s_no_result_code = retrieve_framework_parameter( NO_RESULT_CODE, argc, argv ) == "no";
+ s_save_pattern = retrieve_framework_parameter( SAVE_TEST_PATTERN, argc, argv ) == "yes";
+ s_show_build_info = retrieve_framework_parameter( BUILD_INFO, argc, argv ) == "yes";
+ s_show_progress = retrieve_framework_parameter( SHOW_PROGRESS, argc, argv ) == "yes";
+#ifdef BOOST_TEST_DEFAULTS_TO_CORE_DUMP
+ s_catch_sys_errors = retrieve_framework_parameter( CATCH_SYS_ERRORS, argc, argv ) == "yes";
+#else
+ s_catch_sys_errors = retrieve_framework_parameter( CATCH_SYS_ERRORS, argc, argv ) != "no";
+#endif
+ s_use_alt_stack = retrieve_framework_parameter( USE_ALT_STACK, argc, argv ) != "no";
+ s_detect_fp_except = retrieve_framework_parameter( DETECT_FP_EXCEPT, argc, argv ) == "yes";
+ s_tests_to_run = retrieve_framework_parameter( TESTS_TO_RUN, argc, argv );
+ s_exec_path_to_break= retrieve_framework_parameter( BREAK_EXEC_PATH, argc, argv );
+
+ const_string rs_str = retrieve_framework_parameter( RANDOM_SEED, argc, argv );
+ s_random_seed = rs_str.is_empty() ? 0 : lexical_cast<unsigned int>( rs_str );
+
+ s_log_level = log_level_name[retrieve_framework_parameter( LOG_LEVEL, argc, argv )];
+ s_report_level = report_level_name[retrieve_framework_parameter( REPORT_LEVEL, argc, argv )];
+
+ s_report_format = output_format_name[retrieve_framework_parameter( REPORT_FORMAT, argc, argv )];
+ s_log_format = output_format_name[retrieve_framework_parameter( LOG_FORMAT, argc, argv )];
+
+ const_string output_format = retrieve_framework_parameter( OUTPUT_FORMAT, argc, argv );
+ if( !output_format.is_empty() ) {
+ s_report_format = output_format_name[output_format];
+ s_log_format = output_format_name[output_format];
     }
 
- boost::optional<T> v;
-
- #ifndef UNDER_CE
- env::get( parameter_2_env_var[parameter_name], v );
- #endif
-
- return v? *v : default_value;
-}
-
-//____________________________________________________________________________//
-
-} // local namespace
-
-void
-init( int& argc, char** argv )
-{
- using namespace cla;
-
- try {
- s_cla_parser - cla::ignore_mismatch
- << cla::dual_name_parameter<bool>( AUTO_START_DBG + "|d" )
- - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional,
- cla::description = "Automatically starts debugger if system level error (signal) occurs")
- << cla::named_parameter<std::string>( BREAK_EXEC_PATH )
- - (cla::prefix = "--",cla::separator = "=",cla::guess_name,cla::optional,
- cla::description = "For the exception safety testing allows to break at specific execution path")
- << cla::dual_name_parameter<bool>( BUILD_INFO + "|i" )
- - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional,
- cla::description = "Shows library build information" )
- << cla::dual_name_parameter<bool>( CATCH_SYS_ERRORS + "|s" )
- - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional,
- cla::description = "Allows to switch between catching and ignoring system errors (signals)")
- << cla::named_parameter<bool>( DETECT_FP_EXCEPT )
- - (cla::prefix = "--",cla::separator = "=",cla::guess_name,cla::optional,
- cla::description = "Allows to switch between catching and ignoring floating point exceptions")
- << cla::named_parameter<long>( DETECT_MEM_LEAKS )
- - (cla::prefix = "--",cla::separator = "=",cla::guess_name,cla::optional,
- cla::description = "Allows to switch between catching and ignoring memory leaks")
- << cla::dual_name_parameter<unit_test::output_format>( LOG_FORMAT + "|f" )
- - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional,
- cla::description = "Specifies log format")
- << cla::dual_name_parameter<unit_test::log_level>( LOG_LEVEL + "|l" )
- - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional,
- cla::description = "Specifies log level")
- << cla::dual_name_parameter<unit_test::output_format>( OUTPUT_FORMAT + "|o" )
- - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional,
- cla::description = "Specifies output format (both log and report)")
- << cla::dual_name_parameter<int>( RANDOM_SEED + "|a" )
- - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional,cla::optional_value,
- cla::description = "Allows to switch between sequential and random order of test units execution.\n"
- "Optionally allows to specify concrete seed for random number generator")
- << cla::dual_name_parameter<unit_test::output_format>( REPORT_FORMAT + "|m" )
- - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional,
- cla::description = "Specifies report format")
- << cla::dual_name_parameter<unit_test::report_level>(REPORT_LEVEL + "|r")
- - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional,
- cla::description = "Specifies report level")
- << cla::dual_name_parameter<bool>( RESULT_CODE + "|c" )
- - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional,
- cla::description = "Allows to disable test modules's result code generation")
- << cla::dual_name_parameter<std::string>( TESTS_TO_RUN + "|t" )
- - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional,
- cla::description = "Allows to filter which test units to run")
- << cla::named_parameter<bool>( SAVE_TEST_PATTERN )
- - (cla::prefix = "--",cla::separator = "=",cla::guess_name,cla::optional,
- cla::description = "Allows to switch between saving and matching against test pattern file")
- << cla::dual_name_parameter<bool>( SHOW_PROGRESS + "|p" )
- - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional,
- cla::description = "Turns on progress display")
- << cla::named_parameter<bool>( USE_ALT_STACK )
- - (cla::prefix = "--",cla::separator = "=",cla::guess_name,cla::optional,
- cla::description = "Turns on/off usage of an alternative stack for signal handling")
-
- << cla::dual_name_parameter<bool>( "help|?" )
- - (cla::prefix = "--|-",cla::separator = "=",cla::guess_name,cla::optional,
- cla::description = "this help message")
- ;
-
- s_cla_parser.parse( argc, argv );
-
- if( s_cla_parser["help"] ) {
- s_cla_parser.help( std::cout );
- throw framework::nothing_to_test();
- }
-
- s_report_format = retrieve_parameter( REPORT_FORMAT, s_cla_parser, unit_test::CLF );
- s_log_format = retrieve_parameter( LOG_FORMAT, s_cla_parser, unit_test::CLF );
+ const_string ml_str = retrieve_framework_parameter( DETECT_MEM_LEAK, argc, argv );
+ s_detect_mem_leaks = ml_str.is_empty() ? 1 : interpret_long( ml_str );
 
- unit_test::output_format of = retrieve_parameter( OUTPUT_FORMAT, s_cla_parser, unit_test::INV_OF );
+ const_string dbg = retrieve_framework_parameter( AUTO_START_DBG, argc, argv );
 
- if( of != unit_test::INV_OF )
- s_report_format = s_log_format = of;
- }
- catch( rt::logic_error const& ex ) {
- std::ostringstream err;
-
- err << "Fail to process runtime parameters: " << ex.msg() << std::endl;
- s_cla_parser.usage( err );
+ if( dbg.is_empty() || dbg == "no" )
+ s_auto_start_dbg = false;
+ else {
+ s_auto_start_dbg = true;
 
- throw framework::setup_error( err.str() );
+ if( dbg != "yes" )
+ debug::set_debugger( dbg );
     }
 }
 
@@ -326,7 +253,7 @@
 unit_test::log_level
 log_level()
 {
- return retrieve_parameter( LOG_LEVEL, s_cla_parser, unit_test::log_all_errors );
+ return s_log_level;
 }
 
 //____________________________________________________________________________//
@@ -334,7 +261,7 @@
 bool
 no_result_code()
 {
- return !retrieve_parameter( RESULT_CODE, s_cla_parser, true );
+ return s_no_result_code;
 }
 
 //____________________________________________________________________________//
@@ -342,7 +269,7 @@
 unit_test::report_level
 report_level()
 {
- return retrieve_parameter( REPORT_LEVEL, s_cla_parser, unit_test::CONFIRMATION_REPORT );
+ return s_report_level;
 }
 
 //____________________________________________________________________________//
@@ -350,9 +277,7 @@
 const_string
 test_to_run()
 {
- static std::string s_test_to_run = retrieve_parameter( TESTS_TO_RUN, s_cla_parser, s_empty );
-
- return s_test_to_run;
+ return s_tests_to_run;
 }
 
 //____________________________________________________________________________//
@@ -360,9 +285,7 @@
 const_string
 break_exec_path()
 {
- static std::string s_break_exec_path = retrieve_parameter( BREAK_EXEC_PATH, s_cla_parser, s_empty );
-
- return s_break_exec_path;
+ return s_exec_path_to_break;
 }
 
 //____________________________________________________________________________//
@@ -370,7 +293,7 @@
 bool
 save_pattern()
 {
- return retrieve_parameter( SAVE_TEST_PATTERN, s_cla_parser, false );
+ return s_save_pattern;
 }
 
 //____________________________________________________________________________//
@@ -378,7 +301,7 @@
 bool
 show_progress()
 {
- return retrieve_parameter( SHOW_PROGRESS, s_cla_parser, false );
+ return s_show_progress;
 }
 
 //____________________________________________________________________________//
@@ -386,7 +309,7 @@
 bool
 show_build_info()
 {
- return retrieve_parameter( BUILD_INFO, s_cla_parser, false );
+ return s_show_build_info;
 }
 
 //____________________________________________________________________________//
@@ -394,13 +317,7 @@
 bool
 catch_sys_errors()
 {
- return retrieve_parameter( CATCH_SYS_ERRORS, s_cla_parser,
-#ifdef BOOST_TEST_DEFAULTS_TO_CORE_DUMP
- false
-#else
- true
-#endif
- );
+ return s_catch_sys_errors;
 }
 
 //____________________________________________________________________________//
@@ -408,9 +325,7 @@
 bool
 auto_start_dbg()
 {
- // !! set debugger as an option
- return retrieve_parameter( AUTO_START_DBG, s_cla_parser, false );
-;
+ return s_auto_start_dbg;
 }
 
 //____________________________________________________________________________//
@@ -418,7 +333,7 @@
 bool
 use_alt_stack()
 {
- return retrieve_parameter( USE_ALT_STACK, s_cla_parser, true );
+ return s_use_alt_stack;
 }
 
 //____________________________________________________________________________//
@@ -426,7 +341,7 @@
 bool
 detect_fp_exceptions()
 {
- return retrieve_parameter( DETECT_FP_EXCEPT, s_cla_parser, false );
+ return s_detect_fp_except;
 }
 
 //____________________________________________________________________________//
@@ -450,7 +365,7 @@
 long
 detect_memory_leaks()
 {
- return retrieve_parameter( DETECT_MEM_LEAKS, s_cla_parser, (long)1 );
+ return s_detect_mem_leaks;
 }
 
 //____________________________________________________________________________//
@@ -458,7 +373,7 @@
 int
 random_seed()
 {
- return retrieve_parameter( RANDOM_SEED, s_cla_parser, 0, 1 );
+ return s_random_seed;
 }
 
 //____________________________________________________________________________//

Modified: branches/release/boost/test/utils/runtime/file/config_file_iterator.cpp
==============================================================================
--- branches/release/boost/test/utils/runtime/file/config_file_iterator.cpp (original)
+++ branches/release/boost/test/utils/runtime/file/config_file_iterator.cpp 2009-05-20 19:35:08 EDT (Wed, 20 May 2009)
@@ -18,10 +18,7 @@
 #include <boost/test/utils/runtime/file/config_file_iterator.hpp>
 #include <boost/test/utils/runtime/validation.hpp>
 
-#ifndef UNDER_CE
 #include <boost/test/utils/runtime/env/environment.hpp>
-#endif
-
 
 // Boost
 #include <boost/utility.hpp>
@@ -158,7 +155,7 @@
         }
     }
 
- BOOST_RT_PARAM_VALIDATE_LOGIC( m_stream.is_open(), BOOST_RT_PARAM_LITERAL( "can't open file " ) << file_name );
+ BOOST_RT_PARAM_VALIDATE_LOGIC( m_stream.is_open(), BOOST_RT_PARAM_LITERAL( "couldn't open file " ) << file_name );
 }
 
 //____________________________________________________________________________//
@@ -355,9 +352,7 @@
     if( it == m_symbols_table.end() ) {
         boost::optional<cstring> macro_value; // !! variable actually may have different type
 
- #ifndef UNDER_CE
         env::get( macro_name, macro_value );
- #endif
 
         BOOST_RT_PARAM_VALIDATE_LOGIC( macro_value || ignore_missing || !m_detect_missing_macro,
             BOOST_RT_PARAM_LITERAL( "Unknown macro \"" ) << macro_name << BOOST_RT_PARAM_LITERAL( "\"" ) );

Modified: branches/release/libs/accumulators/example/main.cpp
==============================================================================
--- branches/release/libs/accumulators/example/main.cpp (original)
+++ branches/release/libs/accumulators/example/main.cpp 2009-05-20 19:35:08 EDT (Wed, 20 May 2009)
@@ -54,7 +54,7 @@
     // by value.
     //std::for_each(data.begin(), data.end(), bind<void>(ref(acc), _1));
 
- std::cout << " min""(acc) = " << (min)(acc) << std::endl; // Extra quotes are to prevent complaints from Boost inspect tool
+ std::cout << " min(acc) = " << (min)(acc) << std::endl;
     std::cout << " mean(acc) = " << mean(acc) << std::endl;
 
     // since mean depends on count and sum, we can get their results, too.

Modified: branches/release/libs/iostreams/src/mapped_file.cpp
==============================================================================
--- branches/release/libs/iostreams/src/mapped_file.cpp (original)
+++ branches/release/libs/iostreams/src/mapped_file.cpp 2009-05-20 19:35:08 EDT (Wed, 20 May 2009)
@@ -1,7 +1,12 @@
+// (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
+// (C) Copyright 2004-2007 Jonathan Turkanis
 // (C) Copyright Craig Henderson 2002 'boost/memmap.hpp' from sandbox
-// (C) Copyright Jonathan Turkanis 2004.
 // (C) Copyright Jonathan Graehl 2004.
-// (C) Copyright Jorge Lodos 2008.
+
+// 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/libs/iostreams for documentation.
 
 // Define BOOST_IOSTREAMS_SOURCE so that <boost/iostreams/detail/config.hpp>
 // knows that we are building the library (possibly exporting code), rather
@@ -9,15 +14,21 @@
 #define BOOST_IOSTREAMS_SOURCE
 
 #include <cassert>
-#include <boost/iostreams/detail/config/rtl.hpp>
+#ifndef NDEBUG
+# include <boost/iostreams/detail/absolute_path.hpp>
+#endif
+#include <boost/iostreams/detail/config/dyn_link.hpp>
 #include <boost/iostreams/detail/config/windows_posix.hpp>
-#include <boost/iostreams/detail/file_handle.hpp>
+#include <boost/iostreams/detail/ios.hpp> // failure.
 #include <boost/iostreams/detail/system_failure.hpp>
 #include <boost/iostreams/device/mapped_file.hpp>
 
 #ifdef BOOST_IOSTREAMS_WINDOWS
 # define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
 # include <windows.h>
+# ifndef INVALID_SET_FILE_POINTER
+# define INVALID_SET_FILE_POINTER ((DWORD)-1)
+# endif
 #else
 # include <errno.h>
 # include <fcntl.h>
@@ -27,453 +38,423 @@
 # include <unistd.h> // sysconf.
 #endif
 
+#include <boost/iostreams/detail/config/disable_warnings.hpp>
+
 namespace boost { namespace iostreams {
 
 namespace detail {
 
-// Class containing the platform-sepecific implementation
-// Invariant: The members params_, data_, size_, handle_ (and mapped_handle_
-// on Windows) either
-// - all have default values (or INVALID_HANDLE_VALUE for
-// Windows handles), or
-// - all have values reflecting a successful mapping.
-// In the first case, error_ may be true, reflecting a recent unsuccessful
-// open or close attempt; in the second case, error_ is always false.
-class mapped_file_impl {
-public:
- typedef mapped_file_source::size_type size_type;
- typedef mapped_file_source::param_type param_type;
- typedef mapped_file_source::mapmode mapmode;
- BOOST_STATIC_CONSTANT(
- size_type, max_length = mapped_file_source::max_length);
- mapped_file_impl();
- ~mapped_file_impl();
- void open(param_type p);
- bool is_open() const { return data_ != 0; }
- void close();
- bool error() const { return error_; }
- mapmode flags() const { return params_.flags; }
- std::size_t size() const { return size_; }
- char* data() const { return data_; }
- void resize(stream_offset new_size);
- static int alignment();
-private:
- void open_file(param_type p);
- void try_map_file(param_type p);
- void map_file(param_type& p);
- bool unmap_file();
- void clear(bool error);
- void cleanup_and_throw(const char* msg);
- param_type params_;
- char* data_;
- stream_offset size_;
- file_handle handle_;
+struct mapped_file_impl {
+ mapped_file_impl() { clear(false); }
+ ~mapped_file_impl() { try { close(); } catch (...) { } }
+ void clear(bool error)
+ {
+ data_ = 0;
+ size_ = 0;
+ mode_ = BOOST_IOS::openmode();
+ error_ = error;
+ #ifdef BOOST_IOSTREAMS_WINDOWS
+ handle_ = INVALID_HANDLE_VALUE;
+ mapped_handle_ = NULL;
+ #else
+ handle_ = 0;
+ #endif
+ #ifndef NDEBUG
+ path_.erase();
+ #endif
+ }
+ void close()
+ {
+ bool error = false;
+ #ifdef BOOST_IOSTREAMS_WINDOWS
+ if (handle_ == INVALID_HANDLE_VALUE)
+ return;
+ error = !::UnmapViewOfFile(data_) || error;
+ error = !::CloseHandle(mapped_handle_) || error;
+ error = !::CloseHandle(handle_) || error;
+ handle_ = INVALID_HANDLE_VALUE;
+ mapped_handle_ = NULL;
+ #else
+ if (!handle_)
+ return;
+ error = ::munmap(reinterpret_cast<char*>(data_), size_) != 0 || error;
+ error = ::close(handle_) != 0 || error;
+ handle_ = 0;
+ #endif
+ data_ = 0;
+ size_ = 0;
+ mode_ = BOOST_IOS::openmode();
+ if (error) {
+ std::string msg("error closing mapped file");
+ #ifndef NDEBUG
+ msg += std::string(" (\"") + path_ + "\")";
+ #endif
+ throw_system_failure(msg);
+ }
+ #ifndef NDEBUG
+ path_.erase();
+ #endif
+ }
+ char* data_;
+ std::size_t size_;
+ BOOST_IOS::openmode mode_;
+ bool error_;
 #ifdef BOOST_IOSTREAMS_WINDOWS
- file_handle mapped_handle_;
+ HANDLE handle_;
+ HANDLE mapped_handle_;
+#else
+ int handle_;
+#endif
+#ifndef NDEBUG
+ std::string path_;
 #endif
- bool error_;
 };
 
-mapped_file_impl::mapped_file_impl() { clear(false); }
+} // End namespace detail.
+
+//------------------Definition of mapped_file_source--------------------------//
+
+mapped_file_source::mapped_file_source(mapped_file_params p) { open(p); }
 
-mapped_file_impl::~mapped_file_impl()
-{ try { close(); } catch (...) { } }
+mapped_file_source::mapped_file_source( const std::string& path,
+ mapped_file_source::size_type length,
+ boost::intmax_t offset )
+{ open(path, length, offset); }
 
-void mapped_file_impl::open(param_type p)
+void mapped_file_source::open(mapped_file_params p)
 {
- if (is_open())
- throw BOOST_IOSTREAMS_FAILURE("file already open");
- p.normalize();
- open_file(p);
- map_file(p); // May modify p.hint
- params_ = p;
-}
-
-void mapped_file_impl::close()
-{
- if (data_ == 0)
- return;
- bool error = false;
- error = !unmap_file() || error;
- error =
- #ifdef BOOST_IOSTREAMS_WINDOWS
- !::CloseHandle(handle_)
- #else
- ::close(handle_) != 0
- #endif
- || error;
- clear(error);
- if (error)
- throw_system_failure("failed closing mapped file");
-}
-
-void mapped_file_impl::resize(stream_offset new_size)
-{
- if (!is_open())
- throw BOOST_IOSTREAMS_FAILURE("file is closed");
- if (flags() & mapped_file::priv)
- throw BOOST_IOSTREAMS_FAILURE("can't resize private mapped file");
- if (!(flags() & mapped_file::readwrite))
- throw BOOST_IOSTREAMS_FAILURE("can't resize readonly mapped file");
- if (params_.offset >= new_size)
- throw BOOST_IOSTREAMS_FAILURE("can't resize below mapped offset");
- if (!unmap_file())
- cleanup_and_throw("failed unmapping file");
-#ifdef BOOST_IOSTREAMS_WINDOWS
- stream_offset offset = ::SetFilePointer(handle_, 0, NULL, FILE_CURRENT);
- if (::GetLastError() != NO_ERROR)
- cleanup_and_throw("failed querying file pointer");
- LONG sizehigh = (new_size >> (sizeof(LONG) * 8));
- LONG sizelow = (new_size & 0xffffffff);
- ::SetFilePointer(handle_, sizelow, &sizehigh, FILE_BEGIN);
- if (::GetLastError() != NO_ERROR || !::SetEndOfFile(handle_))
- cleanup_and_throw("failed resizing mapped file");
- sizehigh = (offset >> (sizeof(LONG) * 8));
- sizelow = (offset & 0xffffffff);
- ::SetFilePointer(handle_, sizelow, &sizehigh, FILE_BEGIN);
-#else
- if (BOOST_IOSTREAMS_FD_TRUNCATE(handle_, new_size) == -1)
- cleanup_and_throw("failed resizing mapped file");
-#endif
- size_ = new_size;
- param_type p(params_);
- map_file(p); // May modify p.hint
- params_ = p;
+ p.mode &= ~BOOST_IOS::out;
+ open_impl(p);
 }
 
-int mapped_file_impl::alignment()
+void mapped_file_source::open( const std::string& path,
+ mapped_file_source::size_type length,
+ boost::intmax_t offset )
 {
-#ifdef BOOST_IOSTREAMS_WINDOWS
- SYSTEM_INFO info;
- ::GetSystemInfo(&info);
- return static_cast<int>(info.dwAllocationGranularity);
-#else
- return static_cast<int>(sysconf(_SC_PAGESIZE));
-#endif
+ mapped_file_params p(path);
+ p.mode = BOOST_IOS::in;
+ p.length = length;
+ p.offset = offset;
+ open_impl(p);
 }
 
-void mapped_file_impl::open_file(param_type p)
+mapped_file_source::size_type mapped_file_source::size() const
+{ return pimpl_->size_; }
+
+void mapped_file_source::close() { pimpl_->close(); }
+
+mapped_file_source::operator mapped_file_source::safe_bool() const
 {
- bool readonly = p.flags != mapped_file::readwrite;
-#ifdef BOOST_IOSTREAMS_WINDOWS
+ return !!pimpl_ && pimpl_->error_ == false ?
+ &safe_bool_helper::x : 0;
+}
+
+bool mapped_file_source::operator!() const
+{ return !!pimpl_ || pimpl_->error_; }
+
+BOOST_IOS::openmode mapped_file_source::mode() const { return pimpl_->mode_; }
+
+const char* mapped_file_source::data() const { return pimpl_->data_; }
+
+const char* mapped_file_source::begin() const { return data(); }
+
+const char* mapped_file_source::end() const { return data() + size(); }
+
+#ifdef BOOST_IOSTREAMS_WINDOWS //---------------------------------------------//
+
+namespace detail {
 
- // Open file
- DWORD dwDesiredAccess = readonly ? GENERIC_READ : GENERIC_ALL;
- DWORD dwCreationDisposition = (p.new_file_size != 0 && !readonly) ?
- CREATE_ALWAYS :
- OPEN_EXISTING;
- DWORD dwFlagsandAttributes =
- readonly ?
- FILE_ATTRIBUTE_READONLY :
- FILE_ATTRIBUTE_TEMPORARY;
- handle_ = p.path.is_wide() ?
- ::CreateFileW(
- p.path.c_wstr(),
- dwDesiredAccess,
- FILE_SHARE_READ,
- NULL,
- dwCreationDisposition,
- dwFlagsandAttributes,
- NULL ) :
- ::CreateFileA(
- p.path.c_str(),
- dwDesiredAccess,
- FILE_SHARE_READ,
- NULL,
- dwCreationDisposition,
- dwFlagsandAttributes,
- NULL );
- if (handle_ == INVALID_HANDLE_VALUE)
- cleanup_and_throw("failed opening file");
+void cleanup_and_throw(detail::mapped_file_impl& impl, std::string msg)
+{
+ #ifndef NDEBUG
+ msg += std::string(" (\"") + impl.path_ + "\")";
+ #endif
+ if (impl.mapped_handle_ != INVALID_HANDLE_VALUE)
+ ::CloseHandle(impl.mapped_handle_);
+ if (impl.handle_ != NULL)
+ ::CloseHandle(impl.handle_);
+ impl.clear(true);
+ throw_system_failure(msg);
+}
+
+} // End namespace detail.
+
+void mapped_file_source::open_impl(mapped_file_params p)
+{
+ using namespace std;
+
+ if (is_open())
+ throw BOOST_IOSTREAMS_FAILURE("file already open");
+ if (!pimpl_)
+ pimpl_.reset(new impl_type);
+ else
+ pimpl_->clear(false);
+ bool readonly = (p.mode & BOOST_IOS::out) == 0;
+ pimpl_->mode_ = readonly ? BOOST_IOS::in : (BOOST_IOS::in | BOOST_IOS::out);
+ #ifndef NDEBUG
+ pimpl_->path_ = detail::absolute_path(p.path);
+ #endif
+
+ //--------------Open underlying file--------------------------------------//
+
+ pimpl_->handle_ =
+ ::CreateFileA( p.path.c_str(),
+ readonly ? GENERIC_READ : GENERIC_ALL,
+ FILE_SHARE_READ,
+ NULL,
+ (p.new_file_size != 0 && !readonly) ?
+ CREATE_ALWAYS :
+ OPEN_EXISTING,
+ readonly ?
+ FILE_ATTRIBUTE_READONLY :
+ FILE_ATTRIBUTE_TEMPORARY,
+ NULL );
+
+ if (pimpl_->handle_ == INVALID_HANDLE_VALUE) {
+ detail::cleanup_and_throw(*pimpl_, "failed opening file");
+ }
+
+ //--------------Set file size---------------------------------------------//
 
- // Set file size
     if (p.new_file_size != 0 && !readonly) {
         LONG sizehigh = (p.new_file_size >> (sizeof(LONG) * 8));
         LONG sizelow = (p.new_file_size & 0xffffffff);
- ::SetFilePointer(handle_, sizelow, &sizehigh, FILE_BEGIN);
- if (::GetLastError() != NO_ERROR || !::SetEndOfFile(handle_))
- cleanup_and_throw("failed setting file size");
+ DWORD result =
+ ::SetFilePointer(pimpl_->handle_, sizelow, &sizehigh, FILE_BEGIN);
+ if ( result == INVALID_SET_FILE_POINTER &&
+ ::GetLastError() != NO_ERROR ||
+ !::SetEndOfFile(pimpl_->handle_) )
+ {
+ detail::cleanup_and_throw(*pimpl_, "failed setting file size");
+ }
+ }
+
+ //--------------Create mapping--------------------------------------------//
+
+ try_again: // Target of goto in following section.
+
+ pimpl_->mapped_handle_ =
+ ::CreateFileMappingA( pimpl_->handle_, NULL,
+ readonly ? PAGE_READONLY : PAGE_READWRITE,
+ 0, 0, NULL );
+ if (pimpl_->mapped_handle_ == NULL) {
+ detail::cleanup_and_throw(*pimpl_, "couldn't create mapping");
     }
 
- // Determine file size. Dynamically locate GetFileSizeEx for compatibility
- // with old Platform SDK (thanks to Pavel Vozenilik).
+ //--------------Access data-----------------------------------------------//
+
+ void* data =
+ ::MapViewOfFileEx( pimpl_->mapped_handle_,
+ readonly ? FILE_MAP_READ : FILE_MAP_WRITE,
+ (DWORD) (p.offset >> 32),
+ (DWORD) (p.offset & 0xffffffff),
+ p.length != max_length ? p.length : 0, (LPVOID) p.hint );
+ if (!data) {
+ if (p.hint != 0) {
+ p.hint = 0;
+ goto try_again;
+ }
+ detail::cleanup_and_throw(*pimpl_, "failed mapping view");
+ }
+
+ //--------------Determing file size---------------------------------------//
+
+ // Dynamically locate GetFileSizeEx (thanks to Pavel Vozenilik).
     typedef BOOL (WINAPI *func)(HANDLE, PLARGE_INTEGER);
     HMODULE hmod = ::GetModuleHandleA("kernel32.dll");
     func get_size =
         reinterpret_cast<func>(::GetProcAddress(hmod, "GetFileSizeEx"));
+
     if (get_size) {
         LARGE_INTEGER info;
- if (get_size(handle_, &info)) {
+ if (get_size(pimpl_->handle_, &info)) {
             boost::intmax_t size =
                 ( (static_cast<boost::intmax_t>(info.HighPart) << 32) |
                   info.LowPart );
- size_ =
+ pimpl_->size_ =
                 static_cast<std::size_t>(
                     p.length != max_length ?
                         std::min<boost::intmax_t>(p.length, size) :
                         size
                 );
         } else {
- cleanup_and_throw("failed querying file size");
+ detail::cleanup_and_throw(*pimpl_, "failed getting file size");
             return;
         }
     } else {
         DWORD hi;
         DWORD low;
- if ( (low = ::GetFileSize(handle_, &hi))
+ if ( (low = ::GetFileSize(pimpl_->handle_, &hi))
                  !=
              INVALID_FILE_SIZE )
         {
             boost::intmax_t size =
                 (static_cast<boost::intmax_t>(hi) << 32) | low;
- size_ =
+ pimpl_->size_ =
                 static_cast<std::size_t>(
                     p.length != max_length ?
                         std::min<boost::intmax_t>(p.length, size) :
                         size
                 );
         } else {
- cleanup_and_throw("failed querying file size");
+ detail::cleanup_and_throw(*pimpl_, "failed getting file size");
             return;
         }
     }
-#else // #ifdef BOOST_IOSTREAMS_WINDOWS
-
- // Open file
- int flags = (readonly ? O_RDONLY : O_RDWR);
- if (p.new_file_size != 0 && !readonly)
- flags |= (O_CREAT | O_TRUNC);
- #ifdef _LARGEFILE64_SOURCE
- flags |= O_LARGEFILE;
- #endif
- errno = 0;
- handle_ = ::open(p.path.c_str(), flags, S_IRWXU);
- if (errno != 0)
- cleanup_and_throw("failed opening file");
 
- //--------------Set file size---------------------------------------------//
-
- if (p.new_file_size != 0 && !readonly)
- if (BOOST_IOSTREAMS_FD_TRUNCATE(handle_, p.new_file_size) == -1)
- cleanup_and_throw("failed setting file size");
-
- //--------------Determine file size---------------------------------------//
-
- bool success = true;
- if (p.length != max_length) {
- size_ = p.length;
- } else {
- struct BOOST_IOSTREAMS_FD_STAT info;
- success = ::BOOST_IOSTREAMS_FD_FSTAT(handle_, &info) != -1;
- size_ = info.st_size;
- }
- if (!success)
- cleanup_and_throw("failed querying file size");
-#endif // #ifdef BOOST_IOSTREAMS_WINDOWS
+ pimpl_->data_ = reinterpret_cast<char*>(data);
 }
 
-void mapped_file_impl::try_map_file(param_type p)
-{
- bool priv = p.flags == mapped_file::priv;
- bool readonly = p.flags == mapped_file::readonly;
-#ifdef BOOST_IOSTREAMS_WINDOWS
-
- // Create mapping
- DWORD protect = priv ?
- PAGE_WRITECOPY :
- readonly ?
- PAGE_READONLY :
- PAGE_READWRITE;
- mapped_handle_ =
- ::CreateFileMappingA(
- handle_,
- NULL,
- protect,
- 0,
- 0,
- NULL );
- if (mapped_handle_ == NULL)
- cleanup_and_throw("failed create mapping");
-
- // Access data
- DWORD access = priv ?
- FILE_MAP_COPY :
- readonly ?
- FILE_MAP_READ :
- FILE_MAP_WRITE;
- void* data =
- ::MapViewOfFileEx(
- mapped_handle_,
- access,
- (DWORD) (p.offset >> 32),
- (DWORD) (p.offset & 0xffffffff),
- size_ != max_length ? size_ : 0,
- (LPVOID) p.hint );
- if (!data)
- cleanup_and_throw("failed mapping view");
-#else
- void* data =
- ::BOOST_IOSTREAMS_FD_MMAP(
- const_cast<char*>(p.hint),
- size_,
- readonly ? PROT_READ : (PROT_READ | PROT_WRITE),
- priv ? MAP_PRIVATE : MAP_SHARED,
- handle_,
- p.offset );
- if (data == MAP_FAILED)
- cleanup_and_throw("failed mapping file");
-#endif
- data_ = static_cast<char*>(data);
-}
+bool mapped_file_source::is_open() const
+{ return !!pimpl_ && pimpl_->handle_ != INVALID_HANDLE_VALUE; }
 
-void mapped_file_impl::map_file(param_type& p)
+int mapped_file_source::alignment()
 {
- try {
- try_map_file(p);
- } catch (const std::exception& e) {
- if (p.hint) {
- p.hint = 0;
- try_map_file(p);
- } else {
- throw e;
- }
- }
+ SYSTEM_INFO info;
+ ::GetSystemInfo(&info);
+ return static_cast<int>(info.dwAllocationGranularity);
 }
 
-bool mapped_file_impl::unmap_file()
-{
-#ifdef BOOST_IOSTREAMS_WINDOWS
- bool error = false;
- error = !::UnmapViewOfFile(data_) || error;
- error = !::CloseHandle(mapped_handle_) || error;
- mapped_handle_ = NULL;
- return !error;
-#else
- return ::munmap(data_, size_) == 0;
-#endif
-}
+#else // #ifdef BOOST_IOSTREAMS_WINDOWS //------------------------------------//
 
-void mapped_file_impl::clear(bool error)
-{
- params_ = param_type();
- data_ = 0;
- size_ = 0;
-#ifdef BOOST_IOSTREAMS_WINDOWS
- handle_ = INVALID_HANDLE_VALUE;
- mapped_handle_ = NULL;
-#else
- handle_ = 0;
-#endif
- error_ = error;
-}
+namespace detail {
 
-// Called when an error is encountered during the execution of open_file or
-// map_file
-void mapped_file_impl::cleanup_and_throw(const char* msg)
+ void cleanup_and_throw(detail::mapped_file_impl& impl, std::string msg)
 {
-#ifdef BOOST_IOSTREAMS_WINDOWS
- DWORD error = GetLastError();
- if (mapped_handle_ != INVALID_HANDLE_VALUE)
- ::CloseHandle(mapped_handle_);
- if (handle_ != NULL)
- ::CloseHandle(handle_);
- SetLastError(error);
-#else
- int error = errno;
- if (handle_ != 0)
- ::close(handle_);
- errno = error;
-#endif
- clear(true);
- boost::iostreams::detail::throw_system_failure(msg);
+ #ifndef NDEBUG
+ msg += std::string(" (\"") + impl.path_ + "\")";
+ #endif
+ if (impl.handle_ != 0)
+ ::close(impl.handle_);
+ impl.clear(true);
+ throw_system_failure(msg);
 }
 
-//------------------Implementation of mapped_file_params_base-----------------//
+} // End namespace detail.
 
-void mapped_file_params_base::normalize()
+
+void mapped_file_source::open_impl(mapped_file_params p)
 {
- if (mode && flags)
- throw BOOST_IOSTREAMS_FAILURE(
- "at most one of 'mode' and 'flags' may be specified"
- );
- if (flags) {
- switch (flags) {
- case mapped_file::readonly:
- case mapped_file::readwrite:
- case mapped_file::priv:
- break;
- default:
- throw BOOST_IOSTREAMS_FAILURE("invalid flags");
- }
- } else {
- flags = (mode & BOOST_IOS::out) ?
- mapped_file::readwrite :
- mapped_file::readonly;
- mode = BOOST_IOS::openmode();
- }
- if (offset < 0)
- throw BOOST_IOSTREAMS_FAILURE("invalid offset");
- if (new_file_size < 0)
- throw BOOST_IOSTREAMS_FAILURE("invalid new file size");
-}
+ using namespace std;
 
-} // End namespace detail.
+ if (is_open())
+ throw BOOST_IOSTREAMS_FAILURE("file already open");
+ if (!pimpl_)
+ pimpl_.reset(new impl_type);
+ else
+ pimpl_->clear(false);
+ bool readonly = (p.mode & BOOST_IOS::out) == 0;
+ pimpl_->mode_ = readonly ? BOOST_IOS::in : (BOOST_IOS::in | BOOST_IOS::out);
+ #ifndef NDEBUG
+ pimpl_->path_ = detail::absolute_path(p.path);
+ #endif
 
-//------------------Implementation of mapped_file_source----------------------//
+ //--------------Open underlying file--------------------------------------//
 
-mapped_file_source::mapped_file_source()
- : pimpl_(new impl_type)
- { }
-
-mapped_file_source::mapped_file_source(const mapped_file_source& other)
- : pimpl_(other.pimpl_)
- { }
+ int flags = (readonly ? O_RDONLY : O_RDWR);
+ if (p.new_file_size != 0 && !readonly)
+ flags |= (O_CREAT | O_TRUNC);
+ errno = 0;
+ pimpl_->handle_ = ::open(p.path.c_str(), flags, S_IRWXU);
+ if (errno != 0)
+ detail::cleanup_and_throw(*pimpl_, "failed opening file");
 
-bool mapped_file_source::is_open() const
-{ return pimpl_->is_open(); }
+ //--------------Set file size---------------------------------------------//
 
-void mapped_file_source::close() { pimpl_->close(); }
+ if (p.new_file_size != 0 && !readonly)
+ if (ftruncate(pimpl_->handle_, p.new_file_size) == -1)
+ detail::cleanup_and_throw(*pimpl_, "failed setting file size");
 
-mapped_file_source::operator safe_bool() const
-{ return pimpl_->error() ? &safe_bool_helper::x : 0; }
+ //--------------Determine file size---------------------------------------//
 
-bool mapped_file_source::operator!() const
-{ return pimpl_->error(); }
+ bool success = true;
+ struct stat info;
+ if (p.length != max_length)
+ pimpl_->size_ = p.length;
+ else {
+ success = ::fstat(pimpl_->handle_, &info) != -1;
+ pimpl_->size_ = info.st_size;
+ }
+ if (!success)
+ detail::cleanup_and_throw(*pimpl_, "failed getting file size");
 
-mapped_file_source::mapmode mapped_file_source::flags() const
-{ return pimpl_->flags(); }
+ //--------------Create mapping--------------------------------------------//
 
-mapped_file_source::size_type mapped_file_source::size() const
-{ return pimpl_->size(); }
+ try_again: // Target of goto in following section.
 
-const char* mapped_file_source::data() const { return pimpl_->data(); }
+ char* hint = const_cast<char*>(p.hint);
+ void* data = ::mmap( hint, pimpl_->size_,
+ readonly ? PROT_READ : (PROT_READ | PROT_WRITE),
+ readonly ? MAP_PRIVATE : MAP_SHARED,
+ pimpl_->handle_, p.offset );
+ if (data == MAP_FAILED) {
+ if (hint != 0) {
+ hint = 0;
+ goto try_again;
+ }
+ detail::cleanup_and_throw(*pimpl_, "failed mapping file");
+ }
+ pimpl_->data_ = reinterpret_cast<char*>(data);
 
-const char* mapped_file_source::begin() const { return data(); }
+ return;
+}
 
-const char* mapped_file_source::end() const { return data() + size(); }
-int mapped_file_source::alignment()
-{ return detail::mapped_file_impl::alignment(); }
+bool mapped_file_source::is_open() const
+{ return !!pimpl_ && pimpl_->handle_ != 0; }
 
-void mapped_file_source::init() { pimpl_.reset(new impl_type); }
+int mapped_file_source::alignment()
+{ return static_cast<int>(sysconf(_SC_PAGESIZE)); }
 
-void mapped_file_source::open_impl(const param_type& p)
-{ pimpl_->open(p); }
+#endif // #ifdef BOOST_IOSTREAMS_WINDOWS //-----------------------------------//
 
 //------------------Implementation of mapped_file-----------------------------//
 
-mapped_file::mapped_file(const mapped_file& other)
- : delegate_(other.delegate_)
- { }
+mapped_file::mapped_file(mapped_file_params p) { delegate_.open_impl(p); }
 
-void mapped_file::resize(stream_offset new_size)
-{ delegate_.pimpl_->resize(new_size); }
+mapped_file::mapped_file( const std::string& path, BOOST_IOS::openmode mode,
+ size_type length, stream_offset offset )
+{ open(path, mode, length, offset); }
+
+void mapped_file::open(mapped_file_params p)
+{ delegate_.open_impl(p); }
+
+void mapped_file::open( const std::string& path, BOOST_IOS::openmode mode,
+ size_type length, stream_offset offset )
+{
+ mapped_file_params p(path);
+ p.mode = mode;
+ p.length = length;
+ p.offset = offset;
+ open(p);
+}
 
 //------------------Implementation of mapped_file_sink------------------------//
 
-mapped_file_sink::mapped_file_sink(const mapped_file_sink& other)
- : mapped_file(static_cast<const mapped_file&>(other))
- { }
+mapped_file_sink::mapped_file_sink(mapped_file_params p) { open(p); }
+
+mapped_file_sink::mapped_file_sink( const std::string& path,
+ size_type length, stream_offset offset )
+{ open(path, length, offset); }
+
+void mapped_file_sink::open(mapped_file_params p)
+{
+ p.mode |= BOOST_IOS::out;
+ p.mode &= ~BOOST_IOS::in;
+ mapped_file::open(p);
+}
+
+void mapped_file_sink::open( const std::string& path, size_type length,
+ stream_offset offset )
+{
+ mapped_file_params p(path);
+ p.mode = BOOST_IOS::out;
+ p.length = length;
+ p.offset = offset;
+ open(p);
+}
 
 //----------------------------------------------------------------------------//
 
 } } // End namespaces iostreams, boost.
+
+#include <boost/iostreams/detail/config/enable_warnings.hpp>

Modified: branches/release/libs/iostreams/test/mapped_file_test.cpp
==============================================================================
--- branches/release/libs/iostreams/test/mapped_file_test.cpp (original)
+++ branches/release/libs/iostreams/test/mapped_file_test.cpp 2009-05-20 19:35:08 EDT (Wed, 20 May 2009)
@@ -1,70 +1,33 @@
-// (C) Copyright Jorge Lodos 2008
-// (C) Copyright Jonathan Turkanis 2004
+// (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
+// (C) Copyright 2004-2007 Jonathan Turkanis
 // 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/libs/iostreams for documentation.
 
-// This is the original (boost 1.34) boost::iostream test for the mapped files with the
-// following modifications:
-// 1. The namespace for the mapped file was changed to seglib::filemap.
-// 2. Added test for privately mapped files.
-// 3. The test test_writeable was added for mapped files.
-// 4. The test test_resizeable was added for mapped files.
-//
-
 #include <fstream>
 #include <boost/config.hpp>
 #include <boost/detail/workaround.hpp>
+#include <boost/iostreams/device/mapped_file.hpp>
+#include <boost/iostreams/stream.hpp>
 #include <boost/test/test_tools.hpp>
 #include <boost/test/unit_test.hpp>
-
-#include <boost/iostreams/stream.hpp>
-#include <boost/iostreams/device/mapped_file.hpp>
 #include "detail/temp_file.hpp"
 #include "detail/verification.hpp"
 
+using namespace std;
+using namespace boost;
+using namespace boost::iostreams;
+using namespace boost::iostreams::test;
+using boost::unit_test::test_suite;
+
 // Code generation bugs cause tests to fail with global optimization.
 #if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
 # pragma optimize("g", off)
 #endif
 
-namespace boost { namespace iostreams { namespace test {
-
-bool test_writeable(mapped_file& mf)
-{
- // Test writing
- for (int i = 0; i < data_reps; ++i) {
- memcpy(mf.data(), narrow_data(), chunk_size);
- char buf[chunk_size];
- memcpy(buf, mf.const_data(), chunk_size);
- if (strncmp(buf, narrow_data(), chunk_size) != 0)
- return false;
- memset(mf.data(), 0, chunk_size);
- }
- return true;
-}
-
-bool test_resizeable(mapped_file& mf)
-{
- // Test resizing
- mapped_file::size_type size = mf.size();
- if (size == 0)
- return false;
- mf.resize(size/2);
- if (mf.size() != size/2)
- return false;
- mf.resize(size);
- if (mf.size() != size)
- return false;
- return true;
-}
-
-} } } // End namespaces test, iostreams, boost.
-
 void mapped_file_test()
 {
- using namespace boost::iostreams;
     BOOST_MESSAGE("about to begin");
 
     //--------------Reading from a mapped_file_source-------------------------//
@@ -75,13 +38,13 @@
 
         // Test reading from a stream based on a mapped_file_source,
         // in chars.
- boost::iostreams::test::test_file test1, test2;
- boost::iostreams::stream<mapped_file_source> first(test1.name());
+ test_file test1, test2;
+ stream<mapped_file_source> first(test1.name());
         {
- std::ifstream second( test2.name().c_str(),
+ ifstream second( test2.name().c_str(),
                              BOOST_IOS::in | BOOST_IOS::binary );
             BOOST_CHECK_MESSAGE(
- boost::iostreams::test::compare_streams_in_chars(first, second),
+ compare_streams_in_chars(first, second),
                 "failed reading from stream<mapped_file_source> in chars"
             );
 
@@ -95,10 +58,10 @@
         // in chunks. (Also tests reopening the stream.)
         first.open(mapped_file_source(test1.name()));
         {
- std::ifstream second( test2.name().c_str(),
+ ifstream second( test2.name().c_str(),
                              BOOST_IOS::in | BOOST_IOS::binary );
             BOOST_CHECK_MESSAGE(
- boost::iostreams::test::compare_streams_in_chunks(first, second),
+ compare_streams_in_chunks(first, second),
                 "failed reading from stream<mapped_file_source> in chunks"
             );
 
@@ -113,15 +76,15 @@
     {
         // Test writing to a stream based on a mapped_file_sink, in
         // chars.
- boost::iostreams::test::uppercase_file first, second; // Will overwrite these.
- boost::iostreams::test::test_file test;
+ uppercase_file first, second; // Will overwrite these.
+ test_file test;
 
- boost::iostreams::stream<mapped_file_sink> out;
+ stream<mapped_file_sink> out;
         out.open(mapped_file_sink(first.name()));
- boost::iostreams::test::write_data_in_chars(out);
+ write_data_in_chars(out);
         out.close();
         BOOST_CHECK_MESSAGE(
- boost::iostreams::test::compare_files(first.name(), test.name()),
+ compare_files(first.name(), test.name()),
             "failed writing to stream<mapped_file_sink> in chars"
         );
 
@@ -132,10 +95,10 @@
         // Test writing to a stream based on a mapped_file_sink, in
         // chunks. (Also tests reopening the stream.)
         out.open(mapped_file_sink(second.name()));
- boost::iostreams::test::write_data_in_chunks(out);
+ write_data_in_chunks(out);
         out.close();
         BOOST_CHECK_MESSAGE(
- boost::iostreams::test::compare_files(second.name(), test.name()),
+ compare_files(second.name(), test.name()),
             "failed writing to stream<mapped_file_sink> in chunks"
         );
 
@@ -144,21 +107,21 @@
         );
     }
 
- //--------------Writing to a newly created file---------------------------//
+ //--------------Writing to a newly created file-----------------------------//
 
     {
         // Test writing to a newly created mapped file.
- boost::iostreams::test::temp_file first, second;
- boost::iostreams::test::test_file test;
+ temp_file first, second;
+ test_file test;
 
         mapped_file_params p(first.name());
- p.new_file_size = boost::iostreams::test::data_reps * boost::iostreams::test::data_length();
- boost::iostreams::stream<mapped_file_sink> out;
+ p.new_file_size = data_reps * data_length();
+ stream<mapped_file_sink> out;
         out.open(mapped_file_sink(p));
- boost::iostreams::test::write_data_in_chars(out);
+ write_data_in_chars(out);
         out.close();
         BOOST_CHECK_MESSAGE(
- boost::iostreams::test::compare_files(first.name(), test.name()),
+ compare_files(first.name(), test.name()),
             "failed writing to newly created mapped file in chars"
         );
 
@@ -167,10 +130,10 @@
         // (Also tests reopening the stream.)
         p.path = second.name();
         out.open(mapped_file_sink(p));
- boost::iostreams::test::write_data_in_chunks(out);
+ write_data_in_chunks(out);
         out.close();
         BOOST_CHECK_MESSAGE(
- boost::iostreams::test::compare_files(second.name(), test.name()),
+ compare_files(second.name(), test.name()),
             "failed writing to newly created mapped file in chunks"
         );
     }
@@ -180,11 +143,11 @@
     {
         // Test reading, writing and seeking within a stream based on a
         // mapped_file, in chars.
- boost::iostreams::test::test_file test;
- boost::iostreams::stream<mapped_file> io;
+ test_file test;
+ stream<mapped_file> io;
         io.open(mapped_file(test.name()));
         BOOST_CHECK_MESSAGE(
- boost::iostreams::test::test_seekable_in_chars(io),
+ test_seekable_in_chars(io),
             "failed seeking within stream<mapped_file> in chars"
         );
 
@@ -199,7 +162,7 @@
         // stream.)
         io.open(mapped_file(test.name()));
         BOOST_CHECK_MESSAGE(
- boost::iostreams::test::test_seekable_in_chunks(io),
+ test_seekable_in_chunks(io),
             "failed seeking within stream<mapped_file> in chunks"
         );
 
@@ -207,74 +170,15 @@
             "done seeking within stream<mapped_file> in chunks"
         );
     }
-
- //--------------Resizing a mapped_file------------------------------------//
-
- {
- // Test resizing a mapped_file.
- boost::iostreams::test::test_file test;
- mapped_file mf;
- mf.open(test.name());
- BOOST_CHECK_MESSAGE(
- boost::iostreams::test::test_resizeable(mf),
- "failed resizing a mapped_file"
- );
-
- BOOST_MESSAGE(
- "done resizing a mapped_file"
- );
- }
-
- //--------------Random access with a private mapped_file------------------//
-
- {
- // Use 2 copies of the file to compare later
- boost::iostreams::test::test_file orig, copy;
-
- // Test reading and writing within a mapped_file.
- // Since the file is privately mapped, it should remain
- // unchanged after writing when opened in readonly mode.
- mapped_file mf;
- mf.open(orig.name(), mapped_file::priv);
- BOOST_CHECK_MESSAGE(
- boost::iostreams::test::test_writeable(mf),
- "failed seeking within private mapped_file"
- );
- BOOST_CHECK_MESSAGE(
- boost::iostreams::test::compare_files(orig.name(), copy.name()),
- "failed writing to private mapped_file"
- );
-
- BOOST_MESSAGE(
- "done seeking within private mapped_file"
- );
-
- mf.close();
-
- // Test reopening the mapped file.
- mf.open(orig.name(), mapped_file::priv);
- BOOST_CHECK_MESSAGE(
- boost::iostreams::test::test_writeable(mf),
- "failed reopening private mapped_file"
- );
- BOOST_CHECK_MESSAGE(
- boost::iostreams::test::compare_files(orig.name(), copy.name()),
- "failed writing to reopened private mapped_file"
- );
-
- BOOST_MESSAGE(
- "done reopening private mapped_file"
- );
- }
 }
 
 #if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
 # pragma optimize("", on)
 #endif
 
-boost::unit_test::test_suite* init_unit_test_suite(int, char* [])
+test_suite* init_unit_test_suite(int, char* [])
 {
- boost::unit_test::test_suite* test = BOOST_TEST_SUITE("mapped_file test");
+ test_suite* test = BOOST_TEST_SUITE("mapped_file test");
     test->add(BOOST_TEST_CASE(&mapped_file_test));
     return test;
 }


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