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/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 // A light wrapper around C++'s streams that gets things right
70 // in the quickbook context.
72 // This is far from perfect but it fixes some issues.
75 #if QUICKBOOK_WIDE_STREAMS
76 typedef std::wostream base_ostream;
77 typedef std::wios base_ios;
78 typedef std::wstring string;
80 typedef std::ostream base_ostream;
81 typedef std::ios base_ios;
82 typedef std::string string;
86 explicit ostream(base_ostream& x) : base(x) {}
88 // C strings should always be ascii.
89 ostream& operator<<(char);
90 ostream& operator<<(char const*);
92 // std::string should be UTF-8 (what a mess!)
93 ostream& operator<<(std::string const&);
96 ostream& operator<<(int x);
97 ostream& operator<<(unsigned int x);
98 ostream& operator<<(long x);
99 ostream& operator<<(unsigned long x);
100 ostream& operator<<(fs::path const&);
103 ostream& operator<<(base_ostream& (*)(base_ostream&));
104 ostream& operator<<(base_ios& (*)(base_ios&));
108 std::string input_to_utf8(input_string const&);
109 fs::path input_to_path(input_string const&);
111 std::string path_to_generic(fs::path const&);
112 fs::path generic_to_path(std::string const&);
114 void initialise_output();
118 // Preformats an error/warning message so that it can be parsed by
119 // common IDEs. Uses the ms_errors global to determine if VS format
120 // or GCC format. Returns the stream to continue ouput of the verbose
123 ostream& outerr(fs::path const& file, int line = -1);
124 ostream& outwarn(fs::path const& file, int line = -1);
125 ostream& outerr(file_ptr const&, string_iterator);
126 ostream& outwarn(file_ptr const&, string_iterator);