Imported Upstream version 1.49.0
[platform/upstream/boost.git] / tools / quickbook / src / input_path.hpp
1 /*=============================================================================
2     Copyright (c) 2009 Daniel James
3
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 =============================================================================*/
8
9 #if !defined(BOOST_QUICKBOOK_DETAIL_INPUT_PATH_HPP)
10 #define BOOST_QUICKBOOK_DETAIL_INPUT_PATH_HPP
11
12 #include <boost/config.hpp>
13 #include <boost/filesystem/v3/path.hpp>
14 #include <string>
15 #include <stdexcept>
16 #include <iostream>
17 #include "fwd.hpp"
18
19 #if defined(__cygwin__) || defined(__CYGWIN__)
20 #   define QUICKBOOK_CYGWIN_PATHS 1
21 #elif defined(_WIN32)
22 #   define QUICKBOOK_WIDE_PATHS 1
23 #   if defined(BOOST_MSVC) && BOOST_MSVC >= 1400
24 #       define QUICKBOOK_WIDE_STREAMS 1
25 #   endif
26 #endif
27
28 #if !defined(QUICKBOOK_WIDE_PATHS)
29 #define QUICKBOOK_WIDE_PATHS 0
30 #endif
31
32 #if !defined(QUICKBOOK_WIDE_STREAMS)
33 #define QUICKBOOK_WIDE_STREAMS 0
34 #endif
35
36 #if !defined(QUICKBOOK_CYGWIN_PATHS)
37 #define QUICKBOOK_CYGWIN_PATHS 0
38 #endif
39
40 namespace quickbook
41 {
42     namespace fs = boost::filesystem;
43
44     namespace detail
45     {
46         struct conversion_error : std::runtime_error
47         {
48             conversion_error(char const* m) : std::runtime_error(m) {}
49         };
50
51         // 'generic':   Paths in quickbook source and the generated boostbook.
52         //              Always UTF-8.
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
56         //              (hopefully).
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).
62     
63 #if QUICKBOOK_WIDE_PATHS
64         typedef std::wstring input_string;
65 #else
66         typedef std::string input_string;
67 #endif
68
69 #if QUICKBOOK_WIDE_STREAMS
70         typedef std::wostream ostream;
71         typedef std::wstring stream_string;
72 #else
73         typedef std::ostream ostream;
74         typedef std::string stream_string;
75 #endif
76
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&);
80     
81         std::string path_to_generic(fs::path const&);
82         fs::path generic_to_path(std::string const&);
83
84         void initialise_output();
85         
86         ostream& out();
87
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
91         // error message.
92         ostream& outerr();
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);
97         
98         struct utf8_proxy
99         {
100             std::string value;
101             
102             explicit utf8_proxy(std::string const& v) : value(v) {}
103         };
104
105         void write_utf8(ostream& out, std::string const&);
106         
107         inline ostream& operator<<(ostream& out, utf8_proxy const& p) {
108             write_utf8(out, p.value);
109             return out;
110         }
111
112         inline utf8_proxy utf8(std::string const& value) {
113             return utf8_proxy(value);
114         }
115
116         template <typename It>
117         inline utf8_proxy utf8(It begin, It end) {
118             return utf8_proxy(std::string(begin, end));
119         }
120     }
121 }
122
123 #endif