Adding Boost.Filesystem to BoostParts

This commit is contained in:
Strahinja Val Markovic 2012-07-22 15:09:50 -07:00
parent 6f0dc0b21d
commit b703138cac
20 changed files with 6569 additions and 1 deletions

View File

@ -19,7 +19,7 @@
# the BCP tool:
# http://www.boost.org/doc/libs/1_49_0/tools/bcp/doc/html/index.html
#
# bcp call: bcp boost/python.hpp boost/bind.hpp boost/lambda/lambda.hpp boost/exception/all.hpp boost/tuple/tuple_io.hpp boost/tuple/tuple_comparison.hpp boost/regex.hpp boost/foreach.hpp boost/smart_ptr.hpp boost/algorithm/string_regex.hpp boost/thread.hpp boost/unordered_map.hpp boost/unordered_set.hpp boost/format.hpp boost/ptr_container/ptr_container.hpp ../BoostParts
# bcp call: bcp boost/python.hpp boost/bind.hpp boost/lambda/lambda.hpp boost/exception/all.hpp boost/tuple/tuple_io.hpp boost/tuple/tuple_comparison.hpp boost/regex.hpp boost/foreach.hpp boost/smart_ptr.hpp boost/algorithm/string_regex.hpp boost/thread.hpp boost/unordered_map.hpp boost/unordered_set.hpp boost/format.hpp boost/ptr_container/ptr_container.hpp boost/filesystem.hpp boost/filesystem/fstream.hpp ../BoostParts
# WARNING: When doing this from fresh boost sources, note that in the file
# /boost/config/user.hpp the BOOST_ALL_NO_LIB define has been uncommented.

View File

@ -0,0 +1,47 @@
// boost/detail/bitmask.hpp ------------------------------------------------//
// Copyright Beman Dawes 2006
// Distributed under the Boost Software License, Version 1.0
// http://www.boost.org/LICENSE_1_0.txt
// Usage: enum foo { a=1, b=2, c=4 };
// BOOST_BITMASK( foo );
//
// void f( foo arg );
// ...
// f( a | c );
#ifndef BOOST_BITMASK_HPP
#define BOOST_BITMASK_HPP
#include <boost/cstdint.hpp>
#define BOOST_BITMASK(Bitmask) \
\
inline Bitmask operator| (Bitmask x , Bitmask y ) \
{ return static_cast<Bitmask>( static_cast<boost::int_least32_t>(x) \
| static_cast<boost::int_least32_t>(y)); } \
\
inline Bitmask operator& (Bitmask x , Bitmask y ) \
{ return static_cast<Bitmask>( static_cast<boost::int_least32_t>(x) \
& static_cast<boost::int_least32_t>(y)); } \
\
inline Bitmask operator^ (Bitmask x , Bitmask y ) \
{ return static_cast<Bitmask>( static_cast<boost::int_least32_t>(x) \
^ static_cast<boost::int_least32_t>(y)); } \
\
inline Bitmask operator~ (Bitmask x ) \
{ return static_cast<Bitmask>(~static_cast<boost::int_least32_t>(x)); } \
\
inline Bitmask & operator&=(Bitmask & x , Bitmask y) \
{ x = x & y ; return x ; } \
\
inline Bitmask & operator|=(Bitmask & x , Bitmask y) \
{ x = x | y ; return x ; } \
\
inline Bitmask & operator^=(Bitmask & x , Bitmask y) \
{ x = x ^ y ; return x ; }
#endif // BOOST_BITMASK_HPP

View File

@ -0,0 +1,20 @@
// boost/filesystem.hpp --------------------------------------------------------------//
// Copyright Beman Dawes 2010
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// Library home page: http://www.boost.org/libs/filesystem
//--------------------------------------------------------------------------------------//
#ifndef BOOST_FILESYSTEM_FILESYSTEM_HPP
#define BOOST_FILESYSTEM_FILESYSTEM_HPP
# include <boost/filesystem/config.hpp>
# include <boost/filesystem/path.hpp>
# include <boost/filesystem/operations.hpp>
# include <boost/filesystem/convenience.hpp>
#endif // BOOST_FILESYSTEM_FILESYSTEM_HPP

View File

@ -0,0 +1,109 @@
// boost/filesystem/v3/config.hpp ----------------------------------------------------//
// Copyright Beman Dawes 2003
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// Library home page: http://www.boost.org/libs/filesystem
//--------------------------------------------------------------------------------------//
#ifndef BOOST_FILESYSTEM3_CONFIG_HPP
#define BOOST_FILESYSTEM3_CONFIG_HPP
# if defined(BOOST_FILESYSTEM_VERSION) && BOOST_FILESYSTEM_VERSION != 3
# error Compiling Filesystem version 3 file with BOOST_FILESYSTEM_VERSION defined != 3
# endif
# if !defined(BOOST_FILESYSTEM_VERSION)
# define BOOST_FILESYSTEM_VERSION 3
# endif
#define BOOST_FILESYSTEM_I18N // aid users wishing to compile several versions
// This header implements separate compilation features as described in
// http://www.boost.org/more/separate_compilation.html
#include <boost/config.hpp>
#include <boost/system/api_config.hpp> // for BOOST_POSIX_API or BOOST_WINDOWS_API
#include <boost/detail/workaround.hpp>
// BOOST_FILESYSTEM_DEPRECATED needed for source compiles -----------------------------//
# ifdef BOOST_FILESYSTEM_SOURCE
# define BOOST_FILESYSTEM_DEPRECATED
# endif
// throw an exception ----------------------------------------------------------------//
//
// Exceptions were originally thrown via boost::throw_exception().
// As throw_exception() became more complex, it caused user error reporting
// to be harder to interpret, since the exception reported became much more complex.
// The immediate fix was to throw directly, wrapped in a macro to make any later change
// easier.
#define BOOST_FILESYSTEM_THROW(EX) throw EX
# if defined( BOOST_NO_STD_WSTRING )
# error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
# endif
// This header implements separate compilation features as described in
// http://www.boost.org/more/separate_compilation.html
// normalize macros ------------------------------------------------------------------//
#if !defined(BOOST_FILESYSTEM_DYN_LINK) && !defined(BOOST_FILESYSTEM_STATIC_LINK) \
&& !defined(BOOST_ALL_DYN_LINK) && !defined(BOOST_ALL_STATIC_LINK)
# define BOOST_FILESYSTEM_STATIC_LINK
#endif
#if defined(BOOST_ALL_DYN_LINK) && !defined(BOOST_FILESYSTEM_DYN_LINK)
# define BOOST_FILESYSTEM_DYN_LINK
#elif defined(BOOST_ALL_STATIC_LINK) && !defined(BOOST_FILESYSTEM_STATIC_LINK)
# define BOOST_FILESYSTEM_STATIC_LINK
#endif
#if defined(BOOST_FILESYSTEM_DYN_LINK) && defined(BOOST_FILESYSTEM_STATIC_LINK)
# error Must not define both BOOST_FILESYSTEM_DYN_LINK and BOOST_FILESYSTEM_STATIC_LINK
#endif
#if defined(BOOST_ALL_NO_LIB) && !defined(BOOST_FILESYSTEM_NO_LIB)
# define BOOST_FILESYSTEM_NO_LIB
#endif
// enable dynamic linking ------------------------------------------------------------//
#if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_FILESYSTEM_DYN_LINK)
# if defined(BOOST_FILESYSTEM_SOURCE)
# define BOOST_FILESYSTEM_DECL BOOST_SYMBOL_EXPORT
# else
# define BOOST_FILESYSTEM_DECL BOOST_SYMBOL_IMPORT
# endif
#else
# define BOOST_FILESYSTEM_DECL
#endif
// enable automatic library variant selection ----------------------------------------//
#if !defined(BOOST_FILESYSTEM_SOURCE) && !defined(BOOST_ALL_NO_LIB) \
&& !defined(BOOST_FILESYSTEM_NO_LIB)
//
// Set the name of our library, this will get undef'ed by auto_link.hpp
// once it's done with it:
//
#define BOOST_LIB_NAME boost_filesystem
//
// If we're importing code from a dll, then tell auto_link.hpp about it:
//
#if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_FILESYSTEM_DYN_LINK)
# define BOOST_DYN_LINK
#endif
//
// And include the header that does the work:
//
#include <boost/config/auto_link.hpp>
#endif // auto-linking disabled
#endif // BOOST_FILESYSTEM3_CONFIG_HPP

View File

@ -0,0 +1,58 @@
// boost/filesystem/convenience.hpp ----------------------------------------//
// Copyright Beman Dawes, 2002-2005
// Copyright Vladimir Prus, 2002
// Use, modification, and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See library home page at http://www.boost.org/libs/filesystem
//----------------------------------------------------------------------------//
#ifndef BOOST_FILESYSTEM3_CONVENIENCE_HPP
#define BOOST_FILESYSTEM3_CONVENIENCE_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/operations.hpp>
#include <boost/system/error_code.hpp>
#include <boost/config/abi_prefix.hpp> // must be the last #include
namespace boost
{
namespace filesystem
{
# ifndef BOOST_FILESYSTEM_NO_DEPRECATED
inline std::string extension(const path & p)
{
return p.extension().string();
}
inline std::string basename(const path & p)
{
return p.stem().string();
}
inline path change_extension( const path & p, const path & new_extension )
{
path new_p( p );
new_p.replace_extension( new_extension );
return new_p;
}
# endif
} // namespace filesystem
} // namespace boost
#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
#endif // BOOST_FILESYSTEM3_CONVENIENCE_HPP

View File

@ -0,0 +1,24 @@
// Copyright (c) 2001 Ronald Garcia, Indiana University (garcia@osl.iu.edu)
// Andrew Lumsdaine, Indiana University (lums@osl.iu.edu).
// Distributed under the Boost Software License, Version 1.0.
// (See http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_FILESYSTEM_UTF8_CODECVT_FACET_HPP
#define BOOST_FILESYSTEM_UTF8_CODECVT_FACET_HPP
#include <boost/filesystem/config.hpp>
#define BOOST_UTF8_BEGIN_NAMESPACE \
namespace boost { namespace filesystem { namespace detail {
#define BOOST_UTF8_END_NAMESPACE }}}
#define BOOST_UTF8_DECL BOOST_FILESYSTEM_DECL
#include <boost/detail/utf8_codecvt_facet.hpp>
#undef BOOST_UTF8_BEGIN_NAMESPACE
#undef BOOST_UTF8_END_NAMESPACE
#undef BOOST_UTF8_DECL
#endif

View File

@ -0,0 +1,182 @@
// boost/filesystem/fstream.hpp ------------------------------------------------------//
// Copyright Beman Dawes 2002
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// Library home page: http://www.boost.org/libs/filesystem
//--------------------------------------------------------------------------------------//
#ifndef BOOST_FILESYSTEM3_FSTREAM_HPP
#define BOOST_FILESYSTEM3_FSTREAM_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/path.hpp>
#include <iosfwd>
#include <fstream>
#include <boost/config/abi_prefix.hpp> // must be the last #include
// on Windows, except for standard libaries known to have wchar_t overloads for
// file stream I/O, use path::string() to get a narrow character c_str()
#if defined(BOOST_WINDOWS_API) \
&& (!defined(_CPPLIB_VER) || _CPPLIB_VER < 405 || defined(_STLPORT_VERSION))
// !Dinkumware || early Dinkumware || STLPort masquerading as Dinkumware
# define BOOST_FILESYSTEM_C_STR string().c_str() // use narrow, since wide not available
#else // use the native c_str, which will be narrow on POSIX, wide on Windows
# define BOOST_FILESYSTEM_C_STR c_str()
#endif
namespace boost
{
namespace filesystem
{
//--------------------------------------------------------------------------------------//
// basic_filebuf //
//--------------------------------------------------------------------------------------//
template < class charT, class traits = std::char_traits<charT> >
class basic_filebuf : public std::basic_filebuf<charT,traits>
{
private: // disallow copying
basic_filebuf(const basic_filebuf&);
const basic_filebuf& operator=(const basic_filebuf&);
public:
basic_filebuf() {}
virtual ~basic_filebuf() {}
basic_filebuf<charT,traits>*
open(const path& p, std::ios_base::openmode mode)
{
return std::basic_filebuf<charT,traits>::open(p.BOOST_FILESYSTEM_C_STR, mode)
? this : 0;
}
};
//--------------------------------------------------------------------------------------//
// basic_ifstream //
//--------------------------------------------------------------------------------------//
template < class charT, class traits = std::char_traits<charT> >
class basic_ifstream : public std::basic_ifstream<charT,traits>
{
private: // disallow copying
basic_ifstream(const basic_ifstream&);
const basic_ifstream& operator=(const basic_ifstream&);
public:
basic_ifstream() {}
// use two signatures, rather than one signature with default second
// argument, to workaround VC++ 7.1 bug (ID VSWhidbey 38416)
explicit basic_ifstream(const path& p)
: std::basic_ifstream<charT,traits>(p.BOOST_FILESYSTEM_C_STR, std::ios_base::in) {}
basic_ifstream(const path& p, std::ios_base::openmode mode)
: std::basic_ifstream<charT,traits>(p.BOOST_FILESYSTEM_C_STR, mode) {}
void open(const path& p)
{ std::basic_ifstream<charT,traits>::open(p.BOOST_FILESYSTEM_C_STR, std::ios_base::in); }
void open(const path& p, std::ios_base::openmode mode)
{ std::basic_ifstream<charT,traits>::open(p.BOOST_FILESYSTEM_C_STR, mode); }
virtual ~basic_ifstream() {}
};
//--------------------------------------------------------------------------------------//
// basic_ofstream //
//--------------------------------------------------------------------------------------//
template < class charT, class traits = std::char_traits<charT> >
class basic_ofstream : public std::basic_ofstream<charT,traits>
{
private: // disallow copying
basic_ofstream(const basic_ofstream&);
const basic_ofstream& operator=(const basic_ofstream&);
public:
basic_ofstream() {}
// use two signatures, rather than one signature with default second
// argument, to workaround VC++ 7.1 bug (ID VSWhidbey 38416)
explicit basic_ofstream(const path& p)
: std::basic_ofstream<charT,traits>(p.BOOST_FILESYSTEM_C_STR, std::ios_base::out) {}
basic_ofstream(const path& p, std::ios_base::openmode mode)
: std::basic_ofstream<charT,traits>(p.BOOST_FILESYSTEM_C_STR, mode) {}
void open(const path& p)
{ std::basic_ofstream<charT,traits>::open(p.BOOST_FILESYSTEM_C_STR, std::ios_base::out); }
void open(const path& p, std::ios_base::openmode mode)
{ std::basic_ofstream<charT,traits>::open(p.BOOST_FILESYSTEM_C_STR, mode); }
virtual ~basic_ofstream() {}
};
//--------------------------------------------------------------------------------------//
// basic_fstream //
//--------------------------------------------------------------------------------------//
template < class charT, class traits = std::char_traits<charT> >
class basic_fstream : public std::basic_fstream<charT,traits>
{
private: // disallow copying
basic_fstream(const basic_fstream&);
const basic_fstream & operator=(const basic_fstream&);
public:
basic_fstream() {}
// use two signatures, rather than one signature with default second
// argument, to workaround VC++ 7.1 bug (ID VSWhidbey 38416)
explicit basic_fstream(const path& p)
: std::basic_fstream<charT,traits>(p.BOOST_FILESYSTEM_C_STR,
std::ios_base::in | std::ios_base::out) {}
basic_fstream(const path& p, std::ios_base::openmode mode)
: std::basic_fstream<charT,traits>(p.BOOST_FILESYSTEM_C_STR, mode) {}
void open(const path& p)
{ std::basic_fstream<charT,traits>::open(p.BOOST_FILESYSTEM_C_STR,
std::ios_base::in | std::ios_base::out); }
void open(const path& p, std::ios_base::openmode mode)
{ std::basic_fstream<charT,traits>::open(p.BOOST_FILESYSTEM_C_STR, mode); }
virtual ~basic_fstream() {}
};
//--------------------------------------------------------------------------------------//
// typedefs //
//--------------------------------------------------------------------------------------//
typedef basic_filebuf<char> filebuf;
typedef basic_ifstream<char> ifstream;
typedef basic_ofstream<char> ofstream;
typedef basic_fstream<char> fstream;
typedef basic_filebuf<wchar_t> wfilebuf;
typedef basic_ifstream<wchar_t> wifstream;
typedef basic_ofstream<wchar_t> wofstream;
typedef basic_fstream<wchar_t> wfstream;
} // namespace filesystem
} // namespace boost
#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
#endif // BOOST_FILESYSTEM3_FSTREAM_HPP

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,758 @@
// filesystem path.hpp ---------------------------------------------------------------//
// Copyright Beman Dawes 2002-2005, 2009
// Copyright Vladimir Prus 2002
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// Library home page: http://www.boost.org/libs/filesystem
// path::stem(), extension(), and replace_extension() are based on
// basename(), extension(), and change_extension() from the original
// filesystem/convenience.hpp header by Vladimir Prus.
#ifndef BOOST_FILESYSTEM_PATH_HPP
#define BOOST_FILESYSTEM_PATH_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/filesystem/path_traits.hpp> // includes <cwchar>
#include <boost/system/error_code.hpp>
#include <boost/system/system_error.hpp>
#include <boost/iterator/iterator_facade.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/io/detail/quoted_manip.hpp>
#include <boost/static_assert.hpp>
#include <boost/functional/hash_fwd.hpp>
#include <boost/type_traits/is_integral.hpp>
#include <string>
#include <iterator>
#include <cstring>
#include <iosfwd>
#include <stdexcept>
#include <cassert>
#include <locale>
#include <algorithm>
#include <boost/config/abi_prefix.hpp> // must be the last #include
namespace boost
{
namespace filesystem
{
//------------------------------------------------------------------------------------//
// //
// class path //
// //
//------------------------------------------------------------------------------------//
class BOOST_FILESYSTEM_DECL path
{
public:
// value_type is the character type used by the operating system API to
// represent paths.
# ifdef BOOST_WINDOWS_API
typedef wchar_t value_type;
BOOST_STATIC_CONSTEXPR value_type preferred_separator = L'\\';
# else
typedef char value_type;
BOOST_STATIC_CONSTEXPR value_type preferred_separator = '/';
# endif
typedef std::basic_string<value_type> string_type;
typedef std::codecvt<wchar_t, char,
std::mbstate_t> codecvt_type;
// ----- character encoding conversions -----
// Following the principle of least astonishment, path input arguments
// passed to or obtained from the operating system via objects of
// class path behave as if they were directly passed to or
// obtained from the O/S API, unless conversion is explicitly requested.
//
// POSIX specfies that path strings are passed unchanged to and from the
// API. Note that this is different from the POSIX command line utilities,
// which convert according to a locale.
//
// Thus for POSIX, char strings do not undergo conversion. wchar_t strings
// are converted to/from char using the path locale or, if a conversion
// argument is given, using a conversion object modeled on
// std::wstring_convert.
//
// The path locale, which is global to the thread, can be changed by the
// imbue() function. It is initialized to an implementation defined locale.
//
// For Windows, wchar_t strings do not undergo conversion. char strings
// are converted using the "ANSI" or "OEM" code pages, as determined by
// the AreFileApisANSI() function, or, if a conversion argument is given,
// using a conversion object modeled on std::wstring_convert.
//
// See m_pathname comments for further important rationale.
// TODO: rules needed for operating systems that use / or .
// differently, or format directory paths differently from file paths.
//
// **********************************************************************************
//
// More work needed: How to handle an operating system that may have
// slash characters or dot characters in valid filenames, either because
// it doesn't follow the POSIX standard, or because it allows MBCS
// filename encodings that may contain slash or dot characters. For
// example, ISO/IEC 2022 (JIS) encoding which allows switching to
// JIS x0208-1983 encoding. A valid filename in this set of encodings is
// 0x1B 0x24 0x42 [switch to X0208-1983] 0x24 0x2F [U+304F Kiragana letter KU]
// ^^^^
// Note that 0x2F is the ASCII slash character
//
// **********************************************************************************
// Supported source arguments: half-open iterator range, container, c-array,
// and single pointer to null terminated string.
// All source arguments except pointers to null terminated byte strings support
// multi-byte character strings which may have embedded nulls. Embedded null
// support is required for some Asian languages on Windows.
// [defaults] "const codecvt_type& cvt=codecvt()" default arguments are not used
// because some compilers, such as Microsoft prior to VC++ 10, do not handle defaults
// correctly in templates.
// ----- constructors -----
path(){}
path(const path& p) : m_pathname(p.m_pathname) {}
template <class Source>
path(Source const& source,
typename boost::enable_if<path_traits::is_pathable<
typename boost::decay<Source>::type> >::type* =0)
{
path_traits::dispatch(source, m_pathname, codecvt());
}
// Overloads for the operating system API's native character type. Rationale:
// - Avoids use of codecvt() for native value_type strings. This limits the
// impact of locale("") initialization failures on POSIX systems to programs
// that actually depend on locale(""). It further ensures that exceptions thrown
// as a result of such failues occur after main() has started, so can be caught.
// This is a partial resolution of tickets 4688, 5100, and 5289.
// - A slight optimization for a common use case, particularly on POSIX since
// value_type is char and that is the most common useage.
path(const value_type* s) : m_pathname(s) {}
path(const std::basic_string<value_type>& s) : m_pathname(s) {}
template <class Source>
path(Source const& source, const codecvt_type& cvt)
// see [defaults] note above explaining why codecvt() default arguments are not used
{
path_traits::dispatch(source, m_pathname, cvt);
}
template <class InputIterator>
path(InputIterator begin, InputIterator end)
{
if (begin != end)
{
std::basic_string<typename std::iterator_traits<InputIterator>::value_type>
s(begin, end);
path_traits::convert(s.c_str(), s.c_str()+s.size(), m_pathname, codecvt());
}
}
template <class InputIterator>
path(InputIterator begin, InputIterator end, const codecvt_type& cvt)
{
if (begin != end)
{
std::basic_string<typename std::iterator_traits<InputIterator>::value_type>
s(begin, end);
path_traits::convert(s.c_str(), s.c_str()+s.size(), m_pathname, cvt);
}
}
// ----- assignments -----
path& operator=(const path& p)
{
m_pathname = p.m_pathname;
return *this;
}
path& operator=(const value_type* ptr) // required in case ptr overlaps *this
{
m_pathname = ptr;
return *this;
}
template <class Source>
typename boost::enable_if<path_traits::is_pathable<
typename boost::decay<Source>::type>, path&>::type
operator=(Source const& source)
{
m_pathname.clear();
path_traits::dispatch(source, m_pathname, codecvt());
return *this;
}
path& assign(const value_type* ptr, const codecvt_type&) // required in case ptr overlaps *this
{
m_pathname = ptr;
return *this;
}
template <class Source>
path& assign(Source const& source, const codecvt_type& cvt)
{
m_pathname.clear();
path_traits::dispatch(source, m_pathname, cvt);
return *this;
}
template <class InputIterator>
path& assign(InputIterator begin, InputIterator end)
{
return assign(begin, end, codecvt());
}
template <class InputIterator>
path& assign(InputIterator begin, InputIterator end, const codecvt_type& cvt)
{
m_pathname.clear();
if (begin != end)
{
std::basic_string<typename std::iterator_traits<InputIterator>::value_type>
s(begin, end);
path_traits::convert(s.c_str(), s.c_str()+s.size(), m_pathname, cvt);
}
return *this;
}
// ----- concatenation -----
path& operator+=(const path& p) {m_pathname += p.m_pathname; return *this;}
path& operator+=(const string_type& s) {m_pathname += s; return *this;}
path& operator+=(const value_type* ptr) {m_pathname += ptr; return *this;}
path& operator+=(value_type c) {m_pathname += c; return *this;}
template <class Source>
typename boost::enable_if<path_traits::is_pathable<
typename boost::decay<Source>::type>, path&>::type
operator+=(Source const& source)
{
return concat(source, codecvt());
}
template <class CharT>
typename boost::enable_if<is_integral<CharT>, path&>::type
operator+=(CharT c)
{
CharT tmp[2];
tmp[0] = c;
tmp[1] = 0;
return concat(tmp, codecvt());
}
template <class Source>
path& concat(Source const& source, const codecvt_type& cvt)
{
path_traits::dispatch(source, m_pathname, cvt);
return *this;
}
template <class InputIterator>
path& concat(InputIterator begin, InputIterator end)
{
return concat(begin, end, codecvt());
}
template <class InputIterator>
path& concat(InputIterator begin, InputIterator end, const codecvt_type& cvt)
{
if (begin == end)
return *this;
std::basic_string<typename std::iterator_traits<InputIterator>::value_type>
s(begin, end);
path_traits::convert(s.c_str(), s.c_str()+s.size(), m_pathname, cvt);
return *this;
}
// ----- appends -----
// if a separator is added, it is the preferred separator for the platform;
// slash for POSIX, backslash for Windows
path& operator/=(const path& p);
path& operator/=(const value_type* ptr);
template <class Source>
typename boost::enable_if<path_traits::is_pathable<
typename boost::decay<Source>::type>, path&>::type
operator/=(Source const& source)
{
return append(source, codecvt());
}
path& append(const value_type* ptr, const codecvt_type&) // required in case ptr overlaps *this
{
this->operator/=(ptr);
return *this;
}
template <class Source>
path& append(Source const& source, const codecvt_type& cvt);
template <class InputIterator>
path& append(InputIterator begin, InputIterator end)
{
return append(begin, end, codecvt());
}
template <class InputIterator>
path& append(InputIterator begin, InputIterator end, const codecvt_type& cvt);
// ----- modifiers -----
void clear() { m_pathname.clear(); }
path& make_preferred()
# ifdef BOOST_POSIX_API
{ return *this; } // POSIX no effect
# else // BOOST_WINDOWS_API
; // change slashes to backslashes
# endif
path& remove_filename();
path& replace_extension(const path& new_extension = path());
void swap(path& rhs) { m_pathname.swap(rhs.m_pathname); }
// ----- observers -----
// For operating systems that format file paths differently than directory
// paths, return values from observers are formatted as file names unless there
// is a trailing separator, in which case returns are formatted as directory
// paths. POSIX and Windows make no such distinction.
// Implementations are permitted to return const values or const references.
// The string or path returned by an observer are specified as being formatted
// as "native" or "generic".
//
// For POSIX, these are all the same format; slashes and backslashes are as input and
// are not modified.
//
// For Windows, native: as input; slashes and backslashes are not modified;
// this is the format of the internally stored string.
// generic: backslashes are converted to slashes
// ----- native format observers -----
const string_type& native() const { return m_pathname; } // Throws: nothing
const value_type* c_str() const { return m_pathname.c_str(); } // Throws: nothing
template <class String>
String string() const;
template <class String>
String string(const codecvt_type& cvt) const;
# ifdef BOOST_WINDOWS_API
const std::string string() const { return string(codecvt()); }
const std::string string(const codecvt_type& cvt) const
{
std::string tmp;
if (!m_pathname.empty())
path_traits::convert(&*m_pathname.begin(), &*m_pathname.begin()+m_pathname.size(),
tmp, cvt);
return tmp;
}
// string_type is std::wstring, so there is no conversion
const std::wstring& wstring() const { return m_pathname; }
const std::wstring& wstring(const codecvt_type&) const { return m_pathname; }
# else // BOOST_POSIX_API
// string_type is std::string, so there is no conversion
const std::string& string() const { return m_pathname; }
const std::string& string(const codecvt_type&) const { return m_pathname; }
const std::wstring wstring() const { return wstring(codecvt()); }
const std::wstring wstring(const codecvt_type& cvt) const
{
std::wstring tmp;
if (!m_pathname.empty())
path_traits::convert(&*m_pathname.begin(), &*m_pathname.begin()+m_pathname.size(),
tmp, cvt);
return tmp;
}
# endif
// ----- generic format observers -----
template <class String>
String generic_string() const;
template <class String>
String generic_string(const codecvt_type& cvt) const;
# ifdef BOOST_WINDOWS_API
const std::string generic_string() const { return generic_string(codecvt()); }
const std::string generic_string(const codecvt_type& cvt) const;
const std::wstring generic_wstring() const;
const std::wstring generic_wstring(const codecvt_type&) const { return generic_wstring(); };
# else // BOOST_POSIX_API
// On POSIX-like systems, the generic format is the same as the native format
const std::string& generic_string() const { return m_pathname; }
const std::string& generic_string(const codecvt_type&) const { return m_pathname; }
const std::wstring generic_wstring() const { return wstring(codecvt()); }
const std::wstring generic_wstring(const codecvt_type& cvt) const { return wstring(cvt); }
# endif
// ----- compare -----
int compare(const path& p) const BOOST_NOEXCEPT; // generic, lexicographical
int compare(const std::string& s) const { return compare(path(s)); }
int compare(const value_type* s) const { return compare(path(s)); }
// ----- decomposition -----
path root_path() const;
path root_name() const; // returns 0 or 1 element path
// even on POSIX, root_name() is non-empty() for network paths
path root_directory() const; // returns 0 or 1 element path
path relative_path() const;
path parent_path() const;
path filename() const; // returns 0 or 1 element path
path stem() const; // returns 0 or 1 element path
path extension() const; // returns 0 or 1 element path
// ----- query -----
bool empty() const { return m_pathname.empty(); } // name consistent with std containers
bool has_root_path() const { return has_root_directory() || has_root_name(); }
bool has_root_name() const { return !root_name().empty(); }
bool has_root_directory() const { return !root_directory().empty(); }
bool has_relative_path() const { return !relative_path().empty(); }
bool has_parent_path() const { return !parent_path().empty(); }
bool has_filename() const { return !m_pathname.empty(); }
bool has_stem() const { return !stem().empty(); }
bool has_extension() const { return !extension().empty(); }
bool is_absolute() const
{
# ifdef BOOST_WINDOWS_API
return has_root_name() && has_root_directory();
# else
return has_root_directory();
# endif
}
bool is_relative() const { return !is_absolute(); }
// ----- iterators -----
class iterator;
typedef iterator const_iterator;
iterator begin() const;
iterator end() const;
// ----- static member functions -----
static std::locale imbue(const std::locale& loc);
static const codecvt_type& codecvt();
// ----- deprecated functions -----
# if defined(BOOST_FILESYSTEM_DEPRECATED) && defined(BOOST_FILESYSTEM_NO_DEPRECATED)
# error both BOOST_FILESYSTEM_DEPRECATED and BOOST_FILESYSTEM_NO_DEPRECATED are defined
# endif
# if !defined(BOOST_FILESYSTEM_NO_DEPRECATED)
// recently deprecated functions supplied by default
path& normalize() { return m_normalize(); }
path& remove_leaf() { return remove_filename(); }
path leaf() const { return filename(); }
path branch_path() const { return parent_path(); }
bool has_leaf() const { return !m_pathname.empty(); }
bool has_branch_path() const { return !parent_path().empty(); }
bool is_complete() const { return is_absolute(); }
# endif
# if defined(BOOST_FILESYSTEM_DEPRECATED)
// deprecated functions with enough signature or semantic changes that they are
// not supplied by default
const std::string file_string() const { return string(); }
const std::string directory_string() const { return string(); }
const std::string native_file_string() const { return string(); }
const std::string native_directory_string() const { return string(); }
const string_type external_file_string() const { return native(); }
const string_type external_directory_string() const { return native(); }
// older functions no longer supported
//typedef bool (*name_check)(const std::string & name);
//basic_path(const string_type& str, name_check) { operator/=(str); }
//basic_path(const typename string_type::value_type* s, name_check)
// { operator/=(s);}
//static bool default_name_check_writable() { return false; }
//static void default_name_check(name_check) {}
//static name_check default_name_check() { return 0; }
//basic_path& canonize();
# endif
//--------------------------------------------------------------------------------------//
// class path private members //
//--------------------------------------------------------------------------------------//
private:
# if defined(_MSC_VER)
# pragma warning(push) // Save warning settings
# pragma warning(disable : 4251) // disable warning: class 'std::basic_string<_Elem,_Traits,_Ax>'
# endif // needs to have dll-interface...
/*
m_pathname has the type, encoding, and format required by the native
operating system. Thus for POSIX and Windows there is no conversion for
passing m_pathname.c_str() to the O/S API or when obtaining a path from the
O/S API. POSIX encoding is unspecified other than for dot and slash
characters; POSIX just treats paths as a sequence of bytes. Windows
encoding is UCS-2 or UTF-16 depending on the version.
*/
string_type m_pathname; // Windows: as input; backslashes NOT converted to slashes,
// slashes NOT converted to backslashes
# if defined(_MSC_VER)
# pragma warning(pop) // restore warning settings.
# endif
string_type::size_type m_append_separator_if_needed();
// Returns: If separator is to be appended, m_pathname.size() before append. Otherwise 0.
// Note: An append is never performed if size()==0, so a returned 0 is unambiguous.
void m_erase_redundant_separator(string_type::size_type sep_pos);
string_type::size_type m_parent_path_end() const;
path& m_normalize();
// Was qualified; como433beta8 reports:
// warning #427-D: qualified name is not allowed in member declaration
friend class iterator;
friend bool operator<(const path& lhs, const path& rhs);
// see path::iterator::increment/decrement comment below
static void m_path_iterator_increment(path::iterator & it);
static void m_path_iterator_decrement(path::iterator & it);
}; // class path
namespace detail
{
BOOST_FILESYSTEM_DECL
int lex_compare(path::iterator first1, path::iterator last1,
path::iterator first2, path::iterator last2);
}
# ifndef BOOST_FILESYSTEM_NO_DEPRECATED
typedef path wpath;
# endif
//------------------------------------------------------------------------------------//
// class path::iterator //
//------------------------------------------------------------------------------------//
class path::iterator
: public boost::iterator_facade<
path::iterator,
path const,
boost::bidirectional_traversal_tag >
{
private:
friend class boost::iterator_core_access;
friend class boost::filesystem::path;
friend void m_path_iterator_increment(path::iterator & it);
friend void m_path_iterator_decrement(path::iterator & it);
const path& dereference() const { return m_element; }
bool equal(const iterator & rhs) const
{
return m_path_ptr == rhs.m_path_ptr && m_pos == rhs.m_pos;
}
// iterator_facade derived classes don't seem to like implementations in
// separate translation unit dll's, so forward to class path static members
void increment() { m_path_iterator_increment(*this); }
void decrement() { m_path_iterator_decrement(*this); }
path m_element; // current element
const path* m_path_ptr; // path being iterated over
string_type::size_type m_pos; // position of m_element in
// m_path_ptr->m_pathname.
// if m_element is implicit dot, m_pos is the
// position of the last separator in the path.
// end() iterator is indicated by
// m_pos == m_path_ptr->m_pathname.size()
}; // path::iterator
//------------------------------------------------------------------------------------//
// //
// non-member functions //
// //
//------------------------------------------------------------------------------------//
// std::lexicographical_compare would infinately recurse because path iterators
// yield paths, so provide a path aware version
inline bool lexicographical_compare(path::iterator first1, path::iterator last1,
path::iterator first2, path::iterator last2)
{ return detail::lex_compare(first1, last1, first2, last2) < 0; }
inline bool operator==(const path& lhs, const path& rhs) {return lhs.compare(rhs) == 0;}
inline bool operator==(const path& lhs, const path::string_type& rhs) {return lhs.compare(rhs) == 0;}
inline bool operator==(const path::string_type& lhs, const path& rhs) {return rhs.compare(lhs) == 0;}
inline bool operator==(const path& lhs, const path::value_type* rhs) {return lhs.compare(rhs) == 0;}
inline bool operator==(const path::value_type* lhs, const path& rhs) {return rhs.compare(lhs) == 0;}
inline bool operator!=(const path& lhs, const path& rhs) {return lhs.compare(rhs) != 0;}
inline bool operator!=(const path& lhs, const path::string_type& rhs) {return lhs.compare(rhs) != 0;}
inline bool operator!=(const path::string_type& lhs, const path& rhs) {return rhs.compare(lhs) != 0;}
inline bool operator!=(const path& lhs, const path::value_type* rhs) {return lhs.compare(rhs) != 0;}
inline bool operator!=(const path::value_type* lhs, const path& rhs) {return rhs.compare(lhs) != 0;}
// TODO: why do == and != have additional overloads, but the others don't?
inline bool operator<(const path& lhs, const path& rhs) {return lhs.compare(rhs) < 0;}
inline bool operator<=(const path& lhs, const path& rhs) {return !(rhs < lhs);}
inline bool operator> (const path& lhs, const path& rhs) {return rhs < lhs;}
inline bool operator>=(const path& lhs, const path& rhs) {return !(lhs < rhs);}
inline std::size_t hash_value(const path& x)
{
# ifdef BOOST_WINDOWS_API
std::size_t seed = 0;
for(const path::value_type* it = x.c_str(); *it; ++it)
hash_combine(seed, *it == '/' ? L'\\' : *it);
return seed;
# else // BOOST_POSIX_API
return hash_range(x.native().begin(), x.native().end());
# endif
}
inline void swap(path& lhs, path& rhs) { lhs.swap(rhs); }
inline path operator/(const path& lhs, const path& rhs) { return path(lhs) /= rhs; }
// inserters and extractors
// use boost::io::quoted() to handle spaces in paths
// use '&' as escape character to ease use for Windows paths
template <class Char, class Traits>
inline std::basic_ostream<Char, Traits>&
operator<<(std::basic_ostream<Char, Traits>& os, const path& p)
{
return os
<< boost::io::quoted(p.template string<std::basic_string<Char> >(), static_cast<Char>('&'));
}
template <class Char, class Traits>
inline std::basic_istream<Char, Traits>&
operator>>(std::basic_istream<Char, Traits>& is, path& p)
{
std::basic_string<Char> str;
is >> boost::io::quoted(str, static_cast<Char>('&'));
p = str;
return is;
}
// name_checks
// These functions are holdovers from version 1. It isn't clear they have much
// usefulness, or how to generalize them for later versions.
BOOST_FILESYSTEM_DECL bool portable_posix_name(const std::string & name);
BOOST_FILESYSTEM_DECL bool windows_name(const std::string & name);
BOOST_FILESYSTEM_DECL bool portable_name(const std::string & name);
BOOST_FILESYSTEM_DECL bool portable_directory_name(const std::string & name);
BOOST_FILESYSTEM_DECL bool portable_file_name(const std::string & name);
BOOST_FILESYSTEM_DECL bool native(const std::string & name);
//--------------------------------------------------------------------------------------//
// class path member template implementation //
//--------------------------------------------------------------------------------------//
template <class InputIterator>
path& path::append(InputIterator begin, InputIterator end, const codecvt_type& cvt)
{
if (begin == end)
return *this;
string_type::size_type sep_pos(m_append_separator_if_needed());
std::basic_string<typename std::iterator_traits<InputIterator>::value_type>
s(begin, end);
path_traits::convert(s.c_str(), s.c_str()+s.size(), m_pathname, cvt);
if (sep_pos)
m_erase_redundant_separator(sep_pos);
return *this;
}
template <class Source>
path& path::append(Source const& source, const codecvt_type& cvt)
{
if (path_traits::empty(source))
return *this;
string_type::size_type sep_pos(m_append_separator_if_needed());
path_traits::dispatch(source, m_pathname, cvt);
if (sep_pos)
m_erase_redundant_separator(sep_pos);
return *this;
}
//--------------------------------------------------------------------------------------//
// class path member template specializations //
//--------------------------------------------------------------------------------------//
template <> inline
std::string path::string<std::string>() const
{ return string(); }
template <> inline
std::wstring path::string<std::wstring>() const
{ return wstring(); }
template <> inline
std::string path::string<std::string>(const codecvt_type& cvt) const
{ return string(cvt); }
template <> inline
std::wstring path::string<std::wstring>(const codecvt_type& cvt) const
{ return wstring(cvt); }
template <> inline
std::string path::generic_string<std::string>() const
{ return generic_string(); }
template <> inline
std::wstring path::generic_string<std::wstring>() const
{ return generic_wstring(); }
template <> inline
std::string path::generic_string<std::string>(const codecvt_type& cvt) const
{ return generic_string(cvt); }
template <> inline
std::wstring path::generic_string<std::wstring>(const codecvt_type& cvt) const
{ return generic_wstring(cvt); }
} // namespace filesystem
} // namespace boost
//----------------------------------------------------------------------------//
#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
#endif // BOOST_FILESYSTEM_PATH_HPP

View File

@ -0,0 +1,235 @@
// filesystem path_traits.hpp --------------------------------------------------------//
// Copyright Beman Dawes 2009
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// Library home page: http://www.boost.org/libs/filesystem
#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/utility/enable_if.hpp>
#include <boost/type_traits/is_array.hpp>
#include <boost/type_traits/decay.hpp>
#include <boost/system/error_code.hpp>
#include <cwchar> // for mbstate_t
#include <string>
#include <vector>
#include <list>
#include <iterator>
#include <locale>
#include <boost/assert.hpp>
// #include <iostream> //**** comment me out ****
#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();
// uses std::codecvt_base::result used for error codes:
//
// ok: Conversion successful.
// partial: Not all source characters converted; one or more additional source
// characters are needed to produce the final target character, or the
// size of the target intermediate buffer was too small to hold the result.
// error: A character in the source could not be converted to the target encoding.
// noconv: The source and target characters have the same type and encoding, so no
// conversion was necessary.
class directory_entry;
namespace path_traits {
typedef std::codecvt<wchar_t, char, std::mbstate_t> codecvt_type;
// is_pathable type trait; allows disabling over-agressive class path member templates
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; };
// Pathable empty
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]; }
// value types differ ---------------------------------------------------------------//
//
// A from_end argument of 0 is less efficient than a known end, so use only if needed
BOOST_FILESYSTEM_DECL
void convert(const char* from,
const char* from_end, // 0 for null terminated MBCS
std::wstring & to,
const codecvt_type& cvt);
BOOST_FILESYSTEM_DECL
void convert(const wchar_t* from,
const wchar_t* from_end, // 0 for null terminated MBCS
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);
}
// value types same -----------------------------------------------------------------//
// char
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;
}
// wchar_t
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;
}
// Source dispatch -----------------------------------------------------------------//
// contiguous containers
template <class U> inline
void dispatch(const std::string& c, U& to, const codecvt_type& cvt)
{
if (c.size())
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.size())
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.size())
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.size())
convert(&*c.begin(), &*c.begin() + c.size(), to, cvt);
}
// non-contiguous containers
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.size())
{
std::basic_string<typename Container::value_type> s(c.begin(), c.end());
convert(s.c_str(), s.c_str()+s.size(), to, cvt);
}
}
// c_str
template <class T, class U> inline
void dispatch(T * const & c_str, U& to, const codecvt_type& cvt)
{
// std::cout << "dispatch() const T *\n";
BOOST_ASSERT(c_str);
convert(c_str, to, cvt);
}
// Note: there is no dispatch on C-style arrays because the array may
// contain a string smaller than the array size.
BOOST_FILESYSTEM_DECL
void dispatch(const directory_entry & de,
# ifdef BOOST_WINDOWS_API
std::wstring & to,
# else
std::string & to,
# endif
const codecvt_type&);
}}} // namespace boost::filesystem::path_traits
#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
#endif // BOOST_FILESYSTEM_PATH_TRAITS_HPP

View File

@ -0,0 +1,190 @@
// boost/io/quoted_manip.hpp ---------------------------------------------------------//
// Copyright Beman Dawes 2010
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// Library home page http://www.boost.org/libs/io
//--------------------------------------------------------------------------------------//
#ifndef BOOST_IO_QUOTED_MANIP
#define BOOST_IO_QUOTED_MANIP
#include <iosfwd>
#include <ios>
#include <string>
#include <iterator>
#include <boost/io/ios_state.hpp>
namespace boost
{
namespace io
{
namespace detail { template <class String, class Char> struct quoted_proxy; }
// ------------ public interface ------------------------------------------------//
// manipulator for const std::basic_string&
template <class Char, class Traits, class Alloc>
detail::quoted_proxy<std::basic_string<Char, Traits, Alloc> const &, Char>
quoted(const std::basic_string<Char, Traits, Alloc>& s,
Char escape='\\', Char delim='\"');
// manipulator for non-const std::basic_string&
template <class Char, class Traits, class Alloc>
detail::quoted_proxy<std::basic_string<Char, Traits, Alloc> &, Char>
quoted(std::basic_string<Char, Traits, Alloc>& s,
Char escape='\\', Char delim='\"');
// manipulator for const C-string*
template <class Char>
detail::quoted_proxy<const Char*, Char>
quoted(const Char* s, Char escape='\\', Char delim='\"');
// ----------- implementation details -------------------------------------------//
namespace detail
{
// proxy used as an argument pack
template <class String, class Char>
struct quoted_proxy
{
String string;
Char escape;
Char delim;
quoted_proxy(String s_, Char escape_, Char delim_)
: string(s_), escape(escape_), delim(delim_) {}
private:
// String may be a const type, so disable the assignment operator
quoted_proxy& operator=(const quoted_proxy&); // = deleted
};
// abstract away difference between proxies with const or non-const basic_strings
template <class Char, class Traits, class Alloc>
std::basic_ostream<Char, Traits>&
basic_string_inserter_imp(std::basic_ostream<Char, Traits>& os,
std::basic_string<Char, Traits, Alloc> const & string, Char escape, Char delim)
{
os << delim;
typename std::basic_string<Char, Traits, Alloc>::const_iterator
end_it = string.end();
for (typename std::basic_string<Char, Traits, Alloc>::const_iterator
it = string.begin();
it != end_it;
++it )
{
if (*it == delim || *it == escape)
os << escape;
os << *it;
}
os << delim;
return os;
}
// inserter for const std::basic_string& proxies
template <class Char, class Traits, class Alloc>
inline
std::basic_ostream<Char, Traits>& operator<<(std::basic_ostream<Char, Traits>& os,
const quoted_proxy<std::basic_string<Char, Traits, Alloc> const &, Char>& proxy)
{
return basic_string_inserter_imp(os, proxy.string, proxy.escape, proxy.delim);
}
// inserter for non-const std::basic_string& proxies
template <class Char, class Traits, class Alloc>
inline
std::basic_ostream<Char, Traits>& operator<<(std::basic_ostream<Char, Traits>& os,
const quoted_proxy<std::basic_string<Char, Traits, Alloc>&, Char>& proxy)
{
return basic_string_inserter_imp(os, proxy.string, proxy.escape, proxy.delim);
}
// inserter for const C-string* proxies
template <class Char, class Traits>
std::basic_ostream<Char, Traits>& operator<<(std::basic_ostream<Char, Traits>& os,
const quoted_proxy<const Char*, Char>& proxy)
{
os << proxy.delim;
for (const Char* it = proxy.string;
*it;
++it )
{
if (*it == proxy.delim || *it == proxy.escape)
os << proxy.escape;
os << *it;
}
os << proxy.delim;
return os;
}
// extractor for non-const std::basic_string& proxies
template <class Char, class Traits, class Alloc>
std::basic_istream<Char, Traits>& operator>>(std::basic_istream<Char, Traits>& is,
const quoted_proxy<std::basic_string<Char, Traits, Alloc>&, Char>& proxy)
{
proxy.string.clear();
Char c;
is >> c;
if (c != proxy.delim)
{
is.unget();
is >> proxy.string;
return is;
}
{
boost::io::ios_flags_saver ifs(is);
is >> std::noskipws;
for (;;)
{
is >> c;
if (!is.good()) // cope with I/O errors or end-of-file
break;
if (c == proxy.escape)
{
is >> c;
if (!is.good()) // cope with I/O errors or end-of-file
break;
}
else if (c == proxy.delim)
break;
proxy.string += c;
}
}
return is;
}
} // namespace detail
// manipulator implementation for const std::basic_string&
template <class Char, class Traits, class Alloc>
inline detail::quoted_proxy<std::basic_string<Char, Traits, Alloc> const &, Char>
quoted(const std::basic_string<Char, Traits, Alloc>& s, Char escape, Char delim)
{
return detail::quoted_proxy<std::basic_string<Char, Traits, Alloc> const &, Char>
(s, escape, delim);
}
// manipulator implementation for non-const std::basic_string&
template <class Char, class Traits, class Alloc>
inline detail::quoted_proxy<std::basic_string<Char, Traits, Alloc> &, Char>
quoted(std::basic_string<Char, Traits, Alloc>& s, Char escape, Char delim)
{
return detail::quoted_proxy<std::basic_string<Char, Traits, Alloc>&, Char>
(s, escape, delim);
}
// manipulator implementation for const C-string*
template <class Char>
inline detail::quoted_proxy<const Char*, Char>
quoted(const Char* s, Char escape, Char delim)
{
return detail::quoted_proxy<const Char*, Char> (s, escape, delim);
}
} // namespace io
} // namespace boost
#endif // BOOST_IO_QUOTED_MANIP

View File

@ -0,0 +1,84 @@
// codecvt_error_category implementation file ----------------------------------------//
// Copyright Beman Dawes 2009
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt)
// Library home page at http://www.boost.org/libs/filesystem
//--------------------------------------------------------------------------------------//
#include <boost/config/warning_disable.hpp>
// define BOOST_FILESYSTEM_SOURCE so that <boost/filesystem/config.hpp> knows
// the library is being built (possibly exporting rather than importing code)
#define BOOST_FILESYSTEM_SOURCE
#ifndef BOOST_SYSTEM_NO_DEPRECATED
# define BOOST_SYSTEM_NO_DEPRECATED
#endif
#include <boost/filesystem/config.hpp>
#include <boost/filesystem/path_traits.hpp>
#include <boost/system/error_code.hpp>
#include <locale>
#include <vector>
#include <cstdlib>
#include <cassert>
//--------------------------------------------------------------------------------------//
namespace
{
class codecvt_error_cat : public boost::system::error_category
{
public:
codecvt_error_cat(){}
const char* name() const;
std::string message(int ev) const;
};
const char* codecvt_error_cat::name() const
{
return "codecvt";
}
std::string codecvt_error_cat::message(int ev) const
{
std::string str;
switch (ev)
{
case std::codecvt_base::ok:
str = "ok";
break;
case std::codecvt_base::partial:
str = "partial";
break;
case std::codecvt_base::error:
str = "error";
break;
case std::codecvt_base::noconv:
str = "noconv";
break;
default:
str = "unknown error";
}
return str;
}
} // unnamed namespace
namespace boost
{
namespace filesystem
{
BOOST_FILESYSTEM_DECL const boost::system::error_category& codecvt_error_category()
{
static const codecvt_error_cat codecvt_error_cat_const;
return codecvt_error_cat_const;
}
} // namespace filesystem
} // namespace boost

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,929 @@
// filesystem path.cpp ------------------------------------------------------------- //
// Copyright Beman Dawes 2008
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// Library home page: http://www.boost.org/libs/filesystem
// Old standard library configurations, particularly MingGW, don't support wide strings.
// Report this with an explicit error message.
#include <boost/config.hpp>
# if defined( BOOST_NO_STD_WSTRING )
# error Configuration not supported: Boost.Filesystem V3 and later requires std::wstring support
# endif
// define BOOST_FILESYSTEM_SOURCE so that <boost/system/config.hpp> knows
// the library is being built (possibly exporting rather than importing code)
#define BOOST_FILESYSTEM_SOURCE
#ifndef BOOST_SYSTEM_NO_DEPRECATED
# define BOOST_SYSTEM_NO_DEPRECATED
#endif
#include <boost/filesystem/config.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/scoped_array.hpp>
#include <boost/system/error_code.hpp>
#include <boost/assert.hpp>
#include <algorithm>
#include <cstddef>
#include <cstring>
#include <cassert>
#ifdef BOOST_WINDOWS_API
# include "windows_file_codecvt.hpp"
# include <windows.h>
#elif defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)
# include <boost/filesystem/detail/utf8_codecvt_facet.hpp>
#endif
#ifdef BOOST_FILESYSTEM_DEBUG
# include <iostream>
# include <iomanip>
#endif
namespace fs = boost::filesystem;
using boost::filesystem::path;
using std::string;
using std::wstring;
using boost::system::error_code;
#ifndef BOOST_FILESYSTEM_CODECVT_BUF_SIZE
# define BOOST_FILESYSTEM_CODECVT_BUF_SIZE 256
#endif
//--------------------------------------------------------------------------------------//
// //
// class path helpers //
// //
//--------------------------------------------------------------------------------------//
namespace
{
//------------------------------------------------------------------------------------//
// miscellaneous class path helpers //
//------------------------------------------------------------------------------------//
typedef path::value_type value_type;
typedef path::string_type string_type;
typedef string_type::size_type size_type;
const std::size_t default_codecvt_buf_size = BOOST_FILESYSTEM_CODECVT_BUF_SIZE;
# ifdef BOOST_WINDOWS_API
const wchar_t separator = L'/';
const wchar_t* const separators = L"/\\";
const wchar_t* separator_string = L"/";
const wchar_t* preferred_separator_string = L"\\";
const wchar_t colon = L':';
const wchar_t dot = L'.';
const wchar_t questionmark = L'?';
const fs::path dot_path(L".");
const fs::path dot_dot_path(L"..");
inline bool is_letter(wchar_t c)
{
return (c >= L'a' && c <=L'z') || (c >= L'A' && c <=L'Z');
}
# else
const char separator = '/';
const char* const separators = "/";
const char* separator_string = "/";
const char* preferred_separator_string = "/";
const char colon = ':';
const char dot = '.';
const fs::path dot_path(".");
const fs::path dot_dot_path("..");
# endif
inline bool is_separator(fs::path::value_type c)
{
return c == separator
# ifdef BOOST_WINDOWS_API
|| c == path::preferred_separator
# endif
;
}
bool is_root_separator(const string_type& str, size_type pos);
// pos is position of the separator
size_type filename_pos(const string_type& str,
size_type end_pos); // end_pos is past-the-end position
// Returns: 0 if str itself is filename (or empty)
size_type root_directory_start(const string_type& path, size_type size);
// Returns: npos if no root_directory found
void first_element(
const string_type& src,
size_type& element_pos,
size_type& element_size,
# if !BOOST_WORKAROUND(BOOST_MSVC, <= 1310) // VC++ 7.1
size_type size = string_type::npos
# else
size_type size = -1
# endif
);
} // unnamed namespace
//--------------------------------------------------------------------------------------//
// //
// class path implementation //
// //
//--------------------------------------------------------------------------------------//
namespace boost
{
namespace filesystem
{
path& path::operator/=(const path& p)
{
if (p.empty())
return *this;
if (this == &p) // self-append
{
path rhs(p);
if (!is_separator(rhs.m_pathname[0]))
m_append_separator_if_needed();
m_pathname += rhs.m_pathname;
}
else
{
if (!is_separator(*p.m_pathname.begin()))
m_append_separator_if_needed();
m_pathname += p.m_pathname;
}
return *this;
}
path& path::operator/=(const value_type* ptr)
{
if (!*ptr)
return *this;
if (ptr >= m_pathname.data()
&& ptr < m_pathname.data() + m_pathname.size()) // overlapping source
{
path rhs(ptr);
if (!is_separator(rhs.m_pathname[0]))
m_append_separator_if_needed();
m_pathname += rhs.m_pathname;
}
else
{
if (!is_separator(*ptr))
m_append_separator_if_needed();
m_pathname += ptr;
}
return *this;
}
int path::compare(const path& p) const BOOST_NOEXCEPT
{
return detail::lex_compare(begin(), end(), p.begin(), p.end());
}
# ifdef BOOST_WINDOWS_API
const std::string path::generic_string(const codecvt_type& cvt) const
{
path tmp(*this);
std::replace(tmp.m_pathname.begin(), tmp.m_pathname.end(), L'\\', L'/');
return tmp.string(cvt);
}
const std::wstring path::generic_wstring() const
{
path tmp(*this);
std::replace(tmp.m_pathname.begin(), tmp.m_pathname.end(), L'\\', L'/');
return tmp.wstring();
}
# endif // BOOST_WINDOWS_API
// m_append_separator_if_needed ----------------------------------------------------//
path::string_type::size_type path::m_append_separator_if_needed()
{
if (!m_pathname.empty() &&
# ifdef BOOST_WINDOWS_API
*(m_pathname.end()-1) != colon &&
# endif
!is_separator(*(m_pathname.end()-1)))
{
string_type::size_type tmp(m_pathname.size());
m_pathname += preferred_separator;
return tmp;
}
return 0;
}
// m_erase_redundant_separator -----------------------------------------------------//
void path::m_erase_redundant_separator(string_type::size_type sep_pos)
{
if (sep_pos // a separator was added
&& sep_pos < m_pathname.size() // and something was appended
&& (m_pathname[sep_pos+1] == separator // and it was also separator
# ifdef BOOST_WINDOWS_API
|| m_pathname[sep_pos+1] == preferred_separator // or preferred_separator
# endif
)) { m_pathname.erase(sep_pos, 1); } // erase the added separator
}
// modifiers -----------------------------------------------------------------------//
# ifdef BOOST_WINDOWS_API
path & path::make_preferred()
{
std::replace(m_pathname.begin(), m_pathname.end(), L'/', L'\\');
return *this;
}
# endif
path& path::remove_filename()
{
m_pathname.erase(m_parent_path_end());
return *this;
}
path& path::replace_extension(const path& new_extension)
{
// erase existing extension, including the dot, if any
m_pathname.erase(m_pathname.size()-extension().m_pathname.size());
if (!new_extension.empty())
{
// append new_extension, adding the dot if necessary
if (new_extension.m_pathname[0] != dot)
m_pathname.push_back(dot);
m_pathname.append(new_extension.m_pathname);
}
return *this;
}
// decomposition -------------------------------------------------------------------//
path path::root_path() const
{
path temp(root_name());
if (!root_directory().empty()) temp.m_pathname += root_directory().c_str();
return temp;
}
path path::root_name() const
{
iterator itr(begin());
return (itr.m_pos != m_pathname.size()
&& (
(itr.m_element.m_pathname.size() > 1
&& is_separator(itr.m_element.m_pathname[0])
&& is_separator(itr.m_element.m_pathname[1])
)
# ifdef BOOST_WINDOWS_API
|| itr.m_element.m_pathname[itr.m_element.m_pathname.size()-1] == colon
# endif
))
? itr.m_element
: path();
}
path path::root_directory() const
{
size_type pos(root_directory_start(m_pathname, m_pathname.size()));
return pos == string_type::npos
? path()
: path(m_pathname.c_str() + pos, m_pathname.c_str() + pos + 1);
}
path path::relative_path() const
{
iterator itr(begin());
for (; itr.m_pos != m_pathname.size()
&& (is_separator(itr.m_element.m_pathname[0])
# ifdef BOOST_WINDOWS_API
|| itr.m_element.m_pathname[itr.m_element.m_pathname.size()-1] == colon
# endif
); ++itr) {}
return path(m_pathname.c_str() + itr.m_pos);
}
string_type::size_type path::m_parent_path_end() const
{
size_type end_pos(filename_pos(m_pathname, m_pathname.size()));
bool filename_was_separator(m_pathname.size()
&& is_separator(m_pathname[end_pos]));
// skip separators unless root directory
size_type root_dir_pos(root_directory_start(m_pathname, end_pos));
for (;
end_pos > 0
&& (end_pos-1) != root_dir_pos
&& is_separator(m_pathname[end_pos-1])
;
--end_pos) {}
return (end_pos == 1 && root_dir_pos == 0 && filename_was_separator)
? string_type::npos
: end_pos;
}
path path::parent_path() const
{
size_type end_pos(m_parent_path_end());
return end_pos == string_type::npos
? path()
: path(m_pathname.c_str(), m_pathname.c_str() + end_pos);
}
path path::filename() const
{
size_type pos(filename_pos(m_pathname, m_pathname.size()));
return (m_pathname.size()
&& pos
&& is_separator(m_pathname[pos])
&& !is_root_separator(m_pathname, pos))
? dot_path
: path(m_pathname.c_str() + pos);
}
path path::stem() const
{
path name(filename());
if (name == dot_path || name == dot_dot_path) return name;
size_type pos(name.m_pathname.rfind(dot));
return pos == string_type::npos
? name
: path(name.m_pathname.c_str(), name.m_pathname.c_str() + pos);
}
path path::extension() const
{
path name(filename());
if (name == dot_path || name == dot_dot_path) return path();
size_type pos(name.m_pathname.rfind(dot));
return pos == string_type::npos
? path()
: path(name.m_pathname.c_str() + pos);
}
// m_normalize ----------------------------------------------------------------------//
path& path::m_normalize()
{
if (m_pathname.empty()) return *this;
path temp;
iterator start(begin());
iterator last(end());
iterator stop(last--);
for (iterator itr(start); itr != stop; ++itr)
{
// ignore "." except at start and last
if (itr->native().size() == 1
&& (itr->native())[0] == dot
&& itr != start
&& itr != last) continue;
// ignore a name and following ".."
if (!temp.empty()
&& itr->native().size() == 2
&& (itr->native())[0] == dot
&& (itr->native())[1] == dot) // dot dot
{
string_type lf(temp.filename().native());
if (lf.size() > 0
&& (lf.size() != 1
|| (lf[0] != dot
&& lf[0] != separator))
&& (lf.size() != 2
|| (lf[0] != dot
&& lf[1] != dot
# ifdef BOOST_WINDOWS_API
&& lf[1] != colon
# endif
)
)
)
{
temp.remove_filename();
// if not root directory, must also remove "/" if any
if (temp.m_pathname.size() > 0
&& temp.m_pathname[temp.m_pathname.size()-1]
== separator)
{
string_type::size_type rds(
root_directory_start(temp.m_pathname, temp.m_pathname.size()));
if (rds == string_type::npos
|| rds != temp.m_pathname.size()-1)
{ temp.m_pathname.erase(temp.m_pathname.size()-1); }
}
iterator next(itr);
if (temp.empty() && ++next != stop
&& next == last && *last == dot_path) temp /= dot_path;
continue;
}
}
temp /= *itr;
};
if (temp.empty()) temp /= dot_path;
m_pathname = temp.m_pathname;
return *this;
}
} // namespace filesystem
} // namespace boost
//--------------------------------------------------------------------------------------//
// //
// class path helpers implementation //
// //
//--------------------------------------------------------------------------------------//
namespace
{
// is_root_separator ---------------------------------------------------------------//
bool is_root_separator(const string_type & str, size_type pos)
// pos is position of the separator
{
BOOST_ASSERT_MSG(!str.empty() && is_separator(str[pos]),
"precondition violation");
// subsequent logic expects pos to be for leftmost slash of a set
while (pos > 0 && is_separator(str[pos-1]))
--pos;
// "/" [...]
if (pos == 0)
return true;
# ifdef BOOST_WINDOWS_API
// "c:/" [...]
if (pos == 2 && is_letter(str[0]) && str[1] == colon)
return true;
# endif
// "//" name "/"
if (pos < 3 || !is_separator(str[0]) || !is_separator(str[1]))
return false;
return str.find_first_of(separators, 2) == pos;
}
// filename_pos --------------------------------------------------------------------//
size_type filename_pos(const string_type & str,
size_type end_pos) // end_pos is past-the-end position
// return 0 if str itself is filename (or empty)
{
// case: "//"
if (end_pos == 2
&& is_separator(str[0])
&& is_separator(str[1])) return 0;
// case: ends in "/"
if (end_pos && is_separator(str[end_pos-1]))
return end_pos-1;
// set pos to start of last element
size_type pos(str.find_last_of(separators, end_pos-1));
# ifdef BOOST_WINDOWS_API
if (pos == string_type::npos)
pos = str.find_last_of(colon, end_pos-2);
# endif
return (pos == string_type::npos // path itself must be a filename (or empty)
|| (pos == 1 && is_separator(str[0]))) // or net
? 0 // so filename is entire string
: pos + 1; // or starts after delimiter
}
// root_directory_start ------------------------------------------------------------//
size_type root_directory_start(const string_type & path, size_type size)
// return npos if no root_directory found
{
# ifdef BOOST_WINDOWS_API
// case "c:/"
if (size > 2
&& path[1] == colon
&& is_separator(path[2])) return 2;
# endif
// case "//"
if (size == 2
&& is_separator(path[0])
&& is_separator(path[1])) return string_type::npos;
# ifdef BOOST_WINDOWS_API
// case "\\?\"
if (size > 4
&& is_separator(path[0])
&& is_separator(path[1])
&& path[2] == questionmark
&& is_separator(path[3]))
{
string_type::size_type pos(path.find_first_of(separators, 4));
return pos < size ? pos : string_type::npos;
}
# endif
// case "//net {/}"
if (size > 3
&& is_separator(path[0])
&& is_separator(path[1])
&& !is_separator(path[2]))
{
string_type::size_type pos(path.find_first_of(separators, 2));
return pos < size ? pos : string_type::npos;
}
// case "/"
if (size > 0 && is_separator(path[0])) return 0;
return string_type::npos;
}
// first_element --------------------------------------------------------------------//
// sets pos and len of first element, excluding extra separators
// if src.empty(), sets pos,len, to 0,0.
void first_element(
const string_type & src,
size_type & element_pos,
size_type & element_size,
size_type size
)
{
if (size == string_type::npos) size = src.size();
element_pos = 0;
element_size = 0;
if (src.empty()) return;
string_type::size_type cur(0);
// deal with // [network]
if (size >= 2 && is_separator(src[0])
&& is_separator(src[1])
&& (size == 2
|| !is_separator(src[2])))
{
cur += 2;
element_size += 2;
}
// leading (not non-network) separator
else if (is_separator(src[0]))
{
++element_size;
// bypass extra leading separators
while (cur+1 < size
&& is_separator(src[cur+1]))
{
++cur;
++element_pos;
}
return;
}
// at this point, we have either a plain name, a network name,
// or (on Windows only) a device name
// find the end
while (cur < size
# ifdef BOOST_WINDOWS_API
&& src[cur] != colon
# endif
&& !is_separator(src[cur]))
{
++cur;
++element_size;
}
# ifdef BOOST_WINDOWS_API
if (cur == size) return;
// include device delimiter
if (src[cur] == colon)
{ ++element_size; }
# endif
return;
}
} // unnamed namespace
namespace boost
{
namespace filesystem
{
namespace detail
{
BOOST_FILESYSTEM_DECL
int lex_compare(path::iterator first1, path::iterator last1,
path::iterator first2, path::iterator last2)
{
for (; first1 != last1 && first2 != last2;)
{
if (first1->native() < first2->native()) return -1;
if (first2->native() < first1->native()) return 1;
BOOST_ASSERT(first2->native() == first1->native());
++first1;
++first2;
}
if (first1 == last1 && first2 == last2)
return 0;
return first1 == last1 ? -1 : 1;
}
}
//--------------------------------------------------------------------------------------//
// //
// class path::iterator implementation //
// //
//--------------------------------------------------------------------------------------//
path::iterator path::begin() const
{
iterator itr;
itr.m_path_ptr = this;
size_type element_size;
first_element(m_pathname, itr.m_pos, element_size);
itr.m_element = m_pathname.substr(itr.m_pos, element_size);
if (itr.m_element.m_pathname == preferred_separator_string)
itr.m_element.m_pathname = separator_string; // needed for Windows, harmless on POSIX
return itr;
}
path::iterator path::end() const
{
iterator itr;
itr.m_path_ptr = this;
itr.m_pos = m_pathname.size();
return itr;
}
void path::m_path_iterator_increment(path::iterator & it)
{
BOOST_ASSERT_MSG(it.m_pos < it.m_path_ptr->m_pathname.size(),
"path::basic_iterator increment past end()");
// increment to position past current element; if current element is implicit dot,
// this will cause it.m_pos to represent the end iterator
it.m_pos += it.m_element.m_pathname.size();
// if the end is reached, we are done
if (it.m_pos == it.m_path_ptr->m_pathname.size())
{
it.m_element.clear(); // aids debugging, may release unneeded memory
return;
}
// both POSIX and Windows treat paths that begin with exactly two separators specially
bool was_net(it.m_element.m_pathname.size() > 2
&& is_separator(it.m_element.m_pathname[0])
&& is_separator(it.m_element.m_pathname[1])
&& !is_separator(it.m_element.m_pathname[2]));
// process separator (Windows drive spec is only case not a separator)
if (is_separator(it.m_path_ptr->m_pathname[it.m_pos]))
{
// detect root directory
if (was_net
# ifdef BOOST_WINDOWS_API
// case "c:/"
|| it.m_element.m_pathname[it.m_element.m_pathname.size()-1] == colon
# endif
)
{
it.m_element.m_pathname = separator; // generic format; see docs
return;
}
// skip separators until it.m_pos points to the start of the next element
while (it.m_pos != it.m_path_ptr->m_pathname.size()
&& is_separator(it.m_path_ptr->m_pathname[it.m_pos]))
{ ++it.m_pos; }
// detect trailing separator, and treat it as ".", per POSIX spec
if (it.m_pos == it.m_path_ptr->m_pathname.size()
&& !is_root_separator(it.m_path_ptr->m_pathname, it.m_pos-1))
{
--it.m_pos;
it.m_element = dot_path;
return;
}
}
// get m_element
size_type end_pos(it.m_path_ptr->m_pathname.find_first_of(separators, it.m_pos));
if (end_pos == string_type::npos)
end_pos = it.m_path_ptr->m_pathname.size();
it.m_element = it.m_path_ptr->m_pathname.substr(it.m_pos, end_pos - it.m_pos);
}
void path::m_path_iterator_decrement(path::iterator & it)
{
BOOST_ASSERT_MSG(it.m_pos, "path::iterator decrement past begin()");
size_type end_pos(it.m_pos);
// if at end and there was a trailing non-root '/', return "."
if (it.m_pos == it.m_path_ptr->m_pathname.size()
&& it.m_path_ptr->m_pathname.size() > 1
&& is_separator(it.m_path_ptr->m_pathname[it.m_pos-1])
&& !is_root_separator(it.m_path_ptr->m_pathname, it.m_pos-1)
)
{
--it.m_pos;
it.m_element = dot_path;
return;
}
size_type root_dir_pos(root_directory_start(it.m_path_ptr->m_pathname, end_pos));
// skip separators unless root directory
for (
;
end_pos > 0
&& (end_pos-1) != root_dir_pos
&& is_separator(it.m_path_ptr->m_pathname[end_pos-1])
;
--end_pos) {}
it.m_pos = filename_pos(it.m_path_ptr->m_pathname, end_pos);
it.m_element = it.m_path_ptr->m_pathname.substr(it.m_pos, end_pos - it.m_pos);
if (it.m_element.m_pathname == preferred_separator_string) // needed for Windows, harmless on POSIX
it.m_element.m_pathname = separator_string; // generic format; see docs
}
} // namespace filesystem
} // namespace boost
//--------------------------------------------------------------------------------------//
// //
// detail helpers //
// //
//--------------------------------------------------------------------------------------//
namespace
{
//------------------------------------------------------------------------------------//
// locale helpers //
//------------------------------------------------------------------------------------//
#if defined(BOOST_WINDOWS_API) && defined(BOOST_FILESYSTEM_STATIC_LINK)
inline std::locale default_locale()
{
std::locale global_loc = std::locale();
std::locale loc(global_loc, new windows_file_codecvt);
return loc;
}
inline std::locale& path_locale()
{
static std::locale loc(default_locale());
return loc;
}
inline const path::codecvt_type*& codecvt_facet_ptr()
{
static const std::codecvt<wchar_t, char, std::mbstate_t>*
facet(
&std::use_facet<std::codecvt<wchar_t, char, std::mbstate_t> >
(path_locale()));
return facet;
}
#elif defined(BOOST_WINDOWS_API) && !defined(BOOST_FILESYSTEM_STATIC_LINK)
std::locale path_locale(std::locale(), new windows_file_codecvt);
const std::codecvt<wchar_t, char, std::mbstate_t>*
codecvt_facet_ptr(&std::use_facet<std::codecvt<wchar_t, char, std::mbstate_t> >
(path_locale));
#elif defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)
// "All BSD system functions expect their string parameters to be in UTF-8 encoding
// and nothing else." See
// http://developer.apple.com/mac/library/documentation/MacOSX/Conceptual/BPInternational/Articles/FileEncodings.html
//
// "The kernel will reject any filename that is not a valid UTF-8 string, and it will
// even be normalized (to Unicode NFD) before stored on disk, at least when using HFS.
// The right way to deal with it would be to always convert the filename to UTF-8
// before trying to open/create a file." See
// http://lists.apple.com/archives/unix-porting/2007/Sep/msg00023.html
//
// "How a file name looks at the API level depends on the API. Current Carbon APIs
// handle file names as an array of UTF-16 characters; POSIX ones handle them as an
// array of UTF-8, which is why UTF-8 works well in Terminal. How it's stored on disk
// depends on the disk format; HFS+ uses UTF-16, but that's not important in most
// cases." See
// http://lists.apple.com/archives/applescript-users/2002/Sep/msg00319.html
//
// Many thanks to Peter Dimov for digging out the above references!
std::locale path_locale(std::locale(),
new boost::filesystem::detail::utf8_codecvt_facet);
const std::codecvt<wchar_t, char, std::mbstate_t>*
codecvt_facet_ptr(&std::use_facet<std::codecvt<wchar_t, char, std::mbstate_t> >
(path_locale));
#else // Other POSIX
// ISO C calls std::locale("") "the locale-specific native environment", and this
// locale is the default for many POSIX-based operating systems such as Linux.
// std::locale("") construction can throw (if environmental variables LC_MESSAGES or
// or LANG are wrong, for example), so lazy initialization is used to ensure
// that exceptions occur after main() starts and so can be caught.
std::locale path_locale; // initialized by path::codecvt() below
const std::codecvt<wchar_t, char, std::mbstate_t>* codecvt_facet_ptr; // ditto
# endif
} // unnamed namespace
//--------------------------------------------------------------------------------------//
// path::imbue implementation //
//--------------------------------------------------------------------------------------//
namespace boost
{
namespace filesystem
{
#if defined(BOOST_WINDOWS_API) && defined(BOOST_FILESYSTEM_STATIC_LINK)
const path::codecvt_type& path::codecvt()
{
BOOST_ASSERT_MSG(codecvt_facet_ptr(), "codecvt_facet_ptr() facet hasn't been properly initialized");
return *codecvt_facet_ptr();
}
std::locale path::imbue(const std::locale & loc)
{
std::locale temp(path_locale());
path_locale() = loc;
codecvt_facet_ptr() =
&std::use_facet<std::codecvt<wchar_t, char, std::mbstate_t> >(path_locale());
return temp;
}
#else
const path::codecvt_type& path::codecvt()
{
# if defined(BOOST_POSIX_API) && \
!(defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__))
// A local static initialized by calling path::imbue ensures that std::locale(""),
// which may throw, is called only if path_locale and condecvt_facet will actually
// be used. Thus misconfigured environmental variables will only cause an
// exception if a valid std::locale("") is actually needed.
static std::locale posix_lazy_initialization(path::imbue(std::locale("")));
# endif
return *codecvt_facet_ptr;
}
std::locale path::imbue(const std::locale& loc)
{
std::locale temp(path_locale);
path_locale = loc;
codecvt_facet_ptr =
&std::use_facet<std::codecvt<wchar_t, char, std::mbstate_t> >(path_locale);
return temp;
}
#endif
} // namespace filesystem
} // namespace boost

View File

@ -0,0 +1,200 @@
// filesystem path_traits.cpp --------------------------------------------------------//
// Copyright Beman Dawes 2008, 2009
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// Library home page: http://www.boost.org/libs/filesystem
//--------------------------------------------------------------------------------------//
// define BOOST_FILESYSTEM_SOURCE so that <boost/system/config.hpp> knows
// the library is being built (possibly exporting rather than importing code)
#define BOOST_FILESYSTEM_SOURCE
#ifndef BOOST_SYSTEM_NO_DEPRECATED
# define BOOST_SYSTEM_NO_DEPRECATED
#endif
#include <boost/filesystem/config.hpp>
#include <boost/filesystem/path_traits.hpp>
#include <boost/system/system_error.hpp>
#include <boost/scoped_array.hpp>
#include <locale> // for codecvt_base::result
#include <cstring> // for strlen
#include <cwchar> // for wcslen
namespace pt = boost::filesystem::path_traits;
namespace fs = boost::filesystem;
namespace bs = boost::system;
//--------------------------------------------------------------------------------------//
// configuration //
//--------------------------------------------------------------------------------------//
#ifndef BOOST_FILESYSTEM_CODECVT_BUF_SIZE
# define BOOST_FILESYSTEM_CODECVT_BUF_SIZE 256
#endif
namespace {
const std::size_t default_codecvt_buf_size = BOOST_FILESYSTEM_CODECVT_BUF_SIZE;
//--------------------------------------------------------------------------------------//
// //
// The public convert() functions do buffer management, and then forward to the //
// convert_aux() functions for the actual call to the codecvt facet. //
// //
//--------------------------------------------------------------------------------------//
//--------------------------------------------------------------------------------------//
// convert_aux const char* to wstring //
//--------------------------------------------------------------------------------------//
void convert_aux(
const char* from,
const char* from_end,
wchar_t* to, wchar_t* to_end,
std::wstring & target,
const pt::codecvt_type & cvt)
{
//std::cout << std::hex
// << " from=" << std::size_t(from)
// << " from_end=" << std::size_t(from_end)
// << " to=" << std::size_t(to)
// << " to_end=" << std::size_t(to_end)
// << std::endl;
std::mbstate_t state = std::mbstate_t(); // perhaps unneeded, but cuts bug reports
const char* from_next;
wchar_t* to_next;
std::codecvt_base::result res;
if ((res=cvt.in(state, from, from_end, from_next,
to, to_end, to_next)) != std::codecvt_base::ok)
{
//std::cout << " result is " << static_cast<int>(res) << std::endl;
BOOST_FILESYSTEM_THROW(bs::system_error(res, fs::codecvt_error_category(),
"boost::filesystem::path codecvt to wstring"));
}
target.append(to, to_next);
}
//--------------------------------------------------------------------------------------//
// convert_aux const wchar_t* to string //
//--------------------------------------------------------------------------------------//
void convert_aux(
const wchar_t* from,
const wchar_t* from_end,
char* to, char* to_end,
std::string & target,
const pt::codecvt_type & cvt)
{
//std::cout << std::hex
// << " from=" << std::size_t(from)
// << " from_end=" << std::size_t(from_end)
// << " to=" << std::size_t(to)
// << " to_end=" << std::size_t(to_end)
// << std::endl;
std::mbstate_t state = std::mbstate_t(); // perhaps unneeded, but cuts bug reports
const wchar_t* from_next;
char* to_next;
std::codecvt_base::result res;
if ((res=cvt.out(state, from, from_end, from_next,
to, to_end, to_next)) != std::codecvt_base::ok)
{
//std::cout << " result is " << static_cast<int>(res) << std::endl;
BOOST_FILESYSTEM_THROW(bs::system_error(res, fs::codecvt_error_category(),
"boost::filesystem::path codecvt to string"));
}
target.append(to, to_next);
}
} // unnamed namespace
//--------------------------------------------------------------------------------------//
// path_traits //
//--------------------------------------------------------------------------------------//
namespace boost { namespace filesystem { namespace path_traits {
//--------------------------------------------------------------------------------------//
// convert const char* to wstring //
//--------------------------------------------------------------------------------------//
BOOST_FILESYSTEM_DECL
void convert(const char* from,
const char* from_end, // 0 for null terminated MBCS
std::wstring & to,
const codecvt_type & cvt)
{
BOOST_ASSERT(from);
if (!from_end) // null terminated
{
from_end = from + std::strlen(from);
}
if (from == from_end) return;
std::size_t buf_size = (from_end - from) * 3; // perhaps too large, but that's OK
// dynamically allocate a buffer only if source is unusually large
if (buf_size > default_codecvt_buf_size)
{
boost::scoped_array< wchar_t > buf(new wchar_t [buf_size]);
convert_aux(from, from_end, buf.get(), buf.get()+buf_size, to, cvt);
}
else
{
wchar_t buf[default_codecvt_buf_size];
convert_aux(from, from_end, buf, buf+default_codecvt_buf_size, to, cvt);
}
}
//--------------------------------------------------------------------------------------//
// convert const wchar_t* to string //
//--------------------------------------------------------------------------------------//
BOOST_FILESYSTEM_DECL
void convert(const wchar_t* from,
const wchar_t* from_end, // 0 for null terminated MBCS
std::string & to,
const codecvt_type & cvt)
{
BOOST_ASSERT(from);
if (!from_end) // null terminated
{
from_end = from + std::wcslen(from);
}
if (from == from_end) return;
// The codecvt length functions may not be implemented, and I don't really
// understand them either. Thus this code is just a guess; if it turns
// out the buffer is too small then an error will be reported and the code
// will have to be fixed.
std::size_t buf_size = (from_end - from) * 4; // perhaps too large, but that's OK
buf_size += 4; // encodings like shift-JIS need some prefix space
// dynamically allocate a buffer only if source is unusually large
if (buf_size > default_codecvt_buf_size)
{
boost::scoped_array< char > buf(new char [buf_size]);
convert_aux(from, from_end, buf.get(), buf.get()+buf_size, to, cvt);
}
else
{
char buf[default_codecvt_buf_size];
convert_aux(from, from_end, buf, buf+default_codecvt_buf_size, to, cvt);
}
}
}}} // namespace boost::filesystem::path_traits

View File

@ -0,0 +1,119 @@
// portability.cpp -------------------------------------------------------------------//
// Copyright 2002-2005 Beman Dawes
// Use, modification, and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy
// at http://www.boost.org/LICENSE_1_0.txt)
// See library home page at http://www.boost.org/libs/filesystem
//--------------------------------------------------------------------------------------//
// define BOOST_FILESYSTEM_SOURCE so that <boost/filesystem/config.hpp> knows
// the library is being built (possibly exporting rather than importing code)
#define BOOST_FILESYSTEM_SOURCE
#ifndef BOOST_SYSTEM_NO_DEPRECATED
# define BOOST_SYSTEM_NO_DEPRECATED
#endif
#include <boost/filesystem/config.hpp>
#include <boost/filesystem/path.hpp>
namespace fs = boost::filesystem;
#include <cstring> // SGI MIPSpro compilers need this
# ifdef BOOST_NO_STDC_NAMESPACE
namespace std { using ::strerror; }
# endif
//--------------------------------------------------------------------------------------//
namespace
{
const char invalid_chars[] =
"\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F"
"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"
"<>:\"/\\|";
// note that the terminating '\0' is part of the string - thus the size below
// is sizeof(invalid_chars) rather than sizeof(invalid_chars)-1. I
const std::string windows_invalid_chars(invalid_chars, sizeof(invalid_chars));
const std::string valid_posix(
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._-");
} // unnamed namespace
namespace boost
{
namespace filesystem
{
// name_check functions ----------------------------------------------//
# ifdef BOOST_WINDOWS
BOOST_FILESYSTEM_DECL bool native(const std::string & name)
{
return windows_name(name);
}
# else
BOOST_FILESYSTEM_DECL bool native(const std::string & name)
{
return name.size() != 0
&& name[0] != ' '
&& name.find('/') == std::string::npos;
}
# endif
BOOST_FILESYSTEM_DECL bool portable_posix_name(const std::string & name)
{
return name.size() != 0
&& name.find_first_not_of(valid_posix) == std::string::npos;
}
BOOST_FILESYSTEM_DECL bool windows_name(const std::string & name)
{
return name.size() != 0
&& name[0] != ' '
&& name.find_first_of(windows_invalid_chars) == std::string::npos
&& *(name.end()-1) != ' '
&& (*(name.end()-1) != '.'
|| name.length() == 1 || name == "..");
}
BOOST_FILESYSTEM_DECL bool portable_name(const std::string & name)
{
return
name.size() != 0
&& (name == "."
|| name == ".."
|| (windows_name(name)
&& portable_posix_name(name)
&& name[0] != '.' && name[0] != '-'));
}
BOOST_FILESYSTEM_DECL bool portable_directory_name(const std::string & name)
{
return
name == "."
|| name == ".."
|| (portable_name(name)
&& name.find('.') == std::string::npos);
}
BOOST_FILESYSTEM_DECL bool portable_file_name(const std::string & name)
{
std::string::size_type pos;
return
portable_name(name)
&& name != "."
&& name != ".."
&& ((pos = name.find('.')) == std::string::npos
|| (name.find('.', pos+1) == std::string::npos
&& (pos + 5) > name.length()))
;
}
} // namespace filesystem
} // namespace boost

View File

@ -0,0 +1,142 @@
// filesystem unique_path.cpp --------------------------------------------------------//
// Copyright Beman Dawes 2010
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// Library home page: http://www.boost.org/libs/filesystem
//--------------------------------------------------------------------------------------//
// define BOOST_FILESYSTEM_SOURCE so that <boost/filesystem/config.hpp> knows
// the library is being built (possibly exporting rather than importing code)
#define BOOST_FILESYSTEM_SOURCE
#ifndef BOOST_SYSTEM_NO_DEPRECATED
# define BOOST_SYSTEM_NO_DEPRECATED
#endif
#include <boost/filesystem/operations.hpp>
# ifdef BOOST_POSIX_API
# include <fcntl.h>
# else // BOOST_WINDOWS_API
# include <windows.h>
# include <wincrypt.h>
# pragma comment(lib, "Advapi32.lib")
# endif
namespace {
void fail(int err, boost::system::error_code* ec)
{
if (ec == 0)
BOOST_FILESYSTEM_THROW( boost::system::system_error(err,
boost::system::system_category(),
"boost::filesystem::unique_path"));
ec->assign(err, boost::system::system_category());
return;
}
void system_crypt_random(void* buf, std::size_t len, boost::system::error_code* ec)
{
# ifdef BOOST_POSIX_API
int file = open("/dev/urandom", O_RDONLY);
if (file == -1)
{
file = open("/dev/random", O_RDONLY);
if (file == -1)
{
fail(errno, ec);
return;
}
}
size_t bytes_read = 0;
while (bytes_read < len)
{
ssize_t n = read(file, buf, len - bytes_read);
if (n == -1)
{
close(file);
fail(errno, ec);
return;
}
bytes_read += n;
buf = static_cast<char*>(buf) + n;
}
close(file);
# else // BOOST_WINDOWS_API
HCRYPTPROV handle;
int errval = 0;
if (!::CryptAcquireContextW(&handle, 0, 0, PROV_RSA_FULL, 0))
{
errval = ::GetLastError();
if (errval == NTE_BAD_KEYSET)
{
if (!::CryptAcquireContextW(&handle, 0, 0, PROV_RSA_FULL, CRYPT_NEWKEYSET))
{
errval = ::GetLastError();
}
else errval = 0;
}
}
if (!errval)
{
BOOL gen_ok = ::CryptGenRandom(handle, len, static_cast<unsigned char*>(buf));
if (!gen_ok)
errval = ::GetLastError();
::CryptReleaseContext(handle, 0);
}
if (!errval) return;
fail(errval, ec);
# endif
}
} // unnamed namespace
namespace boost { namespace filesystem { namespace detail {
BOOST_FILESYSTEM_DECL
path unique_path(const path& model, system::error_code* ec)
{
std::wstring s (model.wstring()); // std::string ng for MBCS encoded POSIX
const wchar_t hex[] = L"0123456789abcdef";
const int n_ran = 16;
const int max_nibbles = 2 * n_ran; // 4-bits per nibble
char ran[n_ran];
int nibbles_used = max_nibbles;
for(std::wstring::size_type i=0; i < s.size(); ++i)
{
if (s[i] == L'%') // digit request
{
if (nibbles_used == max_nibbles)
{
system_crypt_random(ran, sizeof(ran), ec);
if (ec != 0 && *ec)
return "";
nibbles_used = 0;
}
int c = ran[nibbles_used/2];
c >>= 4 * (nibbles_used++ & 1); // if odd, shift right 1 nibble
s[i] = hex[c & 0xf]; // convert to hex digit and replace
}
}
if (ec != 0) ec->clear();
return s;
}
}}}

View File

@ -0,0 +1,27 @@
// Copyright Vladimir Prus 2004.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)
// For HP-UX, request that WCHAR_MAX and WCHAR_MIN be defined as macros,
// not casts. See ticket 5048
#define _INCLUDE_STDCSOURCE_199901
#ifndef BOOST_SYSTEM_NO_DEPRECATED
# define BOOST_SYSTEM_NO_DEPRECATED
#endif
#define BOOST_FILESYSTEM_SOURCE
#include <boost/filesystem/config.hpp>
#define BOOST_UTF8_BEGIN_NAMESPACE \
namespace boost { namespace filesystem { namespace detail {
#define BOOST_UTF8_END_NAMESPACE }}}
#define BOOST_UTF8_DECL BOOST_FILESYSTEM_DECL
#include <boost/detail/utf8_codecvt_facet.ipp>
#undef BOOST_UTF8_BEGIN_NAMESPACE
#undef BOOST_UTF8_END_NAMESPACE
#undef BOOST_UTF8_DECL

View File

@ -0,0 +1,75 @@
// filesystem windows_file_codecvt.cpp -----------------------------------------//
// Copyright Beman Dawes 2009
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// Library home page: http://www.boost.org/libs/filesystem
//--------------------------------------------------------------------------------------//
// define BOOST_FILESYSTEM_SOURCE so that <boost/system/config.hpp> knows
// the library is being built (possibly exporting rather than importing code)
#define BOOST_FILESYSTEM_SOURCE
#ifndef BOOST_SYSTEM_NO_DEPRECATED
# define BOOST_SYSTEM_NO_DEPRECATED
#endif
#include <boost/filesystem/config.hpp>
#include <cwchar> // for mbstate_t
#ifdef BOOST_WINDOWS_API
#include "windows_file_codecvt.hpp"
// Versions of MinGW prior to GCC 4.6 requires this
#ifndef WINVER
# define WINVER 0x0500
#endif
#include <windows.h>
std::codecvt_base::result windows_file_codecvt::do_in(
std::mbstate_t &,
const char* from, const char* from_end, const char*& from_next,
wchar_t* to, wchar_t* to_end, wchar_t*& to_next) const
{
UINT codepage = AreFileApisANSI() ? CP_ACP : CP_OEMCP;
int count;
if ((count = ::MultiByteToWideChar(codepage, MB_PRECOMPOSED, from,
from_end - from, to, to_end - to)) == 0)
{
return error; // conversion failed
}
from_next = from_end;
to_next = to + count;
*to_next = L'\0';
return ok;
}
std::codecvt_base::result windows_file_codecvt::do_out(
std::mbstate_t &,
const wchar_t* from, const wchar_t* from_end, const wchar_t* & from_next,
char* to, char* to_end, char* & to_next) const
{
UINT codepage = AreFileApisANSI() ? CP_ACP : CP_OEMCP;
int count;
if ((count = ::WideCharToMultiByte(codepage, WC_NO_BEST_FIT_CHARS, from,
from_end - from, to, to_end - to, 0, 0)) == 0)
{
return error; // conversion failed
}
from_next = from_end;
to_next = to + count;
*to_next = '\0';
return ok;
}
# endif // BOOST_WINDOWS_API

View File

@ -0,0 +1,56 @@
// filesystem windows_file_codecvt.hpp -----------------------------------------------//
// Copyright Beman Dawes 2009
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// Library home page: http://www.boost.org/libs/filesystem
#ifndef BOOST_FILESYSTEM3_WIN_FILE_CODECVT_HPP
#define BOOST_FILESYSTEM3_WIN_FILE_CODECVT_HPP
#include <boost/filesystem/config.hpp>
#include <locale>
//------------------------------------------------------------------------------------//
// //
// class windows_file_codecvt //
// //
// Warning: partial implementation; even do_in and do_out only partially meet the //
// standard library specifications as the "to" buffer must hold the entire result. //
// //
//------------------------------------------------------------------------------------//
class BOOST_FILESYSTEM_DECL windows_file_codecvt
: public std::codecvt< wchar_t, char, std::mbstate_t >
{
public:
explicit windows_file_codecvt()
: std::codecvt<wchar_t, char, std::mbstate_t>() {}
protected:
virtual bool do_always_noconv() const throw() { return false; }
// seems safest to assume variable number of characters since we don't
// actually know what codepage is active
virtual int do_encoding() const throw() { return 0; }
virtual std::codecvt_base::result do_in(std::mbstate_t& state,
const char* from, const char* from_end, const char*& from_next,
wchar_t* to, wchar_t* to_end, wchar_t*& to_next) const;
virtual std::codecvt_base::result do_out(std::mbstate_t & state,
const wchar_t* from, const wchar_t* from_end, const wchar_t*& from_next,
char* to, char* to_end, char*& to_next) const;
virtual std::codecvt_base::result do_unshift(std::mbstate_t&,
char* /*from*/, char* /*to*/, char* & /*next*/) const { return ok; }
virtual int do_length(std::mbstate_t&,
const char* /*from*/, const char* /*from_end*/, std::size_t /*max*/) const { return 0; }
virtual int do_max_length() const throw () { return 0; }
};
#endif // BOOST_FILESYSTEM3_WIN_FILE_CODECVT_HPP