filename.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // Copyright 2009-2021 Intel Corporation
  2. // SPDX-License-Identifier: Apache-2.0
  3. #pragma once
  4. #include "platform.h"
  5. namespace embree
  6. {
  7. /*! Convenience class for handling file names and paths. */
  8. class FileName
  9. {
  10. public:
  11. /*! create an empty filename */
  12. FileName ();
  13. /*! create a valid filename from a string */
  14. FileName (const char* filename);
  15. /*! create a valid filename from a string */
  16. FileName (const std::string& filename);
  17. /*! returns path to home folder */
  18. static FileName homeFolder();
  19. /*! returns path to executable */
  20. static FileName executableFolder();
  21. /*! auto convert into a string */
  22. operator std::string() const { return filename; }
  23. /*! returns a string of the filename */
  24. const std::string str() const { return filename; }
  25. /*! returns a c-string of the filename */
  26. const char* c_str() const { return filename.c_str(); }
  27. /*! returns the path of a filename */
  28. FileName path() const;
  29. /*! returns the file of a filename */
  30. std::string base() const;
  31. /*! returns the base of a filename without extension */
  32. std::string name() const;
  33. /*! returns the file extension */
  34. std::string ext() const;
  35. /*! drops the file extension */
  36. FileName dropExt() const;
  37. /*! replaces the file extension */
  38. FileName setExt(const std::string& ext = "") const;
  39. /*! adds file extension */
  40. FileName addExt(const std::string& ext = "") const;
  41. /*! concatenates two filenames to this/other */
  42. FileName operator +( const FileName& other ) const;
  43. /*! concatenates two filenames to this/other */
  44. FileName operator +( const std::string& other ) const;
  45. /*! removes the base from a filename (if possible) */
  46. FileName operator -( const FileName& base ) const;
  47. /*! == operator */
  48. friend bool operator==(const FileName& a, const FileName& b);
  49. /*! != operator */
  50. friend bool operator!=(const FileName& a, const FileName& b);
  51. /*! output operator */
  52. friend std::ostream& operator<<(std::ostream& cout, const FileName& filename);
  53. private:
  54. std::string filename;
  55. };
  56. }