Boost logo

Boost :

From: Martin (adrianm_at_[hidden])
Date: 2004-09-03 02:54:29


Just a thought on the filesystem implementation.

Why not separate the path from the filesystem?

Let the path be a container for all kind of paths that follow the generic
syntax explained in the boost::filesystem documentation.

Then use implementation classes that handles root name and conversion to
native strings etc.

The benefits would be:
1. The path can be used for other things than filesystems (XPath, Win32
registry)

2. Operations can be implemented selectivly for different types (No need for
the current messy #ifdefs)
bool exists( const path_base<posixfs<std::string> >& aPath);
bool exists( const path_base<win32fs<std::wstring> >& aPath);
bool exists( const path_base<win32reg<boost::fixed_string<100> > >& aPath);

3. Easy to expand the functionality for specific tasks without touching the
boost headers.

The implementation could look something like:

template <class ImplT>
class path_base : private ImplT {
  public:
    typedef ImplT::string_type string_type;
    path_base() : ImplT() {}
    // all path operations as in current implementation
    ...
  private:
    string_type m_path;
};

//
// implementation for win32 filesystem
//
template <class StringT>
class win32fs {
  // root-name ::= root-drive | root-share | root-device
  // root-drive ::= char ":"
  // root-share ::= "//" name
  // root-device ::= name ":"
  protected:
    typedef StringT string_type;
    win32fs() { }
    string_type make_generic(const string_type::value_type* src);
    string_type native_file_string(const string_type& m_path) const { return
algorithm::replace_all_copy(m_root + m_path, "/", "\\"); }
    ...
  private:
    string_type m_root
};
//
// implementation of posix filesystem
//
template <class StringT>
class posixfs {
  win32fs() { }
  string_type make_generic(const string_type::value_type* src);
  string_type native_file_string(const string_type& m_path) const { return
m_path; }
  ...
}

#ifdef BOOST_POSIX
typedef path_base<posixfs<std::string>> path;
#else
...


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk