absolute_path.hpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * Distributed under the Boost Software License, Version 1.0.(See accompanying
  3. * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
  4. *
  5. * See http://www.boost.org/libs/iostreams for documentation.
  6. * File: boost/iostreams/detail/execute.hpp
  7. * Date: Thu Dec 06 13:21:54 MST 2007
  8. * Copyright: 2007-2008 CodeRage, LLC
  9. * Author: Jonathan Turkanis
  10. * Contact: turkanis at coderage dot com
  11. *
  12. * Defines the function boost::iostreams::detail::absolute_path, used for
  13. * debug output for mapped files.
  14. */
  15. #ifndef BOOST_IOSTREAMS_DETAIL_ABSOLUTE_PATH_HPP_INCLUDED
  16. #define BOOST_IOSTREAMS_DETAIL_ABSOLUTE_PATH_HPP_INCLUDED
  17. #include <string>
  18. #include <boost/iostreams/detail/config/windows_posix.hpp>
  19. #ifdef BOOST_IOSTREAMS_WINDOWS
  20. # include <cctype>
  21. #endif
  22. #include <boost/iostreams/detail/current_directory.hpp>
  23. namespace boost { namespace iostreams { namespace detail {
  24. // Resolves the given path relative to the current working directory
  25. inline std::string absolute_path(const std::string& path)
  26. {
  27. #ifdef BOOST_IOSTREAMS_WINDOWS
  28. return path.size() && (path[0] == '/' || path[0] == '\\') ||
  29. path.size() > 1 && std::isalpha(path[0]) && path[1] == ':' ?
  30. path :
  31. current_directory() + '\\' + path;
  32. #else // #ifdef BOOST_IOSTREAMS_WINDOWS
  33. return path.size() && (path[0] == '/') ?
  34. path :
  35. current_directory() + '/' + path;
  36. #endif // #ifdef BOOST_IOSTREAMS_WINDOWS
  37. }
  38. } } } // End namespaces detail, iostreams, boost.
  39. #endif // #ifndef BOOST_IOSTREAMS_DETAIL_ABSOLUTE_PATH_HPP_INCLUDED