123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352 |
- #ifndef BOOST_FILESYSTEM_PATH_TRAITS_HPP
- #define BOOST_FILESYSTEM_PATH_TRAITS_HPP
- #include <boost/config.hpp>
- # if defined( BOOST_NO_STD_WSTRING )
- # error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
- # endif
- #include <boost/filesystem/config.hpp>
- #include <boost/type_traits/is_array.hpp>
- #include <boost/type_traits/decay.hpp>
- #include <boost/system/error_code.hpp>
- #include <boost/core/enable_if.hpp>
- #include <cwchar> // for mbstate_t
- #include <string>
- #include <vector>
- #include <list>
- #include <iterator>
- #include <locale>
- #include <boost/assert.hpp>
- #include <boost/config/abi_prefix.hpp> // must be the last #include
- namespace boost { namespace filesystem {
- BOOST_FILESYSTEM_DECL const system::error_category& codecvt_error_category();
-
-
-
-
-
-
-
-
-
- class directory_entry;
- namespace path_traits {
- typedef std::codecvt<wchar_t, char, std::mbstate_t> codecvt_type;
-
- template <class T>
- struct is_pathable { static const bool value = false; };
- template<> struct is_pathable<char*> { static const bool value = true; };
- template<> struct is_pathable<const char*> { static const bool value = true; };
- template<> struct is_pathable<wchar_t*> { static const bool value = true; };
- template<> struct is_pathable<const wchar_t*> { static const bool value = true; };
- template<> struct is_pathable<std::string> { static const bool value = true; };
- template<> struct is_pathable<std::wstring> { static const bool value = true; };
- template<> struct is_pathable<std::vector<char> > { static const bool value = true; };
- template<> struct is_pathable<std::vector<wchar_t> > { static const bool value = true; };
- template<> struct is_pathable<std::list<char> > { static const bool value = true; };
- template<> struct is_pathable<std::list<wchar_t> > { static const bool value = true; };
- template<> struct is_pathable<directory_entry> { static const bool value = true; };
-
- template <class Container> inline
- // disable_if aids broken compilers (IBM, old GCC, etc.) and is harmless for
- // conforming compilers. Replace by plain "bool" at some future date (2012?)
- typename boost::disable_if<boost::is_array<Container>, bool>::type
- empty(const Container & c)
- { return c.begin() == c.end(); }
- template <class T> inline
- bool empty(T * const & c_str)
- {
- BOOST_ASSERT(c_str);
- return !*c_str;
- }
- template <typename T, size_t N> inline
- bool empty(T (&x)[N])
- { return !x[0]; }
-
-
-
-
- BOOST_FILESYSTEM_DECL
- void convert(const char* from,
- const char* from_end,
- std::wstring & to,
- const codecvt_type& cvt);
- BOOST_FILESYSTEM_DECL
- void convert(const wchar_t* from,
- const wchar_t* from_end,
- std::string & to,
- const codecvt_type& cvt);
- inline
- void convert(const char* from,
- std::wstring & to,
- const codecvt_type& cvt)
- {
- BOOST_ASSERT(from);
- convert(from, 0, to, cvt);
- }
- inline
- void convert(const wchar_t* from,
- std::string & to,
- const codecvt_type& cvt)
- {
- BOOST_ASSERT(from);
- convert(from, 0, to, cvt);
- }
-
- inline
- void convert(const char* from,
- const char* from_end,
- std::wstring & to);
- inline
- void convert(const wchar_t* from,
- const wchar_t* from_end,
- std::string & to);
- inline
- void convert(const char* from,
- std::wstring & to);
- inline
- void convert(const wchar_t* from,
- std::string & to);
-
-
- inline
- void convert(const char* from, const char* from_end, std::string & to,
- const codecvt_type&)
- {
- BOOST_ASSERT(from);
- BOOST_ASSERT(from_end);
- to.append(from, from_end);
- }
- inline
- void convert(const char* from,
- std::string & to,
- const codecvt_type&)
- {
- BOOST_ASSERT(from);
- to += from;
- }
-
- inline
- void convert(const wchar_t* from, const wchar_t* from_end, std::wstring & to,
- const codecvt_type&)
- {
- BOOST_ASSERT(from);
- BOOST_ASSERT(from_end);
- to.append(from, from_end);
- }
- inline
- void convert(const wchar_t* from,
- std::wstring & to,
- const codecvt_type&)
- {
- BOOST_ASSERT(from);
- to += from;
- }
-
- inline
- void convert(const char* from, const char* from_end, std::string & to)
- {
- BOOST_ASSERT(from);
- BOOST_ASSERT(from_end);
- to.append(from, from_end);
- }
- inline
- void convert(const char* from, std::string & to)
- {
- BOOST_ASSERT(from);
- to += from;
- }
-
- inline
- void convert(const wchar_t* from, const wchar_t* from_end, std::wstring & to)
- {
- BOOST_ASSERT(from);
- BOOST_ASSERT(from_end);
- to.append(from, from_end);
- }
- inline
- void convert(const wchar_t* from, std::wstring & to)
- {
- BOOST_ASSERT(from);
- to += from;
- }
-
-
- template <class U> inline
- void dispatch(const std::string& c, U& to, const codecvt_type& cvt)
- {
- if (!c.empty())
- convert(&*c.begin(), &*c.begin() + c.size(), to, cvt);
- }
- template <class U> inline
- void dispatch(const std::wstring& c, U& to, const codecvt_type& cvt)
- {
- if (!c.empty())
- convert(&*c.begin(), &*c.begin() + c.size(), to, cvt);
- }
- template <class U> inline
- void dispatch(const std::vector<char>& c, U& to, const codecvt_type& cvt)
- {
- if (!c.empty())
- convert(&*c.begin(), &*c.begin() + c.size(), to, cvt);
- }
- template <class U> inline
- void dispatch(const std::vector<wchar_t>& c, U& to, const codecvt_type& cvt)
- {
- if (!c.empty())
- convert(&*c.begin(), &*c.begin() + c.size(), to, cvt);
- }
-
- template <class U> inline
- void dispatch(const std::string& c, U& to)
- {
- if (!c.empty())
- convert(&*c.begin(), &*c.begin() + c.size(), to);
- }
- template <class U> inline
- void dispatch(const std::wstring& c, U& to)
- {
- if (!c.empty())
- convert(&*c.begin(), &*c.begin() + c.size(), to);
- }
- template <class U> inline
- void dispatch(const std::vector<char>& c, U& to)
- {
- if (!c.empty())
- convert(&*c.begin(), &*c.begin() + c.size(), to);
- }
- template <class U> inline
- void dispatch(const std::vector<wchar_t>& c, U& to)
- {
- if (!c.empty())
- convert(&*c.begin(), &*c.begin() + c.size(), to);
- }
-
- template <class Container, class U> inline
- // disable_if aids broken compilers (IBM, old GCC, etc.) and is harmless for
- // conforming compilers. Replace by plain "void" at some future date (2012?)
- typename boost::disable_if<boost::is_array<Container>, void>::type
- dispatch(const Container & c, U& to, const codecvt_type& cvt)
- {
- if (!c.empty())
- {
- std::basic_string<typename Container::value_type> s(c.begin(), c.end());
- convert(s.c_str(), s.c_str()+s.size(), to, cvt);
- }
- }
-
- template <class T, class U> inline
- void dispatch(T * const & c_str, U& to, const codecvt_type& cvt)
- {
-
- BOOST_ASSERT(c_str);
- convert(c_str, to, cvt);
- }
-
-
- BOOST_FILESYSTEM_DECL
- void dispatch(const directory_entry & de,
- # ifdef BOOST_WINDOWS_API
- std::wstring & to,
- # else
- std::string & to,
- # endif
- const codecvt_type&);
-
- template <class Container, class U> inline
- // disable_if aids broken compilers (IBM, old GCC, etc.) and is harmless for
- // conforming compilers. Replace by plain "void" at some future date (2012?)
- typename boost::disable_if<boost::is_array<Container>, void>::type
- dispatch(const Container & c, U& to)
- {
- if (!c.empty())
- {
- std::basic_string<typename Container::value_type> seq(c.begin(), c.end());
- convert(seq.c_str(), seq.c_str()+seq.size(), to);
- }
- }
-
- template <class T, class U> inline
- void dispatch(T * const & c_str, U& to)
- {
-
- BOOST_ASSERT(c_str);
- convert(c_str, to);
- }
-
-
- BOOST_FILESYSTEM_DECL
- void dispatch(const directory_entry & de,
- # ifdef BOOST_WINDOWS_API
- std::wstring & to
- # else
- std::string & to
- # endif
- );
- }}}
- #include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
- #endif
|