// Generate an HTML table showing path decomposition -----------------------// // Copyright Beman Dawes 2005. Distributed under the Boost // Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // See http://www.boost.org/libs/filesystem for documentation. // For purposes of generating the table, support both POSIX and Windows paths #define BOOST_FILESYSTEM_NAMESPACE posix #define BOOST_POSIX_PATH #include "boost/filesystem/path.hpp" #undef BOOST_FILESYSTEM_PATH_HPP #undef BOOST_FILESYSTEM_NAMESPACE #define BOOST_FILESYSTEM_NAMESPACE windows #define BOOST_WINDOWS_PATH #include "boost/filesystem/path.hpp" namespace pos = boost::posix; namespace win = boost::windows; #include #include using std::string; using std::cout; namespace { std::ifstream infile; std::ofstream outfile; const string empty_string; struct column_abc { virtual string heading() const = 0; virtual string cell_value( const pos::path & p ) const = 0; virtual string cell_value( const win::path & p ) const = 0; }; struct c0 : public column_abc { string heading() const { return string("string()"); } string cell_value( const pos::path & p ) const { return p.string(); } string cell_value( const win::path & p ) const { return p.string(); } } o0; struct c1 : public column_abc { string heading() const { return string("file_
string()"); } string cell_value( const pos::path & p ) const { return p.file_string(); } string cell_value( const win::path & p ) const { return p.file_string(); } } o1; struct c2 : public column_abc { string heading() const { return string("Elements found
by iteration"); } string cell_value( const pos::path & p ) const { string s; for( pos::path::iterator i(p.begin()); i != p.end(); ++i ) { if ( i != p.begin() ) s += ','; s += '\"'; s += *i; s += '\"'; } if ( s.empty() ) s += "\"\""; return s; } string cell_value( const win::path & p ) const { string s; for( win::path::iterator i(p.begin()); i != p.end(); ++i ) { if ( i != p.begin() ) s += ','; s += '\"'; s += *i; s += '\"'; } if ( s.empty() ) s += "\"\""; return s; } } o2; struct c3 : public column_abc { string heading() const { return string("root_
path()
.string()
"); } string cell_value( const pos::path & p ) const { return p.root_path().string(); } string cell_value( const win::path & p ) const { return p.root_path().string(); } } o3; struct c4 : public column_abc { string heading() const { return string("root_
name()
"); } string cell_value( const pos::path & p ) const { return p.root_name(); } string cell_value( const win::path & p ) const { return p.root_name(); } } o4; struct c5 : public column_abc { string heading() const { return string("root_
directory()
"); } string cell_value( const pos::path & p ) const { return p.root_directory(); } string cell_value( const win::path & p ) const { return p.root_directory(); } } o5; struct c6 : public column_abc { string heading() const { return string("relative_
path()
.string()
"); } string cell_value( const pos::path & p ) const { return p.relative_path().string(); } string cell_value( const win::path & p ) const { return p.relative_path().string(); } } o6; struct c7 : public column_abc { string heading() const { return string("branch_
path()
.string()
"); } string cell_value( const pos::path & p ) const { return p.branch_path().string(); } string cell_value( const win::path & p ) const { return p.branch_path().string(); } } o7; struct c8 : public column_abc { string heading() const { return string("leaf()"); } string cell_value( const pos::path & p ) const { return p.leaf(); } string cell_value( const win::path & p ) const { return p.leaf(); } } o8; const column_abc * column[] = { &o2, &o0, &o1, &o3, &o4, &o5, &o6, &o7, &o8 }; // do_cell ---------------------------------------------------------------// void do_cell( const string & test_case, int i ) { string posix_result( column[i]->cell_value( pos::path(test_case) ) ); string windows_result( column[i]->cell_value( win::path(test_case) ) ); outfile << (posix_result != windows_result ? "" : ""); if ( posix_result.empty() || posix_result[0] != '\"' ) outfile << '\"' << posix_result << '\"'; else outfile << posix_result; if ( posix_result != windows_result ) { outfile << "
"; if ( windows_result.empty() || windows_result[0] != '\"' ) outfile << '\"' << windows_result << '\"'; else outfile << windows_result; } outfile << "
\n"; } // do_row ------------------------------------------------------------------// void do_row( const string & test_case ) { outfile << "\n\"" << test_case << "\"\n"; for ( int i = 0; i < sizeof(column)/sizeof(column_abc&); ++i ) { do_cell( test_case, i ); } outfile << "\n"; } // do_table ----------------------------------------------------------------// void do_table() { outfile << "

Path Decomposition Table for POSIX and Windows

\n" "

Shaded entries indicate cases where POSIX and Windows\n" "implementations yield different results. The top value is the\n" "POSIX result and the bottom value is the Windows result.\n" "\n" "

\n" ; // generate the column headings outfile << "

\n"; for ( int i = 0; i < sizeof(column)/sizeof(column_abc&); ++i ) { outfile << "\n"; } outfile << "\n"; // generate a row for each input line string test_case; while ( std::getline( infile, test_case ) ) { do_row( test_case ); } outfile << "
Constructor
argument
" << column[i]->heading() << "
\n"; } } // unnamed namespace // main --------------------------------------------------------------------// #define BOOST_NO_CPP_MAIN_SUCCESS_MESSAGE #include int cpp_main( int argc, char * argv[] ) // note name! { if ( argc != 3 ) { std::cerr << "Usage: path_table input-file output-file\n" " input-file contains the paths to appear in the table.\n" " output-file will contain the generated HTML.\n" ; return 1; } infile.open( argv[1] ); if ( !infile ) { std::cerr << "Could not open input file: " << argv[1] << std::endl; return 1; } outfile.open( argv[2] ); if ( !outfile ) { std::cerr << "Could not open output file: " << argv[2] << std::endl; return 1; } outfile << "\n" "\n" "Path Decomposition Table\n" "\n" "\n" ; do_table(); outfile << "\n" "\n" ; return 0; }