123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214 |
- #ifndef BOOST_IOSTREAMS_DETAIL_PATH_HPP_INCLUDED
- #define BOOST_IOSTREAMS_DETAIL_PATH_HPP_INCLUDED
- #include <cstring>
- #include <string>
- #include <boost/iostreams/detail/config/wide_streams.hpp>
- #ifndef BOOST_IOSTREAMS_NO_WIDE_STREAMS
- # include <cwchar>
- #endif
- #include <boost/static_assert.hpp>
- #include <boost/type.hpp>
- #include <boost/type_traits/is_same.hpp>
- namespace boost { namespace iostreams { namespace detail {
- #ifndef BOOST_IOSTREAMS_NO_WIDE_STREAMS
- class path {
- template<typename T, typename V>
- struct sfinae
- {
- typedef V type;
- };
- public:
-
- path() : narrow_(), wide_(), is_wide_(false) { }
-
- path(const std::string& p) : narrow_(p), wide_(), is_wide_(false) { }
-
- path(const char* p) : narrow_(p), wide_(), is_wide_(false) { }
-
-
- template<typename Path>
- explicit path(const Path& p, typename Path::external_string_type* = 0)
- {
- init(p.external_file_string());
- }
-
- template<typename Path>
- explicit path(const Path& p, typename Path::codecvt_type* = 0)
- {
- init(p.native());
- }
-
- path(const path& p)
- : narrow_(p.narrow_), wide_(p.wide_), is_wide_(p.is_wide_)
- { }
-
- path& operator=(const path& p)
- {
- narrow_ = p.narrow_;
- wide_ = p.wide_;
- is_wide_ = p.is_wide_;
- return *this;
- }
-
- path& operator=(const std::string& p)
- {
- narrow_ = p;
- wide_.clear();
- is_wide_ = false;
- return *this;
- }
-
- path& operator=(const char* p)
- {
- narrow_.assign(p);
- wide_.clear();
- is_wide_ = false;
- return *this;
- }
- #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1400)
-
-
-
-
-
- template<typename Path>
- typename sfinae<typename Path::external_string_type, path&>::type
- operator=(const Path& p)
- {
- init(p.external_file_string());
- return *this;
- }
- #endif
-
- template<typename Path>
- typename sfinae<typename Path::codecvt_type, path&>::type
- operator=(const Path& p)
- {
- init(p.native());
- return *this;
- }
- bool is_wide() const { return is_wide_; }
-
-
- const char* c_str() const { return narrow_.c_str(); }
-
-
- const wchar_t* c_wstr() const { return wide_.c_str(); }
- private:
-
-
-
- path(const std::wstring&);
- path& operator=(const std::wstring&);
- void init(std::string const& file_path)
- {
- narrow_ = file_path;
- wide_.clear();
- is_wide_ = false;
- }
- void init(std::wstring const& file_path)
- {
- narrow_.clear();
- wide_ = file_path;
- is_wide_ = true;
- }
- std::string narrow_;
- std::wstring wide_;
- bool is_wide_;
- };
- inline bool operator==(const path& lhs, const path& rhs)
- {
- return lhs.is_wide() ?
- rhs.is_wide() && std::wcscmp(lhs.c_wstr(), rhs.c_wstr()) == 0 :
- !rhs.is_wide() && std::strcmp(lhs.c_str(), rhs.c_str()) == 0;
- }
- #else
- class path {
- public:
- path() { }
- path(const std::string& p) : path_(p) { }
- path(const char* p) : path_(p) { }
- template<typename Path>
- path(const Path& p) : path_(p.external_file_string()) { }
- path(const path& p) : path_(p.path_) { }
- path& operator=(const path& other)
- {
- path_ = other.path_;
- return *this;
- }
- path& operator=(const std::string& p)
- {
- path_ = p;
- return *this;
- }
- path& operator=(const char* p)
- {
- path_ = p;
- return *this;
- }
- template<typename Path>
- path& operator=(const Path& p)
- {
- path_ = p.external_file_string();
- return *this;
- }
- bool is_wide() const { return false; }
- const char* c_str() const { return path_.c_str(); }
- const wchar_t* c_wstr() const { return 0; }
- private:
- std::string path_;
- };
- inline bool operator==(const path& lhs, const path& rhs)
- {
- return std::strcmp(lhs.c_str(), rhs.c_str()) == 0 ;
- }
- #endif
- } } }
- #endif
|