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 // For handling native strings and streams.
11 #if !defined(BOOST_QUICKBOOK_DETAIL_NATIVE_TEXT_HPP)
12 #define BOOST_QUICKBOOK_DETAIL_NATIVE_TEXT_HPP
14 #include <boost/config.hpp>
15 #include <boost/filesystem/path.hpp>
16 #include <boost/utility/string_ref.hpp>
22 #if defined(__cygwin__) || defined(__CYGWIN__)
23 # define QUICKBOOK_CYGWIN_PATHS 1
25 # define QUICKBOOK_WIDE_PATHS 1
26 # if defined(BOOST_MSVC) && BOOST_MSVC >= 1400
27 # define QUICKBOOK_WIDE_STREAMS 1
31 #if !defined(QUICKBOOK_WIDE_PATHS)
32 #define QUICKBOOK_WIDE_PATHS 0
35 #if !defined(QUICKBOOK_WIDE_STREAMS)
36 #define QUICKBOOK_WIDE_STREAMS 0
39 #if !defined(QUICKBOOK_CYGWIN_PATHS)
40 #define QUICKBOOK_CYGWIN_PATHS 0
45 namespace fs = boost::filesystem;
49 struct conversion_error : std::runtime_error
51 conversion_error(char const* m) : std::runtime_error(m) {}
54 // 'generic': Paths in quickbook source and the generated boostbook.
57 // Paths (or other parameters) from the command line and
58 // possibly other sources in the future. Wide strings on
59 // normal windows, UTF-8 for cygwin and other platforms
61 // 'path': Stored as a boost::filesystem::path. Since
62 // Boost.Filesystem doesn't support cygwin, this
63 // is always wide on windows. UTF-8 on other
64 // platforms (again, hopefully).
66 #if QUICKBOOK_WIDE_PATHS
67 typedef std::wstring command_line_string;
68 typedef boost::wstring_ref command_line_string_ref;
70 typedef std::string command_line_string;
71 typedef boost::string_ref command_line_string_ref;
74 // A light wrapper around C++'s streams that gets things right
75 // in the quickbook context.
77 // This is far from perfect but it fixes some issues.
80 #if QUICKBOOK_WIDE_STREAMS
81 typedef std::wostream base_ostream;
82 typedef std::wios base_ios;
83 typedef std::wstring string;
84 typedef boost::wstring_ref string_ref;
86 typedef std::ostream base_ostream;
87 typedef std::ios base_ios;
88 typedef std::string string;
89 typedef boost::string_ref string_ref;
93 explicit ostream(base_ostream& x) : base(x) {}
95 // C strings should always be ascii.
96 ostream& operator<<(char);
97 ostream& operator<<(char const*);
99 // std::string should be UTF-8 (what a mess!)
100 ostream& operator<<(std::string const&);
101 ostream& operator<<(boost::string_ref);
103 // Other value types.
104 ostream& operator<<(int x);
105 ostream& operator<<(unsigned int x);
106 ostream& operator<<(long x);
107 ostream& operator<<(unsigned long x);
109 #if !defined(BOOST_NO_LONG_LONG)
110 ostream& operator<<(long long x);
111 ostream& operator<<(unsigned long long x);
114 ostream& operator<<(fs::path const&);
117 ostream& operator<<(base_ostream& (*)(base_ostream&));
118 ostream& operator<<(base_ios& (*)(base_ios&));
122 std::string command_line_to_utf8(command_line_string const&);
123 fs::path command_line_to_path(command_line_string const&);
125 std::string path_to_generic(fs::path const&);
126 fs::path generic_to_path(boost::string_ref);
128 void initialise_output();
132 // Preformats an error/warning message so that it can be parsed by
133 // common IDEs. Set 'ms_errors' to determine if VS format
134 // or GCC format. Returns the stream to continue ouput of the verbose
136 void set_ms_errors(bool);
138 ostream& outerr(fs::path const& file, int line = -1);
139 ostream& outwarn(fs::path const& file, int line = -1);
140 ostream& outerr(file_ptr const&, string_iterator);
141 ostream& outwarn(file_ptr const&, string_iterator);