1 /*=============================================================================
2 Copyright (c) 2009 Daniel James
4 Use, modification and distribution is subject to the Boost Software
5 License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6 http://www.boost.org/LICENSE_1_0.txt)
7 =============================================================================*/
9 #if !defined(BOOST_QUICKBOOK_DETAIL_INPUT_PATH_HPP)
10 #define BOOST_QUICKBOOK_DETAIL_INPUT_PATH_HPP
12 #include <boost/config.hpp>
13 #include <boost/filesystem/v3/path.hpp>
19 #if defined(__cygwin__) || defined(__CYGWIN__)
20 # define QUICKBOOK_CYGWIN_PATHS 1
22 # define QUICKBOOK_WIDE_PATHS 1
23 # if defined(BOOST_MSVC) && BOOST_MSVC >= 1400
24 # define QUICKBOOK_WIDE_STREAMS 1
28 #if !defined(QUICKBOOK_WIDE_PATHS)
29 #define QUICKBOOK_WIDE_PATHS 0
32 #if !defined(QUICKBOOK_WIDE_STREAMS)
33 #define QUICKBOOK_WIDE_STREAMS 0
36 #if !defined(QUICKBOOK_CYGWIN_PATHS)
37 #define QUICKBOOK_CYGWIN_PATHS 0
42 namespace fs = boost::filesystem;
46 struct conversion_error : std::runtime_error
48 conversion_error(char const* m) : std::runtime_error(m) {}
51 // 'generic': Paths in quickbook source and the generated boostbook.
53 // 'input': Paths (or other parameters) from the command line and
54 // possibly other sources in the future. Wide strings on
55 // normal windows, UTF-8 for cygwin and other platforms
57 // 'stream': Strings to be written to a stream.
58 // 'path': Stored as a boost::filesystem::path. Since
59 // Boost.Filesystem doesn't support cygwin, this
60 // is always wide on windows. UTF-8 on other
61 // platforms (again, hopefully).
63 #if QUICKBOOK_WIDE_PATHS
64 typedef std::wstring input_string;
66 typedef std::string input_string;
69 #if QUICKBOOK_WIDE_STREAMS
70 typedef std::wostream ostream;
71 typedef std::wstring stream_string;
73 typedef std::ostream ostream;
74 typedef std::string stream_string;
77 std::string input_to_utf8(input_string const&);
78 fs::path input_to_path(input_string const&);
79 stream_string path_to_stream(fs::path const&);
81 std::string path_to_generic(fs::path const&);
82 fs::path generic_to_path(std::string const&);
84 void initialise_output();
88 // Preformats an error/warning message so that it can be parsed by
89 // common IDEs. Uses the ms_errors global to determine if VS format
90 // or GCC format. Returns the stream to continue ouput of the verbose
93 ostream& outerr(fs::path const& file, int line = -1);
94 ostream& outwarn(fs::path const& file, int line = -1);
95 ostream& outerr(file_ptr const&, string_iterator);
96 ostream& outwarn(file_ptr const&, string_iterator);
102 explicit utf8_proxy(std::string const& v) : value(v) {}
105 void write_utf8(ostream& out, std::string const&);
107 inline ostream& operator<<(ostream& out, utf8_proxy const& p) {
108 write_utf8(out, p.value);
112 inline utf8_proxy utf8(std::string const& value) {
113 return utf8_proxy(value);
116 template <typename It>
117 inline utf8_proxy utf8(It begin, It end) {
118 return utf8_proxy(std::string(begin, end));