filename.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 executable */
  18. static FileName executableFolder();
  19. /*! auto convert into a string */
  20. operator std::string() const { return filename; }
  21. /*! returns a string of the filename */
  22. const std::string str() const { return filename; }
  23. /*! returns a c-string of the filename */
  24. const char* c_str() const { return filename.c_str(); }
  25. /*! returns the path of a filename */
  26. FileName path() const;
  27. /*! returns the file of a filename */
  28. std::string base() const;
  29. /*! returns the base of a filename without extension */
  30. std::string name() const;
  31. /*! returns the file extension */
  32. std::string ext() const;
  33. /*! drops the file extension */
  34. FileName dropExt() const;
  35. /*! replaces the file extension */
  36. FileName setExt(const std::string& ext = "") const;
  37. /*! adds file extension */
  38. FileName addExt(const std::string& ext = "") const;
  39. /*! concatenates two filenames to this/other */
  40. FileName operator +( const FileName& other ) const;
  41. /*! concatenates two filenames to this/other */
  42. FileName operator +( const std::string& other ) const;
  43. /*! removes the base from a filename (if possible) */
  44. FileName operator -( const FileName& base ) const;
  45. /*! == operator */
  46. friend bool operator==(const FileName& a, const FileName& b);
  47. /*! != operator */
  48. friend bool operator!=(const FileName& a, const FileName& b);
  49. /*! output operator */
  50. friend std::ostream& operator<<(std::ostream& cout, const FileName& filename);
  51. private:
  52. std::string filename;
  53. };
  54. }