I subsitute the std allocator with my own stl allocator, and defined a new string type like this:
1 2
|
typedef std::basic_string<char, std::char_traits<char>, MySTLAllocator<char> > my_string;
typedef std::basic_string<wchar_t, std::char_traits<wchar_t>, MySTLAllocator<wchar_t> > my_wstring;
|
And I want to use them in my project, but I met some problem when I use boost.asio and boost.filesystem.
The boost asio directly use std::string, I can not find a way to deal with it. I know I can pass a c style string char* to the asio, but it was less efficiency.
When use the boost.filesystem, I tried this way, but I also met some problem:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
namespace MyNamespace
{
struct path_traits;
typedef boost::filesystem::basic_path<my_string, path_traits> path;
typedef boost::filesystem::basic_path<my_wstring, path_traits> wpath;
struct path_traits
{
typedef my_string internal_string_type;
typedef my_string external_string_type;
static external_string_type to_external( const path &,
const internal_string_type & src ) { return src; }
static internal_string_type to_internal(
const external_string_type & src ) { return src; }
};
typedef boost::filesystem::basic_recursive_directory_iterator<path> recursive_directory_iterator;
typedef boost::filesystem::basic_recursive_directory_iterator<wpath> wrecursive_directory_iterator;
}
namespace boost
{
namespace filesystem
{
template<> struct is_basic_path<MyNamespace::path>
{ BOOST_STATIC_CONSTANT( bool, value = true ); };
template<> struct is_basic_path<MyNamespace::wpath>
{ BOOST_STATIC_CONSTANT( bool, value = true ); };
}
}
namespace MyNamespace
{
inline bool is_directory( const path & ph )
{ return boost::filesystem::is_directory<path>( ph ); }
inline bool is_directory( const wpath & ph )
{ return boost::filesystem::is_directory<wpath>( ph ); }
}
|
For replace all the function is a huge work, and in this way I can not replace it for I met this function, which is also use the std::string directly:
1 2
|
BOOST_FILESYSTEM_DECL file_status
status_api( const std::string & ph, system::error_code & ec );
|
Maybe this way is too bother, I think there must be an easy way to replace the string.
Is there any way to resolve this? Thank you.