Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r68393 - branches/quickbook-filenames/tools/quickbook/src
From: dnljms_at_[hidden]
Date: 2011-01-23 11:44:44


Author: danieljames
Date: 2011-01-23 11:44:32 EST (Sun, 23 Jan 2011)
New Revision: 68393
URL: http://svn.boost.org/trac/boost/changeset/68393

Log:
Use fs::path in more places.
Text files modified:
   branches/quickbook-filenames/tools/quickbook/src/actions.cpp | 3 +--
   branches/quickbook-filenames/tools/quickbook/src/actions_class.cpp | 4 ++--
   branches/quickbook-filenames/tools/quickbook/src/actions_class.hpp | 2 +-
   branches/quickbook-filenames/tools/quickbook/src/doc_info_actions.cpp | 8 ++++----
   branches/quickbook-filenames/tools/quickbook/src/input_path.hpp | 3 ++-
   branches/quickbook-filenames/tools/quickbook/src/quickbook.cpp | 37 ++++++++++++++++++-------------------
   branches/quickbook-filenames/tools/quickbook/src/quickbook.hpp | 5 +++--
   branches/quickbook-filenames/tools/quickbook/src/utils.cpp | 22 ++++------------------
   branches/quickbook-filenames/tools/quickbook/src/utils.hpp | 5 +----
   9 files changed, 36 insertions(+), 53 deletions(-)

Modified: branches/quickbook-filenames/tools/quickbook/src/actions.cpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/actions.cpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/actions.cpp 2011-01-23 11:44:32 EST (Sun, 23 Jan 2011)
@@ -1338,9 +1338,8 @@
                 }
 
                 // Search in each of the include path locations.
- BOOST_FOREACH(std::string const & p, include_path)
+ BOOST_FOREACH(fs::path full, include_path)
                 {
- fs::path full(p);
                     full /= path;
                     if (fs::exists(full))
                     {

Modified: branches/quickbook-filenames/tools/quickbook/src/actions_class.cpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/actions_class.cpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/actions_class.cpp 2011-01-23 11:44:32 EST (Sun, 23 Jan 2011)
@@ -19,7 +19,7 @@
 
 namespace quickbook
 {
- actions::actions(char const* filein_, fs::path const& outdir_, string_stream& out_)
+ actions::actions(fs::path const& filein_, fs::path const& outdir_, string_stream& out_)
         : grammar_()
 
     // header info
@@ -44,7 +44,7 @@
         , list_buffer()
 
     // state
- , filename(fs::absolute(fs::path(filein_)))
+ , filename(fs::absolute(filein_))
         , outdir(outdir_)
         , macro_change_depth(0)
         , macro()

Modified: branches/quickbook-filenames/tools/quickbook/src/actions_class.hpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/actions_class.hpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/actions_class.hpp 2011-01-23 11:44:32 EST (Sun, 23 Jan 2011)
@@ -22,7 +22,7 @@
 
     struct actions
     {
- actions(char const* filein_, fs::path const& outdir, string_stream& out_);
+ actions(fs::path const& filein_, fs::path const& outdir, string_stream& out_);
 
     private:
         boost::scoped_ptr<quickbook_grammar> grammar_;

Modified: branches/quickbook-filenames/tools/quickbook/src/doc_info_actions.cpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/doc_info_actions.cpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/doc_info_actions.cpp 2011-01-23 11:44:32 EST (Sun, 23 Jan 2011)
@@ -77,7 +77,7 @@
             qbk_major_version = 1;
             qbk_minor_version = 1;
             qbk_version_n = 101;
- detail::outwarn(actions.filename.string(),1)
+ detail::outwarn(actions.filename,1)
                 << "Warning: Quickbook version undefined. "
                 "Version 1.1 is assumed" << std::endl;
         }
@@ -89,13 +89,13 @@
         
         if (qbk_version_n == 106)
         {
- detail::outwarn(actions.filename.string(),1)
+ detail::outwarn(actions.filename,1)
                 << "Quickbook 1.6 is still under development and is "
                 "likely to change in the future." << std::endl;
         }
         else if(qbk_version_n < 100 || qbk_version_n > 106)
         {
- detail::outerr(actions.filename.string(),1)
+ detail::outerr(actions.filename,1)
                 << "Unknown version of quickbook: quickbook "
                 << qbk_major_version
                 << "."
@@ -121,7 +121,7 @@
 
             if(!invalid_attributes.empty())
             {
- detail::outwarn(actions.filename.string(),1)
+ detail::outwarn(actions.filename,1)
                     << (invalid_attributes.size() > 1 ?
                         "Invalid attributes" : "Invalid attribute")
                     << " for '" << actions.doc_type << " document info': "

Modified: branches/quickbook-filenames/tools/quickbook/src/input_path.hpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/input_path.hpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/input_path.hpp 2011-01-23 11:44:32 EST (Sun, 23 Jan 2011)
@@ -9,6 +9,7 @@
 #if !defined(BOOST_QUICKBOOK_DETAIL_INPUT_PATH_HPP)
 #define BOOST_QUICKBOOK_DETAIL_INPUT_PATH_HPP
 
+#include <boost/filesystem/v3/path.hpp>
 #include <vector>
 #include <boost/any.hpp>
 #include <string>
@@ -29,7 +30,7 @@
     public:
         explicit input_path(char const* c) : path_(c) {}
         explicit input_path(std::string const& c) : path_(c) {}
- operator std::string() const { return path_; }
+ operator boost::filesystem::path() const { return boost::filesystem::path(path_); }
 
         friend void validate(boost::any&, const std::vector<std::string>&,
             input_path*, int);

Modified: branches/quickbook-filenames/tools/quickbook/src/quickbook.cpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/quickbook.cpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/quickbook.cpp 2011-01-23 11:44:32 EST (Sun, 23 Jan 2011)
@@ -16,11 +16,10 @@
 #include <boost/program_options.hpp>
 #include <boost/filesystem/v3/path.hpp>
 #include <boost/filesystem/v3/operations.hpp>
+#include <boost/filesystem/v3/fstream.hpp>
 #include <boost/ref.hpp>
 
 #include <stdexcept>
-#include <fstream>
-#include <iostream>
 #include <vector>
 
 #if (defined(BOOST_MSVC) && (BOOST_MSVC <= 1310))
@@ -38,7 +37,7 @@
     tm* current_gm_time; // the current UTC time
     bool debug_mode; // for quickbook developers only
     bool ms_errors = false; // output errors/warnings as if for VS
- std::vector<std::string> include_path;
+ std::vector<fs::path> include_path;
     std::vector<std::string> preset_defines;
 
     static void set_macros(actions& actor)
@@ -48,7 +47,7 @@
                 end = preset_defines.end();
                 it != end; ++it)
         {
- // TODO: Set filename in actor???
+ // TODO: Set filename in actor???
             iterator first(it->begin());
             iterator last(it->end());
 
@@ -63,7 +62,7 @@
     //
     ///////////////////////////////////////////////////////////////////////////
     int
- parse_file(char const* filein_, actions& actor, bool ignore_docinfo)
+ parse_file(fs::path const& filein_, actions& actor, bool ignore_docinfo)
     {
         using std::cerr;
         using std::vector;
@@ -94,7 +93,7 @@
 
         if (!info.full)
         {
- file_position const& pos = info.stop.get_position();
+ file_position const& pos = info.stop.get_position();
             detail::outerr(actor.filename, pos.line)
                 << "Syntax Error near column " << pos.column << ".\n";
             ++actor.error_count;
@@ -104,7 +103,7 @@
     }
 
     static int
- parse_document(char const* filein_, fs::path const& outdir, string_stream& out, bool ignore_docinfo = false)
+ parse_document(fs::path const& filein_, fs::path const& outdir, string_stream& out, bool ignore_docinfo = false)
     {
         actions actor(filein_, outdir, out);
 
@@ -126,14 +125,14 @@
 
     static int
     parse_document(
- char const* filein_
- , char const* fileout_
+ fs::path const& filein_
+ , fs::path const& fileout_
       , int indent
       , int linewidth
       , bool pretty_print)
     {
         int result = 0;
- fs::path outdir = fs::path(fileout_).parent_path();
+ fs::path outdir = fileout_.parent_path();
         if (outdir.empty())
             outdir = ".";
         string_stream buffer;
@@ -141,7 +140,7 @@
 
         if (result == 0)
         {
- std::ofstream fileout(fileout_);
+ fs::ofstream fileout(fileout_);
 
             if (pretty_print)
             {
@@ -258,7 +257,7 @@
                 = vm["include-path"].as<
                     std::vector<quickbook::detail::input_path> >();
             quickbook::include_path
- = std::vector<std::string>(paths.begin(), paths.end());
+ = std::vector<boost::filesystem::path>(paths.begin(), paths.end());
         }
 
         if (vm.count("define"))
@@ -269,9 +268,9 @@
 
         if (vm.count("input-file"))
         {
- std::string filein
- = vm["input-file"].as<quickbook::detail::input_path>();
- std::string fileout;
+ boost::filesystem::path filein(
+ vm["input-file"].as<quickbook::detail::input_path>());
+ boost::filesystem::path fileout;
 
             if (vm.count("output-file"))
             {
@@ -279,15 +278,15 @@
             }
             else
             {
- fileout = quickbook::detail::remove_extension(filein.c_str());
- fileout += ".xml";
+ fileout = filein;
+ fileout.replace_extension("xml");
             }
 
             std::cout << "Generating Output File: "
- << fileout
+ << fileout.string() // TODO
                 << std::endl;
 
- return quickbook::parse_document(filein.c_str(), fileout.c_str(), indent, linewidth, pretty_print);
+ return quickbook::parse_document(filein, fileout, indent, linewidth, pretty_print);
         }
         else
         {

Modified: branches/quickbook-filenames/tools/quickbook/src/quickbook.hpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/quickbook.hpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/quickbook.hpp 2011-01-23 11:44:32 EST (Sun, 23 Jan 2011)
@@ -15,6 +15,7 @@
 #include <time.h>
 #include <vector>
 #include <string>
+#include <boost/filesystem/path.hpp>
 #include "fwd.hpp"
 
 namespace quickbook
@@ -22,10 +23,10 @@
     extern tm* current_time; // the current time
     extern tm* current_gm_time; // the current UTC time
     extern bool debug_mode;
- extern std::vector<std::string> include_path;
+ extern std::vector<boost::filesystem::path> include_path;
     extern std::vector<std::string> preset_defines;
 
- int parse_file(char const* filein_, actions& actor, bool ignore_docinfo = false);
+ int parse_file(boost::filesystem::path const& filein_, actions& actor, bool ignore_docinfo = false);
 }
 
 #endif

Modified: branches/quickbook-filenames/tools/quickbook/src/utils.cpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/utils.cpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/utils.cpp 2011-01-23 11:44:32 EST (Sun, 23 Jan 2011)
@@ -9,6 +9,7 @@
 =============================================================================*/
 #include "utils.hpp"
 #include <boost/spirit/include/classic_core.hpp>
+#include <boost/filesystem/v3/fstream.hpp>
 
 #include <cctype>
 #include <cstring>
@@ -118,21 +119,6 @@
         }
     }
 
- // remove the extension from a filename
- std::string
- remove_extension(std::string const& filename)
- {
- std::string::size_type const n = filename.find_last_of('.');
- if(std::string::npos == n)
- {
- return filename;
- }
- else
- {
- return std::string(filename.begin(), filename.begin()+n);
- }
- }
-
     std::string escape_uri(std::string uri)
     {
         for (std::string::size_type n = 0; n < uri.size(); ++n)
@@ -243,7 +229,7 @@
 
     template <class InputIterator, class OutputIterator>
     bool normalize(InputIterator begin, InputIterator end,
- OutputIterator out, std::string const& filename)
+ OutputIterator out, boost::filesystem::path const& filename)
     {
         std::string encoding = read_bom(begin, end, out);
 
@@ -268,7 +254,7 @@
         return true;
     }
 
- int load(std::string const& filename, std::string& storage)
+ int load(boost::filesystem::path const& filename, std::string& storage)
     {
         using std::cerr;
         using std::endl;
@@ -276,7 +262,7 @@
         using std::ifstream;
         using std::istream_iterator;
 
- ifstream in(filename.c_str(), std::ios_base::in);
+ boost::filesystem::ifstream in(filename, std::ios_base::in);
 
         if (!in)
         {

Modified: branches/quickbook-filenames/tools/quickbook/src/utils.hpp
==============================================================================
--- branches/quickbook-filenames/tools/quickbook/src/utils.hpp (original)
+++ branches/quickbook-filenames/tools/quickbook/src/utils.hpp 2011-01-23 11:44:32 EST (Sun, 23 Jan 2011)
@@ -55,9 +55,6 @@
     // un-indent a code segment
     void unindent(std::string& program);
 
- // remove the extension from a filename
- std::string remove_extension(std::string const& filename);
-
     std::string escape_uri(std::string uri);
 
     // Preformats an error/warning message so that it can be parsed by
@@ -70,7 +67,7 @@
 
     // load file into memory with extra trailing newlines to eliminate
     // the need to check for end of file in the grammar.
- int load(std::string const& filename, std::string& storage);
+ int load(boost::filesystem::path const& filename, std::string& storage);
 
     // given a file extension, return the type of the source file
     // we'll have an internal database for known file types.


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk