Reformatted code for more consistent look and better readability.

This commit is contained in:
Andrey Semashev 2021-04-24 22:37:57 +03:00
parent 83429c9bfd
commit c03249c375
93 changed files with 10409 additions and 10003 deletions

View File

@ -29,6 +29,6 @@ int main()
unsigned char buf[16] = {};
boost::winapi::BCRYPT_ALG_HANDLE_ handle;
boost::winapi::NTSTATUS_ status = boost::winapi::BCryptOpenAlgorithmProvider(&handle, boost::winapi::BCRYPT_RNG_ALGORITHM_, NULL, 0);
status = boost::winapi::BCryptGenRandom(handle, reinterpret_cast<boost::winapi::PUCHAR_>(static_cast<unsigned char*>(buf)), static_cast<boost::winapi::ULONG_>(sizeof(buf)), 0);
status = boost::winapi::BCryptGenRandom(handle, reinterpret_cast< boost::winapi::PUCHAR_ >(static_cast< unsigned char* >(buf)), static_cast< boost::winapi::ULONG_ >(sizeof(buf)), 0);
boost::winapi::BCryptCloseAlgorithmProvider(handle, 0);
}

View File

@ -17,92 +17,92 @@ using boost::filesystem::path;
using std::string;
using std::cout;
namespace
namespace {
std::ifstream infile;
std::ofstream posix_outfile;
std::ifstream posix_infile;
std::ofstream outfile;
bool posix;
const string empty_string;
struct column_base
{
std::ifstream infile;
std::ofstream posix_outfile;
std::ifstream posix_infile;
std::ofstream outfile;
bool posix;
const string empty_string;
struct column_base
{
virtual string heading() const = 0;
virtual string cell_value( const path & p ) const = 0;
};
virtual string cell_value(const path& p) const = 0;
};
struct c0 : public column_base
{
struct c0 : public column_base
{
string heading() const { return string("<code>string()</code>"); }
string cell_value( const path & p ) const { return p.string(); }
} o0;
string cell_value(const path& p) const { return p.string(); }
} o0;
struct c1 : public column_base
{
struct c1 : public column_base
{
string heading() const { return string("<code>generic_<br>string()</code>"); }
string cell_value( const path & p ) const { return p.generic_string(); }
} o1;
string cell_value(const path& p) const { return p.generic_string(); }
} o1;
struct c2 : public column_base
{
struct c2 : public column_base
{
string heading() const { return string("Iteration<br>over<br>Elements"); }
string cell_value( const path & p ) const
string cell_value(const path& p) const
{
string s;
for( path::iterator i(p.begin()); i != p.end(); ++i )
for (path::iterator i(p.begin()); i != p.end(); ++i)
{
if ( i != p.begin() ) s += ',';
if (i != p.begin())
s += ',';
s += (*i).string();
}
return s;
}
} o2;
} o2;
struct c3 : public column_base
{
struct c3 : public column_base
{
string heading() const { return string("<code>root_<br>path()</code>"); }
string cell_value( const path & p ) const { return p.root_path().string(); }
} o3;
string cell_value(const path& p) const { return p.root_path().string(); }
} o3;
struct c4 : public column_base
{
struct c4 : public column_base
{
string heading() const { return string("<code>root_<br>name()</code>"); }
string cell_value( const path & p ) const { return p.root_name().string(); }
} o4;
string cell_value(const path& p) const { return p.root_name().string(); }
} o4;
struct c5 : public column_base
{
struct c5 : public column_base
{
string heading() const { return string("<code>root_<br>directory()</code>"); }
string cell_value( const path & p ) const { return p.root_directory().string(); }
} o5;
string cell_value(const path& p) const { return p.root_directory().string(); }
} o5;
struct c6 : public column_base
{
struct c6 : public column_base
{
string heading() const { return string("<code>relative_<br>path()</code>"); }
string cell_value( const path & p ) const { return p.relative_path().string(); }
} o6;
string cell_value(const path& p) const { return p.relative_path().string(); }
} o6;
struct c7 : public column_base
{
struct c7 : public column_base
{
string heading() const { return string("<code>parent_<br>path()</code>"); }
string cell_value( const path & p ) const { return p.parent_path().string(); }
} o7;
string cell_value(const path& p) const { return p.parent_path().string(); }
} o7;
struct c8 : public column_base
{
struct c8 : public column_base
{
string heading() const { return string("<code>filename()</code>"); }
string cell_value( const path & p ) const { return p.filename().string(); }
} o8;
string cell_value(const path& p) const { return p.filename().string(); }
} o8;
const column_base * column[] = { &o2, &o0, &o1, &o3, &o4, &o5, &o6, &o7, &o8 };
const column_base* column[] = { &o2, &o0, &o1, &o3, &o4, &o5, &o6, &o7, &o8 };
// do_cell ---------------------------------------------------------------//
// do_cell ---------------------------------------------------------------//
void do_cell( const string & test_case, int i )
{
void do_cell(const string& test_case, int i)
{
string temp = column[i]->cell_value(path(test_case));
string value;
outfile << "<td>";
@ -126,12 +126,12 @@ namespace
outfile << value;
}
outfile << "</td>\n";
}
}
// do_row ------------------------------------------------------------------//
void do_row( const string & test_case )
{
void do_row(const string& test_case)
{
outfile << "<tr>\n";
if (test_case.empty())
@ -139,32 +139,30 @@ namespace
else
outfile << "<td><code>" << test_case << "</code></td>\n";
for ( int i = 0; i < sizeof(column)/sizeof(column_base&); ++i )
for (int i = 0; i < sizeof(column) / sizeof(column_base&); ++i)
{
do_cell( test_case, i );
do_cell(test_case, i);
}
outfile << "</tr>\n";
}
}
// do_table ----------------------------------------------------------------//
void do_table()
{
outfile <<
"<h1>Path Decomposition Table</h1>\n"
void do_table()
{
outfile << "<h1>Path Decomposition Table</h1>\n"
"<p>Shaded entries indicate cases where <i>POSIX</i> and <i>Windows</i>\n"
"implementations yield different results. The top value is the\n"
"<i>POSIX</i> result and the bottom value is the <i>Windows</i> result.\n"
"<table border=\"1\" cellspacing=\"0\" cellpadding=\"5\">\n"
"<p>\n"
;
"<p>\n";
// generate the column headings
outfile << "<tr><td><b>Constructor<br>argument</b></td>\n";
for ( int i = 0; i < sizeof(column)/sizeof(column_base&); ++i )
for (int i = 0; i < sizeof(column) / sizeof(column_base&); ++i)
{
outfile << "<td><b>" << column[i]->heading() << "</b></td>\n";
}
@ -174,16 +172,16 @@ namespace
// generate a row for each input line
string test_case;
while ( std::getline( infile, test_case ) )
while (std::getline(infile, test_case))
{
if (!test_case.empty() && *--test_case.end() == '\r')
test_case.erase(test_case.size()-1);
test_case.erase(test_case.size() - 1);
if (test_case.empty() || test_case[0] != '#')
do_row( test_case );
do_row(test_case);
}
outfile << "</table>\n";
}
}
} // unnamed namespace
@ -192,24 +190,22 @@ namespace
#define BOOST_NO_CPP_MAIN_SUCCESS_MESSAGE
#include <boost/test/included/prg_exec_monitor.hpp>
int cpp_main( int argc, char * argv[] ) // note name!
int cpp_main(int argc, char* argv[]) // note name!
{
if ( argc != 5 )
if (argc != 5)
{
std::cerr <<
"Usage: path_table \"POSIX\"|\"Windows\" input-file posix-file output-file\n"
std::cerr << "Usage: path_table \"POSIX\"|\"Windows\" input-file posix-file output-file\n"
"Run on POSIX first, then on Windows\n"
" \"POSIX\" causes POSIX results to be saved in posix-file;\n"
" \"Windows\" causes POSIX results read from posix-file\n"
" input-file contains the paths to appear in the table.\n"
" posix-file will be used for POSIX results\n"
" output-file will contain the generated HTML.\n"
;
" output-file will contain the generated HTML.\n";
return 1;
}
infile.open( argv[2] );
if ( !infile )
infile.open(argv[2]);
if (!infile)
{
std::cerr << "Could not open input file: " << argv[2] << std::endl;
return 1;
@ -218,8 +214,8 @@ int cpp_main( int argc, char * argv[] ) // note name!
if (string(argv[1]) == "POSIX")
{
posix = true;
posix_outfile.open( argv[3] );
if ( !posix_outfile )
posix_outfile.open(argv[3]);
if (!posix_outfile)
{
std::cerr << "Could not open POSIX output file: " << argv[3] << std::endl;
return 1;
@ -228,16 +224,16 @@ int cpp_main( int argc, char * argv[] ) // note name!
else
{
posix = false;
posix_infile.open( argv[3] );
if ( !posix_infile )
posix_infile.open(argv[3]);
if (!posix_infile)
{
std::cerr << "Could not open POSIX input file: " << argv[3] << std::endl;
return 1;
}
}
outfile.open( argv[4] );
if ( !outfile )
outfile.open(argv[4]);
if (!outfile)
{
std::cerr << "Could not open output file: " << argv[2] << std::endl;
return 1;
@ -247,14 +243,12 @@ int cpp_main( int argc, char * argv[] ) // note name!
"<head>\n"
"<title>Path Decomposition Table</title>\n"
"</head>\n"
"<body bgcolor=\"#ffffff\" text=\"#000000\">\n"
;
"<body bgcolor=\"#ffffff\" text=\"#000000\">\n";
do_table();
outfile << "</body>\n"
"</html>\n"
;
"</html>\n";
return 0;
}

View File

@ -12,17 +12,18 @@
#include <boost/detail/lightweight_main.hpp>
#include <iostream>
#include <string>
using std::cout;
using std::endl;
using namespace boost::filesystem;
int cpp_main(int argc, char* argv[])
{
# ifdef BOOST_WINDOWS_API
#ifdef BOOST_WINDOWS_API
cout << "BOOST_WINDOWS_API" << endl;
# else
#else
cout << "BOOST_POSIX_API" << endl;
# endif
#endif
path test_dir(current_path() / "dspr_demo");

View File

@ -24,69 +24,75 @@ using boost::system::error_code;
using boost::system::system_error;
namespace fs = boost::filesystem;
namespace
namespace {
void report_system_error(const system_error& ex)
{
void report_system_error(const system_error& ex)
{
cout << " threw system_error:\n"
<< " ex.code().value() is " << ex.code().value() << '\n'
<< " ex.code().category().name() is " << ex.code().category().name() << '\n'
<< " ex.what() is " << ex.what() << '\n'
;
}
<< " ex.what() is " << ex.what() << '\n';
}
void report_filesystem_error(const system_error& ex)
{
void report_filesystem_error(const system_error& ex)
{
cout << " threw filesystem_error exception:\n"
<< " ex.code().value() is " << ex.code().value() << '\n'
<< " ex.code().category().name() is " << ex.code().category().name() << '\n'
<< " ex.what() is " << ex.what() << '\n'
;
}
<< " ex.what() is " << ex.what() << '\n';
}
void report_status(fs::file_status s)
{
void report_status(fs::file_status s)
{
cout << " file_status::type() is ";
switch (s.type())
{
case fs::status_error:
cout << "status_error\n"; break;
cout << "status_error\n";
break;
case fs::file_not_found:
cout << "file_not_found\n"; break;
cout << "file_not_found\n";
break;
case fs::regular_file:
cout << "regular_file\n"; break;
cout << "regular_file\n";
break;
case fs::directory_file:
cout << "directory_file\n"; break;
cout << "directory_file\n";
break;
case fs::symlink_file:
cout << "symlink_file\n"; break;
cout << "symlink_file\n";
break;
case fs::block_file:
cout << "block_file\n"; break;
cout << "block_file\n";
break;
case fs::character_file:
cout << "character_file\n"; break;
cout << "character_file\n";
break;
case fs::fifo_file:
cout << "fifo_file\n"; break;
cout << "fifo_file\n";
break;
case fs::socket_file:
cout << "socket_file\n"; break;
cout << "socket_file\n";
break;
case fs::type_unknown:
cout << "type_unknown\n"; break;
cout << "type_unknown\n";
break;
default:
cout << "not a valid enumeration constant\n";
}
}
}
void report_error_code(const error_code& ec)
{
void report_error_code(const error_code& ec)
{
cout << " ec:\n"
<< " value() is " << ec.value() << '\n'
<< " category().name() is " << ec.category().name() << '\n'
<< " message() is " << ec.message() << '\n'
;
}
bool threw_exception;
<< " message() is " << ec.message() << '\n';
}
bool threw_exception;
} // namespace
int main(int argc, char* argv[])
{
if (argc < 2)
@ -108,10 +114,10 @@ int main(int argc, char* argv[])
//// construct path - with error_code
path p (argv[1]);
path p(argv[1]);
fs::file_status s;
bool b (false);
bool b(false);
fs::directory_iterator di;
// get status - no error_code
@ -119,7 +125,10 @@ int main(int argc, char* argv[])
cout << "\nstatus(\"" << p.string() << "\");\n";
threw_exception = false;
try { s = fs::status(p); }
try
{
s = fs::status(p);
}
catch (const system_error& ex)
{
report_filesystem_error(ex);
@ -141,7 +150,10 @@ int main(int argc, char* argv[])
cout << "\nexists(\"" << p.string() << "\");\n";
threw_exception = false;
try { b = fs::exists(p); }
try
{
b = fs::exists(p);
}
catch (const system_error& ex)
{
report_filesystem_error(ex);
@ -160,7 +172,10 @@ int main(int argc, char* argv[])
cout << "\ndirectory_iterator(\"" << p.string() << "\");\n";
threw_exception = false;
try { di = fs::directory_iterator(p); }
try
{
di = fs::directory_iterator(p);
}
catch (const system_error& ex)
{
report_filesystem_error(ex);

View File

@ -13,10 +13,10 @@
namespace fs = boost::filesystem;
int main( int argc, char* argv[] )
int main(int argc, char* argv[])
{
if ( argc != 2 )
if (argc != 2)
{
std::cout << "Usage: file_size path\n";
return 1;
@ -24,21 +24,21 @@ int main( int argc, char* argv[] )
std::cout << "sizeof(intmax_t) is " << sizeof(boost::intmax_t) << '\n';
fs::path p( argv[1] );
fs::path p(argv[1]);
if ( !fs::exists( p ) )
if (!fs::exists(p))
{
std::cout << "not found: " << argv[1] << std::endl;
return 1;
}
if ( !fs::is_regular( p ) )
if (!fs::is_regular(p))
{
std::cout << "not a regular file: " << argv[1] << std::endl;
return 1;
}
std::cout << "size of " << argv[1] << " is " << fs::file_size( p )
std::cout << "size of " << argv[1] << " is " << fs::file_size(p)
<< std::endl;
return 0;
}

View File

@ -13,42 +13,41 @@
#include <boost/filesystem.hpp>
#include <boost/detail/lightweight_main.hpp>
using std::cout; using std::endl;
using std::cout;
using std::endl;
using namespace boost::filesystem;
namespace
{
path p;
namespace {
void print_boost_macros()
{
path p;
void print_boost_macros()
{
std::cout << "Boost "
<< BOOST_VERSION / 100000 << '.'
<< BOOST_VERSION / 100 % 1000 << '.'
<< BOOST_VERSION % 100 << ", "
# ifndef _WIN64
#ifndef _WIN64
<< BOOST_COMPILER << ", "
# else
#else
<< BOOST_COMPILER << " with _WIN64 defined, "
# endif
#endif
<< BOOST_STDLIB << ", "
<< BOOST_PLATFORM
<< std::endl;
}
}
const char* file_type_tab[] =
{ "status_error", "file_not_found", "regular_file", "directory_file",
const char* file_type_tab[] = { "status_error", "file_not_found", "regular_file", "directory_file",
"symlink_file", "block_file", "character_file", "fifo_file", "socket_file",
"type_unknown"
};
"type_unknown" };
const char* file_type_c_str(enum file_type t)
{
const char* file_type_c_str(enum file_type t)
{
return file_type_tab[t];
}
}
void show_status(file_status s, boost::system::error_code ec)
{
void show_status(file_status s, boost::system::error_code ec)
{
boost::system::error_condition econd;
if (ec)
@ -72,10 +71,10 @@ namespace
cout << "is_directory(s) is " << (is_directory(s) ? "true" : "false") << "\n";
cout << "is_other(s) is " << (is_other(s) ? "true" : "false") << "\n";
cout << "is_symlink(s) is " << (is_symlink(s) ? "true" : "false") << "\n";
}
}
void try_exists()
{
void try_exists()
{
cout << "\nexists(" << p << ") ";
try
{
@ -86,10 +85,10 @@ namespace
{
cout << "throws a filesystem_error exception: " << ex.what() << "\n";
}
}
}
} // namespace
int cpp_main(int argc, char* argv[])
{
print_boost_macros();

View File

@ -13,9 +13,9 @@
#define BOOST_FILESYSTEM_NO_DEPRECATED
#include <boost/filesystem/config.hpp>
# ifdef BOOST_FILESYSTEM_NARROW_ONLY
# error This compiler or standard library does not support wide-character strings or paths
# endif
#ifdef BOOST_FILESYSTEM_NARROW_ONLY
#error This compiler or standard library does not support wide-character strings or paths
#endif
#include "mbpath.hpp"
#include <iostream>
@ -25,33 +25,48 @@
namespace fs = boost::filesystem;
namespace
namespace {
// we can't use boost::filesystem::copy_file() because the argument types
// differ, so provide a not-very-smart replacement.
void copy_file(const fs::wpath& from, const user::mbpath& to)
{
// we can't use boost::filesystem::copy_file() because the argument types
// differ, so provide a not-very-smart replacement.
void copy_file( const fs::wpath & from, const user::mbpath & to )
fs::ifstream from_file(from, std::ios_base::in | std::ios_base::binary);
if (!from_file)
{
fs::ifstream from_file( from, std::ios_base::in | std::ios_base::binary );
if ( !from_file ) { std::cout << "input open failed\n"; return; }
fs::ofstream to_file( to, std::ios_base::out | std::ios_base::binary );
if ( !to_file ) { std::cout << "output open failed\n"; return; }
char c;
while ( from_file.get(c) )
{
to_file.put(c);
if ( to_file.fail() ) { std::cout << "write error\n"; return; }
std::cout << "input open failed\n";
return;
}
if ( !from_file.eof() ) { std::cout << "read error\n"; }
fs::ofstream to_file(to, std::ios_base::out | std::ios_base::binary);
if (!to_file)
{
std::cout << "output open failed\n";
return;
}
char c;
while (from_file.get(c))
{
to_file.put(c);
if (to_file.fail())
{
std::cout << "write error\n";
return;
}
}
if (!from_file.eof())
{
std::cout << "read error\n";
}
}
int main( int argc, char * argv[] )
} // namespace
int main(int argc, char* argv[])
{
if ( argc != 2 )
if (argc != 2)
{
std::cout << "Copy files in the current directory to a target directory\n"
<< "Usage: mbcopy <target-dir>\n";
@ -60,31 +75,26 @@ int main( int argc, char * argv[] )
// For encoding, use Boost UTF-8 codecvt
std::locale global_loc = std::locale();
std::locale loc( global_loc, new fs::detail::utf8_codecvt_facet );
user::mbpath_traits::imbue( loc );
std::locale loc(global_loc, new fs::detail::utf8_codecvt_facet);
user::mbpath_traits::imbue(loc);
std::string target_string( argv[1] );
user::mbpath target_dir( user::mbpath_traits::to_internal( target_string ) );
std::string target_string(argv[1]);
user::mbpath target_dir(user::mbpath_traits::to_internal(target_string));
if ( !fs::is_directory( target_dir ) )
if (!fs::is_directory(target_dir))
{
std::cout << "Error: " << argv[1] << " is not a directory\n";
return 1;
}
for ( fs::wdirectory_iterator it( L"." );
it != fs::wdirectory_iterator(); ++it )
for (fs::wdirectory_iterator it(L".");
it != fs::wdirectory_iterator(); ++it)
{
if ( fs::is_regular_file(it->status()) )
if (fs::is_regular_file(it->status()))
{
copy_file( *it, target_dir / it->path().filename() );
copy_file(*it, target_dir / it->path().filename());
}
}
return 0;
}

View File

@ -9,9 +9,9 @@
// See Boost.Filesystem home page at http://www.boost.org/libs/filesystem
#include <boost/filesystem/config.hpp>
# ifdef BOOST_FILESYSTEM_NARROW_ONLY
# error This compiler or standard library does not support wide-character strings or paths
# endif
#ifdef BOOST_FILESYSTEM_NARROW_ONLY
#error This compiler or standard library does not support wide-character strings or paths
#endif
#include "mbpath.hpp"
#include <boost/system/system_error.hpp>
@ -19,62 +19,60 @@
namespace fs = boost::filesystem;
namespace
{
// ISO C calls this "the locale-specific native environment":
std::locale loc("");
namespace {
const std::codecvt<wchar_t, char, std::mbstate_t> *
cvt( &std::use_facet<std::codecvt<wchar_t, char, std::mbstate_t> >
( loc ) );
// ISO C calls this "the locale-specific native environment":
std::locale loc("");
const std::codecvt< wchar_t, char, std::mbstate_t >*
cvt(&std::use_facet< std::codecvt< wchar_t, char, std::mbstate_t > >(loc));
} // namespace
namespace user {
mbpath_traits::external_string_type
mbpath_traits::to_external(const mbpath& ph, const internal_string_type& src)
{
std::size_t work_size(cvt->max_length() * (src.size() + 1));
boost::scoped_array< char > work(new char[work_size]);
std::mbstate_t state;
const internal_string_type::value_type* from_next;
external_string_type::value_type* to_next;
if (cvt->out(
state, src.c_str(), src.c_str() + src.size(), from_next, work.get(),
work.get() + work_size, to_next) != std::codecvt_base::ok)
boost::throw_exception< fs::basic_filesystem_error< mbpath > >(
fs::basic_filesystem_error< mbpath >(
"user::mbpath::to_external conversion error",
ph, boost::system::error_code(EINVAL, boost::system::errno_ecat)));
*to_next = '\0';
return external_string_type(work.get());
}
namespace user
mbpath_traits::internal_string_type
mbpath_traits::to_internal(const external_string_type& src)
{
mbpath_traits::external_string_type
mbpath_traits::to_external( const mbpath & ph,
const internal_string_type & src )
{
std::size_t work_size( cvt->max_length() * (src.size()+1) );
boost::scoped_array<char> work( new char[ work_size ] );
std::size_t work_size(src.size() + 1);
boost::scoped_array< wchar_t > work(new wchar_t[work_size]);
std::mbstate_t state;
const internal_string_type::value_type * from_next;
external_string_type::value_type * to_next;
if ( cvt->out(
state, src.c_str(), src.c_str()+src.size(), from_next, work.get(),
work.get()+work_size, to_next ) != std::codecvt_base::ok )
boost::throw_exception<fs::basic_filesystem_error<mbpath> >(
fs::basic_filesystem_error<mbpath>(
"user::mbpath::to_external conversion error",
ph, boost::system::error_code( EINVAL, boost::system::errno_ecat ) ) );
*to_next = '\0';
return external_string_type( work.get() );
}
mbpath_traits::internal_string_type
mbpath_traits::to_internal( const external_string_type & src )
{
std::size_t work_size( src.size()+1 );
boost::scoped_array<wchar_t> work( new wchar_t[ work_size ] );
std::mbstate_t state;
const external_string_type::value_type * from_next;
internal_string_type::value_type * to_next;
if ( cvt->in(
state, src.c_str(), src.c_str()+src.size(), from_next, work.get(),
work.get()+work_size, to_next ) != std::codecvt_base::ok )
boost::throw_exception<fs::basic_filesystem_error<mbpath> >(
fs::basic_filesystem_error<mbpath>(
const external_string_type::value_type* from_next;
internal_string_type::value_type* to_next;
if (cvt->in(
state, src.c_str(), src.c_str() + src.size(), from_next, work.get(),
work.get() + work_size, to_next) != std::codecvt_base::ok)
boost::throw_exception< fs::basic_filesystem_error< mbpath > >(
fs::basic_filesystem_error< mbpath >(
"user::mbpath::to_internal conversion error",
boost::system::error_code( EINVAL, boost::system::errno_ecat ) ) );
boost::system::error_code(EINVAL, boost::system::errno_ecat)));
*to_next = L'\0';
return internal_string_type( work.get() );
}
return internal_string_type(work.get());
}
void mbpath_traits::imbue( const std::locale & new_loc )
{
void mbpath_traits::imbue(const std::locale& new_loc)
{
loc = new_loc;
cvt = &std::use_facet
<std::codecvt<wchar_t, char, std::mbstate_t> >( loc );
}
cvt = &std::use_facet< std::codecvt< wchar_t, char, std::mbstate_t > >(loc);
}
} // namespace user

View File

@ -14,31 +14,34 @@
#include <string>
#include <locale>
namespace user
namespace user {
struct mbpath_traits;
typedef boost::filesystem::basic_path< std::wstring, mbpath_traits > mbpath;
struct mbpath_traits
{
struct mbpath_traits;
typedef boost::filesystem::basic_path<std::wstring, mbpath_traits> mbpath;
struct mbpath_traits
{
typedef std::wstring internal_string_type;
typedef std::string external_string_type;
static external_string_type to_external( const mbpath & ph,
const internal_string_type & src );
static external_string_type to_external(const mbpath& ph, const internal_string_type& src);
static internal_string_type to_internal( const external_string_type & src );
static internal_string_type to_internal(const external_string_type& src);
static void imbue(const std::locale& loc);
};
static void imbue( const std::locale & loc );
};
} // namespace user
namespace boost
namespace boost {
namespace filesystem {
template<>
struct is_basic_path< user::mbpath >
{
namespace filesystem
{
template<> struct is_basic_path<user::mbpath>
{ static const bool value = true; };
}
}
static const bool value = true;
};
} // namespace filesystem
} // namespace boost

View File

@ -9,10 +9,14 @@
#include <iostream>
#include <boost/filesystem.hpp>
using namespace std;
using namespace boost::filesystem;
const char * say_what(bool b) { return b ? "true" : "false"; }
const char* say_what(bool b)
{
return b ? "true" : "false";
}
int main(int argc, char* argv[])
{
@ -21,11 +25,11 @@ int main(int argc, char* argv[])
cout << "Usage: path_info path-element [path-element...]\n"
"Composes a path via operator/= from one or more path-element arguments\n"
"Example: path_info foo/bar baz\n"
# ifdef BOOST_POSIX_API
#ifdef BOOST_POSIX_API
" would report info about the composed path foo/bar/baz\n";
# else // BOOST_WINDOWS_API
#else // BOOST_WINDOWS_API
" would report info about the composed path foo/bar\\baz\n";
# endif
#endif
return 1;
}
@ -42,13 +46,13 @@ int main(int argc, char* argv[])
cout << " " << element << '\n';
cout << "\nobservers, native format:" << endl;
# ifdef BOOST_POSIX_API
#ifdef BOOST_POSIX_API
cout << " native()-------------: " << p.native() << endl;
cout << " c_str()--------------: " << p.c_str() << endl;
# else // BOOST_WINDOWS_API
#else // BOOST_WINDOWS_API
wcout << L" native()-------------: " << p.native() << endl;
wcout << L" c_str()--------------: " << p.c_str() << endl;
# endif
#endif
cout << " string()-------------: " << p.string() << endl;
wcout << L" wstring()------------: " << p.wstring() << endl;

View File

@ -12,10 +12,10 @@
// As an example program, we don't want to use any deprecated features
#ifndef BOOST_FILESYSTEM_NO_DEPRECATED
# define BOOST_FILESYSTEM_NO_DEPRECATED
#define BOOST_FILESYSTEM_NO_DEPRECATED
#endif
#ifndef BOOST_SYSTEM_NO_DEPRECATED
# define BOOST_SYSTEM_NO_DEPRECATED
#define BOOST_SYSTEM_NO_DEPRECATED
#endif
#include <boost/filesystem/operations.hpp>
@ -70,15 +70,15 @@ int main(int argc, char* argv[])
++other_count;
std::cout << dir_itr->path().filename() << " [other]\n";
}
}
catch (const std::exception & ex)
catch (const std::exception& ex)
{
++err_count;
std::cout << dir_itr->path().filename() << " " << ex.what() << std::endl;
}
}
std::cout << "\n" << file_count << " files\n"
std::cout << "\n"
<< file_count << " files\n"
<< dir_count << " directories\n"
<< other_count << " others\n"
<< err_count << " errors\n";

View File

@ -20,7 +20,7 @@ int main(int argc, char* argv[])
boost::filesystem::path p(argv[1]), name(p.filename());
for(;;)
for (;;)
{
std::cout << "filename " << name << " has stem " << name.stem()
<< " and extension " << name.extension() << "\n";

View File

@ -14,11 +14,11 @@
namespace fs = boost::filesystem;
typedef std::basic_string<TCHAR> tstring;
typedef std::basic_string< TCHAR > tstring;
void func( const fs::path & p )
void func(fs::path const& p)
{
assert( fs::exists( p ) );
assert(fs::exists(p));
}
int main()
@ -27,13 +27,13 @@ int main()
fs::path cp = fs::current_path();
// demo: get tstring from the path
tstring cp_as_tstring = cp.string<tstring>();
tstring cp_as_tstring = cp.string< tstring >();
// demo: pass tstring to filesystem function taking path
assert( fs::exists( cp_as_tstring ) );
assert(fs::exists(cp_as_tstring));
// demo: pass tstring to user function taking path
func( cp_as_tstring );
func(cp_as_tstring);
return 0;
}

View File

@ -9,6 +9,7 @@
#include <iostream>
#include <boost/filesystem.hpp>
namespace fs = boost::filesystem;
int main(int argc, char* argv[])

View File

@ -9,6 +9,7 @@
#include <iostream>
#include <boost/filesystem.hpp>
using namespace boost::filesystem;
int main(int argc, char* argv[])

View File

@ -9,6 +9,7 @@
#include <iostream>
#include <boost/filesystem.hpp>
using namespace std;
using namespace boost::filesystem;
@ -26,10 +27,8 @@ int main(int argc, char* argv[])
{
if (is_regular_file(p)) // is path p a regular file?
cout << p << " size is " << file_size(p) << '\n';
else if (is_directory(p)) // is path p a directory?
cout << p << " is a directory\n";
else
cout << p << " exists, but is not a regular file or directory\n";
}

View File

@ -9,6 +9,7 @@
#include <iostream>
#include <boost/filesystem.hpp>
using std::cout;
using namespace boost::filesystem;
@ -20,20 +21,21 @@ int main(int argc, char* argv[])
return 1;
}
path p (argv[1]);
path p(argv[1]);
try
{
if (exists(p))
{
if (is_regular_file(p))
{
cout << p << " size is " << file_size(p) << '\n';
}
else if (is_directory(p))
{
cout << p << " is a directory containing:\n";
for (const directory_entry& x : directory_iterator(p))
for (directory_entry const& x : directory_iterator(p))
cout << " " << x.path() << '\n';
}
else
@ -42,8 +44,7 @@ int main(int argc, char* argv[])
else
cout << p << " does not exist\n";
}
catch (const filesystem_error& ex)
catch (filesystem_error& ex)
{
cout << ex.what() << '\n';
}

View File

@ -11,6 +11,7 @@
#include <vector>
#include <algorithm>
#include <boost/filesystem.hpp>
using std::cout;
using namespace boost::filesystem;
@ -22,20 +23,21 @@ int main(int argc, char* argv[])
return 1;
}
path p (argv[1]);
path p(argv[1]);
try
{
if (exists(p))
{
if (is_regular_file(p))
{
cout << p << " size is " << file_size(p) << '\n';
}
else if (is_directory(p))
{
cout << p << " is a directory containing:\n";
std::vector<path> v;
std::vector< path > v;
for (auto&& x : directory_iterator(p))
v.push_back(x.path());
@ -51,8 +53,7 @@ int main(int argc, char* argv[])
else
cout << p << " does not exist\n";
}
catch (const filesystem_error& ex)
catch (filesystem_error& ex)
{
cout << ex.what() << '\n';
}

View File

@ -10,21 +10,22 @@
#include <boost/filesystem/fstream.hpp>
#include <string>
#include <list>
namespace fs = boost::filesystem;
int main()
{
// \u263A is "Unicode WHITE SMILING FACE = have a nice day!"
std::string narrow_string ("smile2");
std::wstring wide_string (L"smile2\u263A");
std::list<char> narrow_list;
std::string narrow_string("smile2");
std::wstring wide_string(L"smile2\u263A");
std::list< char > narrow_list;
narrow_list.push_back('s');
narrow_list.push_back('m');
narrow_list.push_back('i');
narrow_list.push_back('l');
narrow_list.push_back('e');
narrow_list.push_back('3');
std::list<wchar_t> wide_list;
std::list< wchar_t > wide_list;
wide_list.push_back(L's');
wide_list.push_back(L'm');
wide_list.push_back(L'i');
@ -33,20 +34,36 @@ int main()
wide_list.push_back(L'3');
wide_list.push_back(L'\u263A');
{ fs::ofstream f("smile"); }
{ fs::ofstream f(L"smile\u263A"); }
{ fs::ofstream f(narrow_string); }
{ fs::ofstream f(wide_string); }
{ fs::ofstream f(narrow_list); }
{ fs::ofstream f(wide_list); }
{
fs::ofstream f("smile");
}
{
fs::ofstream f(L"smile\u263A");
}
{
fs::ofstream f(narrow_string);
}
{
fs::ofstream f(wide_string);
}
{
fs::ofstream f(narrow_list);
}
{
fs::ofstream f(wide_list);
}
narrow_list.pop_back();
narrow_list.push_back('4');
wide_list.pop_back();
wide_list.pop_back();
wide_list.push_back(L'4');
wide_list.push_back(L'\u263A');
{ fs::ofstream f(fs::path(narrow_list.begin(), narrow_list.end())); }
{ fs::ofstream f(fs::path(wide_list.begin(), wide_list.end())); }
{
fs::ofstream f(fs::path(narrow_list.begin(), narrow_list.end()));
}
{
fs::ofstream f(fs::path(wide_list.begin(), wide_list.end()));
}
return 0;
}

View File

@ -10,6 +10,7 @@
#include <iostream>
#include <exception>
#include <boost/filesystem.hpp>
using namespace boost::filesystem;
int main(int argc, char* argv[])
@ -22,7 +23,7 @@ int main(int argc, char* argv[])
try
{
for (recursive_directory_iterator it (argv[1]);
for (recursive_directory_iterator it(argv[1]);
it != recursive_directory_iterator();
++it)
{
@ -37,8 +38,7 @@ int main(int argc, char* argv[])
}
}
}
catch (const std::exception& ex)
catch (std::exception& ex)
{
std::cout << "************* exception *****************\n";
std::cout << ex.what() << '\n';

View File

@ -10,6 +10,7 @@
#include <iostream>
#include <exception>
#include <boost/filesystem.hpp>
using namespace boost::filesystem;
int main(int argc, char* argv[])
@ -22,25 +23,26 @@ int main(int argc, char* argv[])
try
{
for (recursive_directory_iterator it (argv[1]);
it != recursive_directory_iterator();
)
for (recursive_directory_iterator it(argv[1]);
it != recursive_directory_iterator();)
{
for (int i = 0; i <= it.level(); ++i)
std::cout << " ";
std::cout << it->path() << '\n';
try { ++it; }
catch (const filesystem_error& ex)
try
{
++it;
}
catch (filesystem_error& ex)
{
std::cout << "************* filesystem_error *****************\n";
std::cout << ex.what() << '\n';
}
}
}
catch (const std::exception& ex)
catch (std::exception& ex)
{
std::cout << "************* exception *****************\n";
std::cout << ex.what() << '\n';

View File

@ -24,9 +24,8 @@ int main(int argc, char* argv[])
}
error_code ec;
for (recursive_directory_iterator it (argv[1], ec);
it != recursive_directory_iterator();
)
for (recursive_directory_iterator it(argv[1], ec);
it != recursive_directory_iterator();)
{
for (int i = 0; i <= it.level(); ++i)
std::cout << " ";

View File

@ -12,13 +12,13 @@
#ifndef BOOST_FILESYSTEM_FILESYSTEM_HPP
#define BOOST_FILESYSTEM_FILESYSTEM_HPP
# include <boost/filesystem/config.hpp>
# include <boost/filesystem/path.hpp>
# include <boost/filesystem/exception.hpp>
# include <boost/filesystem/directory.hpp>
# include <boost/filesystem/operations.hpp>
# include <boost/filesystem/file_status.hpp>
# include <boost/filesystem/convenience.hpp>
# include <boost/filesystem/string_file.hpp>
#include <boost/filesystem/config.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/filesystem/exception.hpp>
#include <boost/filesystem/directory.hpp>
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/file_status.hpp>
#include <boost/filesystem/convenience.hpp>
#include <boost/filesystem/string_file.hpp>
#endif // BOOST_FILESYSTEM_FILESYSTEM_HPP

View File

@ -12,13 +12,13 @@
#ifndef BOOST_FILESYSTEM3_CONFIG_HPP
#define BOOST_FILESYSTEM3_CONFIG_HPP
# if defined(BOOST_FILESYSTEM_VERSION) && BOOST_FILESYSTEM_VERSION != 3
# error Compiling Filesystem version 3 file with BOOST_FILESYSTEM_VERSION defined != 3
# endif
#if defined(BOOST_FILESYSTEM_VERSION) && BOOST_FILESYSTEM_VERSION != 3
#error Compiling Filesystem version 3 file with BOOST_FILESYSTEM_VERSION defined != 3
#endif
# if !defined(BOOST_FILESYSTEM_VERSION)
# define BOOST_FILESYSTEM_VERSION 3
# endif
#if !defined(BOOST_FILESYSTEM_VERSION)
#define BOOST_FILESYSTEM_VERSION 3
#endif
#define BOOST_FILESYSTEM_I18N // aid users wishing to compile several versions
@ -31,10 +31,10 @@
// BOOST_FILESYSTEM_DEPRECATED needed for source compiles -----------------------------//
# ifdef BOOST_FILESYSTEM_SOURCE
# define BOOST_FILESYSTEM_DEPRECATED
# undef BOOST_FILESYSTEM_NO_DEPRECATED // fixes #9454, src bld fails if NO_DEP defined
# endif
#ifdef BOOST_FILESYSTEM_SOURCE
#define BOOST_FILESYSTEM_DEPRECATED
#undef BOOST_FILESYSTEM_NO_DEPRECATED // fixes #9454, src bld fails if NO_DEP defined
#endif
// throw an exception ----------------------------------------------------------------//
//
@ -46,50 +46,48 @@
#define BOOST_FILESYSTEM_THROW(EX) throw EX
# if defined( BOOST_NO_STD_WSTRING )
# error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
# endif
#if defined(BOOST_NO_STD_WSTRING)
#error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
#endif
// This header implements separate compilation features as described in
// http://www.boost.org/more/separate_compilation.html
// normalize macros ------------------------------------------------------------------//
#if !defined(BOOST_FILESYSTEM_DYN_LINK) && !defined(BOOST_FILESYSTEM_STATIC_LINK) \
&& !defined(BOOST_ALL_DYN_LINK) && !defined(BOOST_ALL_STATIC_LINK)
# define BOOST_FILESYSTEM_STATIC_LINK
#if !defined(BOOST_FILESYSTEM_DYN_LINK) && !defined(BOOST_FILESYSTEM_STATIC_LINK) && !defined(BOOST_ALL_DYN_LINK) && !defined(BOOST_ALL_STATIC_LINK)
#define BOOST_FILESYSTEM_STATIC_LINK
#endif
#if defined(BOOST_ALL_DYN_LINK) && !defined(BOOST_FILESYSTEM_DYN_LINK)
# define BOOST_FILESYSTEM_DYN_LINK
#define BOOST_FILESYSTEM_DYN_LINK
#elif defined(BOOST_ALL_STATIC_LINK) && !defined(BOOST_FILESYSTEM_STATIC_LINK)
# define BOOST_FILESYSTEM_STATIC_LINK
#define BOOST_FILESYSTEM_STATIC_LINK
#endif
#if defined(BOOST_FILESYSTEM_DYN_LINK) && defined(BOOST_FILESYSTEM_STATIC_LINK)
# error Must not define both BOOST_FILESYSTEM_DYN_LINK and BOOST_FILESYSTEM_STATIC_LINK
#error Must not define both BOOST_FILESYSTEM_DYN_LINK and BOOST_FILESYSTEM_STATIC_LINK
#endif
#if defined(BOOST_ALL_NO_LIB) && !defined(BOOST_FILESYSTEM_NO_LIB)
# define BOOST_FILESYSTEM_NO_LIB
#define BOOST_FILESYSTEM_NO_LIB
#endif
// enable dynamic linking ------------------------------------------------------------//
#if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_FILESYSTEM_DYN_LINK)
# if defined(BOOST_FILESYSTEM_SOURCE)
# define BOOST_FILESYSTEM_DECL BOOST_SYMBOL_EXPORT
# else
# define BOOST_FILESYSTEM_DECL BOOST_SYMBOL_IMPORT
# endif
#if defined(BOOST_FILESYSTEM_SOURCE)
#define BOOST_FILESYSTEM_DECL BOOST_SYMBOL_EXPORT
#else
# define BOOST_FILESYSTEM_DECL
#define BOOST_FILESYSTEM_DECL BOOST_SYMBOL_IMPORT
#endif
#else
#define BOOST_FILESYSTEM_DECL
#endif
// enable automatic library variant selection ----------------------------------------//
#if !defined(BOOST_FILESYSTEM_SOURCE) && !defined(BOOST_ALL_NO_LIB) \
&& !defined(BOOST_FILESYSTEM_NO_LIB)
#if !defined(BOOST_FILESYSTEM_SOURCE) && !defined(BOOST_ALL_NO_LIB) && !defined(BOOST_FILESYSTEM_NO_LIB)
//
// Set the name of our library, this will get undef'ed by auto_link.hpp
// once it's done with it:
@ -99,7 +97,7 @@
// If we're importing code from a dll, then tell auto_link.hpp about it:
//
#if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_FILESYSTEM_DYN_LINK)
# define BOOST_DYN_LINK
#define BOOST_DYN_LINK
#endif
//
// And include the header that does the work:

View File

@ -15,44 +15,42 @@
#include <boost/config.hpp>
# if defined( BOOST_NO_STD_WSTRING )
# error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
# endif
#if defined(BOOST_NO_STD_WSTRING)
#error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
#endif
#include <boost/filesystem/operations.hpp>
#include <boost/system/error_code.hpp>
#include <boost/config/abi_prefix.hpp> // must be the last #include
namespace boost
namespace boost {
namespace filesystem {
#ifndef BOOST_FILESYSTEM_NO_DEPRECATED
inline std::string extension(const path& p)
{
namespace filesystem
{
# ifndef BOOST_FILESYSTEM_NO_DEPRECATED
inline std::string extension(const path & p)
{
return p.extension().string();
}
}
inline std::string basename(const path & p)
{
inline std::string basename(const path& p)
{
return p.stem().string();
}
}
inline path change_extension( const path & p, const path & new_extension )
{
path new_p( p );
new_p.replace_extension( new_extension );
inline path change_extension(const path& p, const path& new_extension)
{
path new_p(p);
new_p.replace_extension(new_extension);
return new_p;
}
}
# endif
#endif
} // namespace filesystem
} // namespace filesystem
} // namespace boost
#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
#endif // BOOST_FILESYSTEM3_CONVENIENCE_HPP

View File

@ -20,24 +20,22 @@
#include <boost/assert.hpp>
#include <cstdlib>
namespace boost
namespace boost {
namespace detail {
inline const char* macro_value(const char* name, const char* value)
{
namespace detail
{
inline const char* macro_value(const char* name, const char* value)
{
static const char* no_value = "[no value]";
static const char* not_defined = "[not defined]";
BOOST_ASSERT_MSG(name, "name argument must not be a null pointer");
BOOST_ASSERT_MSG(value, "value argument must not be a null pointer");
return strcmp(name, value + 1)
? ((*value && *(value+1)) ? (value+1) : no_value)
: not_defined; // name == value+1 so the macro is not defined
}
} // detail
} // boost
return strcmp(name, value + 1) ? ((*value && *(value + 1)) ? (value + 1) : no_value) : not_defined; // name == value+1 so the macro is not defined
}
} // namespace detail
} // namespace boost
#define BOOST_MACRO_VALUE(X) boost::detail::macro_value(#X, BOOST_STRINGIZE(=X))

View File

@ -10,9 +10,14 @@
#include <boost/filesystem/config.hpp>
#define BOOST_UTF8_BEGIN_NAMESPACE \
namespace boost { namespace filesystem { namespace detail {
namespace boost { \
namespace filesystem { \
namespace detail {
#define BOOST_UTF8_END_NAMESPACE }}}
#define BOOST_UTF8_END_NAMESPACE \
} \
} \
}
#define BOOST_UTF8_DECL BOOST_FILESYSTEM_DECL
#include <boost/detail/utf8_codecvt_facet.hpp>

View File

@ -18,9 +18,9 @@
#include <boost/config.hpp>
# if defined( BOOST_NO_STD_WSTRING )
# error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
# endif
#if defined(BOOST_NO_STD_WSTRING)
#error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
#endif
#include <boost/filesystem/config.hpp>
#include <boost/filesystem/path.hpp>
@ -62,22 +62,23 @@ public:
typedef boost::filesystem::path::value_type value_type; // enables class path ctor taking directory_entry
directory_entry() BOOST_NOEXCEPT {}
explicit directory_entry(const boost::filesystem::path& p) :
m_path(p), m_status(file_status()), m_symlink_status(file_status())
{
}
directory_entry(const boost::filesystem::path& p,
file_status st, file_status symlink_st = file_status()) :
directory_entry(const boost::filesystem::path& p, file_status st, file_status symlink_st = file_status()) :
m_path(p), m_status(st), m_symlink_status(symlink_st)
{
}
directory_entry(const directory_entry& rhs) :
directory_entry(directory_entry const& rhs) :
m_path(rhs.m_path), m_status(rhs.m_status), m_symlink_status(rhs.m_symlink_status)
{
}
directory_entry& operator=(const directory_entry& rhs)
directory_entry& operator=(directory_entry const& rhs)
{
m_path = rhs.m_path;
m_status = rhs.m_status;
@ -91,9 +92,12 @@ public:
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
directory_entry(directory_entry&& rhs) BOOST_NOEXCEPT :
m_path(std::move(rhs.m_path)), m_status(std::move(rhs.m_status)), m_symlink_status(std::move(rhs.m_symlink_status))
m_path(std::move(rhs.m_path)),
m_status(std::move(rhs.m_status)),
m_symlink_status(std::move(rhs.m_symlink_status))
{
}
directory_entry& operator=(directory_entry&& rhs) BOOST_NOEXCEPT
{
m_path = std::move(rhs.m_path);
@ -103,16 +107,14 @@ public:
}
#endif
void assign(const boost::filesystem::path& p,
file_status st = file_status(), file_status symlink_st = file_status())
void assign(const boost::filesystem::path& p, file_status st = file_status(), file_status symlink_st = file_status())
{
m_path = p;
m_status = st;
m_symlink_status = symlink_st;
}
void replace_filename(const boost::filesystem::path& p,
file_status st = file_status(), file_status symlink_st = file_status())
void replace_filename(const boost::filesystem::path& p, file_status st = file_status(), file_status symlink_st = file_status())
{
m_path.remove_filename();
m_path /= p;
@ -120,30 +122,33 @@ public:
m_symlink_status = symlink_st;
}
# ifndef BOOST_FILESYSTEM_NO_DEPRECATED
#ifndef BOOST_FILESYSTEM_NO_DEPRECATED
void replace_leaf(const boost::filesystem::path& p, file_status st, file_status symlink_st)
{
replace_filename(p, st, symlink_st);
}
# endif
#endif
const boost::filesystem::path& path() const BOOST_NOEXCEPT { return m_path; }
operator const boost::filesystem::path&() const BOOST_NOEXCEPT { return m_path; }
const boost::filesystem::path& path() const BOOST_NOEXCEPT
{
return m_path;
}
operator boost::filesystem::path const&() const BOOST_NOEXCEPT { return m_path; }
file_status status() const { return get_status(); }
file_status status(system::error_code& ec) const BOOST_NOEXCEPT { return get_status(&ec); }
file_status symlink_status() const { return get_symlink_status(); }
file_status symlink_status(system::error_code& ec) const BOOST_NOEXCEPT { return get_symlink_status(&ec); }
bool operator==(const directory_entry& rhs) const BOOST_NOEXCEPT { return m_path == rhs.m_path; }
bool operator!=(const directory_entry& rhs) const BOOST_NOEXCEPT { return m_path != rhs.m_path; }
bool operator< (const directory_entry& rhs) const BOOST_NOEXCEPT { return m_path < rhs.m_path; }
bool operator<=(const directory_entry& rhs) const BOOST_NOEXCEPT { return m_path <= rhs.m_path; }
bool operator> (const directory_entry& rhs) const BOOST_NOEXCEPT { return m_path > rhs.m_path; }
bool operator>=(const directory_entry& rhs) const BOOST_NOEXCEPT { return m_path >= rhs.m_path; }
bool operator==(directory_entry const& rhs) const BOOST_NOEXCEPT { return m_path == rhs.m_path; }
bool operator!=(directory_entry const& rhs) const BOOST_NOEXCEPT { return m_path != rhs.m_path; }
bool operator<(directory_entry const& rhs) const BOOST_NOEXCEPT { return m_path < rhs.m_path; }
bool operator<=(directory_entry const& rhs) const BOOST_NOEXCEPT { return m_path <= rhs.m_path; }
bool operator>(directory_entry const& rhs) const BOOST_NOEXCEPT { return m_path > rhs.m_path; }
bool operator>=(directory_entry const& rhs) const BOOST_NOEXCEPT { return m_path >= rhs.m_path; }
private:
BOOST_FILESYSTEM_DECL file_status get_status(system::error_code* ec=0) const;
BOOST_FILESYSTEM_DECL file_status get_symlink_status(system::error_code* ec=0) const;
BOOST_FILESYSTEM_DECL file_status get_status(system::error_code* ec = 0) const;
BOOST_FILESYSTEM_DECL file_status get_symlink_status(system::error_code* ec = 0) const;
private:
boost::filesystem::path m_path;
@ -151,7 +156,6 @@ private:
mutable file_status m_symlink_status; // lstat()-like
}; // directory_entry
//--------------------------------------------------------------------------------------//
// //
// directory_entry overloads //
@ -160,28 +164,79 @@ private:
// Without these functions, calling (for example) 'is_directory' with a 'directory_entry' results in:
// - a conversion to 'path' using 'operator const boost::filesystem::path&()',
// - then a call to 'is_directory(const path& p)' which recomputes the status with 'detail::status(p)'.
// - then a call to 'is_directory(path const& p)' which recomputes the status with 'detail::status(p)'.
//
// These functions avoid a costly recomputation of the status if one calls 'is_directory(e)' instead of 'is_directory(e.status())'
inline file_status status (const directory_entry& e) { return e.status(); }
inline file_status status (const directory_entry& e, system::error_code& ec) BOOST_NOEXCEPT { return e.status(ec); }
inline bool type_present (const directory_entry& e) { return filesystem::type_present(e.status()); }
inline bool type_present (const directory_entry& e, system::error_code& ec) BOOST_NOEXCEPT { return filesystem::type_present(e.status(ec)); }
inline bool status_known (const directory_entry& e) { return filesystem::status_known(e.status()); }
inline bool status_known (const directory_entry& e, system::error_code& ec) BOOST_NOEXCEPT { return filesystem::status_known(e.status(ec)); }
inline bool exists (const directory_entry& e) { return filesystem::exists(e.status()); }
inline bool exists (const directory_entry& e, system::error_code& ec) BOOST_NOEXCEPT { return filesystem::exists(e.status(ec)); }
inline bool is_regular_file(const directory_entry& e) { return filesystem::is_regular_file(e.status()); }
inline bool is_regular_file(const directory_entry& e, system::error_code& ec) BOOST_NOEXCEPT { return filesystem::is_regular_file(e.status(ec)); }
inline bool is_directory (const directory_entry& e) { return filesystem::is_directory(e.status()); }
inline bool is_directory (const directory_entry& e, system::error_code& ec) BOOST_NOEXCEPT { return filesystem::is_directory(e.status(ec)); }
inline bool is_symlink (const directory_entry& e) { return filesystem::is_symlink(e.symlink_status()); }
inline bool is_symlink (const directory_entry& e, system::error_code& ec) BOOST_NOEXCEPT { return filesystem::is_symlink(e.symlink_status(ec)); }
inline bool is_other (const directory_entry& e) { return filesystem::is_other(e.status()); }
inline bool is_other (const directory_entry& e, system::error_code& ec) BOOST_NOEXCEPT { return filesystem::is_other(e.status(ec)); }
inline file_status status(directory_entry const& e)
{
return e.status();
}
inline file_status status(directory_entry const& e, system::error_code& ec) BOOST_NOEXCEPT
{
return e.status(ec);
}
inline bool type_present(directory_entry const& e)
{
return filesystem::type_present(e.status());
}
inline bool type_present(directory_entry const& e, system::error_code& ec) BOOST_NOEXCEPT
{
return filesystem::type_present(e.status(ec));
}
inline bool status_known(directory_entry const& e)
{
return filesystem::status_known(e.status());
}
inline bool status_known(directory_entry const& e, system::error_code& ec) BOOST_NOEXCEPT
{
return filesystem::status_known(e.status(ec));
}
inline bool exists(directory_entry const& e)
{
return filesystem::exists(e.status());
}
inline bool exists(directory_entry const& e, system::error_code& ec) BOOST_NOEXCEPT
{
return filesystem::exists(e.status(ec));
}
inline bool is_regular_file(directory_entry const& e)
{
return filesystem::is_regular_file(e.status());
}
inline bool is_regular_file(directory_entry const& e, system::error_code& ec) BOOST_NOEXCEPT
{
return filesystem::is_regular_file(e.status(ec));
}
inline bool is_directory(directory_entry const& e)
{
return filesystem::is_directory(e.status());
}
inline bool is_directory(directory_entry const& e, system::error_code& ec) BOOST_NOEXCEPT
{
return filesystem::is_directory(e.status(ec));
}
inline bool is_symlink(directory_entry const& e)
{
return filesystem::is_symlink(e.symlink_status());
}
inline bool is_symlink(directory_entry const& e, system::error_code& ec) BOOST_NOEXCEPT
{
return filesystem::is_symlink(e.symlink_status(ec));
}
inline bool is_other(directory_entry const& e)
{
return filesystem::is_other(e.status());
}
inline bool is_other(directory_entry const& e, system::error_code& ec) BOOST_NOEXCEPT
{
return filesystem::is_other(e.status(ec));
}
#ifndef BOOST_FILESYSTEM_NO_DEPRECATED
inline bool is_regular (const directory_entry& e) { return filesystem::is_regular(e.status()); }
inline bool is_regular(directory_entry const& e)
{
return filesystem::is_regular(e.status());
}
#endif
//--------------------------------------------------------------------------------------//
@ -209,12 +264,12 @@ class directory_iterator;
namespace detail {
BOOST_FILESYSTEM_DECL
system::error_code dir_itr_close(// never throws()
system::error_code dir_itr_close( // never throws()
void*& handle
#if defined(BOOST_POSIX_API)
, void*& buffer
#endif
) BOOST_NOEXCEPT;
) BOOST_NOEXCEPT;
struct dir_itr_imp :
public boost::intrusive_ref_counter< dir_itr_imp >
@ -245,7 +300,7 @@ struct dir_itr_imp :
};
// see path::iterator: comment below
BOOST_FILESYSTEM_DECL void directory_iterator_construct(directory_iterator& it, const path& p, unsigned int opts, system::error_code* ec);
BOOST_FILESYSTEM_DECL void directory_iterator_construct(directory_iterator& it, path const& p, unsigned int opts, system::error_code* ec);
BOOST_FILESYSTEM_DECL void directory_iterator_increment(directory_iterator& it, system::error_code* ec);
} // namespace detail
@ -265,7 +320,7 @@ class directory_iterator :
{
friend class boost::iterator_core_access;
friend BOOST_FILESYSTEM_DECL void detail::directory_iterator_construct(directory_iterator& it, const path& p, unsigned int opts, system::error_code* ec);
friend BOOST_FILESYSTEM_DECL void detail::directory_iterator_construct(directory_iterator& it, path const& p, unsigned int opts, system::error_code* ec);
friend BOOST_FILESYSTEM_DECL void detail::directory_iterator_increment(directory_iterator& it, system::error_code* ec);
public:
@ -273,23 +328,23 @@ public:
// iterator_facade derived classes don't seem to like implementations in
// separate translation unit dll's, so forward to detail functions
explicit directory_iterator(const path& p, BOOST_SCOPED_ENUM_NATIVE(directory_options) opts = directory_options::none)
explicit directory_iterator(path const& p, BOOST_SCOPED_ENUM_NATIVE(directory_options) opts = directory_options::none)
{
detail::directory_iterator_construct(*this, p, static_cast< unsigned int >(opts), 0);
}
directory_iterator(const path& p, system::error_code& ec) BOOST_NOEXCEPT
directory_iterator(path const& p, system::error_code& ec) BOOST_NOEXCEPT
{
detail::directory_iterator_construct(*this, p, static_cast< unsigned int >(directory_options::none), &ec);
}
directory_iterator(const path& p, BOOST_SCOPED_ENUM_NATIVE(directory_options) opts, system::error_code& ec) BOOST_NOEXCEPT
directory_iterator(path const& p, BOOST_SCOPED_ENUM_NATIVE(directory_options) opts, system::error_code& ec) BOOST_NOEXCEPT
{
detail::directory_iterator_construct(*this, p, static_cast< unsigned int >(opts), &ec);
}
BOOST_DEFAULTED_FUNCTION(directory_iterator(directory_iterator const& that), : m_imp(that.m_imp) {})
BOOST_DEFAULTED_FUNCTION(directory_iterator& operator= (directory_iterator const& that), { m_imp = that.m_imp; return *this; })
BOOST_DEFAULTED_FUNCTION(directory_iterator& operator=(directory_iterator const& that), { m_imp = that.m_imp; return *this; })
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
directory_iterator(directory_iterator&& that) BOOST_NOEXCEPT :
@ -297,7 +352,7 @@ public:
{
}
directory_iterator& operator= (directory_iterator&& that) BOOST_NOEXCEPT
directory_iterator& operator=(directory_iterator&& that) BOOST_NOEXCEPT
{
m_imp = std::move(that.m_imp);
return *this;
@ -346,37 +401,66 @@ private:
// begin() and end() are only used by a range-based for statement in the context of
// auto - thus the top-level const is stripped - so returning const is harmless and
// emphasizes begin() is just a pass through.
inline const directory_iterator& begin(const directory_iterator& iter) BOOST_NOEXCEPT { return iter; }
inline directory_iterator end(const directory_iterator&) BOOST_NOEXCEPT { return directory_iterator(); }
inline directory_iterator const& begin(directory_iterator const& iter) BOOST_NOEXCEPT
{
return iter;
}
inline directory_iterator end(directory_iterator const&) BOOST_NOEXCEPT
{
return directory_iterator();
}
// enable C++14 generic accessors for range const iterators
inline const directory_iterator& cbegin(const directory_iterator& iter) BOOST_NOEXCEPT { return iter; }
inline directory_iterator cend(const directory_iterator&) BOOST_NOEXCEPT { return directory_iterator(); }
inline directory_iterator const& cbegin(directory_iterator const& iter) BOOST_NOEXCEPT
{
return iter;
}
inline directory_iterator cend(directory_iterator const&) BOOST_NOEXCEPT
{
return directory_iterator();
}
// enable directory_iterator BOOST_FOREACH -----------------------------------------//
inline directory_iterator& range_begin(directory_iterator& iter) BOOST_NOEXCEPT { return iter; }
inline directory_iterator range_begin(const directory_iterator& iter) BOOST_NOEXCEPT { return iter; }
inline directory_iterator range_end(directory_iterator&) BOOST_NOEXCEPT { return directory_iterator(); }
inline directory_iterator range_end(const directory_iterator&) BOOST_NOEXCEPT { return directory_iterator(); }
inline directory_iterator& range_begin(directory_iterator& iter) BOOST_NOEXCEPT
{
return iter;
}
inline directory_iterator range_begin(directory_iterator const& iter) BOOST_NOEXCEPT
{
return iter;
}
inline directory_iterator range_end(directory_iterator&) BOOST_NOEXCEPT
{
return directory_iterator();
}
inline directory_iterator range_end(directory_iterator const&) BOOST_NOEXCEPT
{
return directory_iterator();
}
} // namespace filesystem
// namespace boost template specializations
template<typename C, typename Enabler>
template< typename C, typename Enabler >
struct range_mutable_iterator;
template<>
struct range_mutable_iterator<boost::filesystem::directory_iterator, void>
struct range_mutable_iterator< boost::filesystem::directory_iterator, void >
{
typedef boost::filesystem::directory_iterator type;
};
template<typename C, typename Enabler>
template< typename C, typename Enabler >
struct range_const_iterator;
template<>
struct range_const_iterator<boost::filesystem::directory_iterator, void>
struct range_const_iterator< boost::filesystem::directory_iterator, void >
{
typedef boost::filesystem::directory_iterator type;
};
@ -418,7 +502,7 @@ struct recur_dir_itr_imp :
explicit recur_dir_itr_imp(unsigned int opts) BOOST_NOEXCEPT : m_options(opts) {}
};
BOOST_FILESYSTEM_DECL void recursive_directory_iterator_construct(recursive_directory_iterator& it, const path& dir_path, unsigned int opts, system::error_code* ec);
BOOST_FILESYSTEM_DECL void recursive_directory_iterator_construct(recursive_directory_iterator& it, path const& dir_path, unsigned int opts, system::error_code* ec);
BOOST_FILESYSTEM_DECL void recursive_directory_iterator_increment(recursive_directory_iterator& it, system::error_code* ec);
BOOST_FILESYSTEM_DECL void recursive_directory_iterator_pop(recursive_directory_iterator& it, system::error_code* ec);
@ -439,48 +523,48 @@ class recursive_directory_iterator :
{
friend class boost::iterator_core_access;
friend BOOST_FILESYSTEM_DECL void detail::recursive_directory_iterator_construct(recursive_directory_iterator& it, const path& dir_path, unsigned int opts, system::error_code* ec);
friend BOOST_FILESYSTEM_DECL void detail::recursive_directory_iterator_construct(recursive_directory_iterator& it, path const& dir_path, unsigned int opts, system::error_code* ec);
friend BOOST_FILESYSTEM_DECL void detail::recursive_directory_iterator_increment(recursive_directory_iterator& it, system::error_code* ec);
friend BOOST_FILESYSTEM_DECL void detail::recursive_directory_iterator_pop(recursive_directory_iterator& it, system::error_code* ec);
public:
recursive_directory_iterator() BOOST_NOEXCEPT {} // creates the "end" iterator
explicit recursive_directory_iterator(const path& dir_path)
explicit recursive_directory_iterator(path const& dir_path)
{
detail::recursive_directory_iterator_construct(*this, dir_path, static_cast< unsigned int >(directory_options::none), 0);
}
recursive_directory_iterator(const path& dir_path, system::error_code& ec)
recursive_directory_iterator(path const& dir_path, system::error_code& ec)
{
detail::recursive_directory_iterator_construct(*this, dir_path, static_cast< unsigned int >(directory_options::none), &ec);
}
recursive_directory_iterator(const path& dir_path, BOOST_SCOPED_ENUM_NATIVE(directory_options) opts)
recursive_directory_iterator(path const& dir_path, BOOST_SCOPED_ENUM_NATIVE(directory_options) opts)
{
detail::recursive_directory_iterator_construct(*this, dir_path, static_cast< unsigned int >(opts), 0);
}
recursive_directory_iterator(const path& dir_path, BOOST_SCOPED_ENUM_NATIVE(directory_options) opts, system::error_code& ec)
recursive_directory_iterator(path const& dir_path, BOOST_SCOPED_ENUM_NATIVE(directory_options) opts, system::error_code& ec)
{
detail::recursive_directory_iterator_construct(*this, dir_path, static_cast< unsigned int >(opts), &ec);
}
#if !defined(BOOST_FILESYSTEM_NO_DEPRECATED)
// Deprecated constructors
recursive_directory_iterator(const path& dir_path, BOOST_SCOPED_ENUM_NATIVE(symlink_option) opts)
recursive_directory_iterator(path const& dir_path, BOOST_SCOPED_ENUM_NATIVE(symlink_option) opts)
{
detail::recursive_directory_iterator_construct(*this, dir_path, static_cast< unsigned int >(opts), 0);
}
recursive_directory_iterator(const path& dir_path, BOOST_SCOPED_ENUM_NATIVE(symlink_option) opts, system::error_code& ec) BOOST_NOEXCEPT
recursive_directory_iterator(path const& dir_path, BOOST_SCOPED_ENUM_NATIVE(symlink_option) opts, system::error_code& ec) BOOST_NOEXCEPT
{
detail::recursive_directory_iterator_construct(*this, dir_path, static_cast< unsigned int >(opts), &ec);
}
#endif // BOOST_FILESYSTEM_NO_DEPRECATED
BOOST_DEFAULTED_FUNCTION(recursive_directory_iterator(recursive_directory_iterator const& that), : m_imp(that.m_imp) {})
BOOST_DEFAULTED_FUNCTION(recursive_directory_iterator& operator= (recursive_directory_iterator const& that), { m_imp = that.m_imp; return *this; })
BOOST_DEFAULTED_FUNCTION(recursive_directory_iterator& operator=(recursive_directory_iterator const& that), { m_imp = that.m_imp; return *this; })
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
recursive_directory_iterator(recursive_directory_iterator&& that) BOOST_NOEXCEPT :
@ -488,7 +572,7 @@ public:
{
}
recursive_directory_iterator& operator= (recursive_directory_iterator&& that) BOOST_NOEXCEPT
recursive_directory_iterator& operator=(recursive_directory_iterator&& that) BOOST_NOEXCEPT
{
m_imp = std::move(that.m_imp);
return *this;
@ -514,7 +598,10 @@ public:
}
#ifndef BOOST_FILESYSTEM_NO_DEPRECATED
int level() const BOOST_NOEXCEPT { return depth(); }
int level() const BOOST_NOEXCEPT
{
return depth();
}
bool no_push_pending() const BOOST_NOEXCEPT { return !recursion_pending(); }
bool no_push_request() const BOOST_NOEXCEPT { return !recursion_pending(); }
#endif
@ -539,7 +626,10 @@ public:
}
#ifndef BOOST_FILESYSTEM_NO_DEPRECATED
void no_push(bool value = true) BOOST_NOEXCEPT { disable_recursion_pending(value); }
void no_push(bool value = true) BOOST_NOEXCEPT
{
disable_recursion_pending(value);
}
#endif
file_status status() const
@ -594,30 +684,60 @@ typedef recursive_directory_iterator wrecursive_directory_iterator;
// begin() and end() are only used by a range-based for statement in the context of
// auto - thus the top-level const is stripped - so returning const is harmless and
// emphasizes begin() is just a pass through.
inline const recursive_directory_iterator& begin(const recursive_directory_iterator& iter) BOOST_NOEXCEPT { return iter; }
inline recursive_directory_iterator end(const recursive_directory_iterator&) BOOST_NOEXCEPT { return recursive_directory_iterator(); }
inline recursive_directory_iterator const& begin(recursive_directory_iterator const& iter) BOOST_NOEXCEPT
{
return iter;
}
inline recursive_directory_iterator end(recursive_directory_iterator const&) BOOST_NOEXCEPT
{
return recursive_directory_iterator();
}
// enable C++14 generic accessors for range const iterators
inline const recursive_directory_iterator& cbegin(const recursive_directory_iterator& iter) BOOST_NOEXCEPT { return iter; }
inline recursive_directory_iterator cend(const recursive_directory_iterator&) BOOST_NOEXCEPT { return recursive_directory_iterator(); }
inline recursive_directory_iterator const& cbegin(recursive_directory_iterator const& iter) BOOST_NOEXCEPT
{
return iter;
}
inline recursive_directory_iterator cend(recursive_directory_iterator const&) BOOST_NOEXCEPT
{
return recursive_directory_iterator();
}
// enable recursive directory iterator BOOST_FOREACH -------------------------------//
inline recursive_directory_iterator& range_begin(recursive_directory_iterator& iter) BOOST_NOEXCEPT { return iter; }
inline recursive_directory_iterator range_begin(const recursive_directory_iterator& iter) BOOST_NOEXCEPT { return iter; }
inline recursive_directory_iterator range_end(recursive_directory_iterator&) BOOST_NOEXCEPT { return recursive_directory_iterator(); }
inline recursive_directory_iterator range_end(const recursive_directory_iterator&) BOOST_NOEXCEPT { return recursive_directory_iterator(); }
inline recursive_directory_iterator& range_begin(recursive_directory_iterator& iter) BOOST_NOEXCEPT
{
return iter;
}
inline recursive_directory_iterator range_begin(recursive_directory_iterator const& iter) BOOST_NOEXCEPT
{
return iter;
}
inline recursive_directory_iterator range_end(recursive_directory_iterator&) BOOST_NOEXCEPT
{
return recursive_directory_iterator();
}
inline recursive_directory_iterator range_end(recursive_directory_iterator const&) BOOST_NOEXCEPT
{
return recursive_directory_iterator();
}
} // namespace filesystem
// namespace boost template specializations
template<>
struct range_mutable_iterator<boost::filesystem::recursive_directory_iterator, void>
struct range_mutable_iterator< boost::filesystem::recursive_directory_iterator, void >
{
typedef boost::filesystem::recursive_directory_iterator type;
};
template<>
struct range_const_iterator<boost::filesystem::recursive_directory_iterator, void>
struct range_const_iterator< boost::filesystem::recursive_directory_iterator, void >
{
typedef boost::filesystem::recursive_directory_iterator type;
};
@ -625,4 +745,5 @@ struct range_const_iterator<boost::filesystem::recursive_directory_iterator, voi
} // namespace boost
#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
#endif // BOOST_FILESYSTEM3_DIRECTORY_HPP

View File

@ -13,9 +13,9 @@
#include <boost/config.hpp>
# if defined( BOOST_NO_STD_WSTRING )
# error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
# endif
#if defined(BOOST_NO_STD_WSTRING)
#error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
#endif
#include <boost/filesystem/config.hpp>
#include <boost/filesystem/path.hpp>
@ -31,9 +31,9 @@
#if defined(BOOST_MSVC)
#pragma warning(push)
// 'm_A' : class 'A' needs to have dll-interface to be used by clients of class 'B'
#pragma warning(disable: 4251)
#pragma warning(disable : 4251)
// non dll-interface class 'A' used as base for dll-interface class 'B'
#pragma warning(disable: 4275)
#pragma warning(disable : 4275)
#endif
namespace boost {
@ -56,7 +56,7 @@ public:
BOOST_FILESYSTEM_DECL filesystem_error(const std::string& what_arg, const path& path1_arg, const path& path2_arg, system::error_code ec);
BOOST_FILESYSTEM_DECL filesystem_error(filesystem_error const& that);
BOOST_FILESYSTEM_DECL filesystem_error& operator= (filesystem_error const& that);
BOOST_FILESYSTEM_DECL filesystem_error& operator=(filesystem_error const& that);
BOOST_FILESYSTEM_DECL ~filesystem_error() BOOST_NOEXCEPT_OR_NOTHROW;
@ -83,8 +83,14 @@ private:
std::string m_what; // not built until needed
BOOST_DEFAULTED_FUNCTION(impl(), {})
explicit impl(path const& path1) : m_path1(path1) {}
impl(path const& path1, path const& path2) : m_path1(path1), m_path2(path2) {}
explicit impl(path const& path1) :
m_path1(path1)
{
}
impl(path const& path1, path const& path2) :
m_path1(path1), m_path2(path2)
{
}
};
boost::intrusive_ptr< impl > m_imp_ptr;
};
@ -97,4 +103,5 @@ private:
#endif
#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
#endif // BOOST_FILESYSTEM3_EXCEPTION_HPP

View File

@ -18,12 +18,11 @@
#include <boost/config.hpp>
# if defined( BOOST_NO_STD_WSTRING )
# error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
# endif
#if defined(BOOST_NO_STD_WSTRING)
#error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
#endif
#include <boost/filesystem/config.hpp>
#include <boost/detail/bitmask.hpp>
#include <boost/config/abi_prefix.hpp> // must be the last #include
@ -40,9 +39,9 @@ namespace filesystem {
enum file_type
{
status_error,
# ifndef BOOST_FILESYSTEM_NO_DEPRECATED
#ifndef BOOST_FILESYSTEM_NO_DEPRECATED
status_unknown = status_error,
# endif
#endif
file_not_found,
regular_file,
directory_file,
@ -116,7 +115,7 @@ enum perms
// BOOST_BITMASK op~ casts to int32_least_t, producing invalid enum values
_detail_extend_perms_32_1 = 0x7fffffff,
_detail_extend_perms_32_2 = -0x7fffffff-1
_detail_extend_perms_32_2 = -0x7fffffff - 1
};
BOOST_BITMASK(perms)
@ -129,15 +128,18 @@ class file_status
{
public:
BOOST_CONSTEXPR file_status() BOOST_NOEXCEPT :
m_value(status_error), m_perms(perms_not_known)
m_value(status_error),
m_perms(perms_not_known)
{
}
explicit BOOST_CONSTEXPR file_status(file_type v) BOOST_NOEXCEPT :
m_value(v), m_perms(perms_not_known)
m_value(v),
m_perms(perms_not_known)
{
}
BOOST_CONSTEXPR file_status(file_type v, perms prms) BOOST_NOEXCEPT :
m_value(v), m_perms(prms)
m_value(v),
m_perms(prms)
{
}
@ -146,7 +148,8 @@ public:
// functions. GCC is not even consistent for the same release on different platforms.
BOOST_CONSTEXPR file_status(const file_status& rhs) BOOST_NOEXCEPT :
m_value(rhs.m_value), m_perms(rhs.m_perms)
m_value(rhs.m_value),
m_perms(rhs.m_perms)
{
}
BOOST_CXX14_CONSTEXPR file_status& operator=(const file_status& rhs) BOOST_NOEXCEPT
@ -156,10 +159,11 @@ public:
return *this;
}
# if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
// Note: std::move is not constexpr in C++11, that's why we're not using it here
BOOST_CONSTEXPR file_status(file_status&& rhs) BOOST_NOEXCEPT :
m_value(static_cast< file_type&& >(rhs.m_value)), m_perms(static_cast< enum perms&& >(rhs.m_perms))
m_value(static_cast< file_type&& >(rhs.m_value)),
m_perms(static_cast< enum perms&& >(rhs.m_perms))
{
}
BOOST_CXX14_CONSTEXPR file_status& operator=(file_status&& rhs) BOOST_NOEXCEPT
@ -168,7 +172,7 @@ public:
m_perms = static_cast< enum perms&& >(rhs.m_perms);
return *this;
}
# endif
#endif
// observers
BOOST_CONSTEXPR file_type type() const BOOST_NOEXCEPT { return m_value; }
@ -196,42 +200,52 @@ inline BOOST_CONSTEXPR bool type_present(file_status f) BOOST_NOEXCEPT
{
return f.type() != status_error;
}
inline BOOST_CONSTEXPR bool permissions_present(file_status f) BOOST_NOEXCEPT
{
return f.permissions() != perms_not_known;
}
inline BOOST_CONSTEXPR bool status_known(file_status f) BOOST_NOEXCEPT
{
return filesystem::type_present(f) && filesystem::permissions_present(f);
}
inline BOOST_CONSTEXPR bool exists(file_status f) BOOST_NOEXCEPT
{
return f.type() != status_error && f.type() != file_not_found;
}
inline BOOST_CONSTEXPR bool is_regular_file(file_status f) BOOST_NOEXCEPT
{
return f.type() == regular_file;
}
inline BOOST_CONSTEXPR bool is_directory(file_status f) BOOST_NOEXCEPT
{
return f.type() == directory_file;
}
inline BOOST_CONSTEXPR bool is_symlink(file_status f) BOOST_NOEXCEPT
{
return f.type() == symlink_file;
}
inline BOOST_CONSTEXPR bool is_other(file_status f) BOOST_NOEXCEPT
{
return filesystem::exists(f) && !filesystem::is_regular_file(f)
&& !filesystem::is_directory(f) && !filesystem::is_symlink(f);
return filesystem::exists(f) && !filesystem::is_regular_file(f) && !filesystem::is_directory(f) && !filesystem::is_symlink(f);
}
# ifndef BOOST_FILESYSTEM_NO_DEPRECATED
inline bool is_regular(file_status f) BOOST_NOEXCEPT { return filesystem::is_regular_file(f); }
# endif
#ifndef BOOST_FILESYSTEM_NO_DEPRECATED
inline bool is_regular(file_status f) BOOST_NOEXCEPT
{
return filesystem::is_regular_file(f);
}
#endif
} // namespace filesystem
} // namespace boost
#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
#endif // BOOST_FILESYSTEM3_FILE_STATUS_HPP

View File

@ -14,9 +14,9 @@
#include <boost/config.hpp>
# if defined( BOOST_NO_STD_WSTRING )
# error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
# endif
#if defined(BOOST_NO_STD_WSTRING)
#error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
#endif
#include <boost/filesystem/path.hpp>
#include <iosfwd>
@ -26,160 +26,160 @@
// on Windows, except for standard libaries known to have wchar_t overloads for
// file stream I/O, use path::string() to get a narrow character c_str()
#if defined(BOOST_WINDOWS_API) \
&& (!defined(_CPPLIB_VER) || _CPPLIB_VER < 405 || defined(_STLPORT_VERSION))
// !Dinkumware || early Dinkumware || STLPort masquerading as Dinkumware
# define BOOST_FILESYSTEM_C_STR string().c_str() // use narrow, since wide not available
#if defined(BOOST_WINDOWS_API) && (!defined(_CPPLIB_VER) || _CPPLIB_VER < 405 || defined(_STLPORT_VERSION))
// !Dinkumware || early Dinkumware || STLPort masquerading as Dinkumware
#define BOOST_FILESYSTEM_C_STR string().c_str() // use narrow, since wide not available
#else // use the native c_str, which will be narrow on POSIX, wide on Windows
# define BOOST_FILESYSTEM_C_STR c_str()
#define BOOST_FILESYSTEM_C_STR c_str()
#endif
#if defined(BOOST_MSVC)
#pragma warning(push)
// 'boost::filesystem::basic_fstream<charT>' : inherits 'std::basic_istream<_Elem,_Traits>::std::basic_istream<_Elem,_Traits>::_Add_vtordisp1' via dominance
#pragma warning(disable: 4250)
#pragma warning(disable : 4250)
#endif
namespace boost
{
namespace filesystem
{
namespace boost {
namespace filesystem {
//--------------------------------------------------------------------------------------//
// basic_filebuf //
//--------------------------------------------------------------------------------------//
template < class charT, class traits = std::char_traits<charT> >
class basic_filebuf : public std::basic_filebuf<charT,traits>
{
private: // disallow copying
basic_filebuf(const basic_filebuf&);
const basic_filebuf& operator=(const basic_filebuf&);
template< class charT, class traits = std::char_traits< charT > >
class basic_filebuf :
public std::basic_filebuf< charT, traits >
{
public:
BOOST_DEFAULTED_FUNCTION(basic_filebuf(), {})
BOOST_DELETED_FUNCTION(basic_filebuf(const basic_filebuf&))
BOOST_DELETED_FUNCTION(const basic_filebuf& operator=(const basic_filebuf&))
public:
basic_filebuf() {}
virtual ~basic_filebuf() {}
basic_filebuf<charT,traits>*
open(const path& p, std::ios_base::openmode mode)
public:
basic_filebuf< charT, traits >* open(const path& p, std::ios_base::openmode mode)
{
return std::basic_filebuf<charT,traits>::open(p.BOOST_FILESYSTEM_C_STR, mode)
? this : 0;
return std::basic_filebuf< charT, traits >::open(p.BOOST_FILESYSTEM_C_STR, mode) ? this : 0;
}
};
};
//--------------------------------------------------------------------------------------//
// basic_ifstream //
//--------------------------------------------------------------------------------------//
template < class charT, class traits = std::char_traits<charT> >
class basic_ifstream : public std::basic_ifstream<charT,traits>
{
private: // disallow copying
basic_ifstream(const basic_ifstream&);
const basic_ifstream& operator=(const basic_ifstream&);
public:
basic_ifstream() {}
template< class charT, class traits = std::char_traits< charT > >
class basic_ifstream :
public std::basic_ifstream< charT, traits >
{
public:
BOOST_DEFAULTED_FUNCTION(basic_ifstream(), {})
// use two signatures, rather than one signature with default second
// argument, to workaround VC++ 7.1 bug (ID VSWhidbey 38416)
explicit basic_ifstream(const path& p)
: std::basic_ifstream<charT,traits>(p.BOOST_FILESYSTEM_C_STR, std::ios_base::in) {}
explicit basic_ifstream(const path& p) :
std::basic_ifstream< charT, traits >(p.BOOST_FILESYSTEM_C_STR, std::ios_base::in) {}
basic_ifstream(const path& p, std::ios_base::openmode mode)
: std::basic_ifstream<charT,traits>(p.BOOST_FILESYSTEM_C_STR, mode) {}
basic_ifstream(const path& p, std::ios_base::openmode mode) :
std::basic_ifstream< charT, traits >(p.BOOST_FILESYSTEM_C_STR, mode) {}
BOOST_DELETED_FUNCTION(basic_ifstream(const basic_ifstream&))
BOOST_DELETED_FUNCTION(const basic_ifstream& operator=(const basic_ifstream&))
public:
void open(const path& p)
{ std::basic_ifstream<charT,traits>::open(p.BOOST_FILESYSTEM_C_STR, std::ios_base::in); }
{
std::basic_ifstream< charT, traits >::open(p.BOOST_FILESYSTEM_C_STR, std::ios_base::in);
}
void open(const path& p, std::ios_base::openmode mode)
{ std::basic_ifstream<charT,traits>::open(p.BOOST_FILESYSTEM_C_STR, mode); }
virtual ~basic_ifstream() {}
};
{
std::basic_ifstream< charT, traits >::open(p.BOOST_FILESYSTEM_C_STR, mode);
}
};
//--------------------------------------------------------------------------------------//
// basic_ofstream //
//--------------------------------------------------------------------------------------//
template < class charT, class traits = std::char_traits<charT> >
class basic_ofstream : public std::basic_ofstream<charT,traits>
{
private: // disallow copying
basic_ofstream(const basic_ofstream&);
const basic_ofstream& operator=(const basic_ofstream&);
public:
basic_ofstream() {}
template< class charT, class traits = std::char_traits< charT > >
class basic_ofstream :
public std::basic_ofstream< charT, traits >
{
public:
BOOST_DEFAULTED_FUNCTION(basic_ofstream(), {})
// use two signatures, rather than one signature with default second
// argument, to workaround VC++ 7.1 bug (ID VSWhidbey 38416)
explicit basic_ofstream(const path& p)
: std::basic_ofstream<charT,traits>(p.BOOST_FILESYSTEM_C_STR, std::ios_base::out) {}
explicit basic_ofstream(const path& p) :
std::basic_ofstream< charT, traits >(p.BOOST_FILESYSTEM_C_STR, std::ios_base::out) {}
basic_ofstream(const path& p, std::ios_base::openmode mode)
: std::basic_ofstream<charT,traits>(p.BOOST_FILESYSTEM_C_STR, mode) {}
basic_ofstream(const path& p, std::ios_base::openmode mode) :
std::basic_ofstream< charT, traits >(p.BOOST_FILESYSTEM_C_STR, mode) {}
BOOST_DELETED_FUNCTION(basic_ofstream(const basic_ofstream&))
BOOST_DELETED_FUNCTION(const basic_ofstream& operator=(const basic_ofstream&))
public:
void open(const path& p)
{ std::basic_ofstream<charT,traits>::open(p.BOOST_FILESYSTEM_C_STR, std::ios_base::out); }
{
std::basic_ofstream< charT, traits >::open(p.BOOST_FILESYSTEM_C_STR, std::ios_base::out);
}
void open(const path& p, std::ios_base::openmode mode)
{ std::basic_ofstream<charT,traits>::open(p.BOOST_FILESYSTEM_C_STR, mode); }
virtual ~basic_ofstream() {}
};
{
std::basic_ofstream< charT, traits >::open(p.BOOST_FILESYSTEM_C_STR, mode);
}
};
//--------------------------------------------------------------------------------------//
// basic_fstream //
//--------------------------------------------------------------------------------------//
template < class charT, class traits = std::char_traits<charT> >
class basic_fstream : public std::basic_fstream<charT,traits>
{
private: // disallow copying
basic_fstream(const basic_fstream&);
const basic_fstream & operator=(const basic_fstream&);
public:
basic_fstream() {}
template< class charT, class traits = std::char_traits< charT > >
class basic_fstream :
public std::basic_fstream< charT, traits >
{
public:
BOOST_DEFAULTED_FUNCTION(basic_fstream(), {})
// use two signatures, rather than one signature with default second
// argument, to workaround VC++ 7.1 bug (ID VSWhidbey 38416)
explicit basic_fstream(const path& p)
: std::basic_fstream<charT,traits>(p.BOOST_FILESYSTEM_C_STR,
std::ios_base::in | std::ios_base::out) {}
explicit basic_fstream(const path& p) :
std::basic_fstream< charT, traits >(p.BOOST_FILESYSTEM_C_STR, std::ios_base::in | std::ios_base::out) {}
basic_fstream(const path& p, std::ios_base::openmode mode)
: std::basic_fstream<charT,traits>(p.BOOST_FILESYSTEM_C_STR, mode) {}
basic_fstream(const path& p, std::ios_base::openmode mode) :
std::basic_fstream< charT, traits >(p.BOOST_FILESYSTEM_C_STR, mode) {}
BOOST_DELETED_FUNCTION(basic_fstream(const basic_fstream&))
BOOST_DELETED_FUNCTION(const basic_fstream& operator=(const basic_fstream&))
public:
void open(const path& p)
{ std::basic_fstream<charT,traits>::open(p.BOOST_FILESYSTEM_C_STR,
std::ios_base::in | std::ios_base::out); }
{
std::basic_fstream< charT, traits >::open(p.BOOST_FILESYSTEM_C_STR, std::ios_base::in | std::ios_base::out);
}
void open(const path& p, std::ios_base::openmode mode)
{ std::basic_fstream<charT,traits>::open(p.BOOST_FILESYSTEM_C_STR, mode); }
virtual ~basic_fstream() {}
};
{
std::basic_fstream< charT, traits >::open(p.BOOST_FILESYSTEM_C_STR, mode);
}
};
//--------------------------------------------------------------------------------------//
// typedefs //
//--------------------------------------------------------------------------------------//
typedef basic_filebuf<char> filebuf;
typedef basic_ifstream<char> ifstream;
typedef basic_ofstream<char> ofstream;
typedef basic_fstream<char> fstream;
typedef basic_filebuf< char > filebuf;
typedef basic_ifstream< char > ifstream;
typedef basic_ofstream< char > ofstream;
typedef basic_fstream< char > fstream;
typedef basic_filebuf<wchar_t> wfilebuf;
typedef basic_ifstream<wchar_t> wifstream;
typedef basic_ofstream<wchar_t> wofstream;
typedef basic_fstream<wchar_t> wfstream;
typedef basic_filebuf< wchar_t > wfilebuf;
typedef basic_ifstream< wchar_t > wifstream;
typedef basic_ofstream< wchar_t > wofstream;
typedef basic_fstream< wchar_t > wfstream;
} // namespace filesystem
} // namespace boost
@ -189,4 +189,5 @@ namespace filesystem
#endif
#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
#endif // BOOST_FILESYSTEM3_FSTREAM_HPP

View File

@ -18,9 +18,9 @@
#include <boost/config.hpp>
# if defined( BOOST_NO_STD_WSTRING )
# error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
# endif
#if defined(BOOST_NO_STD_WSTRING)
#error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
#endif
#include <boost/filesystem/config.hpp>
#include <boost/filesystem/path.hpp>
@ -93,80 +93,78 @@ BOOST_SCOPED_ENUM_DECLARE_END(copy_option)
namespace detail {
BOOST_FILESYSTEM_DECL
path absolute(const path& p, const path& base, system::error_code* ec=0);
path absolute(path const& p, path const& base, system::error_code* ec = 0);
BOOST_FILESYSTEM_DECL
file_status status(const path&p, system::error_code* ec=0);
file_status status(path const& p, system::error_code* ec = 0);
BOOST_FILESYSTEM_DECL
file_status symlink_status(const path& p, system::error_code* ec=0);
file_status symlink_status(path const& p, system::error_code* ec = 0);
BOOST_FILESYSTEM_DECL
bool is_empty(const path& p, system::error_code* ec=0);
bool is_empty(path const& p, system::error_code* ec = 0);
BOOST_FILESYSTEM_DECL
path initial_path(system::error_code* ec=0);
path initial_path(system::error_code* ec = 0);
BOOST_FILESYSTEM_DECL
path canonical(const path& p, const path& base, system::error_code* ec=0);
path canonical(path const& p, path const& base, system::error_code* ec = 0);
BOOST_FILESYSTEM_DECL
void copy(const path& from, const path& to, unsigned int options, system::error_code* ec=0);
void copy(path const& from, path const& to, unsigned int options, system::error_code* ec = 0);
#if !defined(BOOST_FILESYSTEM_NO_DEPRECATED)
BOOST_FILESYSTEM_DECL
void copy_directory(const path& from, const path& to, system::error_code* ec=0);
void copy_directory(path const& from, path const& to, system::error_code* ec = 0);
#endif
BOOST_FILESYSTEM_DECL
bool copy_file(const path& from, const path& to, // See ticket #2925
unsigned int options, system::error_code* ec=0); // see copy_options for options
bool copy_file(path const& from, path const& to, // See ticket #2925
unsigned int options, system::error_code* ec = 0); // see copy_options for options
BOOST_FILESYSTEM_DECL
void copy_symlink(const path& existing_symlink, const path& new_symlink, system::error_code* ec=0);
void copy_symlink(path const& existing_symlink, path const& new_symlink, system::error_code* ec = 0);
BOOST_FILESYSTEM_DECL
bool create_directories(const path& p, system::error_code* ec=0);
bool create_directories(path const& p, system::error_code* ec = 0);
BOOST_FILESYSTEM_DECL
bool create_directory(const path& p, const path* existing, system::error_code* ec=0);
bool create_directory(path const& p, const path* existing, system::error_code* ec = 0);
BOOST_FILESYSTEM_DECL
void create_directory_symlink(const path& to, const path& from,
system::error_code* ec=0);
void create_directory_symlink(path const& to, path const& from, system::error_code* ec = 0);
BOOST_FILESYSTEM_DECL
void create_hard_link(const path& to, const path& from, system::error_code* ec=0);
void create_hard_link(path const& to, path const& from, system::error_code* ec = 0);
BOOST_FILESYSTEM_DECL
void create_symlink(const path& to, const path& from, system::error_code* ec=0);
void create_symlink(path const& to, path const& from, system::error_code* ec = 0);
BOOST_FILESYSTEM_DECL
path current_path(system::error_code* ec=0);
path current_path(system::error_code* ec = 0);
BOOST_FILESYSTEM_DECL
void current_path(const path& p, system::error_code* ec=0);
void current_path(path const& p, system::error_code* ec = 0);
BOOST_FILESYSTEM_DECL
bool equivalent(const path& p1, const path& p2, system::error_code* ec=0);
bool equivalent(path const& p1, path const& p2, system::error_code* ec = 0);
BOOST_FILESYSTEM_DECL
boost::uintmax_t file_size(const path& p, system::error_code* ec=0);
boost::uintmax_t file_size(path const& p, system::error_code* ec = 0);
BOOST_FILESYSTEM_DECL
boost::uintmax_t hard_link_count(const path& p, system::error_code* ec=0);
boost::uintmax_t hard_link_count(path const& p, system::error_code* ec = 0);
BOOST_FILESYSTEM_DECL
std::time_t creation_time(const path& p, system::error_code* ec=0);
std::time_t creation_time(path const& p, system::error_code* ec = 0);
BOOST_FILESYSTEM_DECL
std::time_t last_write_time(const path& p, system::error_code* ec=0);
std::time_t last_write_time(path const& p, system::error_code* ec = 0);
BOOST_FILESYSTEM_DECL
void last_write_time(const path& p, const std::time_t new_time,
system::error_code* ec=0);
void last_write_time(path const& p, const std::time_t new_time, system::error_code* ec = 0);
BOOST_FILESYSTEM_DECL
void permissions(const path& p, perms prms, system::error_code* ec=0);
void permissions(path const& p, perms prms, system::error_code* ec = 0);
BOOST_FILESYSTEM_DECL
path read_symlink(const path& p, system::error_code* ec=0);
path read_symlink(path const& p, system::error_code* ec = 0);
BOOST_FILESYSTEM_DECL
path relative(const path& p, const path& base, system::error_code* ec = 0);
path relative(path const& p, path const& base, system::error_code* ec = 0);
BOOST_FILESYSTEM_DECL
bool remove(const path& p, system::error_code* ec=0);
bool remove(path const& p, system::error_code* ec = 0);
BOOST_FILESYSTEM_DECL
boost::uintmax_t remove_all(const path& p, system::error_code* ec=0);
boost::uintmax_t remove_all(path const& p, system::error_code* ec = 0);
BOOST_FILESYSTEM_DECL
void rename(const path& old_p, const path& new_p, system::error_code* ec=0);
void rename(path const& old_p, path const& new_p, system::error_code* ec = 0);
BOOST_FILESYSTEM_DECL
void resize_file(const path& p, uintmax_t size, system::error_code* ec=0);
void resize_file(path const& p, uintmax_t size, system::error_code* ec = 0);
BOOST_FILESYSTEM_DECL
space_info space(const path& p, system::error_code* ec=0);
space_info space(path const& p, system::error_code* ec = 0);
BOOST_FILESYSTEM_DECL
path system_complete(const path& p, system::error_code* ec=0);
path system_complete(path const& p, system::error_code* ec = 0);
BOOST_FILESYSTEM_DECL
path temp_directory_path(system::error_code* ec=0);
path temp_directory_path(system::error_code* ec = 0);
BOOST_FILESYSTEM_DECL
path unique_path(const path& p, system::error_code* ec=0);
path unique_path(path const& p, system::error_code* ec = 0);
BOOST_FILESYSTEM_DECL
path weakly_canonical(const path& p, system::error_code* ec = 0);
path weakly_canonical(path const& p, system::error_code* ec = 0);
} // namespace detail
@ -176,54 +174,97 @@ path weakly_canonical(const path& p, system::error_code* ec = 0);
// //
//--------------------------------------------------------------------------------------//
inline
file_status status(const path& p) {return detail::status(p);}
inline
file_status status(const path& p, system::error_code& ec)
{return detail::status(p, &ec);}
inline
file_status symlink_status(const path& p) {return detail::symlink_status(p);}
inline
file_status symlink_status(const path& p, system::error_code& ec)
{return detail::symlink_status(p, &ec);}
inline
bool exists(const path& p) {return exists(detail::status(p));}
inline
bool exists(const path& p, system::error_code& ec)
{return exists(detail::status(p, &ec));}
inline
bool is_directory(const path& p) {return is_directory(detail::status(p));}
inline
bool is_directory(const path& p, system::error_code& ec)
{return is_directory(detail::status(p, &ec));}
inline
bool is_regular_file(const path& p) {return is_regular_file(detail::status(p));}
inline
bool is_regular_file(const path& p, system::error_code& ec)
{return is_regular_file(detail::status(p, &ec));}
inline
bool is_other(const path& p) {return is_other(detail::status(p));}
inline
bool is_other(const path& p, system::error_code& ec)
{return is_other(detail::status(p, &ec));}
inline
bool is_symlink(const path& p) {return is_symlink(detail::symlink_status(p));}
inline
bool is_symlink(const path& p, system::error_code& ec)
{return is_symlink(detail::symlink_status(p, &ec));}
inline file_status status(path const& p)
{
return detail::status(p);
}
inline file_status status(path const& p, system::error_code& ec)
{
return detail::status(p, &ec);
}
inline file_status symlink_status(path const& p)
{
return detail::symlink_status(p);
}
inline file_status symlink_status(path const& p, system::error_code& ec)
{
return detail::symlink_status(p, &ec);
}
inline bool exists(path const& p)
{
return exists(detail::status(p));
}
inline bool exists(path const& p, system::error_code& ec)
{
return exists(detail::status(p, &ec));
}
inline bool is_directory(path const& p)
{
return is_directory(detail::status(p));
}
inline bool is_directory(path const& p, system::error_code& ec)
{
return is_directory(detail::status(p, &ec));
}
inline bool is_regular_file(path const& p)
{
return is_regular_file(detail::status(p));
}
inline bool is_regular_file(path const& p, system::error_code& ec)
{
return is_regular_file(detail::status(p, &ec));
}
inline bool is_other(path const& p)
{
return is_other(detail::status(p));
}
inline bool is_other(path const& p, system::error_code& ec)
{
return is_other(detail::status(p, &ec));
}
inline bool is_symlink(path const& p)
{
return is_symlink(detail::symlink_status(p));
}
inline bool is_symlink(path const& p, system::error_code& ec)
{
return is_symlink(detail::symlink_status(p, &ec));
}
#ifndef BOOST_FILESYSTEM_NO_DEPRECATED
inline
bool is_regular(const path& p) {return is_regular(detail::status(p));}
inline
bool is_regular(const path& p, system::error_code& ec)
{return is_regular(detail::status(p, &ec));}
inline bool is_regular(path const& p)
{
return is_regular(detail::status(p));
}
inline bool is_regular(path const& p, system::error_code& ec)
{
return is_regular(detail::status(p, &ec));
}
#endif
inline
bool is_empty(const path& p) {return detail::is_empty(p);}
inline
bool is_empty(const path& p, system::error_code& ec)
{return detail::is_empty(p, &ec);}
inline bool is_empty(path const& p)
{
return detail::is_empty(p);
}
inline bool is_empty(path const& p, system::error_code& ec)
{
return detail::is_empty(p, &ec);
}
//--------------------------------------------------------------------------------------//
// //
@ -231,306 +272,428 @@ bool is_empty(const path& p, system::error_code& ec)
// //
//--------------------------------------------------------------------------------------//
inline
path initial_path() {return detail::initial_path();}
inline path initial_path()
{
return detail::initial_path();
}
inline
path initial_path(system::error_code& ec) {return detail::initial_path(&ec);}
inline path initial_path(system::error_code& ec)
{
return detail::initial_path(&ec);
}
template <class Path>
path initial_path() {return initial_path();}
template <class Path>
path initial_path(system::error_code& ec) {return detail::initial_path(&ec);}
template< class Path >
path initial_path()
{
return initial_path();
}
template< class Path >
path initial_path(system::error_code& ec)
{
return detail::initial_path(&ec);
}
inline
path current_path() {return detail::current_path();}
inline path current_path()
{
return detail::current_path();
}
inline
path current_path(system::error_code& ec) {return detail::current_path(&ec);}
inline path current_path(system::error_code& ec)
{
return detail::current_path(&ec);
}
inline
void current_path(const path& p) {detail::current_path(p);}
inline void current_path(path const& p)
{
detail::current_path(p);
}
inline
void current_path(const path& p, system::error_code& ec) BOOST_NOEXCEPT {detail::current_path(p, &ec);}
inline void current_path(path const& p, system::error_code& ec) BOOST_NOEXCEPT
{
detail::current_path(p, &ec);
}
inline
path absolute(const path& p, const path& base=current_path()) {return detail::absolute(p, base);}
inline
path absolute(const path& p, system::error_code& ec)
inline path absolute(path const& p, path const& base = current_path())
{
return detail::absolute(p, base);
}
inline path absolute(path const& p, system::error_code& ec)
{
path base = current_path(ec);
if (ec)
return path();
return detail::absolute(p, base, &ec);
}
inline
path absolute(const path& p, const path& base, system::error_code& ec) {return detail::absolute(p, base, &ec);}
inline
path canonical(const path& p, const path& base=current_path())
{return detail::canonical(p, base);}
inline
path canonical(const path& p, system::error_code& ec)
inline path absolute(path const& p, path const& base, system::error_code& ec)
{
return detail::absolute(p, base, &ec);
}
inline path canonical(path const& p, path const& base = current_path())
{
return detail::canonical(p, base);
}
inline path canonical(path const& p, system::error_code& ec)
{
path base = current_path(ec);
if (ec)
return path();
return detail::canonical(p, base, &ec);
}
inline
path canonical(const path& p, const path& base, system::error_code& ec)
{return detail::canonical(p, base, &ec);}
inline path canonical(path const& p, path const& base, system::error_code& ec)
{
return detail::canonical(p, base, &ec);
}
#ifndef BOOST_FILESYSTEM_NO_DEPRECATED
inline
path complete(const path& p)
inline path complete(path const& p)
{
return absolute(p, initial_path());
}
inline
path complete(const path& p, const path& base)
inline path complete(path const& p, path const& base)
{
return absolute(p, base);
}
#endif
inline
void copy(const path& from, const path& to)
inline void copy(path const& from, path const& to)
{
detail::copy(from, to, static_cast< unsigned int >(copy_options::none));
}
inline
void copy(const path& from, const path& to, system::error_code& ec) BOOST_NOEXCEPT
inline void copy(path const& from, path const& to, system::error_code& ec) BOOST_NOEXCEPT
{
detail::copy(from, to, static_cast< unsigned int >(copy_options::none), &ec);
}
inline
void copy(const path& from, const path& to, BOOST_SCOPED_ENUM_NATIVE(copy_options) options)
inline void copy(path const& from, path const& to, BOOST_SCOPED_ENUM_NATIVE(copy_options) options)
{
detail::copy(from, to, static_cast< unsigned int >(options));
}
inline
void copy(const path& from, const path& to, BOOST_SCOPED_ENUM_NATIVE(copy_options) options, system::error_code& ec) BOOST_NOEXCEPT
inline void copy(path const& from, path const& to, BOOST_SCOPED_ENUM_NATIVE(copy_options) options, system::error_code& ec) BOOST_NOEXCEPT
{
detail::copy(from, to, static_cast< unsigned int >(options), &ec);
}
#if !defined(BOOST_FILESYSTEM_NO_DEPRECATED)
inline
void copy_directory(const path& from, const path& to)
{detail::copy_directory(from, to);}
inline
void copy_directory(const path& from, const path& to, system::error_code& ec) BOOST_NOEXCEPT
{detail::copy_directory(from, to, &ec);}
inline void copy_directory(path const& from, path const& to)
{
detail::copy_directory(from, to);
}
inline void copy_directory(path const& from, path const& to, system::error_code& ec) BOOST_NOEXCEPT
{
detail::copy_directory(from, to, &ec);
}
#endif
inline
bool copy_file(const path& from, const path& to)
inline bool copy_file(path const& from, path const& to)
{
return detail::copy_file(from, to, static_cast< unsigned int >(copy_options::none));
}
inline
bool copy_file(const path& from, const path& to, system::error_code& ec) BOOST_NOEXCEPT
inline bool copy_file(path const& from, path const& to, system::error_code& ec) BOOST_NOEXCEPT
{
return detail::copy_file(from, to, static_cast< unsigned int >(copy_options::none), &ec);
}
inline
bool copy_file(const path& from, const path& to, // See ticket #2925
inline bool copy_file(path const& from, path const& to, // See ticket #2925
BOOST_SCOPED_ENUM_NATIVE(copy_options) options)
{
return detail::copy_file(from, to, static_cast< unsigned int >(options));
}
inline
bool copy_file(const path& from, const path& to, // See ticket #2925
inline bool copy_file(path const& from, path const& to, // See ticket #2925
BOOST_SCOPED_ENUM_NATIVE(copy_options) options, system::error_code& ec) BOOST_NOEXCEPT
{
return detail::copy_file(from, to, static_cast< unsigned int >(options), &ec);
}
#if !defined(BOOST_FILESYSTEM_NO_DEPRECATED)
inline
bool copy_file(const path& from, const path& to, // See ticket #2925
inline bool copy_file(path const& from, path const& to, // See ticket #2925
BOOST_SCOPED_ENUM_NATIVE(copy_option) options)
{
return detail::copy_file(from, to, static_cast< unsigned int >(options));
}
inline
bool copy_file(const path& from, const path& to, // See ticket #2925
inline bool copy_file(path const& from, path const& to, // See ticket #2925
BOOST_SCOPED_ENUM_NATIVE(copy_option) options, system::error_code& ec) BOOST_NOEXCEPT
{
return detail::copy_file(from, to, static_cast< unsigned int >(options), &ec);
}
#endif // !defined(BOOST_FILESYSTEM_NO_DEPRECATED)
inline
void copy_symlink(const path& existing_symlink,
const path& new_symlink) {detail::copy_symlink(existing_symlink, new_symlink);}
inline
void copy_symlink(const path& existing_symlink, const path& new_symlink,
system::error_code& ec) BOOST_NOEXCEPT
{detail::copy_symlink(existing_symlink, new_symlink, &ec);}
inline
bool create_directories(const path& p) {return detail::create_directories(p);}
inline void copy_symlink(path const& existing_symlink, path const& new_symlink)
{
detail::copy_symlink(existing_symlink, new_symlink);
}
inline
bool create_directories(const path& p, system::error_code& ec) BOOST_NOEXCEPT
{return detail::create_directories(p, &ec);}
inline
bool create_directory(const path& p) {return detail::create_directory(p, 0);}
inline void copy_symlink(path const& existing_symlink, path const& new_symlink, system::error_code& ec) BOOST_NOEXCEPT
{
detail::copy_symlink(existing_symlink, new_symlink, &ec);
}
inline
bool create_directory(const path& p, system::error_code& ec) BOOST_NOEXCEPT
{return detail::create_directory(p, 0, &ec);}
inline
bool create_directory(const path& p, const path& existing)
{return detail::create_directory(p, &existing);}
inline
bool create_directory(const path& p, const path& existing, system::error_code& ec) BOOST_NOEXCEPT
{return detail::create_directory(p, &existing, &ec);}
inline
void create_directory_symlink(const path& to, const path& from)
{detail::create_directory_symlink(to, from);}
inline
void create_directory_symlink(const path& to, const path& from, system::error_code& ec) BOOST_NOEXCEPT
{detail::create_directory_symlink(to, from, &ec);}
inline
void create_hard_link(const path& to, const path& new_hard_link) {detail::create_hard_link(to, new_hard_link);}
inline bool create_directories(path const& p)
{
return detail::create_directories(p);
}
inline
void create_hard_link(const path& to, const path& new_hard_link, system::error_code& ec) BOOST_NOEXCEPT
{detail::create_hard_link(to, new_hard_link, &ec);}
inline
void create_symlink(const path& to, const path& new_symlink) {detail::create_symlink(to, new_symlink);}
inline bool create_directories(path const& p, system::error_code& ec) BOOST_NOEXCEPT
{
return detail::create_directories(p, &ec);
}
inline
void create_symlink(const path& to, const path& new_symlink, system::error_code& ec) BOOST_NOEXCEPT
{detail::create_symlink(to, new_symlink, &ec);}
inline
bool equivalent(const path& p1, const path& p2) {return detail::equivalent(p1, p2);}
inline bool create_directory(path const& p)
{
return detail::create_directory(p, 0);
}
inline
bool equivalent(const path& p1, const path& p2, system::error_code& ec) BOOST_NOEXCEPT
{return detail::equivalent(p1, p2, &ec);}
inline
boost::uintmax_t file_size(const path& p) {return detail::file_size(p);}
inline bool create_directory(path const& p, system::error_code& ec) BOOST_NOEXCEPT
{
return detail::create_directory(p, 0, &ec);
}
inline
boost::uintmax_t file_size(const path& p, system::error_code& ec) BOOST_NOEXCEPT
{return detail::file_size(p, &ec);}
inline
boost::uintmax_t hard_link_count(const path& p) {return detail::hard_link_count(p);}
inline bool create_directory(path const& p, path const& existing)
{
return detail::create_directory(p, &existing);
}
inline
boost::uintmax_t hard_link_count(const path& p, system::error_code& ec) BOOST_NOEXCEPT
{return detail::hard_link_count(p, &ec);}
inline
std::time_t creation_time(const path& p) { return detail::creation_time(p); }
inline bool create_directory(path const& p, path const& existing, system::error_code& ec) BOOST_NOEXCEPT
{
return detail::create_directory(p, &existing, &ec);
}
inline
std::time_t creation_time(const path& p, system::error_code& ec) BOOST_NOEXCEPT
{ return detail::creation_time(p, &ec); }
inline
std::time_t last_write_time(const path& p) {return detail::last_write_time(p);}
inline void create_directory_symlink(path const& to, path const& from)
{
detail::create_directory_symlink(to, from);
}
inline
std::time_t last_write_time(const path& p, system::error_code& ec) BOOST_NOEXCEPT
{return detail::last_write_time(p, &ec);}
inline
void last_write_time(const path& p, const std::time_t new_time)
{detail::last_write_time(p, new_time);}
inline
void last_write_time(const path& p, const std::time_t new_time,
system::error_code& ec) BOOST_NOEXCEPT
{detail::last_write_time(p, new_time, &ec);}
inline
void permissions(const path& p, perms prms)
{detail::permissions(p, prms);}
inline
void permissions(const path& p, perms prms, system::error_code& ec) BOOST_NOEXCEPT
{detail::permissions(p, prms, &ec);}
inline void create_directory_symlink(path const& to, path const& from, system::error_code& ec) BOOST_NOEXCEPT
{
detail::create_directory_symlink(to, from, &ec);
}
inline
path read_symlink(const path& p) {return detail::read_symlink(p);}
inline void create_hard_link(path const& to, path const& new_hard_link)
{
detail::create_hard_link(to, new_hard_link);
}
inline
path read_symlink(const path& p, system::error_code& ec)
{return detail::read_symlink(p, &ec);}
inline void create_hard_link(path const& to, path const& new_hard_link, system::error_code& ec) BOOST_NOEXCEPT
{
detail::create_hard_link(to, new_hard_link, &ec);
}
inline
bool remove(const path& p) {return detail::remove(p);}
inline void create_symlink(path const& to, path const& new_symlink)
{
detail::create_symlink(to, new_symlink);
}
inline
bool remove(const path& p, system::error_code& ec) BOOST_NOEXCEPT
{return detail::remove(p, &ec);}
inline void create_symlink(path const& to, path const& new_symlink, system::error_code& ec) BOOST_NOEXCEPT
{
detail::create_symlink(to, new_symlink, &ec);
}
inline
boost::uintmax_t remove_all(const path& p) {return detail::remove_all(p);}
inline bool equivalent(path const& p1, path const& p2)
{
return detail::equivalent(p1, p2);
}
inline
boost::uintmax_t remove_all(const path& p, system::error_code& ec) BOOST_NOEXCEPT
{return detail::remove_all(p, &ec);}
inline
void rename(const path& old_p, const path& new_p) {detail::rename(old_p, new_p);}
inline bool equivalent(path const& p1, path const& p2, system::error_code& ec) BOOST_NOEXCEPT
{
return detail::equivalent(p1, p2, &ec);
}
inline
void rename(const path& old_p, const path& new_p, system::error_code& ec) BOOST_NOEXCEPT
{detail::rename(old_p, new_p, &ec);}
inline // name suggested by Scott McMurray
void resize_file(const path& p, uintmax_t size) {detail::resize_file(p, size);}
inline boost::uintmax_t file_size(path const& p)
{
return detail::file_size(p);
}
inline
void resize_file(const path& p, uintmax_t size, system::error_code& ec) BOOST_NOEXCEPT
{detail::resize_file(p, size, &ec);}
inline
path relative(const path& p, const path& base=current_path())
{return detail::relative(p, base);}
inline
path relative(const path& p, system::error_code& ec)
inline boost::uintmax_t file_size(path const& p, system::error_code& ec) BOOST_NOEXCEPT
{
return detail::file_size(p, &ec);
}
inline boost::uintmax_t hard_link_count(path const& p)
{
return detail::hard_link_count(p);
}
inline boost::uintmax_t hard_link_count(path const& p, system::error_code& ec) BOOST_NOEXCEPT
{
return detail::hard_link_count(p, &ec);
}
inline std::time_t creation_time(path const& p)
{
return detail::creation_time(p);
}
inline std::time_t creation_time(path const& p, system::error_code& ec) BOOST_NOEXCEPT
{
return detail::creation_time(p, &ec);
}
inline std::time_t last_write_time(path const& p)
{
return detail::last_write_time(p);
}
inline std::time_t last_write_time(path const& p, system::error_code& ec) BOOST_NOEXCEPT
{
return detail::last_write_time(p, &ec);
}
inline void last_write_time(path const& p, const std::time_t new_time)
{
detail::last_write_time(p, new_time);
}
inline void last_write_time(path const& p, const std::time_t new_time, system::error_code& ec) BOOST_NOEXCEPT
{
detail::last_write_time(p, new_time, &ec);
}
inline void permissions(path const& p, perms prms)
{
detail::permissions(p, prms);
}
inline void permissions(path const& p, perms prms, system::error_code& ec) BOOST_NOEXCEPT
{
detail::permissions(p, prms, &ec);
}
inline path read_symlink(path const& p)
{
return detail::read_symlink(p);
}
inline path read_symlink(path const& p, system::error_code& ec)
{
return detail::read_symlink(p, &ec);
}
inline bool remove(path const& p)
{
return detail::remove(p);
}
inline bool remove(path const& p, system::error_code& ec) BOOST_NOEXCEPT
{
return detail::remove(p, &ec);
}
inline boost::uintmax_t remove_all(path const& p)
{
return detail::remove_all(p);
}
inline boost::uintmax_t remove_all(path const& p, system::error_code& ec) BOOST_NOEXCEPT
{
return detail::remove_all(p, &ec);
}
inline void rename(path const& old_p, path const& new_p)
{
detail::rename(old_p, new_p);
}
inline void rename(path const& old_p, path const& new_p, system::error_code& ec) BOOST_NOEXCEPT
{
detail::rename(old_p, new_p, &ec);
}
// name suggested by Scott McMurray
inline void resize_file(path const& p, uintmax_t size)
{
detail::resize_file(p, size);
}
inline void resize_file(path const& p, uintmax_t size, system::error_code& ec) BOOST_NOEXCEPT
{
detail::resize_file(p, size, &ec);
}
inline path relative(path const& p, path const& base = current_path())
{
return detail::relative(p, base);
}
inline path relative(path const& p, system::error_code& ec)
{
path base = current_path(ec);
if (ec)
return path();
return detail::relative(p, base, &ec);
}
inline
path relative(const path& p, const path& base, system::error_code& ec)
{return detail::relative(p, base, &ec);}
inline
space_info space(const path& p) {return detail::space(p);}
inline
space_info space(const path& p, system::error_code& ec) BOOST_NOEXCEPT
{return detail::space(p, &ec);}
inline path relative(path const& p, path const& base, system::error_code& ec)
{
return detail::relative(p, base, &ec);
}
inline space_info space(path const& p)
{
return detail::space(p);
}
inline space_info space(path const& p, system::error_code& ec) BOOST_NOEXCEPT
{
return detail::space(p, &ec);
}
#ifndef BOOST_FILESYSTEM_NO_DEPRECATED
inline bool symbolic_link_exists(const path& p)
{ return is_symlink(filesystem::symlink_status(p)); }
inline bool symbolic_link_exists(path const& p)
{
return is_symlink(filesystem::symlink_status(p));
}
#endif
inline
path system_complete(const path& p) {return detail::system_complete(p);}
inline path system_complete(path const& p)
{
return detail::system_complete(p);
}
inline
path system_complete(const path& p, system::error_code& ec)
{return detail::system_complete(p, &ec);}
inline
path temp_directory_path() {return detail::temp_directory_path();}
inline path system_complete(path const& p, system::error_code& ec)
{
return detail::system_complete(p, &ec);
}
inline
path temp_directory_path(system::error_code& ec)
{return detail::temp_directory_path(&ec);}
inline
path unique_path(const path& p="%%%%-%%%%-%%%%-%%%%")
{return detail::unique_path(p);}
inline
path unique_path(const path& p, system::error_code& ec)
{return detail::unique_path(p, &ec);}
inline
path weakly_canonical(const path& p) {return detail::weakly_canonical(p);}
inline path temp_directory_path()
{
return detail::temp_directory_path();
}
inline
path weakly_canonical(const path& p, system::error_code& ec)
{return detail::weakly_canonical(p, &ec);}
inline path temp_directory_path(system::error_code& ec)
{
return detail::temp_directory_path(&ec);
}
inline path unique_path(path const& p = "%%%%-%%%%-%%%%-%%%%")
{
return detail::unique_path(p);
}
inline path unique_path(path const& p, system::error_code& ec)
{
return detail::unique_path(p, &ec);
}
inline path weakly_canonical(path const& p)
{
return detail::weakly_canonical(p);
}
inline path weakly_canonical(path const& p, system::error_code& ec)
{
return detail::weakly_canonical(p, &ec);
}
// test helper -----------------------------------------------------------------------//
@ -548,4 +711,5 @@ BOOST_FILESYSTEM_DECL bool possible_large_file_size_support();
} // namespace boost
#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
#endif // BOOST_FILESYSTEM3_OPERATIONS_HPP

File diff suppressed because it is too large Load Diff

View File

@ -12,15 +12,16 @@
#include <boost/config.hpp>
# if defined( BOOST_NO_STD_WSTRING )
# error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
# endif
#if defined(BOOST_NO_STD_WSTRING)
#error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
#endif
#include <boost/filesystem/config.hpp>
#include <boost/type_traits/is_array.hpp>
#include <boost/type_traits/decay.hpp>
#include <boost/system/error_code.hpp>
#include <boost/core/enable_if.hpp>
#include <cstddef>
#include <cwchar> // for mbstate_t
#include <string>
#include <vector>
@ -32,320 +33,358 @@
#include <boost/config/abi_prefix.hpp> // must be the last #include
namespace boost { namespace filesystem {
namespace boost {
namespace filesystem {
BOOST_FILESYSTEM_DECL const system::error_category& codecvt_error_category();
// uses std::codecvt_base::result used for error codes:
//
// ok: Conversion successful.
// partial: Not all source characters converted; one or more additional source
// characters are needed to produce the final target character, or the
// size of the target intermediate buffer was too small to hold the result.
// error: A character in the source could not be converted to the target encoding.
// noconv: The source and target characters have the same type and encoding, so no
// conversion was necessary.
BOOST_FILESYSTEM_DECL const system::error_category& codecvt_error_category();
// uses std::codecvt_base::result used for error codes:
//
// ok: Conversion successful.
// partial: Not all source characters converted; one or more additional source
// characters are needed to produce the final target character, or the
// size of the target intermediate buffer was too small to hold the result.
// error: A character in the source could not be converted to the target encoding.
// noconv: The source and target characters have the same type and encoding, so no
// conversion was necessary.
class directory_entry;
class directory_entry;
namespace path_traits {
typedef std::codecvt<wchar_t, char, std::mbstate_t> codecvt_type;
typedef std::codecvt< wchar_t, char, std::mbstate_t > codecvt_type;
// is_pathable type trait; allows disabling over-agressive class path member templates
// is_pathable type trait; allows disabling over-agressive class path member templates
template <class T>
struct is_pathable { static const bool value = false; };
template< class T >
struct is_pathable
{
static const bool value = false;
};
template<> struct is_pathable<char*> { static const bool value = true; };
template<> struct is_pathable<const char*> { static const bool value = true; };
template<> struct is_pathable<wchar_t*> { static const bool value = true; };
template<> struct is_pathable<const wchar_t*> { static const bool value = true; };
template<> struct is_pathable<std::string> { static const bool value = true; };
template<> struct is_pathable<std::wstring> { static const bool value = true; };
template<> struct is_pathable<std::vector<char> > { static const bool value = true; };
template<> struct is_pathable<std::vector<wchar_t> > { static const bool value = true; };
template<> struct is_pathable<std::list<char> > { static const bool value = true; };
template<> struct is_pathable<std::list<wchar_t> > { static const bool value = true; };
template<> struct is_pathable<directory_entry> { static const bool value = true; };
template<>
struct is_pathable< char* >
{
static const bool value = true;
};
// Pathable empty
template<>
struct is_pathable< const char* >
{
static const bool value = true;
};
template <class Container> inline
template<>
struct is_pathable< wchar_t* >
{
static const bool value = true;
};
template<>
struct is_pathable< const wchar_t* >
{
static const bool value = true;
};
template<>
struct is_pathable< std::string >
{
static const bool value = true;
};
template<>
struct is_pathable< std::wstring >
{
static const bool value = true;
};
template<>
struct is_pathable< std::vector< char > >
{
static const bool value = true;
};
template<>
struct is_pathable< std::vector< wchar_t > >
{
static const bool value = true;
};
template<>
struct is_pathable< std::list< char > >
{
static const bool value = true;
};
template<>
struct is_pathable< std::list< wchar_t > >
{
static const bool value = true;
};
template<>
struct is_pathable< directory_entry >
{
static const bool value = true;
};
// Pathable empty
template< class Container >
inline
// disable_if aids broken compilers (IBM, old GCC, etc.) and is harmless for
// conforming compilers. Replace by plain "bool" at some future date (2012?)
typename boost::disable_if<boost::is_array<Container>, bool>::type
empty(const Container & c)
{ return c.begin() == c.end(); }
typename boost::disable_if< boost::is_array< Container >, bool >::type
empty(Container const& c)
{
return c.begin() == c.end();
}
template <class T> inline
bool empty(T * const & c_str)
{
template< class T >
inline bool empty(T* const& c_str)
{
BOOST_ASSERT(c_str);
return !*c_str;
}
}
template <typename T, size_t N> inline
bool empty(T (&x)[N])
{ return !x[0]; }
template< typename T, std::size_t N >
inline bool empty(T (&x)[N])
{
return !x[0];
}
// value types differ ---------------------------------------------------------------//
//
// A from_end argument of 0 is less efficient than a known end, so use only if needed
// value types differ ---------------------------------------------------------------//
//
// A from_end argument of 0 is less efficient than a known end, so use only if needed
// with codecvt
// with codecvt
BOOST_FILESYSTEM_DECL
void convert(const char* from,
BOOST_FILESYSTEM_DECL
void convert(const char* from,
const char* from_end, // 0 for null terminated MBCS
std::wstring & to,
const codecvt_type& cvt);
std::wstring& to, codecvt_type const& cvt);
BOOST_FILESYSTEM_DECL
void convert(const wchar_t* from,
BOOST_FILESYSTEM_DECL
void convert(const wchar_t* from,
const wchar_t* from_end, // 0 for null terminated MBCS
std::string & to,
const codecvt_type& cvt);
std::string& to, codecvt_type const& cvt);
inline
void convert(const char* from,
std::wstring & to,
const codecvt_type& cvt)
{
inline void convert(const char* from, std::wstring& to, codecvt_type const& cvt)
{
BOOST_ASSERT(from);
convert(from, 0, to, cvt);
}
}
inline
void convert(const wchar_t* from,
std::string & to,
const codecvt_type& cvt)
{
inline void convert(const wchar_t* from, std::string& to, codecvt_type const& cvt)
{
BOOST_ASSERT(from);
convert(from, 0, to, cvt);
}
}
// without codecvt
// without codecvt
inline
void convert(const char* from,
inline void convert(const char* from,
const char* from_end, // 0 for null terminated MBCS
std::wstring & to);
std::wstring& to);
inline
void convert(const wchar_t* from,
inline void convert(const wchar_t* from,
const wchar_t* from_end, // 0 for null terminated MBCS
std::string & to);
std::string& to);
inline
void convert(const char* from,
std::wstring & to);
inline void convert(const char* from, std::wstring& to);
inline
void convert(const wchar_t* from,
std::string & to);
inline void convert(const wchar_t* from, std::string& to);
// value types same -----------------------------------------------------------------//
// value types same -----------------------------------------------------------------//
// char with codecvt
// char with codecvt
inline
void convert(const char* from, const char* from_end, std::string & to,
const codecvt_type&)
{
inline void convert(const char* from, const char* from_end, std::string& to, codecvt_type const&)
{
BOOST_ASSERT(from);
BOOST_ASSERT(from_end);
to.append(from, from_end);
}
}
inline
void convert(const char* from,
std::string & to,
const codecvt_type&)
{
inline void convert(const char* from, std::string& to, codecvt_type const&)
{
BOOST_ASSERT(from);
to += from;
}
}
// wchar_t with codecvt
// wchar_t with codecvt
inline
void convert(const wchar_t* from, const wchar_t* from_end, std::wstring & to,
const codecvt_type&)
{
inline void convert(const wchar_t* from, const wchar_t* from_end, std::wstring& to, codecvt_type const&)
{
BOOST_ASSERT(from);
BOOST_ASSERT(from_end);
to.append(from, from_end);
}
}
inline
void convert(const wchar_t* from,
std::wstring & to,
const codecvt_type&)
{
inline void convert(const wchar_t* from, std::wstring& to, codecvt_type const&)
{
BOOST_ASSERT(from);
to += from;
}
}
// char without codecvt
// char without codecvt
inline
void convert(const char* from, const char* from_end, std::string & to)
{
inline void convert(const char* from, const char* from_end, std::string& to)
{
BOOST_ASSERT(from);
BOOST_ASSERT(from_end);
to.append(from, from_end);
}
}
inline
void convert(const char* from, std::string & to)
{
inline void convert(const char* from, std::string& to)
{
BOOST_ASSERT(from);
to += from;
}
}
// wchar_t without codecvt
// wchar_t without codecvt
inline
void convert(const wchar_t* from, const wchar_t* from_end, std::wstring & to)
{
inline void convert(const wchar_t* from, const wchar_t* from_end, std::wstring& to)
{
BOOST_ASSERT(from);
BOOST_ASSERT(from_end);
to.append(from, from_end);
}
}
inline
void convert(const wchar_t* from, std::wstring & to)
{
inline void convert(const wchar_t* from, std::wstring& to)
{
BOOST_ASSERT(from);
to += from;
}
}
// Source dispatch -----------------------------------------------------------------//
// Source dispatch -----------------------------------------------------------------//
// contiguous containers with codecvt
template <class U> inline
void dispatch(const std::string& c, U& to, const codecvt_type& cvt)
{
// contiguous containers with codecvt
template< class U >
inline void dispatch(std::string const& c, U& to, codecvt_type const& cvt)
{
if (!c.empty())
convert(&*c.begin(), &*c.begin() + c.size(), to, cvt);
}
template <class U> inline
void dispatch(const std::wstring& c, U& to, const codecvt_type& cvt)
{
}
template< class U >
inline void dispatch(std::wstring const& c, U& to, codecvt_type const& cvt)
{
if (!c.empty())
convert(&*c.begin(), &*c.begin() + c.size(), to, cvt);
}
template <class U> inline
void dispatch(const std::vector<char>& c, U& to, const codecvt_type& cvt)
{
}
template< class U >
inline void dispatch(std::vector< char > const& c, U& to, codecvt_type const& cvt)
{
if (!c.empty())
convert(&*c.begin(), &*c.begin() + c.size(), to, cvt);
}
template <class U> inline
void dispatch(const std::vector<wchar_t>& c, U& to, const codecvt_type& cvt)
{
}
template< class U >
inline void dispatch(std::vector< wchar_t > const& c, U& to, codecvt_type const& cvt)
{
if (!c.empty())
convert(&*c.begin(), &*c.begin() + c.size(), to, cvt);
}
}
// contiguous containers without codecvt
template <class U> inline
void dispatch(const std::string& c, U& to)
{
// contiguous containers without codecvt
template< class U >
inline void dispatch(std::string const& c, U& to)
{
if (!c.empty())
convert(&*c.begin(), &*c.begin() + c.size(), to);
}
template <class U> inline
void dispatch(const std::wstring& c, U& to)
{
}
template< class U >
inline void dispatch(std::wstring const& c, U& to)
{
if (!c.empty())
convert(&*c.begin(), &*c.begin() + c.size(), to);
}
template <class U> inline
void dispatch(const std::vector<char>& c, U& to)
{
}
template< class U >
inline void dispatch(std::vector< char > const& c, U& to)
{
if (!c.empty())
convert(&*c.begin(), &*c.begin() + c.size(), to);
}
template <class U> inline
void dispatch(const std::vector<wchar_t>& c, U& to)
{
}
template< class U >
inline void dispatch(std::vector< wchar_t > const& c, U& to)
{
if (!c.empty())
convert(&*c.begin(), &*c.begin() + c.size(), to);
}
}
// non-contiguous containers with codecvt
template <class Container, class U> inline
// non-contiguous containers with codecvt
template< class Container, class U >
inline
// disable_if aids broken compilers (IBM, old GCC, etc.) and is harmless for
// conforming compilers. Replace by plain "void" at some future date (2012?)
typename boost::disable_if<boost::is_array<Container>, void>::type
dispatch(const Container & c, U& to, const codecvt_type& cvt)
{
typename boost::disable_if< boost::is_array< Container >, void >::type
dispatch(Container const& c, U& to, codecvt_type const& cvt)
{
if (!c.empty())
{
std::basic_string<typename Container::value_type> s(c.begin(), c.end());
convert(s.c_str(), s.c_str()+s.size(), to, cvt);
}
std::basic_string< typename Container::value_type > s(c.begin(), c.end());
convert(s.c_str(), s.c_str() + s.size(), to, cvt);
}
}
// c_str
template <class T, class U> inline
void dispatch(T * const & c_str, U& to, const codecvt_type& cvt)
{
// c_str
template< class T, class U >
inline void dispatch(T* const& c_str, U& to, codecvt_type const& cvt)
{
// std::cout << "dispatch() const T *\n";
BOOST_ASSERT(c_str);
convert(c_str, to, cvt);
}
}
// Note: there is no dispatch on C-style arrays because the array may
// contain a string smaller than the array size.
// Note: there is no dispatch on C-style arrays because the array may
// contain a string smaller than the array size.
BOOST_FILESYSTEM_DECL
void dispatch(const directory_entry & de,
# ifdef BOOST_WINDOWS_API
std::wstring & to,
# else
std::string & to,
# endif
const codecvt_type&);
BOOST_FILESYSTEM_DECL
void dispatch(directory_entry const& de,
#ifdef BOOST_WINDOWS_API
std::wstring& to,
#else
std::string& to,
#endif
codecvt_type const&);
// non-contiguous containers without codecvt
template <class Container, class U> inline
// non-contiguous containers without codecvt
template< class Container, class U >
inline
// disable_if aids broken compilers (IBM, old GCC, etc.) and is harmless for
// conforming compilers. Replace by plain "void" at some future date (2012?)
typename boost::disable_if<boost::is_array<Container>, void>::type
dispatch(const Container & c, U& to)
{
typename boost::disable_if< boost::is_array< Container >, void >::type
dispatch(Container const& c, U& to)
{
if (!c.empty())
{
std::basic_string<typename Container::value_type> seq(c.begin(), c.end());
convert(seq.c_str(), seq.c_str()+seq.size(), to);
}
std::basic_string< typename Container::value_type > seq(c.begin(), c.end());
convert(seq.c_str(), seq.c_str() + seq.size(), to);
}
}
// c_str
template <class T, class U> inline
void dispatch(T * const & c_str, U& to)
{
// c_str
template< class T, class U >
inline void dispatch(T* const& c_str, U& to)
{
// std::cout << "dispatch() const T *\n";
BOOST_ASSERT(c_str);
convert(c_str, to);
}
}
// Note: there is no dispatch on C-style arrays because the array may
// contain a string smaller than the array size.
// Note: there is no dispatch on C-style arrays because the array may
// contain a string smaller than the array size.
BOOST_FILESYSTEM_DECL
void dispatch(const directory_entry & de,
# ifdef BOOST_WINDOWS_API
std::wstring & to
# else
std::string & to
# endif
);
BOOST_FILESYSTEM_DECL
void dispatch(directory_entry const& de,
#ifdef BOOST_WINDOWS_API
std::wstring& to
#else
std::string& to
#endif
);
}}} // namespace boost::filesystem::path_traits
} // namespace path_traits
} // namespace filesystem
} // namespace boost
#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas

View File

@ -10,34 +10,35 @@
#ifndef BOOST_FILESYSTEM_STRING_FILE_HPP
#define BOOST_FILESYSTEM_STRING_FILE_HPP
#include <cstddef>
#include <string>
#include <ios>
#include <boost/filesystem/path.hpp>
#include <boost/filesystem/fstream.hpp>
#include <boost/filesystem/operations.hpp>
namespace boost
{
namespace filesystem
{
inline
void save_string_file(const path& p, const std::string& str)
namespace boost {
namespace filesystem {
inline void save_string_file(path const& p, std::string const& str)
{
filesystem::ofstream file;
file.exceptions(std::ofstream::failbit | std::ofstream::badbit);
file.exceptions(std::ios_base::failbit | std::ios_base::badbit);
file.open(p, std::ios_base::binary);
file.write(str.c_str(), str.size());
}
inline
void load_string_file(const path& p, std::string& str)
inline void load_string_file(path const& p, std::string& str)
{
filesystem::ifstream file;
file.exceptions(std::ifstream::failbit | std::ifstream::badbit);
file.exceptions(std::ios_base::failbit | std::ios_base::badbit);
file.open(p, std::ios_base::binary);
std::size_t sz = static_cast<std::size_t>(filesystem::file_size(p));
std::size_t sz = static_cast< std::size_t >(filesystem::file_size(p));
str.resize(sz, '\0');
file.read(&str[0], sz);
}
} // namespace filesystem
} // namespace boost
#endif // include guard
#endif // BOOST_FILESYSTEM_STRING_FILE_HPP

View File

@ -13,32 +13,38 @@
#include <boost/config/warning_disable.hpp>
#include <boost/filesystem/config.hpp>
#include <boost/filesystem/path_traits.hpp>
#include <boost/system/error_code.hpp>
#include <locale>
#include <string>
#include <vector>
#include <cstdlib>
#include <cassert>
//--------------------------------------------------------------------------------------//
namespace
namespace boost {
namespace filesystem {
namespace {
class codecvt_error_cat BOOST_FINAL :
public boost::system::error_category
{
class codecvt_error_cat : public boost::system::error_category
{
public:
codecvt_error_cat(){}
public:
BOOST_DEFAULTED_FUNCTION(codecvt_error_cat(), {})
const char* name() const BOOST_SYSTEM_NOEXCEPT BOOST_OVERRIDE;
std::string message(int ev) const BOOST_OVERRIDE;
};
};
const char* codecvt_error_cat::name() const BOOST_SYSTEM_NOEXCEPT
{
const char* codecvt_error_cat::name() const BOOST_SYSTEM_NOEXCEPT
{
return "codecvt";
}
}
std::string codecvt_error_cat::message(int ev) const
{
std::string codecvt_error_cat::message(int ev) const
{
std::string str;
switch (ev)
{
@ -56,22 +62,18 @@ namespace
break;
default:
str = "unknown error";
break;
}
return str;
}
}
} // unnamed namespace
namespace boost
BOOST_FILESYSTEM_DECL boost::system::error_category const& codecvt_error_category()
{
namespace filesystem
{
BOOST_FILESYSTEM_DECL const boost::system::error_category& codecvt_error_category()
{
static const codecvt_error_cat codecvt_error_cat_const;
return codecvt_error_cat_const;
}
}
} // namespace filesystem
} // namespace filesystem
} // namespace boost

View File

@ -13,6 +13,7 @@
#include "platform_config.hpp"
#include <boost/filesystem/config.hpp>
#include <boost/filesystem/directory.hpp>
#include <boost/filesystem/exception.hpp>
#include <boost/filesystem/operations.hpp>
@ -36,14 +37,13 @@
#include <unistd.h>
#include <fcntl.h>
#if defined(_POSIX_THREAD_SAFE_FUNCTIONS) && (_POSIX_THREAD_SAFE_FUNCTIONS+0 >= 0)\
&& defined(_SC_THREAD_SAFE_FUNCTIONS)\
&& !defined(__CYGWIN__)\
&& !(defined(linux) || defined(__linux) || defined(__linux__))\
&& !defined(__ANDROID__)\
&& (!defined(__hpux) || defined(_REENTRANT)) \
&& (!defined(_AIX) || defined(__THREAD_SAFE))\
&& !defined(__wasm)
#if defined(_POSIX_THREAD_SAFE_FUNCTIONS) && (_POSIX_THREAD_SAFE_FUNCTIONS + 0 >= 0) && defined(_SC_THREAD_SAFE_FUNCTIONS) && \
!defined(__CYGWIN__) && \
!(defined(linux) || defined(__linux) || defined(__linux__)) && \
!defined(__ANDROID__) && \
(!defined(__hpux) || defined(_REENTRANT)) && \
(!defined(_AIX) || defined(__THREAD_SAFE)) && \
!defined(__wasm)
#define BOOST_FILESYSTEM_USE_READDIR_R
#endif
@ -63,8 +63,7 @@
// macros being tested come from dirent.h.
//
// TODO: find out what macros indicate dirent::d_type present in more libraries
#if defined(BOOST_WINDOWS_API)\
|| defined(_DIRENT_HAVE_D_TYPE)// defined by GNU C library if d_type present
#if defined(BOOST_WINDOWS_API) || defined(_DIRENT_HAVE_D_TYPE) // defined by GNU C library if d_type present
#define BOOST_FILESYSTEM_STATUS_CACHE
#endif
@ -125,24 +124,26 @@ file_status directory_entry::get_symlink_status(system::error_code* ec) const
namespace path_traits {
void dispatch(const directory_entry& de,
BOOST_FILESYSTEM_DECL
void dispatch(directory_entry const& de,
#ifdef BOOST_WINDOWS_API
std::wstring& to,
#else
std::string& to,
#endif
const codecvt_type&)
codecvt_type const&)
{
to = de.path().native();
}
void dispatch(const directory_entry& de,
BOOST_FILESYSTEM_DECL
void dispatch(directory_entry const& de,
#ifdef BOOST_WINDOWS_API
std::wstring& to
#else
std::string& to
#endif
)
)
{
to = de.path().native();
}
@ -203,9 +204,7 @@ inline std::size_t path_max()
#endif // BOOST_FILESYSTEM_USE_READDIR_R
error_code dir_itr_first(void*& handle, void*& buffer,
const char* dir, std::string& target,
fs::file_status&, fs::file_status&)
error_code dir_itr_first(void*& handle, void*& buffer, const char* dir, std::string& target, fs::file_status&, fs::file_status&)
{
if ((handle = ::opendir(dir)) == 0)
{
@ -255,11 +254,10 @@ inline int readdir_r_simulator(DIR* dirp, void*& buffer, struct dirent** result)
return 0;
}
error_code dir_itr_increment(void*& handle, void*& buffer,
std::string& target, fs::file_status& sf, fs::file_status& symlink_sf)
error_code dir_itr_increment(void*& handle, void*& buffer, std::string& target, fs::file_status& sf, fs::file_status& symlink_sf)
{
dirent* result = NULL;
int err = readdir_r_simulator(static_cast<DIR*>(handle), buffer, &result);
int err = readdir_r_simulator(static_cast< DIR* >(handle), buffer, &result);
if (BOOST_UNLIKELY(err != 0))
return error_code(err, system_category());
if (result == NULL)
@ -294,29 +292,26 @@ error_code dir_itr_increment(void*& handle, void*& buffer,
#else // BOOST_WINDOWS_API
error_code dir_itr_first(void*& handle, const fs::path& dir,
std::wstring& target, fs::file_status& sf, fs::file_status& symlink_sf)
error_code dir_itr_first(void*& handle, fs::path const& dir, std::wstring& target, fs::file_status& sf, fs::file_status& symlink_sf)
// Note: an empty root directory has no "." or ".." entries, so this
// causes a ERROR_FILE_NOT_FOUND error which we do not considered an
// error. It is treated as eof instead.
{
// use a form of search Sebastian Martel reports will work with Win98
std::wstring dirpath(dir.wstring());
dirpath += (dirpath.empty()
|| (dirpath[dirpath.size()-1] != L'\\'
&& dirpath[dirpath.size()-1] != L'/'
&& dirpath[dirpath.size()-1] != L':'))? L"\\*" : L"*";
dirpath += (dirpath.empty() || (dirpath[dirpath.size() - 1] != L'\\' && dirpath[dirpath.size() - 1] != L'/' && dirpath[dirpath.size() - 1] != L':')) ? L"\\*" : L"*";
WIN32_FIND_DATAW data;
if ((handle = ::FindFirstFileW(dirpath.c_str(), &data))
== INVALID_HANDLE_VALUE)
if ((handle = ::FindFirstFileW(dirpath.c_str(), &data)) == INVALID_HANDLE_VALUE)
{
handle = 0; // signal eof
DWORD error = ::GetLastError();
return error_code( (error == ERROR_FILE_NOT_FOUND
return error_code((error == ERROR_FILE_NOT_FOUND
// Windows Mobile returns ERROR_NO_MORE_FILES; see ticket #3551
|| error == ERROR_NO_MORE_FILES)
? 0 : error, system_category() );
|| error == ERROR_NO_MORE_FILES) ?
0 :
error,
system_category());
}
target = data.cFileName;
if (data.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)
@ -348,7 +343,7 @@ error_code dir_itr_first(void*& handle, const fs::path& dir,
error_code dir_itr_increment(void*& handle, std::wstring& target, fs::file_status& sf, fs::file_status& symlink_sf)
{
WIN32_FIND_DATAW data;
if (::FindNextFileW(handle, &data)== 0)// fails
if (::FindNextFileW(handle, &data) == 0) // fails
{
DWORD error = ::GetLastError();
fs::detail::dir_itr_close(handle);
@ -388,7 +383,7 @@ BOOST_CONSTEXPR_OR_CONST err_t not_found_error_code =
#else
ENOENT
#endif
;
;
} // namespace
@ -412,7 +407,7 @@ system::error_code dir_itr_close( // never throws
if (handle != NULL)
{
DIR* h = static_cast<DIR*>(handle);
DIR* h = static_cast< DIR* >(handle);
handle = NULL;
int err = 0;
if (BOOST_UNLIKELY(::closedir(h) != 0))
@ -437,10 +432,9 @@ system::error_code dir_itr_close( // never throws
}
BOOST_FILESYSTEM_DECL
void directory_iterator_construct(directory_iterator& it, const path& p, unsigned int opts, system::error_code* ec)
void directory_iterator_construct(directory_iterator& it, path const& p, unsigned int opts, system::error_code* ec)
{
if (error(p.empty() ? not_found_error_code : 0, p, ec,
"boost::filesystem::directory_iterator::construct"))
if (error(p.empty() ? not_found_error_code : 0, p, ec, "boost::filesystem::directory_iterator::construct"))
{
return;
}
@ -465,9 +459,9 @@ void directory_iterator_construct(directory_iterator& it, const path& p, unsigne
path::string_type filename;
file_status file_stat, symlink_file_stat;
error_code result = dir_itr_first(imp->handle,
# if defined(BOOST_POSIX_API)
#if defined(BOOST_POSIX_API)
imp->buffer,
# endif
#endif
p.c_str(), filename, file_stat, symlink_file_stat);
if (result)
@ -475,8 +469,7 @@ void directory_iterator_construct(directory_iterator& it, const path& p, unsigne
if (result != make_error_condition(system::errc::permission_denied) ||
(opts & static_cast< unsigned int >(directory_options::skip_permission_denied)) == 0u)
{
error(result.value(), p,
ec, "boost::filesystem::directory_iterator::construct");
error(result.value(), p, ec, "boost::filesystem::directory_iterator::construct");
}
return;
@ -523,9 +516,9 @@ void directory_iterator_increment(directory_iterator& it, system::error_code* ec
for (;;)
{
increment_ec = dir_itr_increment(it.m_imp->handle,
# if defined(BOOST_POSIX_API)
#if defined(BOOST_POSIX_API)
it.m_imp->buffer,
# endif
#endif
filename, file_stat, symlink_file_stat);
if (BOOST_UNLIKELY(!!increment_ec)) // happens if filesystem is corrupt, such as on a damaged optical disc
@ -536,9 +529,7 @@ void directory_iterator_increment(directory_iterator& it, system::error_code* ec
if (ec == NULL)
{
BOOST_FILESYSTEM_THROW(
filesystem_error("boost::filesystem::directory_iterator::operator++",
error_path,
increment_ec));
filesystem_error("boost::filesystem::directory_iterator::operator++", error_path, increment_ec));
}
*ec = increment_ec;
return;
@ -577,7 +568,7 @@ void directory_iterator_increment(directory_iterator& it, system::error_code* ec
//--------------------------------------------------------------------------------------//
BOOST_FILESYSTEM_DECL
void recursive_directory_iterator_construct(recursive_directory_iterator& it, const path& dir_path, unsigned int opts, system::error_code* ec)
void recursive_directory_iterator_construct(recursive_directory_iterator& it, path const& dir_path, unsigned int opts, system::error_code* ec)
{
if (ec)
ec->clear();
@ -748,8 +739,7 @@ inline push_directory_result recursive_directory_iterator_push_directory(detail:
if (BOOST_UNLIKELY(!!ec))
{
if (ec == make_error_condition(system::errc::no_such_file_or_directory) && fs::is_symlink(symlink_stat) &&
(imp->m_options & static_cast< unsigned int >(directory_options::follow_directory_symlink | directory_options::skip_dangling_symlinks))
== static_cast< unsigned int >(directory_options::follow_directory_symlink | directory_options::skip_dangling_symlinks))
(imp->m_options & static_cast< unsigned int >(directory_options::follow_directory_symlink | directory_options::skip_dangling_symlinks)) == static_cast< unsigned int >(directory_options::follow_directory_symlink | directory_options::skip_dangling_symlinks))
{
// Skip dangling symlink and continue iteration on the current depth level
ec = error_code();

View File

@ -55,8 +55,8 @@ typedef boost::winapi::DWORD_ err_t;
// Implemented in exception.cpp
void emit_error(err_t error_num, system::error_code* ec, const char* message);
void emit_error(err_t error_num, const path& p, system::error_code* ec, const char* message);
void emit_error(err_t error_num, const path& p1, const path& p2, system::error_code* ec, const char* message);
void emit_error(err_t error_num, path const& p, system::error_code* ec, const char* message);
void emit_error(err_t error_num, path const& p1, path const& p2, system::error_code* ec, const char* message);
inline bool error(err_t error_num, system::error_code* ec, const char* message)
{
@ -73,7 +73,7 @@ inline bool error(err_t error_num, system::error_code* ec, const char* message)
}
}
inline bool error(err_t error_num, const path& p, system::error_code* ec, const char* message)
inline bool error(err_t error_num, path const& p, system::error_code* ec, const char* message)
{
if (BOOST_LIKELY(!error_num))
{
@ -88,7 +88,7 @@ inline bool error(err_t error_num, const path& p, system::error_code* ec, const
}
}
inline bool error(err_t error_num, const path& p1, const path& p2, system::error_code* ec, const char* message)
inline bool error(err_t error_num, path const& p1, path const& p2, system::error_code* ec, const char* message)
{
if (BOOST_LIKELY(!error_num))
{

View File

@ -35,7 +35,7 @@ BOOST_FILESYSTEM_DECL filesystem_error::filesystem_error(const std::string& what
}
}
BOOST_FILESYSTEM_DECL filesystem_error::filesystem_error(const std::string& what_arg, const path& path1_arg, system::error_code ec) :
BOOST_FILESYSTEM_DECL filesystem_error::filesystem_error(const std::string& what_arg, path const& path1_arg, system::error_code ec) :
system::system_error(ec, what_arg)
{
try
@ -48,7 +48,7 @@ BOOST_FILESYSTEM_DECL filesystem_error::filesystem_error(const std::string& what
}
}
BOOST_FILESYSTEM_DECL filesystem_error::filesystem_error(const std::string& what_arg, const path& path1_arg, const path& path2_arg, system::error_code ec) :
BOOST_FILESYSTEM_DECL filesystem_error::filesystem_error(const std::string& what_arg, path const& path1_arg, path const& path2_arg, system::error_code ec) :
system::system_error(ec, what_arg)
{
try
@ -67,7 +67,7 @@ BOOST_FILESYSTEM_DECL filesystem_error::filesystem_error(filesystem_error const&
{
}
BOOST_FILESYSTEM_DECL filesystem_error& filesystem_error::operator= (filesystem_error const& that)
BOOST_FILESYSTEM_DECL filesystem_error& filesystem_error::operator=(filesystem_error const& that)
{
static_cast< system::system_error& >(*this) = static_cast< system::system_error const& >(that);
m_imp_ptr = that.m_imp_ptr;
@ -80,7 +80,8 @@ BOOST_FILESYSTEM_DECL filesystem_error::~filesystem_error() BOOST_NOEXCEPT_OR_NO
BOOST_FILESYSTEM_DECL const char* filesystem_error::what() const BOOST_NOEXCEPT_OR_NOTHROW
{
if (m_imp_ptr.get()) try
if (m_imp_ptr.get())
try
{
if (m_imp_ptr->m_what.empty())
{
@ -109,7 +110,7 @@ BOOST_FILESYSTEM_DECL const char* filesystem_error::what() const BOOST_NOEXCEPT_
return system::system_error::what();
}
BOOST_FILESYSTEM_DECL const path& filesystem_error::get_empty_path() BOOST_NOEXCEPT
BOOST_FILESYSTEM_DECL path const& filesystem_error::get_empty_path() BOOST_NOEXCEPT
{
static const path empty_path;
return empty_path;
@ -125,7 +126,7 @@ void emit_error(err_t error_num, system::error_code* ec, const char* message)
ec->assign(error_num, system::system_category());
}
void emit_error(err_t error_num, const path& p, system::error_code* ec, const char* message)
void emit_error(err_t error_num, path const& p, system::error_code* ec, const char* message)
{
if (!ec)
BOOST_FILESYSTEM_THROW(filesystem_error(message, p, system::error_code(error_num, system::system_category())));
@ -133,7 +134,7 @@ void emit_error(err_t error_num, const path& p, system::error_code* ec, const ch
ec->assign(error_num, system::system_category());
}
void emit_error(err_t error_num, const path& p1, const path& p2, system::error_code* ec, const char* message)
void emit_error(err_t error_num, path const& p1, path const& p2, system::error_code* ec, const char* message)
{
if (ec == 0)
BOOST_FILESYSTEM_THROW(filesystem_error(message, p1, p2, system::error_code(error_num, system::system_category())));

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -11,12 +11,16 @@
#include "platform_config.hpp"
#include <boost/filesystem/config.hpp>
#include <boost/filesystem/path_traits.hpp>
#include <boost/system/system_error.hpp>
#include <boost/scoped_array.hpp>
#include <boost/smart_ptr/scoped_array.hpp>
#include <boost/assert.hpp>
#include <string>
#include <locale> // for codecvt_base::result
#include <cstring> // for strlen
#include <cwchar> // for wcslen
#include <cstddef>
namespace pt = boost::filesystem::path_traits;
namespace fs = boost::filesystem;
@ -27,13 +31,12 @@ namespace bs = boost::system;
//--------------------------------------------------------------------------------------//
#ifndef BOOST_FILESYSTEM_CODECVT_BUF_SIZE
# define BOOST_FILESYSTEM_CODECVT_BUF_SIZE 256
#define BOOST_FILESYSTEM_CODECVT_BUF_SIZE 256
#endif
namespace {
const std::size_t default_codecvt_buf_size = BOOST_FILESYSTEM_CODECVT_BUF_SIZE;
BOOST_CONSTEXPR_OR_CONST std::size_t default_codecvt_buf_size = BOOST_FILESYSTEM_CODECVT_BUF_SIZE;
//--------------------------------------------------------------------------------------//
// //
@ -46,13 +49,13 @@ namespace {
// convert_aux const char* to wstring //
//--------------------------------------------------------------------------------------//
void convert_aux(
void convert_aux(
const char* from,
const char* from_end,
wchar_t* to, wchar_t* to_end,
std::wstring & target,
const pt::codecvt_type & cvt)
{
std::wstring& target,
pt::codecvt_type const& cvt)
{
//std::cout << std::hex
// << " from=" << std::size_t(from)
// << " from_end=" << std::size_t(from_end)
@ -66,27 +69,25 @@ namespace {
std::codecvt_base::result res;
if ((res=cvt.in(state, from, from_end, from_next,
to, to_end, to_next)) != std::codecvt_base::ok)
if ((res = cvt.in(state, from, from_end, from_next, to, to_end, to_next)) != std::codecvt_base::ok)
{
//std::cout << " result is " << static_cast<int>(res) << std::endl;
BOOST_FILESYSTEM_THROW(bs::system_error(res, fs::codecvt_error_category(),
"boost::filesystem::path codecvt to wstring"));
BOOST_FILESYSTEM_THROW(bs::system_error(res, fs::codecvt_error_category(), "boost::filesystem::path codecvt to wstring"));
}
target.append(to, to_next);
}
}
//--------------------------------------------------------------------------------------//
// convert_aux const wchar_t* to string //
//--------------------------------------------------------------------------------------//
void convert_aux(
void convert_aux(
const wchar_t* from,
const wchar_t* from_end,
char* to, char* to_end,
std::string & target,
const pt::codecvt_type & cvt)
{
std::string& target,
pt::codecvt_type const& cvt)
{
//std::cout << std::hex
// << " from=" << std::size_t(from)
// << " from_end=" << std::size_t(from_end)
@ -100,15 +101,13 @@ namespace {
std::codecvt_base::result res;
if ((res=cvt.out(state, from, from_end, from_next,
to, to_end, to_next)) != std::codecvt_base::ok)
if ((res = cvt.out(state, from, from_end, from_next, to, to_end, to_next)) != std::codecvt_base::ok)
{
//std::cout << " result is " << static_cast<int>(res) << std::endl;
BOOST_FILESYSTEM_THROW(bs::system_error(res, fs::codecvt_error_category(),
"boost::filesystem::path codecvt to string"));
BOOST_FILESYSTEM_THROW(bs::system_error(res, fs::codecvt_error_category(), "boost::filesystem::path codecvt to string"));
}
target.append(to, to_next);
}
}
} // unnamed namespace
@ -116,18 +115,19 @@ namespace {
// path_traits //
//--------------------------------------------------------------------------------------//
namespace boost { namespace filesystem { namespace path_traits {
namespace boost {
namespace filesystem {
namespace path_traits {
//--------------------------------------------------------------------------------------//
// convert const char* to wstring //
//--------------------------------------------------------------------------------------//
BOOST_FILESYSTEM_DECL
void convert(const char* from,
BOOST_FILESYSTEM_DECL
void convert(const char* from,
const char* from_end, // 0 for null terminated MBCS
std::wstring & to,
const codecvt_type & cvt)
{
std::wstring& to, codecvt_type const& cvt)
{
BOOST_ASSERT(from);
if (!from_end) // null terminated
@ -135,33 +135,33 @@ namespace boost { namespace filesystem { namespace path_traits {
from_end = from + std::strlen(from);
}
if (from == from_end) return;
if (from == from_end)
return;
std::size_t buf_size = (from_end - from) * 3; // perhaps too large, but that's OK
// dynamically allocate a buffer only if source is unusually large
if (buf_size > default_codecvt_buf_size)
{
boost::scoped_array< wchar_t > buf(new wchar_t [buf_size]);
convert_aux(from, from_end, buf.get(), buf.get()+buf_size, to, cvt);
boost::scoped_array< wchar_t > buf(new wchar_t[buf_size]);
convert_aux(from, from_end, buf.get(), buf.get() + buf_size, to, cvt);
}
else
{
wchar_t buf[default_codecvt_buf_size];
convert_aux(from, from_end, buf, buf+default_codecvt_buf_size, to, cvt);
}
convert_aux(from, from_end, buf, buf + default_codecvt_buf_size, to, cvt);
}
}
//--------------------------------------------------------------------------------------//
// convert const wchar_t* to string //
//--------------------------------------------------------------------------------------//
BOOST_FILESYSTEM_DECL
void convert(const wchar_t* from,
BOOST_FILESYSTEM_DECL
void convert(const wchar_t* from,
const wchar_t* from_end, // 0 for null terminated MBCS
std::string & to,
const codecvt_type & cvt)
{
std::string& to, codecvt_type const& cvt)
{
BOOST_ASSERT(from);
if (!from_end) // null terminated
@ -169,7 +169,8 @@ namespace boost { namespace filesystem { namespace path_traits {
from_end = from + std::wcslen(from);
}
if (from == from_end) return;
if (from == from_end)
return;
// The codecvt length functions may not be implemented, and I don't really
// understand them either. Thus this code is just a guess; if it turns
@ -181,13 +182,16 @@ namespace boost { namespace filesystem { namespace path_traits {
// dynamically allocate a buffer only if source is unusually large
if (buf_size > default_codecvt_buf_size)
{
boost::scoped_array< char > buf(new char [buf_size]);
convert_aux(from, from_end, buf.get(), buf.get()+buf_size, to, cvt);
boost::scoped_array< char > buf(new char[buf_size]);
convert_aux(from, from_end, buf.get(), buf.get() + buf_size, to, cvt);
}
else
{
char buf[default_codecvt_buf_size];
convert_aux(from, from_end, buf, buf+default_codecvt_buf_size, to, cvt);
convert_aux(from, from_end, buf, buf + default_codecvt_buf_size, to, cvt);
}
}
}}} // namespace boost::filesystem::path_traits
}
} // namespace path_traits
} // namespace filesystem
} // namespace boost

View File

@ -68,7 +68,7 @@
#define _INCLUDE_STDCSOURCE_199901
#endif
#if defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || defined(__TOS_WIN__) || defined(__WINDOWS__) ||\
#if defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || defined(__TOS_WIN__) || defined(__WINDOWS__) || \
defined(__CYGWIN__)
// Define target Windows version macros before including any other headers
#include <boost/winapi/config.hpp>

View File

@ -11,100 +11,79 @@
#include "platform_config.hpp"
#include <boost/filesystem/config.hpp>
#include <boost/filesystem/path.hpp>
namespace fs = boost::filesystem;
#include <cstring> // SGI MIPSpro compilers need this
#include <string>
# ifdef BOOST_NO_STDC_NAMESPACE
namespace std { using ::strerror; }
# endif
#ifdef BOOST_NO_STDC_NAMESPACE
namespace std {
using ::strerror;
}
#endif
//--------------------------------------------------------------------------------------//
namespace
{
const char invalid_chars[] =
namespace {
BOOST_CONSTEXPR_OR_CONST char invalid_chars[] =
"\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F"
"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"
"<>:\"/\\|";
// note that the terminating '\0' is part of the string - thus the size below
// is sizeof(invalid_chars) rather than sizeof(invalid_chars)-1. I
const std::string windows_invalid_chars(invalid_chars, sizeof(invalid_chars));
// note that the terminating '\0' is part of the string - thus the size below
// is sizeof(invalid_chars) rather than sizeof(invalid_chars)-1. I
const std::string windows_invalid_chars(invalid_chars, sizeof(invalid_chars));
const std::string valid_posix(
const std::string valid_posix(
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._-");
} // unnamed namespace
namespace boost
namespace boost {
namespace filesystem {
// name_check functions ----------------------------------------------//
#ifdef BOOST_WINDOWS
BOOST_FILESYSTEM_DECL bool native(const std::string& name)
{
namespace filesystem
{
// name_check functions ----------------------------------------------//
# ifdef BOOST_WINDOWS
BOOST_FILESYSTEM_DECL bool native(const std::string & name)
{
return windows_name(name);
}
# else
BOOST_FILESYSTEM_DECL bool native(const std::string & name)
{
return !name.empty()
&& name[0] != ' '
&& name.find('/') == std::string::npos;
}
# endif
}
#else
BOOST_FILESYSTEM_DECL bool native(const std::string& name)
{
return !name.empty() && name[0] != ' ' && name.find('/') == std::string::npos;
}
#endif
BOOST_FILESYSTEM_DECL bool portable_posix_name(const std::string & name)
{
return !name.empty()
&& name.find_first_not_of(valid_posix) == std::string::npos;
}
BOOST_FILESYSTEM_DECL bool portable_posix_name(const std::string& name)
{
return !name.empty() && name.find_first_not_of(valid_posix) == std::string::npos;
}
BOOST_FILESYSTEM_DECL bool windows_name(const std::string & name)
{
return !name.empty()
&& name[0] != ' '
&& name.find_first_of(windows_invalid_chars) == std::string::npos
&& *(name.end()-1) != ' '
&& (*(name.end()-1) != '.'
|| name.size() == 1 || name == "..");
}
BOOST_FILESYSTEM_DECL bool windows_name(const std::string& name)
{
return !name.empty() && name[0] != ' ' && name.find_first_of(windows_invalid_chars) == std::string::npos && *(name.end() - 1) != ' ' && (*(name.end() - 1) != '.' || name.size() == 1 || name == "..");
}
BOOST_FILESYSTEM_DECL bool portable_name(const std::string & name)
{
return !name.empty()
&& (name == "."
|| name == ".."
|| (windows_name(name)
&& portable_posix_name(name)
&& name[0] != '.' && name[0] != '-'));
}
BOOST_FILESYSTEM_DECL bool portable_name(const std::string& name)
{
return !name.empty() && (name == "." || name == ".." || (windows_name(name) && portable_posix_name(name) && name[0] != '.' && name[0] != '-'));
}
BOOST_FILESYSTEM_DECL bool portable_directory_name(const std::string & name)
{
return
name == "."
|| name == ".."
|| (portable_name(name)
&& name.find('.') == std::string::npos);
}
BOOST_FILESYSTEM_DECL bool portable_directory_name(const std::string& name)
{
return name == "." || name == ".." || (portable_name(name) && name.find('.') == std::string::npos);
}
BOOST_FILESYSTEM_DECL bool portable_file_name(const std::string & name)
{
BOOST_FILESYSTEM_DECL bool portable_file_name(const std::string& name)
{
std::string::size_type pos;
return
portable_name(name)
&& name != "."
&& name != ".."
&& ((pos = name.find('.')) == std::string::npos
|| (name.find('.', pos+1) == std::string::npos
&& (pos + 5) > name.size()));
}
return portable_name(name) && name != "." && name != ".." && ((pos = name.find('.')) == std::string::npos || (name.find('.', pos + 1) == std::string::npos && (pos + 5) > name.size()));
}
} // namespace filesystem
} // namespace filesystem
} // namespace boost

View File

@ -17,62 +17,73 @@
#include <boost/predef/os/bsd/free.h>
#ifdef BOOST_POSIX_API
# include <cerrno>
# include <stddef.h>
# include <fcntl.h>
# ifdef BOOST_HAS_UNISTD_H
# include <unistd.h>
# endif
# if BOOST_OS_BSD_OPEN >= BOOST_VERSION_NUMBER(2, 1, 0) || BOOST_OS_BSD_FREE >= BOOST_VERSION_NUMBER(8, 0, 0) || BOOST_LIB_C_CLOUDABI
# include <stdlib.h>
# define BOOST_FILESYSTEM_HAS_ARC4RANDOM
# endif
# if (defined(__linux__) || defined(__linux) || defined(linux)) && (!defined(__ANDROID__) || __ANDROID_API__ >= 28)
# include <sys/syscall.h>
# if defined(SYS_getrandom)
# define BOOST_FILESYSTEM_HAS_SYS_GETRANDOM
# endif // defined(SYS_getrandom)
# if defined(__has_include)
# if __has_include(<sys/random.h>)
# define BOOST_FILESYSTEM_HAS_GETRANDOM
# endif
# elif defined(__GLIBC__)
# if __GLIBC_PREREQ(2, 25)
# define BOOST_FILESYSTEM_HAS_GETRANDOM
# endif
# endif
# if defined(BOOST_FILESYSTEM_HAS_GETRANDOM)
# include <sys/random.h>
# endif
# endif // (defined(__linux__) || defined(__linux) || defined(linux)) && (!defined(__ANDROID__) || __ANDROID_API__ >= 28)
#else // BOOST_WINDOWS_API
// We use auto-linking below to help users of static builds of Boost.Filesystem to link to whatever Windows SDK library we selected.
// The dependency information is currently not exposed in CMake config files generated by Boost.Build (https://github.com/boostorg/boost_install/issues/18),
// which makes it non-trivial for users to discover the libraries they need. This feature is deprecated and may be removed in the future,
// when the situation with CMake config files improves.
// Note that the library build system is the principal source of linking the library, which must work regardless of auto-linking.
# include <boost/predef/platform.h>
# include <boost/winapi/basic_types.hpp>
# if defined(BOOST_FILESYSTEM_HAS_BCRYPT) // defined on the command line by the project
# include <boost/winapi/error_codes.hpp>
# include <boost/winapi/bcrypt.hpp>
# if !defined(BOOST_FILESYSTEM_NO_DEPRECATED) && defined(_MSC_VER)
# pragma comment(lib, "bcrypt.lib")
# endif // !defined(BOOST_FILESYSTEM_NO_DEPRECATED) && defined(_MSC_VER)
# else // defined(BOOST_FILESYSTEM_HAS_BCRYPT)
# include <boost/winapi/crypt.hpp>
# include <boost/winapi/get_last_error.hpp>
# if !defined(BOOST_FILESYSTEM_NO_DEPRECATED) && defined(_MSC_VER)
# if !defined(_WIN32_WCE)
# pragma comment(lib, "advapi32.lib")
# else
# pragma comment(lib, "coredll.lib")
# endif
# endif // !defined(BOOST_FILESYSTEM_NO_DEPRECATED) && defined(_MSC_VER)
# endif // defined(BOOST_FILESYSTEM_HAS_BCRYPT)
#include <cerrno>
#include <stddef.h>
#include <fcntl.h>
#ifdef BOOST_HAS_UNISTD_H
#include <unistd.h>
#endif
#if BOOST_OS_BSD_OPEN >= BOOST_VERSION_NUMBER(2, 1, 0) || \
BOOST_OS_BSD_FREE >= BOOST_VERSION_NUMBER(8, 0, 0) || \
BOOST_LIB_C_CLOUDABI
#include <stdlib.h>
#define BOOST_FILESYSTEM_HAS_ARC4RANDOM
#endif
#if (defined(__linux__) || defined(__linux) || defined(linux)) && \
(!defined(__ANDROID__) || __ANDROID_API__ >= 28)
#include <sys/syscall.h>
#if defined(SYS_getrandom)
#define BOOST_FILESYSTEM_HAS_SYS_GETRANDOM
#endif // defined(SYS_getrandom)
#if defined(__has_include)
#if __has_include(<sys/random.h>)
#define BOOST_FILESYSTEM_HAS_GETRANDOM
#endif
#elif defined(__GLIBC__)
#if __GLIBC_PREREQ(2, 25)
#define BOOST_FILESYSTEM_HAS_GETRANDOM
#endif
#endif // BOOST_FILESYSTEM_HAS_GETRANDOM definition
#if defined(BOOST_FILESYSTEM_HAS_GETRANDOM)
#include <sys/random.h>
#endif
#endif // (defined(__linux__) || defined(__linux) || defined(linux)) && (!defined(__ANDROID__) || __ANDROID_API__ >= 28)
#else // BOOST_WINDOWS_API
// We use auto-linking below to help users of static builds of Boost.Filesystem to link to whatever Windows SDK library we selected.
// The dependency information is currently not exposed in CMake config files generated by Boost.Build (https://github.com/boostorg/boost_install/issues/18),
// which makes it non-trivial for users to discover the libraries they need. This feature is deprecated and may be removed in the future,
// when the situation with CMake config files improves.
// Note that the library build system is the principal source of linking the library, which must work regardless of auto-linking.
#include <boost/predef/platform.h>
#include <boost/winapi/basic_types.hpp>
#if defined(BOOST_FILESYSTEM_HAS_BCRYPT) // defined on the command line by the project
#include <boost/winapi/error_codes.hpp>
#include <boost/winapi/bcrypt.hpp>
#if !defined(BOOST_FILESYSTEM_NO_DEPRECATED) && defined(_MSC_VER)
#pragma comment(lib, "bcrypt.lib")
#endif // !defined(BOOST_FILESYSTEM_NO_DEPRECATED) && defined(_MSC_VER)
#else // defined(BOOST_FILESYSTEM_HAS_BCRYPT)
#include <boost/winapi/crypt.hpp>
#include <boost/winapi/get_last_error.hpp>
#if !defined(BOOST_FILESYSTEM_NO_DEPRECATED) && defined(_MSC_VER)
#if !defined(_WIN32_WCE)
#pragma comment(lib, "advapi32.lib")
#else
#pragma comment(lib, "coredll.lib")
#endif
#endif // !defined(BOOST_FILESYSTEM_NO_DEPRECATED) && defined(_MSC_VER)
#endif // defined(BOOST_FILESYSTEM_HAS_BCRYPT)
#endif // BOOST_POSIX_API
#include <cstddef>
#include <boost/filesystem/config.hpp>
#include <boost/filesystem/operations.hpp>
#include "error_handling.hpp"
@ -83,7 +94,9 @@
#endif
#endif // defined(BOOST_POSIX_API)
namespace boost { namespace filesystem { namespace detail {
namespace boost {
namespace filesystem {
namespace detail {
namespace {
@ -132,7 +145,7 @@ void system_crypt_random(void* buf, std::size_t len, boost::system::error_code*
}
bytes_read += n;
buf = static_cast<char*>(buf) + n;
buf = static_cast< char* >(buf) + n;
}
#elif defined(BOOST_FILESYSTEM_HAS_ARC4RANDOM)
@ -166,7 +179,7 @@ void system_crypt_random(void* buf, std::size_t len, boost::system::error_code*
return;
}
bytes_read += n;
buf = static_cast<char*>(buf) + n;
buf = static_cast< char* >(buf) + n;
}
close(file);
@ -186,7 +199,7 @@ void system_crypt_random(void* buf, std::size_t len, boost::system::error_code*
return;
}
status = boost::winapi::BCryptGenRandom(handle, static_cast<boost::winapi::PUCHAR_>(buf), static_cast<boost::winapi::ULONG_>(len), 0);
status = boost::winapi::BCryptGenRandom(handle, static_cast< boost::winapi::PUCHAR_ >(buf), static_cast< boost::winapi::ULONG_ >(len), 0);
boost::winapi::BCryptCloseAlgorithmProvider(handle, 0);
@ -206,7 +219,7 @@ void system_crypt_random(void* buf, std::size_t len, boost::system::error_code*
return;
}
boost::winapi::BOOL_ gen_ok = boost::winapi::CryptGenRandom(handle, static_cast<boost::winapi::DWORD_>(len), static_cast<boost::winapi::BYTE_*>(buf));
boost::winapi::BOOL_ gen_ok = boost::winapi::CryptGenRandom(handle, static_cast< boost::winapi::DWORD_ >(len), static_cast< boost::winapi::BYTE_* >(buf));
if (BOOST_UNLIKELY(!gen_ok))
err = boost::winapi::GetLastError();
@ -240,7 +253,7 @@ path unique_path(const path& model, system::error_code* ec)
// bytes and 40-7F as trailing bytes, whereas % is 25.
// So, use string on POSIX and avoid conversions.
path::string_type s( model.native() );
path::string_type s(model.native());
char ran[16] = {}; // init to avoid clang static analyzer message
// see ticket #8954
@ -264,9 +277,12 @@ path unique_path(const path& model, system::error_code* ec)
}
}
if (ec != 0) ec->clear();
if (ec != 0)
ec->clear();
return s;
}
}}}
} // namespace detail
} // namespace filesystem
} // namespace boost

View File

@ -5,10 +5,17 @@
#include "platform_config.hpp"
#define BOOST_UTF8_BEGIN_NAMESPACE \
namespace boost { namespace filesystem { namespace detail {
#include <boost/filesystem/config.hpp>
#define BOOST_UTF8_END_NAMESPACE }}}
#define BOOST_UTF8_BEGIN_NAMESPACE \
namespace boost { \
namespace filesystem { \
namespace detail {
#define BOOST_UTF8_END_NAMESPACE \
} \
} \
}
#define BOOST_UTF8_DECL BOOST_FILESYSTEM_DECL
#include <boost/detail/utf8_codecvt_facet.ipp>

View File

@ -20,15 +20,14 @@
#include <windows.h>
std::codecvt_base::result windows_file_codecvt::do_in(
std::mbstate_t &,
std::mbstate_t&,
const char* from, const char* from_end, const char*& from_next,
wchar_t* to, wchar_t* to_end, wchar_t*& to_next) const
{
UINT codepage = AreFileApisANSI() ? CP_ACP : CP_OEMCP;
int count;
if ((count = ::MultiByteToWideChar(codepage, MB_PRECOMPOSED, from,
static_cast<int>(from_end - from), to, static_cast<int>(to_end - to))) == 0)
if ((count = ::MultiByteToWideChar(codepage, MB_PRECOMPOSED, from, static_cast< int >(from_end - from), to, static_cast< int >(to_end - to))) == 0)
{
return error; // conversion failed
}
@ -40,15 +39,14 @@ std::codecvt_base::result windows_file_codecvt::do_in(
}
std::codecvt_base::result windows_file_codecvt::do_out(
std::mbstate_t &,
const wchar_t* from, const wchar_t* from_end, const wchar_t* & from_next,
char* to, char* to_end, char* & to_next) const
std::mbstate_t&,
const wchar_t* from, const wchar_t* from_end, const wchar_t*& from_next,
char* to, char* to_end, char*& to_next) const
{
UINT codepage = AreFileApisANSI() ? CP_ACP : CP_OEMCP;
int count;
if ((count = ::WideCharToMultiByte(codepage, WC_NO_BEST_FIT_CHARS, from,
static_cast<int>(from_end - from), to, static_cast<int>(to_end - to), 0, 0)) == 0)
if ((count = ::WideCharToMultiByte(codepage, WC_NO_BEST_FIT_CHARS, from, static_cast< int >(from_end - from), to, static_cast< int >(to_end - to), 0, 0)) == 0)
{
return error; // conversion failed
}

View File

@ -23,35 +23,26 @@
// //
//------------------------------------------------------------------------------------//
class BOOST_SYMBOL_VISIBLE windows_file_codecvt
: public std::codecvt< wchar_t, char, std::mbstate_t >
class BOOST_SYMBOL_VISIBLE windows_file_codecvt :
public std::codecvt< wchar_t, char, std::mbstate_t >
{
public:
explicit windows_file_codecvt(std::size_t refs = 0)
: std::codecvt<wchar_t, char, std::mbstate_t>(refs) {}
protected:
explicit windows_file_codecvt(std::size_t refs = 0) :
std::codecvt< wchar_t, char, std::mbstate_t >(refs)
{
}
protected:
virtual bool do_always_noconv() const throw() { return false; }
// seems safest to assume variable number of characters since we don't
// actually know what codepage is active
virtual int do_encoding() const throw() { return 0; }
virtual std::codecvt_base::result do_in(std::mbstate_t& state,
const char* from, const char* from_end, const char*& from_next,
wchar_t* to, wchar_t* to_end, wchar_t*& to_next) const;
virtual std::codecvt_base::result do_out(std::mbstate_t & state,
const wchar_t* from, const wchar_t* from_end, const wchar_t*& from_next,
char* to, char* to_end, char*& to_next) const;
virtual std::codecvt_base::result do_unshift(std::mbstate_t&,
char* /*from*/, char* /*to*/, char* & /*next*/) const { return ok; }
virtual int do_length(std::mbstate_t&,
const char* /*from*/, const char* /*from_end*/, std::size_t /*max*/) const { return 0; }
virtual int do_max_length() const throw () { return 0; }
virtual std::codecvt_base::result do_in(std::mbstate_t& state, const char* from, const char* from_end, const char*& from_next, wchar_t* to, wchar_t* to_end, wchar_t*& to_next) const;
virtual std::codecvt_base::result do_out(std::mbstate_t& state, const wchar_t* from, const wchar_t* from_end, const wchar_t*& from_next, char* to, char* to_end, char*& to_next) const;
virtual std::codecvt_base::result do_unshift(std::mbstate_t&, char* /*from*/, char* /*to*/, char*& /*next*/) const { return ok; }
virtual int do_length(std::mbstate_t&, const char* /*from*/, const char* /*from_end*/, std::size_t /*max*/) const { return 0; }
virtual int do_max_length() const throw() { return 0; }
};
#endif // BOOST_FILESYSTEM3_WIN_FILE_CODECVT_HPP

View File

@ -24,8 +24,7 @@ namespace detail {
inline bool equal_extension(wchar_t const* p, wchar_t const (&x1)[5], wchar_t const (&x2)[5])
{
return
(p[0] == x1[0] || p[0] == x2[0]) &&
return (p[0] == x1[0] || p[0] == x2[0]) &&
(p[1] == x1[1] || p[1] == x2[1]) &&
(p[2] == x1[2] || p[2] == x2[2]) &&
(p[3] == x1[3] || p[3] == x2[3]) &&
@ -39,10 +38,7 @@ inline boost::filesystem::perms make_permissions(const boost::filesystem::path&
prms |= boost::filesystem::owner_write | boost::filesystem::group_write | boost::filesystem::others_write;
boost::filesystem::path ext = p.extension();
wchar_t const* q = ext.c_str();
if (equal_extension(q, L".exe", L".EXE")
|| equal_extension(q, L".com", L".COM")
|| equal_extension(q, L".bat", L".BAT")
|| equal_extension(q, L".cmd", L".CMD"))
if (equal_extension(q, L".exe", L".EXE") || equal_extension(q, L".com", L".COM") || equal_extension(q, L".bat", L".BAT") || equal_extension(q, L".cmd", L".CMD"))
prms |= boost::filesystem::owner_exe | boost::filesystem::group_exe | boost::filesystem::others_exe;
return prms;
}

View File

@ -16,12 +16,11 @@
using std::cout;
using std::endl;
int main()
{
cout << "Verify macro reporting works correctly\n";
cout << " NOSUCHMACRO: " << BOOST_MACRO_VALUE(NOSUCHMACRO) << endl;
# define SUCHAMACRO
#define SUCHAMACRO
cout << " SUCHAMACRO: " << BOOST_MACRO_VALUE(SUCHAMACRO) << endl;
cout << " BOOST_VERSION: " << BOOST_MACRO_VALUE(BOOST_VERSION) << endl;
@ -47,6 +46,5 @@ int main()
//cout << " : " << BOOST_MACRO_VALUE() << endl;
//cout << " : " << BOOST_MACRO_VALUE() << endl;
return 0;
}

View File

@ -12,10 +12,10 @@
// See deprecated_test for tests of deprecated features
#ifndef BOOST_FILESYSTEM_NO_DEPRECATED
# define BOOST_FILESYSTEM_NO_DEPRECATED
#define BOOST_FILESYSTEM_NO_DEPRECATED
#endif
#ifndef BOOST_SYSTEM_NO_DEPRECATED
# define BOOST_SYSTEM_NO_DEPRECATED
#define BOOST_SYSTEM_NO_DEPRECATED
#endif
#include <boost/filesystem/convenience.hpp>
@ -23,9 +23,9 @@
#include <boost/filesystem/exception.hpp>
#include <boost/config.hpp>
# if defined( BOOST_NO_STD_WSTRING )
# error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
# endif
#if defined(BOOST_NO_STD_WSTRING)
#error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
#endif
#include <boost/core/lightweight_test.hpp>
#include <boost/detail/lightweight_main.hpp>
@ -37,32 +37,34 @@ namespace fs = boost::filesystem;
using fs::path;
namespace sys = boost::system;
namespace
namespace {
template< typename F >
bool throws_fs_error(F func)
{
template< typename F >
bool throws_fs_error(F func)
try
{
try { func(); }
func();
}
catch (const fs::filesystem_error &)
catch (const fs::filesystem_error&)
{
return true;
}
return false;
}
void create_recursive_iterator(const fs::path & ph)
{
fs::recursive_directory_iterator it(ph);
}
}
void create_recursive_iterator(const fs::path& ph)
{
fs::recursive_directory_iterator it(ph);
}
} // namespace
// ------------------------------------------------------------------------------------//
int cpp_main(int, char*[])
{
// create_directories() tests --------------------------------------------------------//
// create_directories() tests --------------------------------------------------------//
BOOST_TEST(!fs::create_directories("/")); // should be harmless
@ -96,7 +98,7 @@ int cpp_main(int, char*[])
BOOST_TEST(throws_fs_error(
boost::bind(fs::create_directories, is_a_file / "aa")));
// recursive_directory_iterator tests ----------------------------------------//
// recursive_directory_iterator tests ----------------------------------------//
sys::error_code ec;
fs::recursive_directory_iterator it("/no-such-path", ec);
@ -117,7 +119,9 @@ int cpp_main(int, char*[])
for (it = fs::recursive_directory_iterator(unique_dir);
it != fs::recursive_directory_iterator(); ++it)
{ std::cout << it->path() << '\n'; }
{
std::cout << it->path() << '\n';
}
it = fs::recursive_directory_iterator(unique_dir);
BOOST_TEST(it->path() == unique_yy);
@ -169,8 +173,7 @@ int cpp_main(int, char*[])
ec.clear();
BOOST_TEST(!ec);
// check that two argument failed constructor creates the end iterator
BOOST_TEST(fs::recursive_directory_iterator("nosuchdir", ec)
== fs::recursive_directory_iterator());
BOOST_TEST(fs::recursive_directory_iterator("nosuchdir", ec) == fs::recursive_directory_iterator());
BOOST_TEST(ec);
fs::remove_all(unique_dir); // clean up behind ourselves

View File

@ -25,11 +25,10 @@
// on Windows, except for standard libaries known to have wchar_t overloads for
// file stream I/O, use path::string() to get a narrow character c_str()
#if defined(BOOST_WINDOWS_API) \
&& (!defined(_CPPLIB_VER) || _CPPLIB_VER < 405) // not Dinkumware || no wide overloads
# define BOOST_FILESYSTEM_C_STR string().c_str() // use narrow, since wide not available
#if defined(BOOST_WINDOWS_API) && (!defined(_CPPLIB_VER) || _CPPLIB_VER < 405) // not Dinkumware || no wide overloads
#define BOOST_FILESYSTEM_C_STR string().c_str() // use narrow, since wide not available
#else // use the native c_str, which will be narrow on POSIX, wide on Windows
# define BOOST_FILESYSTEM_C_STR c_str()
#define BOOST_FILESYSTEM_C_STR c_str()
#endif
namespace fs = boost::filesystem;
@ -88,7 +87,9 @@ directory_tree collect_directory_tree(fs::path const& root_dir)
std::cout << "Collecting directory tree in: " << root_dir << '\n';
directory_tree tree;
fs::recursive_directory_iterator it(root_dir, fs::directory_options::skip_permission_denied | fs::directory_options::follow_directory_symlink | fs::directory_options::skip_dangling_symlinks), end;
fs::recursive_directory_iterator it(root_dir, fs::directory_options::skip_permission_denied |
fs::directory_options::follow_directory_symlink | fs::directory_options::skip_dangling_symlinks);
fs::recursive_directory_iterator end;
while (it != end)
{
fs::path p = fs::relative(it->path(), root_dir);
@ -312,17 +313,18 @@ int main()
{
fs::create_symlink("f1", root_dir / "s1");
symlinks_supported = true;
std::cout <<
" *** For information only ***\n"
" create_symlink() attempt succeeded" << std::endl;
std::cout << " *** For information only ***\n"
" create_symlink() attempt succeeded"
<< std::endl;
}
catch (fs::filesystem_error& e)
{
std::cout <<
" *** For information only ***\n"
std::cout << " *** For information only ***\n"
" create_symlink() attempt failed\n"
" filesystem_error.what() reports: " << e.what() << "\n"
" create_symlink() may not be supported on this operating system or file system" << std::endl;
" filesystem_error.what() reports: "
<< e.what() << "\n"
" create_symlink() may not be supported on this operating system or file system"
<< std::endl;
}
if (symlinks_supported)

View File

@ -16,9 +16,9 @@
#include <boost/filesystem.hpp>
#include <boost/config.hpp>
# if defined( BOOST_NO_STD_WSTRING )
# error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
# endif
#if defined(BOOST_NO_STD_WSTRING)
#error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
#endif
#include <boost/core/lightweight_test.hpp>
#include <boost/detail/lightweight_main.hpp>
@ -28,24 +28,23 @@ using boost::filesystem::path;
#define PATH_CHECK(a, b) check(a, b, __LINE__)
namespace
{
std::string platform(BOOST_PLATFORM);
namespace {
std::string platform(BOOST_PLATFORM);
void check(const fs::path & source,
const std::string & expected, int line)
{
if (source.generic_string()== expected) return;
void check(const fs::path& source, const std::string& expected, int line)
{
if (source.generic_string() == expected)
return;
++::boost::detail::test_errors();
std::cout << '(' << line << ") source.string(): \"" << source.string()
<< "\" != expected: \"" << expected
<< "\"" << std::endl;
}
}
void normalize_test()
{
void normalize_test()
{
PATH_CHECK(path("").normalize(), "");
PATH_CHECK(path("/").normalize(), "/");
PATH_CHECK(path("//").normalize(), "//");
@ -63,14 +62,14 @@ namespace
PATH_CHECK(path("../foo").normalize(), "../foo");
PATH_CHECK(path("foo/..").normalize(), ".");
PATH_CHECK(path("foo/../").normalize(), "./.");
PATH_CHECK((path("foo") / "..").normalize() , ".");
PATH_CHECK((path("foo") / "..").normalize(), ".");
PATH_CHECK(path("foo/...").normalize(), "foo/...");
PATH_CHECK(path("foo/.../").normalize(), "foo/.../.");
PATH_CHECK(path("foo/..bar").normalize(), "foo/..bar");
PATH_CHECK(path("../f").normalize(), "../f");
PATH_CHECK(path("/../f").normalize(), "/../f");
PATH_CHECK(path("f/..").normalize(), ".");
PATH_CHECK((path("f") / "..").normalize() , ".");
PATH_CHECK((path("f") / "..").normalize(), ".");
PATH_CHECK(path("foo/../..").normalize(), "..");
PATH_CHECK(path("foo/../../").normalize(), "../.");
PATH_CHECK(path("foo/../../..").normalize(), "../..");
@ -148,25 +147,25 @@ namespace
PATH_CHECK(path("c:/../../foo/").normalize(), "../foo/.");
PATH_CHECK(path("c:/..foo").normalize(), "c:/..foo");
}
}
}
// misc_test ------------------------------------------------------------------------//
// misc_test ------------------------------------------------------------------------//
void misc_test()
{
void misc_test()
{
fs::path p;
fs::initial_path<fs::path>();
fs::initial_path<fs::wpath>();
fs::initial_path< fs::path >();
fs::initial_path< fs::wpath >();
p.file_string();
p.directory_string();
}
}
// path_rename_test -----------------------------------------------------------------//
// path_rename_test -----------------------------------------------------------------//
void path_rename_test()
{
void path_rename_test()
{
fs::path p("foo/bar/blah");
BOOST_TEST_EQ(path("foo/bar/blah").remove_leaf(), "foo/bar");
@ -182,11 +181,10 @@ namespace
p = "foo\\bar\\blah";
BOOST_TEST_EQ(p.branch_path(), "foo\\bar");
}
}
}
} // unnamed namespace
//--------------------------------------------------------------------------------------//
int cpp_main(int /*argc*/, char* /*argv*/[])
@ -194,9 +192,7 @@ int cpp_main(int /*argc*/, char* /*argv*/[])
// The choice of platform is make at runtime rather than compile-time
// so that compile errors for all platforms will be detected even though
// only the current platform is runtime tested.
platform = (platform == "Win32" || platform == "Win64" || platform == "Cygwin")
? "Windows"
: "POSIX";
platform = (platform == "Win32" || platform == "Win64" || platform == "Cygwin") ? "Windows" : "POSIX";
std::cout << "Platform is " << platform << '\n';
BOOST_TEST(fs::initial_path() == fs::current_path());
@ -219,7 +215,7 @@ int cpp_main(int /*argc*/, char* /*argv*/[])
normalize_test();
BOOST_TEST(fs::path("foo/bar").generic() == fs::path("foo/bar"));
// extension() tests ---------------------------------------------------------//
// extension() tests ---------------------------------------------------------//
BOOST_TEST(fs::extension("a/b") == "");
BOOST_TEST(fs::extension("a/b.txt") == ".txt");
@ -229,7 +225,7 @@ int cpp_main(int /*argc*/, char* /*argv*/[])
BOOST_TEST(fs::extension("") == "");
BOOST_TEST(fs::extension("a/") == "");
// basename() tests ----------------------------------------------------------//
// basename() tests ----------------------------------------------------------//
BOOST_TEST(fs::basename("b") == "b");
BOOST_TEST(fs::basename("a/b.txt") == "b");
@ -238,7 +234,7 @@ int cpp_main(int /*argc*/, char* /*argv*/[])
BOOST_TEST(fs::basename("a.b.c.") == "a.b.c");
BOOST_TEST(fs::basename("") == "");
// change_extension tests ---------------------------------------------------//
// change_extension tests ---------------------------------------------------//
BOOST_TEST(fs::change_extension("a.txt", ".tex").string() == "a.tex");
BOOST_TEST(fs::change_extension("a.", ".tex").string() == "a.tex");

View File

@ -6,21 +6,21 @@
class path
{
public:
path( const char * )
path(const char*)
{
std::cout << "path( const char * )\n";
}
path( const std::string & )
path(const std::string&)
{
std::cout << "path( std::string & )\n";
}
// for maximum efficiency, either signature must work
# ifdef BY_VALUE
#ifdef BY_VALUE
operator const std::string() const
# else
#else
operator const std::string&() const
# endif
#endif
{
std::cout << "operator string\n";
return m_path;
@ -38,7 +38,7 @@ private:
std::string m_path;
};
bool operator==( const path &, const path & )
bool operator==(const path&, const path&)
{
std::cout << "operator==( const path &, const path & )\n";
return true;
@ -47,35 +47,35 @@ bool operator==( const path &, const path & )
// These are the critical use cases. If any of these don't compile, usability
// is unacceptably degraded.
void f( const path & )
void f(const path&)
{
std::cout << "f( const path & )\n";
}
int main()
{
f( "foo" );
f( std::string( "foo" ) );
f( path( "foo" ) );
f("foo");
f(std::string("foo"));
f(path("foo"));
std::cout << '\n';
std::string s1( path( "foo" ) );
std::string s2 = path( "foo" );
s2 = path( "foo" );
std::string s1(path("foo"));
std::string s2 = path("foo");
s2 = path("foo");
#ifdef NAMED_CONVERSION
s2 = path( "foo" ).string();
s2 = path("foo").string();
#endif
std::cout << '\n';
// these must call bool path( const path &, const path & );
path( "foo" ) == path( "foo" );
path( "foo" ) == "foo";
path( "foo" ) == std::string( "foo" );
"foo" == path( "foo" );
std::string( "foo" ) == path( "foo" );
path("foo") == path("foo");
path("foo") == "foo";
path("foo") == std::string("foo");
"foo" == path("foo");
std::string("foo") == path("foo");
return 0;
}

View File

@ -14,10 +14,10 @@
#include <iostream>
#include <exception>
int main( int argc, char * argv[] )
int main(int argc, char* argv[])
{
boost::filesystem::path::default_name_check( boost::filesystem::native );
if ( argc != 3 )
boost::filesystem::path::default_name_check(boost::filesystem::native);
if (argc != 3)
{
std::cout << "Usage: equivalent path1 path2\n";
return 2;
@ -26,9 +26,9 @@ int main( int argc, char * argv[] )
bool eq;
try
{
eq = boost::filesystem::equivalent( argv[1], argv[2] );
eq = boost::filesystem::equivalent(argv[1], argv[2]);
}
catch ( const std::exception & ex )
catch (const std::exception& ex)
{
std::cout << ex.what() << "\n";
return 3;

View File

@ -19,7 +19,7 @@ int main()
{
fs::directory_iterator const it;
BOOST_FOREACH( fs::path const& p, it )
BOOST_FOREACH(fs::path const& p, it)
{
p.string();
}
@ -30,7 +30,7 @@ int main()
{
fs::directory_iterator const it;
for( fs::path const& p: it )
for (fs::path const& p : it)
{
p.string();
}
@ -41,7 +41,7 @@ int main()
{
fs::recursive_directory_iterator it;
BOOST_FOREACH( fs::path const& p, it )
BOOST_FOREACH(fs::path const& p, it)
{
p.string();
}
@ -52,7 +52,7 @@ int main()
{
fs::recursive_directory_iterator const it;
for( fs::path const& p: it )
for (fs::path const& p : it)
{
p.string();
}

View File

@ -11,18 +11,18 @@
// See deprecated_test for tests of deprecated features
#ifndef BOOST_FILESYSTEM_NO_DEPRECATED
# define BOOST_FILESYSTEM_NO_DEPRECATED
#define BOOST_FILESYSTEM_NO_DEPRECATED
#endif
#ifndef BOOST_SYSTEM_NO_DEPRECATED
# define BOOST_SYSTEM_NO_DEPRECATED
#define BOOST_SYSTEM_NO_DEPRECATED
#endif
#include <boost/filesystem/fstream.hpp>
#include <boost/config.hpp>
# if defined( BOOST_NO_STD_WSTRING )
# error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
# endif
#if defined(BOOST_NO_STD_WSTRING)
#error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
#endif
#include <boost/filesystem/operations.hpp>
#include <string>
@ -35,18 +35,19 @@ namespace fs = boost::filesystem;
#include <boost/config.hpp>
#ifdef BOOST_NO_STDC_NAMESPACE
namespace std { using ::remove; }
namespace std {
using ::remove;
}
#endif
#include <boost/core/lightweight_test.hpp>
#include <boost/detail/lightweight_main.hpp>
namespace
{
bool cleanup = true;
namespace {
bool cleanup = true;
void test(const fs::path & p)
{
void test(const fs::path& p)
{
fs::remove(p);
{
std::cout << " in test 1\n";
@ -116,7 +117,7 @@ namespace
}
{
std::cout << " in test 13\n";
fs::fstream tfs(p, std::ios_base::in|std::ios_base::out);
fs::fstream tfs(p, std::ios_base::in | std::ios_base::out);
BOOST_TEST(tfs.is_open());
}
{
@ -128,19 +129,20 @@ namespace
{
std::cout << " in test 15\n";
fs::fstream tfs;
tfs.open(p, std::ios_base::in|std::ios_base::out);
tfs.open(p, std::ios_base::in | std::ios_base::out);
BOOST_TEST(tfs.is_open());
}
if (cleanup)
fs::remove(p);
} // test
} // test
} // unnamed namespace
int cpp_main(int argc, char*[])
{
if (argc > 1) cleanup = false;
if (argc > 1)
cleanup = false;
std::cout << "BOOST_FILESYSTEM_C_STR defined as \""
<< BOOST_STRINGIZE(BOOST_FILESYSTEM_C_STR) << "\"\n";
@ -149,7 +151,6 @@ int cpp_main(int argc, char*[])
std::cout << "narrow character tests:\n";
test("narrow_fstream_test");
// So that tests are run with known encoding, use Boost UTF-8 codecvt
std::locale global_loc = std::locale();
std::locale loc(global_loc, new fs::detail::utf8_codecvt_facet);

View File

@ -5,4 +5,3 @@ int main(void)
boost::filesystem::copy_file("a", "b");
return 0;
}

View File

@ -11,10 +11,12 @@ int main(int argc, char** argv)
cout << "current path is " << my_path << endl;
cout << "parent path is " << my_path.parent_path() << endl;
}
catch(std::exception& e) {
cerr << endl << "Error during execution: " << e.what() << endl << endl;
catch (std::exception& e)
{
cerr << endl
<< "Error during execution: " << e.what() << endl
<< endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}

View File

@ -8,7 +8,7 @@ boost::mutex mut;
#define FNAME ("remove-test")
void remover()
{
while(1)
while (1)
{
boost::filesystem::remove(FNAME);
}
@ -16,7 +16,8 @@ void remover()
void creater()
{
for(int i=0; i<100000; i++) std::fstream(FNAME, std::fstream::out);
for (int i = 0; i < 100000; i++)
std::fstream(FNAME, std::fstream::out);
}
int main()
@ -24,15 +25,16 @@ int main()
boost::filesystem::remove(FNAME);
boost::filesystem::remove(FNAME);
std::cout <<
"If you got this far, it's OK to remove a file that doesn't exist\n"
std::cout << "If you got this far, it's OK to remove a file that doesn't exist\n"
"Now trying with one creator thread and two remover threads.\n"
"This is likely to crash after just a few seconds at most." <<
std::endl;
"This is likely to crash after just a few seconds at most."
<< std::endl;
boost::thread c(creater), r1(remover), r2(remover);
c.join();
r1.interrupt(); r1.join();
r2.interrupt(); r2.join();
r1.interrupt();
r1.join();
r2.interrupt();
r2.join();
}

View File

@ -8,18 +8,17 @@
namespace fs = boost::filesystem;
using namespace boost::adaptors;
int main() {
int main()
{
fs::recursive_directory_iterator beg("."), end;
auto fileFilter = [](fs::path const & path)
{
auto fileFilter = [](fs::path const& path) {
return is_regular_file(path);
};
std::vector<fs::path> paths;
copy(boost::make_iterator_range(beg, end) | filtered(fileFilter),
std::back_inserter(paths));
std::vector< fs::path > paths;
copy(boost::make_iterator_range(beg, end) | filtered(fileFilter), std::back_inserter(paths));
for(auto& p : paths)
for (auto& p : paths)
std::cout << p << "\n";
}

View File

@ -6,20 +6,20 @@
namespace fs = boost::filesystem;
int main(void) {
int main(void)
{
std::locale global_loc = std::locale();
std::locale loc(global_loc, new stdext::cvt::codecvt_cp950<wchar_t>);
std::locale loc(global_loc, new stdext::cvt::codecvt_cp950< wchar_t >);
fs::path::imbue(loc);
std::cout <<
"HEADS UP! PIPE OUTPUT TO FILE AND INSPECT WITH HEX OR CP950 EDITOR.\n"
std::cout << "HEADS UP! PIPE OUTPUT TO FILE AND INSPECT WITH HEX OR CP950 EDITOR.\n"
"WINDOWS COMMAND PROMPT FONTS DON'T SUPPORT CHINESE,\n"
"EVEN WITH CODEPAGE SET AND EVEN AS OF WIN 10 TECH PREVIEW." << std::endl;
"EVEN WITH CODEPAGE SET AND EVEN AS OF WIN 10 TECH PREVIEW."
<< std::endl;
fs::recursive_directory_iterator end;
fs::recursive_directory_iterator iter
("C:/boost/test-files/utf-8");
fs::recursive_directory_iterator iter("C:/boost/test-files/utf-8");
while (iter != end)
{

View File

@ -16,5 +16,3 @@ int main()
std::cout << path("a/b/c/d/e/").stem() << std::endl;
return 0;
}

View File

@ -30,7 +30,7 @@ public:
Test test1;
Test test2;
int cpp_main(int, char* [])
int cpp_main(int, char*[])
{
return 0;
}

View File

@ -15,6 +15,6 @@ namespace fs = boost::filesystem;
int main()
{
BOOST_TEST_THROWS( fs::copy( "/tmp/non-existent-a", "/tmp/non-existent-b" ), std::exception );
BOOST_TEST_THROWS(fs::copy("/tmp/non-existent-a", "/tmp/non-existent-b"), std::exception);
return boost::report_errors();
}

View File

@ -1,7 +1,7 @@
// Before running this test: export LANG=foo
#include <boost/filesystem.hpp>
int main() {
int main()
{
boost::filesystem::path("/abc").root_directory();
}

View File

@ -1,10 +1,9 @@
#include "boost/filesystem.hpp"
static const boost::filesystem::path::codecvt_type &dummy =
static const boost::filesystem::path::codecvt_type& dummy =
boost::filesystem::path::codecvt();
int main()
{
return 0;
}

View File

@ -34,7 +34,7 @@ int cpp_main(int argc, char* argv[])
cout << "Hello, 9219" << endl;
cout << "This is a test for non-Windows systems" << endl;
BOOST_TEST(fs::exists(const_cast<char*>(".")));
BOOST_TEST(fs::exists(const_cast< char* >(".")));
return ::boost::report_errors();
} // cpp_main

View File

@ -22,7 +22,8 @@ namespace fs = boost::filesystem;
struct TmpDir
{
fs::path path;
TmpDir(const fs::path& base): path(fs::absolute(base) / fs::unique_path())
TmpDir(const fs::path& base) :
path(fs::absolute(base) / fs::unique_path())
{
fs::create_directories(path);
}
@ -49,13 +50,13 @@ int main()
BOOST_TEST(fs::exists(junction));
// Due to a bug there was a dependency on the current path so try the below for all:
std::vector<fs::path> paths;
std::vector< fs::path > paths;
paths.push_back(cwd);
paths.push_back(junction);
paths.push_back(real);
paths.push_back(junction / subDir);
paths.push_back(real / subDir);
for (std::vector<fs::path>::iterator it = paths.begin(); it != paths.end(); ++it)
for (std::vector< fs::path >::iterator it = paths.begin(); it != paths.end(); ++it)
{
std::cout << "Testing in " << *it << std::endl;
fs::current_path(*it);
@ -82,4 +83,3 @@ int main()
}
#endif // defined(BOOST_FILESYSTEM_HAS_MKLINK)

View File

@ -9,6 +9,6 @@ void myFunc()
copy_options opt(copy_options::overwrite_existing);
copy_file(path("p1"),path("p2"),copy_options::overwrite_existing);
// copy_file(path("p1"),path("p2"),opt);
copy_file(path("p1"), path("p2"), copy_options::overwrite_existing);
// copy_file(path("p1"),path("p2"),opt);
}

View File

@ -19,12 +19,15 @@
#include <cerrno>
#ifdef NDEBUG
# error This program depends on assert() so makes no sense if NDEBUG is defined
#error This program depends on assert() so makes no sense if NDEBUG is defined
#endif
int main(int argc, char *argv[])
int main(int argc, char* argv[])
{
{ std::ofstream file("out"); file << "contents"; }
{
std::ofstream file("out");
file << "contents";
}
assert(!::symlink("out", "sym"));

View File

@ -11,18 +11,18 @@
// See deprecated_test for tests of deprecated features
#ifndef BOOST_FILESYSTEM_NO_DEPRECATED
# define BOOST_FILESYSTEM_NO_DEPRECATED
#define BOOST_FILESYSTEM_NO_DEPRECATED
#endif
#ifndef BOOST_SYSTEM_NO_DEPRECATED
# define BOOST_SYSTEM_NO_DEPRECATED
#define BOOST_SYSTEM_NO_DEPRECATED
#endif
#include <boost/filesystem/operations.hpp>
#include <boost/config.hpp>
# if defined( BOOST_NO_STD_WSTRING )
# error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
# endif
#if defined(BOOST_NO_STD_WSTRING)
#error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
#endif
#include <boost/cerrno.hpp>
#include <boost/core/lightweight_test.hpp>
@ -39,16 +39,15 @@ using std::cout;
using std::endl;
#ifdef BOOST_WINDOWS_API
# include <windows.h>
#include <windows.h>
#endif
namespace
{
typedef int errno_t;
std::string platform(BOOST_PLATFORM);
bool report_throws = false;
bool cleanup = true;
bool skip_long_windows_tests = false;
unsigned short language_id; // 0 except for Windows
namespace {
typedef int errno_t;
std::string platform(BOOST_PLATFORM);
bool report_throws = false;
bool cleanup = true;
bool skip_long_windows_tests = false;
unsigned short language_id; // 0 except for Windows
} // unnamed namespace
@ -81,18 +80,18 @@ int cpp_main(int argc, char* argv[])
// The choice of platform to test is made at runtime rather than compile-time
// so that compile errors for all platforms will be detected even though
// only the current platform is runtime tested.
# if defined(BOOST_POSIX_API)
#if defined(BOOST_POSIX_API)
platform = "POSIX";
# elif defined(BOOST_WINDOWS_API)
#elif defined(BOOST_WINDOWS_API)
platform = "Windows";
# if !defined(__MINGW32__) && !defined(__CYGWIN__)
#if !defined(__MINGW32__) && !defined(__CYGWIN__)
language_id = ::GetUserDefaultUILanguage();
# else
#else
language_id = 0x0409; // Assume US English
# endif
# else
# error neither BOOST_POSIX_API nor BOOST_WINDOWS_API is defined. See boost/system/api_config.hpp
# endif
#endif
#else
#error neither BOOST_POSIX_API nor BOOST_WINDOWS_API is defined. See boost/system/api_config.hpp
#endif
cout << "API is " << platform << endl;
cout << "initial_path() is " << fs::initial_path() << endl;
fs::path ip = fs::initial_path();

View File

@ -16,23 +16,26 @@
#include <cstddef>
# include <windows.h>
# include <winnt.h>
#include <windows.h>
#include <winnt.h>
#ifdef _MSC_VER
# pragma comment(lib, "Advapi32.lib")
#pragma comment(lib, "Advapi32.lib")
#endif
// Test correct boost::filesystem::status when reparse point ReparseTag set to IO_REPARSE_TAG_FILE_PLACEHOLDER
// https://docs.microsoft.com/en-us/windows/compatibility/placeholder-files?redirectedfrom=MSDN
#if !defined(__MINGW32__) || defined(__MINGW64__)
typedef struct _REPARSE_DATA_BUFFER {
typedef struct _REPARSE_DATA_BUFFER
{
ULONG ReparseTag;
USHORT ReparseDataLength;
USHORT Reserved;
union {
struct {
union
{
struct
{
USHORT SubstituteNameOffset;
USHORT SubstituteNameLength;
USHORT PrintNameOffset;
@ -40,14 +43,16 @@ typedef struct _REPARSE_DATA_BUFFER {
ULONG Flags;
WCHAR PathBuffer[1];
} SymbolicLinkReparseBuffer;
struct {
struct
{
USHORT SubstituteNameOffset;
USHORT SubstituteNameLength;
USHORT PrintNameOffset;
USHORT PrintNameLength;
WCHAR PathBuffer[1];
} MountPointReparseBuffer;
struct {
struct
{
UCHAR DataBuffer[1];
} GenericReparseBuffer;
};
@ -55,15 +60,15 @@ typedef struct _REPARSE_DATA_BUFFER {
#endif
#ifndef IO_REPARSE_TAG_FILE_PLACEHOLDER
# define IO_REPARSE_TAG_FILE_PLACEHOLDER (0x80000015L)
#define IO_REPARSE_TAG_FILE_PLACEHOLDER (0x80000015L)
#endif
#ifndef FSCTL_SET_REPARSE_POINT
# define FSCTL_SET_REPARSE_POINT (0x000900a4)
#define FSCTL_SET_REPARSE_POINT (0x000900a4)
#endif
#ifndef REPARSE_DATA_BUFFER_HEADER_SIZE
# define REPARSE_DATA_BUFFER_HEADER_SIZE FIELD_OFFSET(REPARSE_DATA_BUFFER, GenericReparseBuffer)
#define REPARSE_DATA_BUFFER_HEADER_SIZE FIELD_OFFSET(REPARSE_DATA_BUFFER, GenericReparseBuffer)
#endif
bool obtain_restore_privilege()
@ -104,9 +109,7 @@ bool create_io_reparse_file_placeholder(const wchar_t* name)
return false;
}
HANDLE hHandle = CreateFileW(name, GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS,
FILE_FLAG_OPEN_REPARSE_POINT, 0);
HANDLE hHandle = CreateFileW(name, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_FLAG_OPEN_REPARSE_POINT, 0);
if (hHandle == INVALID_HANDLE_VALUE)
{
@ -114,14 +117,12 @@ bool create_io_reparse_file_placeholder(const wchar_t* name)
return false;
}
PREPARSE_DATA_BUFFER pReparse = reinterpret_cast<PREPARSE_DATA_BUFFER>(GlobalAlloc(GPTR, MAXIMUM_REPARSE_DATA_BUFFER_SIZE));
PREPARSE_DATA_BUFFER pReparse = reinterpret_cast< PREPARSE_DATA_BUFFER >(GlobalAlloc(GPTR, MAXIMUM_REPARSE_DATA_BUFFER_SIZE));
//note: IO_REPARSE_TAG_FILE_PLACEHOLDER - just to show that reparse point could be not only symlink or junction
pReparse->ReparseTag = IO_REPARSE_TAG_FILE_PLACEHOLDER;
DWORD dwLen;
bool ret = DeviceIoControl(hHandle, FSCTL_SET_REPARSE_POINT, pReparse,
pReparse->ReparseDataLength + REPARSE_DATA_BUFFER_HEADER_SIZE,
NULL, 0, &dwLen, NULL) != 0;
bool ret = DeviceIoControl(hHandle, FSCTL_SET_REPARSE_POINT, pReparse, pReparse->ReparseDataLength + REPARSE_DATA_BUFFER_HEADER_SIZE, NULL, 0, &dwLen, NULL) != 0;
if (!ret)
{

View File

@ -14,9 +14,9 @@
#include <boost/filesystem/operations.hpp>
#include <boost/config.hpp>
# if defined( BOOST_NO_STD_WSTRING )
# error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
# endif
#if defined(BOOST_NO_STD_WSTRING)
#error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
#endif
namespace fs = boost::filesystem;
@ -24,7 +24,7 @@ namespace fs = boost::filesystem;
int main()
{
if ( fs::detail::possible_large_file_size_support() )
if (fs::detail::possible_large_file_size_support())
{
std::cout << "It appears that file sizes greater that 2 gigabytes are possible\n"
"for this configuration on this platform since the operating system\n"

View File

@ -12,23 +12,20 @@
using namespace std;
#ifdef _MSC_VER
# pragma warning(push)
# pragma warning(disable: 4996) // ... Function call with parameters that may be unsafe
#pragma warning(push)
#pragma warning(disable : 4996) // ... Function call with parameters that may be unsafe
#endif
namespace
namespace {
void facet_info(const locale& loc, const char* msg)
{
void facet_info(const locale& loc, const char* msg)
{
cout << "has_facet<std::codecvt<wchar_t, char, std::mbstate_t> >("
<< msg << ") is "
<< (has_facet<std::codecvt<wchar_t, char, std::mbstate_t> >(loc)
? "true\n"
: "false\n");
}
<< (has_facet< std::codecvt< wchar_t, char, std::mbstate_t > >(loc) ? "true\n" : "false\n");
}
void default_info()
{
void default_info()
{
try
{
locale loc;
@ -39,10 +36,10 @@ namespace
{
cout << "\nlocale default construction threw: " << ex.what() << endl;
}
}
}
void null_string_info()
{
void null_string_info()
{
try
{
locale loc("");
@ -53,10 +50,10 @@ namespace
{
cout << "\nlocale(\"\") construction threw: " << ex.what() << endl;
}
}
}
void classic_info()
{
void classic_info()
{
try
{
locale loc(locale::classic());
@ -67,8 +64,8 @@ namespace
{
cout << "\nlocale(locale::clasic()) copy construction threw: " << ex.what() << endl;
}
}
}
} // namespace
int main()
{
@ -84,5 +81,5 @@ int main()
}
#ifdef _MSC_VER
# pragma warning(pop)
#pragma warning(pop)
#endif

View File

@ -20,8 +20,7 @@ using namespace boost::filesystem;
#include <boost/core/lightweight_test.hpp>
#include <boost/detail/lightweight_main.hpp>
namespace
{
namespace {
} // unnamed namespace
int cpp_main(int, char*[])
@ -30,8 +29,7 @@ int cpp_main(int, char*[])
std::string prefix("d:\\temp\\");
std::cout << "prefix is " << prefix << '\n';
const std::size_t safe_size
= 260 - prefix.size() - 100; // Windows MAX_PATH is 260
const std::size_t safe_size = 260 - prefix.size() - 100; // Windows MAX_PATH is 260
std::string safe_x_string(safe_size, 'x');
std::string safe_y_string(safe_size, 'y');

View File

@ -15,19 +15,18 @@
#undef BOOST_SYSTEM_STATIC_LINK
#ifndef BOOST_ALL_NO_LIB
# define BOOST_ALL_NO_LIB
#define BOOST_ALL_NO_LIB
#endif
#include <boost/filesystem/config.hpp>
#include <boost/system/config.hpp>
#ifndef BOOST_FILESYSTEM_STATIC_LINK
# error BOOST_FILESYSTEM_STATIC_LINK not set by default
#error BOOST_FILESYSTEM_STATIC_LINK not set by default
#endif
#ifndef BOOST_SYSTEM_STATIC_LINK
# error BOOST_SYSTEM_STATIC_LINK not set by default
#error BOOST_SYSTEM_STATIC_LINK not set by default
#endif
int main()

View File

@ -9,13 +9,11 @@
#include <boost/filesystem.hpp>
namespace boost
{
namespace filesystem
{
void tu2();
}
namespace boost {
namespace filesystem {
void tu2();
}
} // namespace boost
int main()
{

View File

@ -9,10 +9,12 @@
#include <boost/filesystem.hpp>
namespace boost
namespace boost {
namespace filesystem {
void tu2()
{
namespace filesystem
{
void tu2() {}
}
}
} // namespace filesystem
} // namespace boost

File diff suppressed because it is too large Load Diff

View File

@ -13,23 +13,22 @@
// ------------------------------------------------------------------------------------//
#include <boost/config/warning_disable.hpp>
// See deprecated_test for tests of deprecated features
#ifndef BOOST_FILESYSTEM_NO_DEPRECATED
# define BOOST_FILESYSTEM_NO_DEPRECATED
#define BOOST_FILESYSTEM_NO_DEPRECATED
#endif
#ifndef BOOST_SYSTEM_NO_DEPRECATED
# define BOOST_SYSTEM_NO_DEPRECATED
#define BOOST_SYSTEM_NO_DEPRECATED
#endif
#include <boost/filesystem.hpp> // make sure filesystem.hpp works
#include <boost/config.hpp>
# if defined( BOOST_NO_STD_WSTRING )
# error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
# endif
#if defined(BOOST_NO_STD_WSTRING)
#error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
#endif
#include <boost/system/error_code.hpp>
#include <boost/core/lightweight_test.hpp>
@ -44,23 +43,23 @@ using std::string;
#define CHECK(x) check(x, __FILE__, __LINE__)
namespace
{
bool cleanup = true;
namespace {
bool cleanup = true;
void check(bool ok, const char* file, int line)
{
if (ok) return;
void check(bool ok, const char* file, int line)
{
if (ok)
return;
++::boost::detail::test_errors();
cout << file << '(' << line << "): test failed\n";
}
}
// file_status_test ----------------------------------------------------------------//
// file_status_test ----------------------------------------------------------------//
void file_status_test()
{
void file_status_test()
{
cout << "file_status test..." << endl;
file_status s = status(".");
@ -74,17 +73,17 @@ namespace
cout << " symlink_status(\".\") permissions are "
<< std::oct << (v & 0777) << std::dec << endl;
CHECK((v & 0400) == 0400);
}
}
// query_test ----------------------------------------------------------------------//
// query_test ----------------------------------------------------------------------//
void query_test()
{
void query_test()
{
cout << "query test..." << endl;
error_code ec;
CHECK(file_size("no-such-file", ec) == static_cast<boost::uintmax_t>(-1));
CHECK(file_size("no-such-file", ec) == static_cast< boost::uintmax_t >(-1));
CHECK(ec == errc::no_such_file_or_directory);
CHECK(status("no-such-file") == file_status(file_not_found, no_perms));
@ -97,7 +96,7 @@ namespace
if (ec)
{
cout << "exists(\"/\", ec) resulted in non-zero ec.value()" << endl;
cout << "ec value: " << ec.value() << ", message: "<< ec.message() << endl;
cout << "ec value: " << ec.value() << ", message: " << ec.message() << endl;
}
CHECK(!ec);
@ -106,12 +105,12 @@ namespace
CHECK(!is_regular_file("/"));
CHECK(!boost::filesystem::is_empty("/"));
CHECK(!is_other("/"));
}
}
// directory_iterator_test -----------------------------------------------//
// directory_iterator_test -----------------------------------------------//
void directory_iterator_test()
{
void directory_iterator_test()
{
cout << "directory_iterator_test..." << endl;
directory_iterator end;
@ -167,12 +166,12 @@ namespace
}
cout << "directory_iterator_test complete" << endl;
}
}
// recursive_directory_iterator_test -----------------------------------------------//
// recursive_directory_iterator_test -----------------------------------------------//
void recursive_directory_iterator_test()
{
void recursive_directory_iterator_test()
{
cout << "recursive_directory_iterator_test..." << endl;
recursive_directory_iterator end;
@ -229,12 +228,12 @@ namespace
}
cout << "recursive_directory_iterator_test complete" << endl;
}
}
// operations_test -------------------------------------------------------//
// operations_test -------------------------------------------------------//
void operations_test()
{
void operations_test()
{
cout << "operations test..." << endl;
error_code ec;
@ -254,16 +253,15 @@ namespace
std::time_t ft = last_write_time(".");
ft = -1;
last_write_time(".", ft, ec);
}
}
// directory_entry_test ------------------------------------------------------------//
// directory_entry_test ------------------------------------------------------------//
void directory_entry_test()
{
void directory_entry_test()
{
cout << "directory_entry test..." << endl;
directory_entry de("foo.bar",
file_status(regular_file, owner_all), file_status(directory_file, group_all));
directory_entry de("foo.bar", file_status(regular_file, owner_all), file_status(directory_file, group_all));
CHECK(de.path() == "foo.bar");
CHECK(de.status() == file_status(regular_file, owner_all));
@ -273,22 +271,22 @@ namespace
CHECK(de != directory_entry("goo.bar"));
de.replace_filename("bar.foo");
CHECK(de.path() == "bar.foo");
}
}
// directory_entry_overload_test ---------------------------------------------------//
// directory_entry_overload_test ---------------------------------------------------//
void directory_entry_overload_test()
{
void directory_entry_overload_test()
{
cout << "directory_entry overload test..." << endl;
directory_iterator it(".");
path p(*it);
}
}
// error_handling_test -------------------------------------------------------------//
// error_handling_test -------------------------------------------------------------//
void error_handling_test()
{
void error_handling_test()
{
cout << "error handling test..." << endl;
bool threw(false);
@ -296,11 +294,12 @@ namespace
{
file_size("no-such-file");
}
catch (const boost::filesystem::filesystem_error & ex)
catch (const boost::filesystem::filesystem_error& ex)
{
threw = true;
cout << "\nas expected, attempt to get size of non-existent file threw a filesystem_error\n"
"what() returns " << ex.what() << "\n";
"what() returns "
<< ex.what() << "\n";
}
catch (...)
{
@ -311,12 +310,12 @@ namespace
error_code ec;
CHECK(!create_directory("/", ec));
}
}
// string_file_tests ---------------------------------------------------------------//
// string_file_tests ---------------------------------------------------------------//
void string_file_tests(const path& temp_dir)
{
void string_file_tests(const path& temp_dir)
{
cout << "string_file_tests..." << endl;
std::string contents("0123456789");
path p(temp_dir / "string_file");
@ -326,7 +325,7 @@ namespace
std::string round_trip;
load_string_file(p, round_trip);
BOOST_TEST_EQ(contents, round_trip);
}
}
} // unnamed namespace
@ -355,7 +354,7 @@ int cpp_main(int argc, char* argv[])
cout << "argv[1] is '" << argv[1] << "', changing current_path() to it" << endl;
error_code ec;
current_path( argv[1], ec );
current_path(argv[1], ec);
if (ec)
{
@ -395,7 +394,7 @@ int cpp_main(int argc, char* argv[])
// above was added just to simplify testing, but it ended up detecting
// a bug (failure to close an internal search handle).
cout << "post-test removal complete" << endl;
// BOOST_TEST(!fs::exists(dir)); // nice test, but doesn't play well with TortoiseGit cache
// BOOST_TEST(!fs::exists(dir)); // nice test, but doesn't play well with TortoiseGit cache
}
return ::boost::report_errors();

View File

@ -43,19 +43,19 @@
// See deprecated_test for tests of deprecated features
#ifndef BOOST_FILESYSTEM_NO_DEPRECATED
# define BOOST_FILESYSTEM_NO_DEPRECATED
#define BOOST_FILESYSTEM_NO_DEPRECATED
#endif
#ifndef BOOST_SYSTEM_NO_DEPRECATED
# define BOOST_SYSTEM_NO_DEPRECATED
#define BOOST_SYSTEM_NO_DEPRECATED
#endif
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/exception.hpp>
#include <boost/config.hpp>
# if defined( BOOST_NO_STD_WSTRING )
# error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
# endif
#if defined(BOOST_NO_STD_WSTRING)
#error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
#endif
#include <boost/utility.hpp>
#include <boost/next_prior.hpp>
@ -74,20 +74,18 @@ using boost::next;
using boost::prior;
#ifdef BOOST_WINDOWS_API
# define BOOST_DIR_SEP "\\"
#define BOOST_DIR_SEP "\\"
#else
# define BOOST_DIR_SEP "/"
#define BOOST_DIR_SEP "/"
#endif
#define PATH_TEST_EQ(a, b) check(a, b, __FILE__, __LINE__)
namespace
{
std::string platform(BOOST_PLATFORM);
namespace {
std::string platform(BOOST_PLATFORM);
void check(const fs::path & source,
const std::string & expected, const char* file, int line)
{
void check(const fs::path& source, const std::string& expected, const char* file, int line)
{
if (source.string() == expected)
return;
@ -97,23 +95,26 @@ namespace
<< "\"" << std::endl;
++::boost::detail::test_errors();
}
}
path p1("fe/fi/fo/fum");
path p2(p1);
path p3;
path p4("foobar");
path p5;
path p1("fe/fi/fo/fum");
path p2(p1);
path p3;
path p4("foobar");
path p5;
// exception_tests -----------------------------------------------------------------//
// exception_tests -----------------------------------------------------------------//
void exception_tests()
{
void exception_tests()
{
std::cout << "exception_tests..." << std::endl;
const std::string str_1("string-1");
boost::system::error_code ec(12345, boost::system::system_category());
try { throw fs::filesystem_error(str_1, ec); }
catch (const fs::filesystem_error & ex)
try
{
throw fs::filesystem_error(str_1, ec);
}
catch (const fs::filesystem_error& ex)
{
//std::cout << ex.what() << "*" << std::endl;
//BOOST_TEST(std::strcmp(ex.what(),
@ -121,8 +122,11 @@ namespace
BOOST_TEST(ex.code() == ec);
}
try { throw fs::filesystem_error(str_1, "p1", "p2", ec); }
catch (const fs::filesystem_error & ex)
try
{
throw fs::filesystem_error(str_1, "p1", "p2", ec);
}
catch (const fs::filesystem_error& ex)
{
//std::cout << ex.what() << "*" << std::endl;
//BOOST_TEST(std::strcmp(ex.what(),
@ -131,15 +135,15 @@ namespace
BOOST_TEST(ex.path1() == "p1");
BOOST_TEST(ex.path2() == "p2");
}
}
}
// overload_tests ------------------------------------------------------------------//
// overload_tests ------------------------------------------------------------------//
// These verify various overloads don't cause compiler errors
// They pre-date operations_unit_test.cpp
// These verify various overloads don't cause compiler errors
// They pre-date operations_unit_test.cpp
void overload_tests()
{
void overload_tests()
{
std::cout << "overload_tests..." << std::endl;
fs::exists(p1);
@ -156,12 +160,12 @@ namespace
p4 /= path("foo");
p4 /= "foo";
p4 /= std::string("foo");
}
}
// iterator_tests ------------------------------------------------------------------//
// iterator_tests ------------------------------------------------------------------//
void iterator_tests()
{
void iterator_tests()
{
std::cout << "iterator_tests..." << std::endl;
path itr_ck = "";
@ -430,12 +434,12 @@ namespace
PATH_TEST_EQ(itr->string(), "/");
BOOST_TEST(++itr == itr_ck.end());
}
}
}
// non_member_tests ----------------------------------------------------------------//
// non_member_tests ----------------------------------------------------------------//
void non_member_tests()
{
void non_member_tests()
{
std::cout << "non_member_tests..." << std::endl;
// test non-member functions, particularly operator overloads
@ -482,22 +486,22 @@ namespace
PATH_TEST_EQ(path("foo") / "bar", "foo\\bar"); // const char* arg
PATH_TEST_EQ(path("foo") / path("woo/bar").filename(), "foo\\bar"); // const std::string & arg
PATH_TEST_EQ("foo" / path("bar"), "foo\\bar");
PATH_TEST_EQ(path("..") / ".." , "..\\..");
PATH_TEST_EQ(path("/") / ".." , "/..");
PATH_TEST_EQ(path("/..") / ".." , "/..\\..");
PATH_TEST_EQ(path("..") / "foo" , "..\\foo");
PATH_TEST_EQ(path("foo") / ".." , "foo\\..");
PATH_TEST_EQ(path("..") / "f" , "..\\f");
PATH_TEST_EQ(path("/..") / "f" , "/..\\f");
PATH_TEST_EQ(path("f") / ".." , "f\\..");
PATH_TEST_EQ(path("foo") / ".." / ".." , "foo\\..\\..");
PATH_TEST_EQ(path("foo") / ".." / ".." / ".." , "foo\\..\\..\\..");
PATH_TEST_EQ(path("f") / ".." / "b" , "f\\..\\b");
PATH_TEST_EQ(path("foo") / ".." / "bar" , "foo\\..\\bar");
PATH_TEST_EQ(path("foo") / "bar" / ".." , "foo\\bar\\..");
PATH_TEST_EQ(path("..") / "..", "..\\..");
PATH_TEST_EQ(path("/") / "..", "/..");
PATH_TEST_EQ(path("/..") / "..", "/..\\..");
PATH_TEST_EQ(path("..") / "foo", "..\\foo");
PATH_TEST_EQ(path("foo") / "..", "foo\\..");
PATH_TEST_EQ(path("..") / "f", "..\\f");
PATH_TEST_EQ(path("/..") / "f", "/..\\f");
PATH_TEST_EQ(path("f") / "..", "f\\..");
PATH_TEST_EQ(path("foo") / ".." / "..", "foo\\..\\..");
PATH_TEST_EQ(path("foo") / ".." / ".." / "..", "foo\\..\\..\\..");
PATH_TEST_EQ(path("f") / ".." / "b", "f\\..\\b");
PATH_TEST_EQ(path("foo") / ".." / "bar", "foo\\..\\bar");
PATH_TEST_EQ(path("foo") / "bar" / "..", "foo\\bar\\..");
PATH_TEST_EQ(path("foo") / "bar" / ".." / "..", "foo\\bar\\..\\..");
PATH_TEST_EQ(path("foo") / "bar" / ".." / "blah", "foo\\bar\\..\\blah");
PATH_TEST_EQ(path("f") / "b" / ".." , "f\\b\\..");
PATH_TEST_EQ(path("f") / "b" / "..", "f\\b\\..");
PATH_TEST_EQ(path("f") / "b" / ".." / "a", "f\\b\\..\\a");
PATH_TEST_EQ(path("foo") / "bar" / "blah" / ".." / "..", "foo\\bar\\blah\\..\\..");
PATH_TEST_EQ(path("foo") / "bar" / "blah" / ".." / ".." / "bletch", "foo\\bar\\blah\\..\\..\\bletch");
@ -530,22 +534,22 @@ namespace
PATH_TEST_EQ(path("foo") / "bar", "foo/bar"); // const char* arg
PATH_TEST_EQ(path("foo") / path("woo/bar").filename(), "foo/bar"); // const std::string & arg
PATH_TEST_EQ("foo" / path("bar"), "foo/bar");
PATH_TEST_EQ(path("..") / ".." , "../..");
PATH_TEST_EQ(path("/") / ".." , "/..");
PATH_TEST_EQ(path("/..") / ".." , "/../..");
PATH_TEST_EQ(path("..") / "foo" , "../foo");
PATH_TEST_EQ(path("foo") / ".." , "foo/..");
PATH_TEST_EQ(path("..") / "f" , "../f");
PATH_TEST_EQ(path("/..") / "f" , "/../f");
PATH_TEST_EQ(path("f") / ".." , "f/..");
PATH_TEST_EQ(path("foo") / ".." / ".." , "foo/../..");
PATH_TEST_EQ(path("foo") / ".." / ".." / ".." , "foo/../../..");
PATH_TEST_EQ(path("f") / ".." / "b" , "f/../b");
PATH_TEST_EQ(path("foo") / ".." / "bar" , "foo/../bar");
PATH_TEST_EQ(path("foo") / "bar" / ".." , "foo/bar/..");
PATH_TEST_EQ(path("..") / "..", "../..");
PATH_TEST_EQ(path("/") / "..", "/..");
PATH_TEST_EQ(path("/..") / "..", "/../..");
PATH_TEST_EQ(path("..") / "foo", "../foo");
PATH_TEST_EQ(path("foo") / "..", "foo/..");
PATH_TEST_EQ(path("..") / "f", "../f");
PATH_TEST_EQ(path("/..") / "f", "/../f");
PATH_TEST_EQ(path("f") / "..", "f/..");
PATH_TEST_EQ(path("foo") / ".." / "..", "foo/../..");
PATH_TEST_EQ(path("foo") / ".." / ".." / "..", "foo/../../..");
PATH_TEST_EQ(path("f") / ".." / "b", "f/../b");
PATH_TEST_EQ(path("foo") / ".." / "bar", "foo/../bar");
PATH_TEST_EQ(path("foo") / "bar" / "..", "foo/bar/..");
PATH_TEST_EQ(path("foo") / "bar" / ".." / "..", "foo/bar/../..");
PATH_TEST_EQ(path("foo") / "bar" / ".." / "blah", "foo/bar/../blah");
PATH_TEST_EQ(path("f") / "b" / ".." , "f/b/..");
PATH_TEST_EQ(path("f") / "b" / "..", "f/b/..");
PATH_TEST_EQ(path("f") / "b" / ".." / "a", "f/b/../a");
PATH_TEST_EQ(path("foo") / "bar" / "blah" / ".." / "..", "foo/bar/blah/../..");
PATH_TEST_EQ(path("foo") / "bar" / "blah" / ".." / ".." / "bletch", "foo/bar/blah/../../bletch");
@ -669,8 +673,8 @@ namespace
if (platform == "Windows")
{
std::cout << " Windows relational tests..." << std::endl;
path p10 ("c:\\file");
path p11 ("c:/file");
path p10("c:\\file");
path p11("c:/file");
// check each overload
BOOST_TEST(p10.generic_string() == p11.generic_string());
BOOST_TEST(p10 == p11);
@ -748,15 +752,15 @@ namespace
<< fs::relative("/abc/xyz/def", "/abc") << std::endl;
BOOST_TEST(fs::relative("abc\\xyz\\def", "abc") == path("xyz/def"));
}
}
}
// query_and_decomposition_tests ---------------------------------------------------//
//
// remove_filename() is also tested here, because its specification depends on
// a decomposition function.
// query_and_decomposition_tests ---------------------------------------------------//
//
// remove_filename() is also tested here, because its specification depends on
// a decomposition function.
void query_and_decomposition_tests()
{
void query_and_decomposition_tests()
{
std::cout << "query_and_decomposition_tests..." << std::endl;
// these are the examples given in reference docs, so check they work
@ -1382,20 +1386,19 @@ namespace
p = path("/usr/local/bin:/usr/bin:/bin");
BOOST_TEST(p.string() == "/usr/local/bin:/usr/bin:/bin");
} // POSIX
}
}
// composition_tests ----------------------------------------------------------------//
// composition_tests ----------------------------------------------------------------//
void composition_tests()
{
void composition_tests()
{
std::cout << "composition_tests..." << std::endl;
}
}
// construction_tests ---------------------------------------------------------------//
// construction_tests ---------------------------------------------------------------//
void construction_tests()
{
void construction_tests()
{
std::cout << "construction_tests..." << std::endl;
PATH_TEST_EQ("", "");
@ -1522,22 +1525,22 @@ namespace
PATH_TEST_EQ("././..", "././..");
PATH_TEST_EQ("./../.", "./../.");
PATH_TEST_EQ(".././.", ".././.");
}
}
// append_tests --------------------------------------------------------------------//
// append_tests --------------------------------------------------------------------//
void append_test_aux(const path & p, const std::string & s, const std::string & expect)
{
void append_test_aux(const path& p, const std::string& s, const std::string& expect)
{
PATH_TEST_EQ((p / path(s)).string(), expect);
PATH_TEST_EQ((p / s.c_str()).string(), expect);
PATH_TEST_EQ((p / s).string(), expect);
path x(p);
x.append(s.begin(), s.end());
PATH_TEST_EQ(x.string(), expect);
}
}
void append_tests()
{
void append_tests()
{
std::cout << "append_tests..." << std::endl;
// There are many control paths to be exercised, since empty paths and arguments,
@ -1605,7 +1608,6 @@ namespace
PATH_TEST_EQ(path("foo/") / "bar", "foo/bar");
append_test_aux("foo/", "bar", "foo/bar");
if (platform == "Windows")
{
PATH_TEST_EQ(path("foo") / "bar", "foo\\bar");
@ -1638,12 +1640,12 @@ namespace
path p6819;
p6819 /= u.a;
BOOST_TEST_EQ(p6819, path("ab"));
}
}
// self_assign_and_append_tests ------------------------------------------------------//
void self_assign_and_append_tests()
{
void self_assign_and_append_tests()
{
std::cout << "self_assign_and_append_tests..." << std::endl;
path p;
@ -1660,7 +1662,7 @@ namespace
PATH_TEST_EQ(p, "snafubar");
p = "snafubar";
PATH_TEST_EQ(p = p.c_str()+5, "bar");
PATH_TEST_EQ(p = p.c_str() + 5, "bar");
p = "snafubar";
PATH_TEST_EQ(p.assign(p.c_str() + 5, p.c_str() + 7), "ba");
@ -1679,13 +1681,12 @@ namespace
p = "snafubar";
PATH_TEST_EQ(p.append(p.c_str() + 5, p.c_str() + 7), "snafubar" BOOST_DIR_SEP "ba");
}
}
// name_function_tests -------------------------------------------------------------//
// name_function_tests -------------------------------------------------------------//
void name_function_tests()
{
void name_function_tests()
{
std::cout << "name_function_tests..." << std::endl;
BOOST_TEST(fs::portable_posix_name(std::string("x")));
@ -1763,12 +1764,12 @@ namespace
BOOST_TEST(!fs::portable_name(std::string("foo.")));
BOOST_TEST(!fs::portable_directory_name(std::string("foo.")));
BOOST_TEST(!fs::portable_file_name(std::string("foo.")));
}
}
// replace_extension_tests ---------------------------------------------------------//
// replace_extension_tests ---------------------------------------------------------//
void replace_extension_tests()
{
void replace_extension_tests()
{
std::cout << "replace_extension_tests..." << std::endl;
BOOST_TEST(path().replace_extension().empty());
@ -1793,32 +1794,29 @@ namespace
BOOST_TEST(path("a/b").replace_extension(".c") == "a/b.c");
PATH_TEST_EQ(path("a.txt/b").replace_extension(".c"), "a.txt/b.c"); // ticket 4702
BOOST_TEST(path("foo.txt").replace_extension("exe") == "foo.exe"); // ticket 5118
BOOST_TEST(path("foo.txt").replace_extension(".tar.bz2")
== "foo.tar.bz2"); // ticket 5118
}
BOOST_TEST(path("foo.txt").replace_extension(".tar.bz2") == "foo.tar.bz2"); // ticket 5118
}
// make_preferred_tests ------------------------------------------------------------//
// make_preferred_tests ------------------------------------------------------------//
void make_preferred_tests()
{
void make_preferred_tests()
{
std::cout << "make_preferred_tests..." << std::endl;
if (platform == "Windows")
{
BOOST_TEST(path("//abc\\def/ghi").make_preferred().native()
== path("\\\\abc\\def\\ghi").native());
BOOST_TEST(path("//abc\\def/ghi").make_preferred().native() == path("\\\\abc\\def\\ghi").native());
}
else
{
BOOST_TEST(path("//abc\\def/ghi").make_preferred().native()
== path("//abc\\def/ghi").native());
}
BOOST_TEST(path("//abc\\def/ghi").make_preferred().native() == path("//abc\\def/ghi").native());
}
}
// lexically_normal_tests ----------------------------------------------------------//
// lexically_normal_tests ----------------------------------------------------------//
void lexically_normal_tests()
{
void lexically_normal_tests()
{
std::cout << "lexically_normal_tests..." << std::endl;
// Note: lexically_lexically_normal() uses /= to build up some results, so these results will
@ -1844,14 +1842,14 @@ namespace
PATH_TEST_EQ(path("../foo").lexically_normal().generic_path(), "../foo");
PATH_TEST_EQ(path("foo/..").lexically_normal().generic_path(), ".");
PATH_TEST_EQ(path("foo/../").lexically_normal().generic_path(), "./.");
PATH_TEST_EQ((path("foo") / "..").lexically_normal().generic_path() , ".");
PATH_TEST_EQ((path("foo") / "..").lexically_normal().generic_path(), ".");
PATH_TEST_EQ(path("foo/...").lexically_normal().generic_path(), "foo/...");
PATH_TEST_EQ(path("foo/.../").lexically_normal().generic_path(), "foo/.../.");
PATH_TEST_EQ(path("foo/..bar").lexically_normal().generic_path(), "foo/..bar");
PATH_TEST_EQ(path("../f").lexically_normal().generic_path(), "../f");
PATH_TEST_EQ(path("/../f").lexically_normal().generic_path(), "/../f");
PATH_TEST_EQ(path("f/..").lexically_normal().generic_path(), ".");
PATH_TEST_EQ((path("f") / "..").lexically_normal().generic_path() , ".");
PATH_TEST_EQ((path("f") / "..").lexically_normal().generic_path(), ".");
PATH_TEST_EQ(path("foo/../..").lexically_normal().generic_path(), "..");
PATH_TEST_EQ(path("foo/../../").lexically_normal().generic_path(), "../.");
PATH_TEST_EQ(path("foo/../../..").lexically_normal().generic_path(), "../..");
@ -1933,13 +1931,13 @@ namespace
PATH_TEST_EQ(path("c:/../../foo/").lexically_normal(), "../foo/.");
PATH_TEST_EQ(path("c:/..foo").lexically_normal(), "c:/..foo");
}
}
}
inline void odr_use(const path::value_type& c)
{
inline void odr_use(const path::value_type& c)
{
static const path::value_type dummy = '\0';
BOOST_TEST(&c != &dummy);
}
}
} // unnamed namespace
@ -1958,9 +1956,7 @@ int cpp_main(int, char*[])
// The choice of platform is make at runtime rather than compile-time
// so that compile errors for all platforms will be detected even though
// only the current platform is runtime tested.
platform = (platform == "Win32" || platform == "Win64" || platform == "Cygwin")
? "Windows"
: "POSIX";
platform = (platform == "Win32" || platform == "Win64" || platform == "Cygwin") ? "Windows" : "POSIX";
std::cout << "Platform is " << platform << '\n';
BOOST_TEST(p1.string() != p3.string());
@ -1988,14 +1984,14 @@ int cpp_main(int, char*[])
// verify deprecated names still available
# ifndef BOOST_FILESYSTEM_NO_DEPRECATED
#ifndef BOOST_FILESYSTEM_NO_DEPRECATED
p1.branch_path();
p1.leaf();
path p_remove_leaf;
p_remove_leaf.remove_leaf();
# endif
#endif
std::string s1("//:somestring"); // this used to be treated specially
@ -2008,7 +2004,7 @@ int cpp_main(int, char*[])
// this code, courtesy of David Whetstone, detects a now fixed bug that
// derefereced the end iterator (assuming debug build with checked itors)
std::vector<char> v1;
std::vector< char > v1;
p5.assign(v1.begin(), v1.end());
std::string s2(v1.begin(), v1.end());
PATH_TEST_EQ(p5.string(), s2);
@ -2026,7 +2022,7 @@ int cpp_main(int, char*[])
BOOST_TEST(path("foo").empty() == false);
// inserter and extractor tests
# if !defined(BOOST_MSVC) || BOOST_MSVC > 1300 // bypass VC++ 7.0 and earlier
#if !defined(BOOST_MSVC) || BOOST_MSVC > 1300 // bypass VC++ 7.0 and earlier
std::cout << "\nInserter and extractor test...";
std::stringstream ss;
ss << fs::path("foo/bar") << std::endl;
@ -2034,7 +2030,7 @@ int cpp_main(int, char*[])
ss >> round_trip;
BOOST_TEST(round_trip.string() == "foo/bar");
std::cout << round_trip.string() << "..." << round_trip << " complete\n";
# endif
#endif
// Check that path constants have definitions
// https://svn.boost.org/trac10/ticket/12759

View File

@ -10,10 +10,10 @@
#include <boost/config/warning_disable.hpp>
#ifndef BOOST_FILESYSTEM_NO_DEPRECATED
# define BOOST_FILESYSTEM_NO_DEPRECATED
#define BOOST_FILESYSTEM_NO_DEPRECATED
#endif
#ifndef BOOST_SYSTEM_NO_DEPRECATED
# define BOOST_SYSTEM_NO_DEPRECATED
#define BOOST_SYSTEM_NO_DEPRECATED
#endif
#include <boost/timer/timer.hpp>
@ -21,9 +21,9 @@
#include <boost/cstdint.hpp>
#include <boost/config.hpp>
# if defined( BOOST_NO_STD_WSTRING )
# error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
# endif
#if defined(BOOST_NO_STD_WSTRING)
#error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
#endif
#include <boost/detail/lightweight_main.hpp>
@ -36,13 +36,12 @@ using namespace boost::timer;
using std::cout;
using std::endl;
namespace
{
boost::int64_t max_cycles;
namespace {
boost::int64_t max_cycles;
template <class STD_STRING>
nanosecond_type time_ctor(const STD_STRING& s)
{
template< class STD_STRING >
nanosecond_type time_ctor(const STD_STRING& s)
{
boost::timer::auto_cpu_timer tmr;
boost::int64_t count = 0;
do
@ -53,10 +52,10 @@ namespace
boost::timer::cpu_times elapsed = tmr.elapsed();
return elapsed.user + elapsed.system;
}
}
nanosecond_type time_loop()
{
nanosecond_type time_loop()
{
boost::timer::auto_cpu_timer tmr;
boost::int64_t count = 0;
do
@ -66,7 +65,7 @@ namespace
boost::timer::cpu_times elapsed = tmr.elapsed();
return elapsed.user + elapsed.system;
}
}
} // unnamed namespace
//--------------------------------------------------------------------------------------//
@ -94,9 +93,9 @@ int cpp_main(int argc, char* argv[])
nanosecond_type w = time_ctor(std::wstring(L"/foo/bar/baz"));
if (s > w)
cout << "narrow/wide CPU-time ratio = " << long double(s)/w << endl;
cout << "narrow/wide CPU-time ratio = " << long double(s) / w << endl;
else
cout << "wide/narrow CPU-time ratio = " << long double(w)/s << endl;
cout << "wide/narrow CPU-time ratio = " << long double(w) / s << endl;
cout << "returning from main()" << endl;
return 0;

View File

@ -23,10 +23,10 @@
// See deprecated_test for tests of deprecated features
#ifndef BOOST_FILESYSTEM_NO_DEPRECATED
# define BOOST_FILESYSTEM_NO_DEPRECATED
#define BOOST_FILESYSTEM_NO_DEPRECATED
#endif
#ifndef BOOST_SYSTEM_NO_DEPRECATED
# define BOOST_SYSTEM_NO_DEPRECATED
#define BOOST_SYSTEM_NO_DEPRECATED
#endif
#include <boost/filesystem/path.hpp>
@ -57,26 +57,25 @@ using std::wstring;
#define CHECK(x) check(x, __FILE__, __LINE__)
#define PATH_IS(a, b) check_path(a, b, __FILE__, __LINE__)
#define NATIVE_IS(p, s, ws) check_native(p, s, ws, __FILE__, __LINE__)
#define IS(a,b) check_equal(a, b, __FILE__, __LINE__)
#define IS(a, b) check_equal(a, b, __FILE__, __LINE__)
#if defined(_MSC_VER)
# pragma warning(push) // Save warning settings.
# pragma warning(disable : 4428) // Disable universal-character-name encountered in source warning.
#pragma warning(push) // Save warning settings.
#pragma warning(disable : 4428) // Disable universal-character-name encountered in source warning.
#endif
namespace
namespace {
boost::system::error_code ec;
const boost::system::error_code ok;
const boost::system::error_code ng(-1, boost::system::system_category());
std::string platform(BOOST_PLATFORM);
void check_path(const path& source, const wstring& expected, const char* file, int line)
{
boost::system::error_code ec;
const boost::system::error_code ok;
const boost::system::error_code ng(-1, boost::system::system_category());
std::string platform(BOOST_PLATFORM);
void check_path(const path& source,
const wstring& expected, const char* file, int line)
{
if (source == expected) return;
if (source == expected)
return;
++::boost::detail::test_errors();
@ -84,23 +83,23 @@ namespace
std::wcout << L'(' << line << L"): source.wstring(): \""
<< source.wstring()
<< L"\" != expected: \"" << expected
<< L"\"\n" ;
}
<< L"\"\n";
}
# ifdef BOOST_WINDOWS_API
void check_native(const path& p,
const string&, const wstring& expected, const char* file, int line)
# else
void check_native(const path& p,
const string& expected, const wstring&, const char* file, int line)
# endif
{
if (p.native() == expected) return;
#ifdef BOOST_WINDOWS_API
void check_native(const path& p, const string&, const wstring& expected, const char* file, int line)
#else
void check_native(const path& p, const string& expected, const wstring&, const char* file, int line)
#endif
{
if (p.native() == expected)
return;
++::boost::detail::test_errors();
std::cout << file << '(' << line << "): native() is not equal expected\n"
" native---: " << std::hex;
" native---: "
<< std::hex;
path::string_type nat(p.native());
for (path::string_type::const_iterator it = nat.begin(); it != nat.end(); ++it)
std::cout << long(*it) << ' ';
@ -108,13 +107,13 @@ namespace
for (path::string_type::const_iterator it = expected.begin(); it != expected.end(); ++it)
std::cout << long(*it) << ' ';
std::cout << std::dec << std::endl;
}
}
template< class T1, class T2 >
void check_equal(const T1& value,
const T2& expected, const char* file, int line)
{
if (value == expected) return;
template< class T1, class T2 >
void check_equal(const T1& value, const T2& expected, const char* file, int line)
{
if (value == expected)
return;
++::boost::detail::test_errors();
@ -122,33 +121,40 @@ namespace
std::wcout << L'(' << line << L"): value: \"" << value
<< L"\" != expected: \"" << expected
<< L"\"\n" ;
}
<< L"\"\n";
}
void check(bool ok_, const char* file, int line)
{
if (ok_) return;
void check(bool ok_, const char* file, int line)
{
if (ok_)
return;
++::boost::detail::test_errors();
std::cout << file << '(' << line << "): test failed\n";
}
}
string s("string");
wstring ws(L"wstring");
std::list<char> l; // see main() for initialization to s, t, r, i, n, g
std::list<wchar_t> wl; // see main() for initialization to w, s, t, r, i, n, g
std::vector<char> v; // see main() for initialization to f, u, z
std::vector<wchar_t> wv; // see main() for initialization to w, f, u, z
string s("string");
wstring ws(L"wstring");
std::list< char > l; // see main() for initialization to s, t, r, i, n, g
std::list< wchar_t > wl; // see main() for initialization to w, s, t, r, i, n, g
std::vector< char > v; // see main() for initialization to f, u, z
std::vector< wchar_t > wv; // see main() for initialization to w, f, u, z
class Base {};
class Derived : public Base {};
void fun(const boost::shared_ptr< Base >&) {}
class Base
{
};
class Derived : public Base
{
};
void fun(const boost::shared_ptr< Base >&)
{
}
// test_constructors ---------------------------------------------------------------//
// test_constructors ---------------------------------------------------------------//
void test_constructors()
{
void test_constructors()
{
std::cout << "testing constructors..." << std::endl;
path x0; // default constructor
@ -212,11 +218,11 @@ namespace
PATH_IS(x9, L"wstring");
BOOST_TEST_EQ(x9.native().size(), 7U);
path x8nc(const_cast<char*>(s.c_str())); // char* null terminated
path x8nc(const_cast< char* >(s.c_str())); // char* null terminated
PATH_IS(x8nc, L"string");
BOOST_TEST_EQ(x8nc.native().size(), 6U);
path x9nc(const_cast<wchar_t*>(ws.c_str())); // wchar_t* null terminated
path x9nc(const_cast< wchar_t* >(ws.c_str())); // wchar_t* null terminated
PATH_IS(x9nc, L"wstring");
BOOST_TEST_EQ(x9nc.native().size(), 7U);
@ -232,18 +238,18 @@ namespace
// easy-to-make coding errors
// path e1(x0, path::codecvt()); // fails to compile, and that is OK
boost::shared_ptr< Derived > pDerived( new Derived() );
fun( pDerived ); // tests constructor member template enable_if working correctly;
boost::shared_ptr< Derived > pDerived(new Derived());
fun(pDerived); // tests constructor member template enable_if working correctly;
// will fail to compile if enable_if not taking path off the table
}
}
path x;
path y;
path x;
path y;
// test_assignments ----------------------------------------------------------------//
// test_assignments ----------------------------------------------------------------//
void test_assignments()
{
void test_assignments()
{
std::cout << "testing assignments..." << std::endl;
x = path("yet another path"); // another path
@ -277,15 +283,15 @@ namespace
x = ws.c_str(); // const wchar_t* null terminated
PATH_IS(x, L"wstring");
}
}
// test_move_construction_and_assignment -------------------------------------------//
// test_move_construction_and_assignment -------------------------------------------//
void test_move_construction_and_assignment()
{
void test_move_construction_and_assignment()
{
std::cout << "testing move_construction_and_assignment..." << std::endl;
# if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
path from("long enough to avoid small object optimization");
path to(std::move(from));
BOOST_TEST(to == "long enough to avoid small object optimization");
@ -298,24 +304,22 @@ namespace
BOOST_TEST(to2 == "long enough to avoid small object optimization");
if (!from2.empty())
cout << "Note: move assignment did not result in empty rhs path" << endl;
# else
std::cout <<
"Test skipped because compiler does not support move semantics" << std::endl;
# endif
#else
std::cout << "Test skipped because compiler does not support move semantics" << std::endl;
#endif
}
}
// test_appends --------------------------------------------------------------------//
// test_appends --------------------------------------------------------------------//
void test_appends()
{
void test_appends()
{
std::cout << "testing appends..." << std::endl;
# ifdef BOOST_WINDOWS_API
# define BOOST_FS_FOO L"/foo\\"
# else // POSIX paths
# define BOOST_FS_FOO L"/foo/"
# endif
#ifdef BOOST_WINDOWS_API
#define BOOST_FS_FOO L"/foo\\"
#else // POSIX paths
#define BOOST_FS_FOO L"/foo/"
#endif
x = "/foo";
x /= path(""); // empty path
@ -368,12 +372,12 @@ namespace
x = "/foo";
x /= ws.c_str(); // const wchar_t* null terminated
PATH_IS(x, BOOST_FS_FOO L"wstring");
}
}
// test_concats --------------------------------------------------------------------//
// test_concats --------------------------------------------------------------------//
void test_concats()
{
void test_concats()
{
std::cout << "testing concats..." << std::endl;
x = "/foo";
@ -435,12 +439,12 @@ namespace
x = "foo-";
x += L'x'; // wchar
PATH_IS(x, L"foo-x");
}
}
// test_observers ------------------------------------------------------------------//
// test_observers ------------------------------------------------------------------//
void test_observers()
{
void test_observers()
{
std::cout << "testing observers..." << std::endl;
path p0("abc");
@ -456,7 +460,7 @@ namespace
CHECK(p0.native().size() == 0);
CHECK(p0.size() == 0);
# ifdef BOOST_WINDOWS_API
#ifdef BOOST_WINDOWS_API
path p("abc\\def/ghi");
@ -469,11 +473,11 @@ namespace
CHECK(p.generic_string() == "abc/def/ghi");
CHECK(p.generic_wstring() == L"abc/def/ghi");
CHECK(p.generic_string<string>() == "abc/def/ghi");
CHECK(p.generic_string<wstring>() == L"abc/def/ghi");
CHECK(p.generic_string<path::string_type>() == L"abc/def/ghi");
CHECK(p.generic_string< string >() == "abc/def/ghi");
CHECK(p.generic_string< wstring >() == L"abc/def/ghi");
CHECK(p.generic_string< path::string_type >() == L"abc/def/ghi");
# else // BOOST_POSIX_API
#else // BOOST_POSIX_API
path p("abc\\def/ghi");
@ -486,26 +490,26 @@ namespace
CHECK(p.generic_string() == "abc\\def/ghi");
CHECK(p.generic_wstring() == L"abc\\def/ghi");
CHECK(p.generic_string<string>() == "abc\\def/ghi");
CHECK(p.generic_string<wstring>() == L"abc\\def/ghi");
CHECK(p.generic_string<path::string_type>() == "abc\\def/ghi");
CHECK(p.generic_string< string >() == "abc\\def/ghi");
CHECK(p.generic_string< wstring >() == L"abc\\def/ghi");
CHECK(p.generic_string< path::string_type >() == "abc\\def/ghi");
# endif
}
#endif
}
// test_relationals ----------------------------------------------------------------//
// test_relationals ----------------------------------------------------------------//
void test_relationals()
{
void test_relationals()
{
std::cout << "testing relationals..." << std::endl;
boost::hash<path> hash;
boost::hash< path > hash;
# ifdef BOOST_WINDOWS_API
#ifdef BOOST_WINDOWS_API
// this is a critical use case to meet user expectations
CHECK(path("c:\\abc") == path("c:/abc"));
CHECK(hash(path("c:\\abc")) == hash(path("c:/abc")));
# endif
#endif
const path p("bar");
const path p2("baz");
@ -554,10 +558,10 @@ namespace
CHECK(p2 >= p);
}
// test_inserter_and_extractor -----------------------------------------------------//
// test_inserter_and_extractor -----------------------------------------------------//
void test_inserter_and_extractor()
{
void test_inserter_and_extractor()
{
std::cout << "testing inserter and extractor..." << std::endl;
path p1("foo bar"); // verify space in path roundtrips per ticket #3863
@ -579,12 +583,12 @@ namespace
wss << wp1;
wss >> wp2;
CHECK(wp1 == wp2);
}
}
// test_other_non_members ----------------------------------------------------------//
// test_other_non_members ----------------------------------------------------------//
void test_other_non_members()
{
void test_other_non_members()
{
std::cout << "testing other_non_members..." << std::endl;
path p1("foo");
@ -624,17 +628,17 @@ namespace
CHECK(path("foo/").filename_is_dot());
CHECK(path("/").filename() == path("/"));
CHECK(!path("/").filename_is_dot());
# ifdef BOOST_WINDOWS_API
#ifdef BOOST_WINDOWS_API
CHECK(path("c:.").filename() == path("."));
CHECK(path("c:.").filename_is_dot());
CHECK(path("c:/").filename() == path("/"));
CHECK(!path("c:\\").filename_is_dot());
# else
#else
CHECK(path("c:.").filename() == path("c:."));
CHECK(!path("c:.").filename_is_dot());
CHECK(path("c:/").filename() == path("."));
CHECK(path("c:/").filename_is_dot());
# endif
#endif
// check that the implementation code to make the edge cases above work right
// doesn't cause some non-edge cases to fail
@ -651,7 +655,7 @@ namespace
std::cout << path("/foo.").filename_is_dot(); // outputs 0
std::cout << path("..").filename_is_dot(); // outputs 0
cout << std::endl;
}
}
// // test_modifiers ------------------------------------------------------------------//
//
@ -661,10 +665,10 @@ namespace
//
// }
// test_iterators ------------------------------------------------------------------//
// test_iterators ------------------------------------------------------------------//
void test_iterators()
{
void test_iterators()
{
std::cout << "testing iterators..." << std::endl;
path p1;
@ -687,12 +691,12 @@ namespace
CHECK(*++it == "bar");
CHECK(*++it == "baz");
CHECK(++it == p3.end());
}
}
// test_reverse_iterators ----------------------------------------------------------//
// test_reverse_iterators ----------------------------------------------------------//
void test_reverse_iterators()
{
void test_reverse_iterators()
{
std::cout << "testing reverse_iterators..." << std::endl;
path p1;
@ -715,12 +719,12 @@ namespace
CHECK(*++it == "bar");
CHECK(*++it == "foo");
CHECK(++it == p3.rend());
}
}
// test_modifiers ------------------------------------------------------------------//
// test_modifiers ------------------------------------------------------------------//
void test_modifiers()
{
void test_modifiers()
{
std::cout << "testing modifiers..." << std::endl;
CHECK(path("").remove_filename() == "");
@ -736,12 +740,12 @@ namespace
BOOST_TEST_EQ(path("/..").remove_filename(), path("/"));
BOOST_TEST_EQ(path("//").remove_filename(), path(""));
BOOST_TEST_EQ(path("////").remove_filename(), path(""));
}
}
// test_decompositions -------------------------------------------------------------//
// test_decompositions -------------------------------------------------------------//
void test_decompositions()
{
void test_decompositions()
{
std::cout << "testing decompositions..." << std::endl;
CHECK(path("").root_name().string() == "");
@ -764,9 +768,9 @@ namespace
CHECK(path("//netname").root_path().string() == "//netname");
CHECK(path("//netname/foo").root_path().string() == "//netname/");
# ifdef BOOST_WINDOWS_API
#ifdef BOOST_WINDOWS_API
CHECK(path("c:/foo").root_path().string() == "c:/");
# endif
#endif
CHECK(path("").relative_path().string() == "");
CHECK(path("/").relative_path().string() == "");
@ -785,12 +789,12 @@ namespace
CHECK(path("foo.bar.baz.tar.bz2").extension().string() == ".bz2");
CHECK(path("/foo/bar/baz.zoo").extension().string() == ".zoo");
CHECK(path("/foo/bar.woo/baz").extension().string() == "");
}
}
// test_queries --------------------------------------------------------------------//
// test_queries --------------------------------------------------------------------//
void test_queries()
{
void test_queries()
{
std::cout << "testing queries..." << std::endl;
path p1("");
@ -819,13 +823,12 @@ namespace
CHECK(p2.has_extension());
CHECK(p2.is_absolute());
CHECK(!p2.is_relative());
}
}
// test_imbue_locale ---------------------------------------------------------------//
// test_imbue_locale ---------------------------------------------------------------//
void test_imbue_locale()
{
void test_imbue_locale()
{
std::cout << "testing imbue locale..." << std::endl;
// weak test case for before/after states since we don't know what characters the
@ -853,15 +856,15 @@ namespace
CHECK(before == after);
std::cout << " locale testing complete" << std::endl;
}
}
// test_codecvt_argument -----------------------------------------------------------//
// test_codecvt_argument -----------------------------------------------------------//
void test_codecvt_argument()
{
void test_codecvt_argument()
{
std::cout << "testing codecvt arguments..." << std::endl;
const char * c1 = "a1";
const char* c1 = "a1";
const std::string s1(c1);
const std::wstring ws1(L"b2"); // off-by-one mimics test_codecvt
const std::string s2("y8");
@ -894,7 +897,7 @@ namespace
// assigns
p1.clear();
std::cout << " assigns test " << ++t << std::endl;
p1.assign(s1,cvt);
p1.assign(s1, cvt);
NATIVE_IS(p1, s1, ws1);
p1.clear();
std::cout << " test " << ++t << std::endl;
@ -905,7 +908,7 @@ namespace
// appends
p1.clear();
std::cout << " appends test " << ++t << std::endl;
p1.append(s1,cvt);
p1.append(s1, cvt);
NATIVE_IS(p1, s1, ws1);
p1.clear();
std::cout << " test " << ++t << std::endl;
@ -915,31 +918,31 @@ namespace
// native observers
std::cout << " native observers test " << ++t << std::endl;
CHECK(p.string<std::string>(cvt) == s1);
CHECK(p.string< std::string >(cvt) == s1);
std::cout << " test " << ++t << std::endl;
CHECK(p.string(cvt) == s1);
std::cout << " test " << ++t << std::endl;
CHECK(p.string<std::wstring>(cvt) == ws1);
CHECK(p.string< std::wstring >(cvt) == ws1);
std::cout << " test " << ++t << std::endl;
CHECK(p.wstring(cvt) == ws1);
// generic observers
std::cout << " generic observers test " << ++t << std::endl;
CHECK(p.generic_string<std::string>(cvt) == s1);
CHECK(p.generic_string< std::string >(cvt) == s1);
std::cout << " test " << ++t << std::endl;
CHECK(p.generic_string(cvt) == s1);
std::cout << " test " << ++t << std::endl;
CHECK(p.generic_string<std::wstring>(cvt) == ws1);
CHECK(p.generic_string< std::wstring >(cvt) == ws1);
std::cout << " test " << ++t << std::endl;
CHECK(p.generic_wstring(cvt) == ws1);
std::cout << " codecvt arguments testing complete" << std::endl;
}
}
// test_overloads ------------------------------------------------------------------//
// test_overloads ------------------------------------------------------------------//
void test_overloads()
{
void test_overloads()
{
std::cout << "testing overloads..." << std::endl;
std::string sto("hello");
const char a[] = "goodbye";
@ -954,52 +957,54 @@ namespace
path wp2(wsto.c_str());
path wp3(wa);
path wp4(L"foo");
}
// test_error_handling -------------------------------------------------------------//
class error_codecvt :
public std::codecvt< wchar_t, char, std::mbstate_t >
{
public:
explicit error_codecvt() :
std::codecvt< wchar_t, char, std::mbstate_t >()
{
}
// test_error_handling -------------------------------------------------------------//
class error_codecvt
: public std::codecvt< wchar_t, char, std::mbstate_t >
{
public:
explicit error_codecvt()
: std::codecvt<wchar_t, char, std::mbstate_t>() {}
protected:
protected:
virtual bool do_always_noconv() const throw() { return false; }
virtual int do_encoding() const throw() { return 0; }
virtual std::codecvt_base::result do_in(std::mbstate_t&,
const char*, const char*, const char*&,
wchar_t*, wchar_t*, wchar_t*&) const
virtual std::codecvt_base::result do_in(std::mbstate_t&, const char*, const char*, const char*&, wchar_t*, wchar_t*, wchar_t*&) const
{
static std::codecvt_base::result r = std::codecvt_base::noconv;
if (r == std::codecvt_base::partial) r = std::codecvt_base::error;
else if (r == std::codecvt_base::error) r = std::codecvt_base::noconv;
else r = std::codecvt_base::partial;
if (r == std::codecvt_base::partial)
r = std::codecvt_base::error;
else if (r == std::codecvt_base::error)
r = std::codecvt_base::noconv;
else
r = std::codecvt_base::partial;
return r;
}
virtual std::codecvt_base::result do_out(std::mbstate_t &,
const wchar_t*, const wchar_t*, const wchar_t*&,
char*, char*, char*&) const
virtual std::codecvt_base::result do_out(std::mbstate_t&, const wchar_t*, const wchar_t*, const wchar_t*&, char*, char*, char*&) const
{
static std::codecvt_base::result r = std::codecvt_base::noconv;
if (r == std::codecvt_base::partial) r = std::codecvt_base::error;
else if (r == std::codecvt_base::error) r = std::codecvt_base::noconv;
else r = std::codecvt_base::partial;
if (r == std::codecvt_base::partial)
r = std::codecvt_base::error;
else if (r == std::codecvt_base::error)
r = std::codecvt_base::noconv;
else
r = std::codecvt_base::partial;
return r;
}
virtual std::codecvt_base::result do_unshift(std::mbstate_t&,
char*, char*, char* &) const { return ok; }
virtual int do_length(std::mbstate_t &,
const char*, const char*, std::size_t) const { return 0; }
virtual int do_max_length() const throw () { return 0; }
};
virtual std::codecvt_base::result do_unshift(std::mbstate_t&, char*, char*, char*&) const { return ok; }
virtual int do_length(std::mbstate_t&, const char*, const char*, std::size_t) const { return 0; }
virtual int do_max_length() const throw() { return 0; }
};
void test_error_handling()
{
void test_error_handling()
{
std::cout << "testing error handling..." << std::endl;
std::locale global_loc = std::locale();
@ -1010,60 +1015,75 @@ namespace
// These tests rely on a path constructor that fails in the locale conversion.
// Thus construction has to call codecvt. Force that by using a narrow string
// for Windows, and a wide string for POSIX.
# ifdef BOOST_WINDOWS_API
# define STRING_FOO_ "foo"
# else
# define STRING_FOO_ L"foo"
# endif
#ifdef BOOST_WINDOWS_API
#define STRING_FOO_ "foo"
#else
#define STRING_FOO_ L"foo"
#endif
{
std::cout << " testing std::codecvt_base::partial error..." << std::endl;
bool exception_thrown (false);
try { path(STRING_FOO_); }
catch (const bs::system_error & ex)
bool exception_thrown(false);
try
{
path(STRING_FOO_);
}
catch (const bs::system_error& ex)
{
exception_thrown = true;
BOOST_TEST_EQ(ex.code(), bs::error_code(std::codecvt_base::partial,
fs::codecvt_error_category()));
BOOST_TEST_EQ(ex.code(), bs::error_code(std::codecvt_base::partial, fs::codecvt_error_category()));
}
catch (...)
{
std::cout << "***** unexpected exception type *****" << std::endl;
}
catch (...) { std::cout << "***** unexpected exception type *****" << std::endl; }
BOOST_TEST(exception_thrown);
}
{
std::cout << " testing std::codecvt_base::error error..." << std::endl;
bool exception_thrown (false);
try { path(STRING_FOO_); }
catch (const bs::system_error & ex)
bool exception_thrown(false);
try
{
path(STRING_FOO_);
}
catch (const bs::system_error& ex)
{
exception_thrown = true;
BOOST_TEST_EQ(ex.code(), bs::error_code(std::codecvt_base::error,
fs::codecvt_error_category()));
BOOST_TEST_EQ(ex.code(), bs::error_code(std::codecvt_base::error, fs::codecvt_error_category()));
}
catch (...)
{
std::cout << "***** unexpected exception type *****" << std::endl;
}
catch (...) { std::cout << "***** unexpected exception type *****" << std::endl; }
BOOST_TEST(exception_thrown);
}
{
std::cout << " testing std::codecvt_base::noconv error..." << std::endl;
bool exception_thrown (false);
try { path(STRING_FOO_); }
catch (const bs::system_error & ex)
bool exception_thrown(false);
try
{
path(STRING_FOO_);
}
catch (const bs::system_error& ex)
{
exception_thrown = true;
BOOST_TEST_EQ(ex.code(), bs::error_code(std::codecvt_base::noconv,
fs::codecvt_error_category()));
BOOST_TEST_EQ(ex.code(), bs::error_code(std::codecvt_base::noconv, fs::codecvt_error_category()));
}
catch (...)
{
std::cout << "***** unexpected exception type *****" << std::endl;
}
catch (...) { std::cout << "***** unexpected exception type *****" << std::endl; }
BOOST_TEST(exception_thrown);
}
std::cout << " restoring original locale ..." << std::endl;
path::imbue(old_loc);
std::cout << " testing error handling complete" << std::endl;
}
}
# if 0
#if 0
// // test_locales --------------------------------------------------------------------//
//
@ -1073,63 +1093,59 @@ namespace
//
// }
// test_user_supplied_type ---------------------------------------------------------//
// test_user_supplied_type ---------------------------------------------------------//
typedef std::basic_string<int> user_string;
typedef std::basic_string<int> user_string;
} // unnamed namespace
namespace boost
{
namespace filesystem
{
namespace path_traits
{
template<> struct is_iterator<const user_string::value_type *> { static const bool value = true; };
template<> struct is_iterator<user_string::value_type *> { static const bool value = true; };
template<> struct is_iterator<user_string::iterator> { static const bool value = true; };
template<> struct is_iterator<user_string::const_iterator> { static const bool value = true; };
template<> struct is_container<user_string> { static const bool value = true; };
namespace boost {
namespace filesystem {
namespace path_traits {
template<>
void append<user_string::value_type>(const user_string::value_type * begin,
const user_string::value_type * end, string_type & target, system::error_code & ec)
{
template<> struct is_iterator< const user_string::value_type* > { static const bool value = true; };
template<> struct is_iterator< user_string::value_type* > { static const bool value = true; };
template<> struct is_iterator< user_string::iterator > { static const bool value = true; };
template<> struct is_iterator< user_string::const_iterator > { static const bool value = true; };
template<> struct is_container< user_string > { static const bool value = true; };
template<>
void append< user_string::value_type >(const user_string::value_type* begin,
const user_string::value_type* end, string_type& target, system::error_code& ec)
{
for (; begin != end && *begin; ++begin)
target += *begin + 1; // change so that results distinguishable from char cvts
}
}
# ifdef __GNUC__
// This specialization shouldn't be needed, and VC++, Intel, and others work
// fine without it. But gcc 4.3.2, and presumably other versions, need it.
template<>
void append<user_string::value_type>(const user_string::value_type * begin,
string_type & target, system::error_code & ec)
{
#ifdef __GNUC__
// This specialization shouldn't be needed, and VC++, Intel, and others work
// fine without it. But gcc 4.3.2, and presumably other versions, need it.
template<>
void append< user_string::value_type >(const user_string::value_type* begin,
string_type& target, system::error_code& ec)
{
path_traits::append<user_string::value_type>(begin,
static_cast<const user_string::value_type *>(0), target, ec);
}
# endif
}
#endif
template<>
user_string convert<user_string>(const string_type & source,
system::error_code & ec)
{
template<>
user_string convert< user_string >(string_type const& source, system::error_code& ec)
{
user_string temp;
for (string_type::const_iterator it = source.begin();
it != source.end(); ++it)
for (string_type::const_iterator it = source.begin(); it != source.end(); ++it)
temp += *it - 1;
return temp;
}
} // namespace path_traits
}
} // namespace path_traits
} // namespace filesystem
} // namespace boost
namespace
{
namespace {
void test_user_supplied_type()
{
void test_user_supplied_type()
{
std::cout << "testing user supplied type..." << std::endl;
user_string::value_type usr_c_str[] = { 'a', 'b', 'c', 0 };
@ -1140,12 +1156,12 @@ namespace
CHECK(p1 == "bcd");
user_string s1(p1.string<user_string>());
CHECK(s1 == usr);
}
}
# endif
#endif
inline const char* macro_value(const char* name, const char* value)
{
inline const char* macro_value(const char* name, const char* value)
{
static const char* no_value = "[no value]";
static const char* not_defined = "[not defined]";
@ -1158,10 +1174,8 @@ namespace
//}
//return not_defined;
return 0 == strcmp(name, value + 1)
? not_defined
: (value[1] ? value : no_value);
}
return 0 == strcmp(name, value + 1) ? not_defined : (value[1] ? value : no_value);
}
#define BOOST_MACRO_VALUE(X) macro_value(#X, BOOST_STRINGIZE(=X))
@ -1188,12 +1202,12 @@ int test_main(int, char*[])
cout << "BOOST_FILESYSTEM_DECL "
<< BOOST_MACRO_VALUE(BOOST_FILESYSTEM_DECL) << endl;
//#ifdef BOOST_FILESYSTEM_DECL
// cout << "BOOST_FILESYSTEM_DECL is defined as "
// << BOOST_STRINGIZE(BOOST_FILESYSTEM_DECL) << endl;
//#else
// cout << "BOOST_FILESYSTEM_DECL is not defined" << endl;
//#endif
//#ifdef BOOST_FILESYSTEM_DECL
// cout << "BOOST_FILESYSTEM_DECL is defined as "
// << BOOST_STRINGIZE(BOOST_FILESYSTEM_DECL) << endl;
//#else
// cout << "BOOST_FILESYSTEM_DECL is not defined" << endl;
//#endif
l.push_back('s');
l.push_back('t');
@ -1239,9 +1253,7 @@ int test_main(int, char*[])
test_error_handling();
#if 0
test_user_supplied_type();
#endif
std::string foo("\\abc");

View File

@ -15,10 +15,10 @@ namespace fs = boost::filesystem;
int main()
{
fs::path p1( "a" );
fs::path p1("a");
fs::path p2 = p1 / "b";
BOOST_TEST_EQ( p2, "a/b" );
BOOST_TEST_EQ(p2, "a/b");
return boost::report_errors();
}

View File

@ -22,10 +22,10 @@ using boost::filesystem::path;
using std::cout;
using std::endl;
namespace
namespace {
void lexically_relative_test()
{
void lexically_relative_test()
{
cout << "lexically_relative_test..." << endl;
BOOST_TEST(path("").lexically_relative("") == "");
@ -76,23 +76,24 @@ namespace
// Some tests from Jamie Allsop's paper
BOOST_TEST(path("/a/d").lexically_relative("/a/b/c") == "../../d");
BOOST_TEST(path("/a/b/c").lexically_relative("/a/d") == "../b/c");
#ifdef BOOST_WINDOWS_API
#ifdef BOOST_WINDOWS_API
BOOST_TEST(path("c:\\y").lexically_relative("c:\\x") == "../y");
#else
#else
BOOST_TEST(path("c:\\y").lexically_relative("c:\\x") == "");
#endif
#endif
BOOST_TEST(path("d:\\y").lexically_relative("c:\\x") == "");
// From issue #1976
BOOST_TEST(path("/foo/new").lexically_relative("/foo/bar") == "../new");
}
}
void lexically_proximate_test()
{
void lexically_proximate_test()
{
cout << "lexically_proximate_test..." << endl;
// paths unrelated
BOOST_TEST(path("a/b/c").lexically_proximate("x") == "a/b/c");
}
}
} // unnamed namespace
//--------------------------------------------------------------------------------------//

View File

@ -18,9 +18,9 @@
#include <string>
#include <cstring>
#ifndef BOOST_LIGHTWEIGHT_MAIN
# include <boost/test/prg_exec_monitor.hpp>
#include <boost/test/prg_exec_monitor.hpp>
#else
# include <boost/detail/lightweight_main.hpp>
#include <boost/detail/lightweight_main.hpp>
#endif
namespace fs = boost::filesystem;
@ -30,9 +30,8 @@ using std::endl;
using std::string;
using std::wstring;
namespace
{
bool cleanup = true;
namespace {
bool cleanup = true;
}
// cpp_main ----------------------------------------------------------------//

View File

@ -14,34 +14,33 @@
#include <locale>
#include <cwchar> // for mbstate_t
//------------------------------------------------------------------------------------//
// //
// class test_codecvt //
// //
// Warning: partial implementation; even do_in and do_out only partially meet the //
// standard library specifications as the "to" buffer must hold the entire result. //
// //
// The value of a wide character is the value of the corresponding narrow character //
// plus 1. This ensures that compares against expected values will fail if the //
// code conversion did not occur as expected. //
// //
//------------------------------------------------------------------------------------//
//------------------------------------------------------------------------------------//
// //
// class test_codecvt //
// //
// Warning: partial implementation; even do_in and do_out only partially meet the //
// standard library specifications as the "to" buffer must hold the entire result. //
// //
// The value of a wide character is the value of the corresponding narrow character //
// plus 1. This ensures that compares against expected values will fail if the //
// code conversion did not occur as expected. //
// //
//------------------------------------------------------------------------------------//
class test_codecvt
: public std::codecvt< wchar_t, char, std::mbstate_t >
class test_codecvt :
public std::codecvt< wchar_t, char, std::mbstate_t >
{
public:
explicit test_codecvt() :
std::codecvt< wchar_t, char, std::mbstate_t >()
{
public:
explicit test_codecvt()
: std::codecvt<wchar_t, char, std::mbstate_t>() {}
protected:
}
protected:
virtual bool do_always_noconv() const throw() { return false; }
virtual int do_encoding() const throw() { return 0; }
virtual std::codecvt_base::result do_in(std::mbstate_t&,
const char* from, const char* from_end, const char*& from_next,
wchar_t* to, wchar_t* to_end, wchar_t*& to_next) const
virtual std::codecvt_base::result do_in(std::mbstate_t&, const char* from, const char* from_end, const char*& from_next, wchar_t* to, wchar_t* to_end, wchar_t*& to_next) const
{
for (; from != from_end && to != to_end; ++from, ++to)
*to = wchar_t(*from + 1);
@ -53,12 +52,10 @@
return ok;
}
virtual std::codecvt_base::result do_out(std::mbstate_t&,
const wchar_t* from, const wchar_t* from_end, const wchar_t*& from_next,
char* to, char* to_end, char*& to_next) const
virtual std::codecvt_base::result do_out(std::mbstate_t&, const wchar_t* from, const wchar_t* from_end, const wchar_t*& from_next, char* to, char* to_end, char*& to_next) const
{
for (; from != from_end && to != to_end; ++from, ++to)
*to = static_cast<char>(*from - 1);
*to = static_cast< char >(*from - 1);
if (to == to_end)
return error;
*to = '\0';
@ -67,13 +64,9 @@
return ok;
}
virtual std::codecvt_base::result do_unshift(std::mbstate_t&,
char* /*from*/, char* /*to*/, char* & /*next*/) const { return ok; }
virtual int do_length(std::mbstate_t&,
const char* /*from*/, const char* /*from_end*/, std::size_t /*max*/) const { return 0; }
virtual int do_max_length() const throw () { return 0; }
};
virtual std::codecvt_base::result do_unshift(std::mbstate_t&, char* /*from*/, char* /*to*/, char*& /*next*/) const { return ok; }
virtual int do_length(std::mbstate_t&, const char* /*from*/, const char* /*from_end*/, std::size_t /*max*/) const { return 0; }
virtual int do_max_length() const throw() { return 0; }
};
#endif // BOOST_FILESYSTEM3_TEST_CODECVT_HPP

View File

@ -24,25 +24,25 @@
using std::make_pair;
namespace fs = boost::filesystem;
int cpp_main( int argc, char* argv[])
int cpp_main(int argc, char* argv[])
{
typedef std::map<DWORD, std::string> decode_type;
typedef std::map< DWORD, std::string > decode_type;
decode_type table;
table.insert(make_pair<DWORD, std::string>(FILE_ATTRIBUTE_ARCHIVE, "FILE_ATTRIBUTE_ARCHIVE"));
table.insert(make_pair<DWORD, std::string>(FILE_ATTRIBUTE_COMPRESSED, "FILE_ATTRIBUTE_COMPRESSED"));
table.insert(make_pair<DWORD, std::string>(FILE_ATTRIBUTE_DEVICE, "FILE_ATTRIBUTE_DEVICE"));
table.insert(make_pair<DWORD, std::string>(FILE_ATTRIBUTE_DIRECTORY, "FILE_ATTRIBUTE_DIRECTORY"));
table.insert(make_pair<DWORD, std::string>(FILE_ATTRIBUTE_ENCRYPTED, "FILE_ATTRIBUTE_ENCRYPTED"));
table.insert(make_pair<DWORD, std::string>(FILE_ATTRIBUTE_HIDDEN, "FILE_ATTRIBUTE_HIDDEN"));
table.insert(make_pair<DWORD, std::string>(FILE_ATTRIBUTE_NOT_CONTENT_INDEXED, "FILE_ATTRIBUTE_NOT_CONTENT_INDEXED"));
table.insert(make_pair<DWORD, std::string>(FILE_ATTRIBUTE_OFFLINE, "FILE_ATTRIBUTE_OFFLINE"));
table.insert(make_pair<DWORD, std::string>(FILE_ATTRIBUTE_READONLY, "FILE_ATTRIBUTE_READONLY"));
table.insert(make_pair<DWORD, std::string>(FILE_ATTRIBUTE_REPARSE_POINT, "FILE_ATTRIBUTE_REPARSE_POINT"));
table.insert(make_pair<DWORD, std::string>(FILE_ATTRIBUTE_SPARSE_FILE, "FILE_ATTRIBUTE_SPARSE_FILE"));
table.insert(make_pair<DWORD, std::string>(FILE_ATTRIBUTE_SYSTEM, "FILE_ATTRIBUTE_SYSTEM"));
table.insert(make_pair<DWORD, std::string>(FILE_ATTRIBUTE_TEMPORARY, "FILE_ATTRIBUTE_TEMPORARY"));
table.insert(make_pair<DWORD, std::string>(FILE_ATTRIBUTE_VIRTUAL, "FILE_ATTRIBUTE_VIRTUAL"));
table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_ARCHIVE, "FILE_ATTRIBUTE_ARCHIVE"));
table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_COMPRESSED, "FILE_ATTRIBUTE_COMPRESSED"));
table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_DEVICE, "FILE_ATTRIBUTE_DEVICE"));
table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_DIRECTORY, "FILE_ATTRIBUTE_DIRECTORY"));
table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_ENCRYPTED, "FILE_ATTRIBUTE_ENCRYPTED"));
table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_HIDDEN, "FILE_ATTRIBUTE_HIDDEN"));
table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_NOT_CONTENT_INDEXED, "FILE_ATTRIBUTE_NOT_CONTENT_INDEXED"));
table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_OFFLINE, "FILE_ATTRIBUTE_OFFLINE"));
table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_READONLY, "FILE_ATTRIBUTE_READONLY"));
table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_REPARSE_POINT, "FILE_ATTRIBUTE_REPARSE_POINT"));
table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_SPARSE_FILE, "FILE_ATTRIBUTE_SPARSE_FILE"));
table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_SYSTEM, "FILE_ATTRIBUTE_SYSTEM"));
table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_TEMPORARY, "FILE_ATTRIBUTE_TEMPORARY"));
table.insert(make_pair< DWORD, std::string >(FILE_ATTRIBUTE_VIRTUAL, "FILE_ATTRIBUTE_VIRTUAL"));
if (argc < 2)
{