filename.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // ======================================================================== //
  2. // Copyright 2009-2017 Intel Corporation //
  3. // //
  4. // Licensed under the Apache License, Version 2.0 (the "License"); //
  5. // you may not use this file except in compliance with the License. //
  6. // You may obtain a copy of the License at //
  7. // //
  8. // http://www.apache.org/licenses/LICENSE-2.0 //
  9. // //
  10. // Unless required by applicable law or agreed to in writing, software //
  11. // distributed under the License is distributed on an "AS IS" BASIS, //
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //
  13. // See the License for the specific language governing permissions and //
  14. // limitations under the License. //
  15. // ======================================================================== //
  16. #pragma once
  17. #include "platform.h"
  18. namespace embree
  19. {
  20. /*! Convenience class for handling file names and paths. */
  21. class FileName
  22. {
  23. public:
  24. /*! create an empty filename */
  25. FileName ();
  26. /*! create a valid filename from a string */
  27. FileName (const char* filename);
  28. /*! create a valid filename from a string */
  29. FileName (const std::string& filename);
  30. /*! returns path to home folder */
  31. static FileName homeFolder();
  32. /*! returns path to executable */
  33. static FileName executableFolder();
  34. /*! auto convert into a string */
  35. operator std::string() const { return filename; }
  36. /*! returns a string of the filename */
  37. const std::string str() const { return filename; }
  38. /*! returns a c-string of the filename */
  39. const char* c_str() const { return filename.c_str(); }
  40. /*! returns the path of a filename */
  41. FileName path() const;
  42. /*! returns the file of a filename */
  43. std::string base() const;
  44. /*! returns the base of a filename without extension */
  45. std::string name() const;
  46. /*! returns the file extension */
  47. std::string ext() const;
  48. /*! drops the file extension */
  49. FileName dropExt() const;
  50. /*! replaces the file extension */
  51. FileName setExt(const std::string& ext = "") const;
  52. /*! adds file extension */
  53. FileName addExt(const std::string& ext = "") const;
  54. /*! concatenates two filenames to this/other */
  55. FileName operator +( const FileName& other ) const;
  56. /*! concatenates two filenames to this/other */
  57. FileName operator +( const std::string& other ) const;
  58. /*! removes the base from a filename (if possible) */
  59. FileName operator -( const FileName& base ) const;
  60. /*! == operator */
  61. friend bool operator==(const FileName& a, const FileName& b);
  62. /*! != operator */
  63. friend bool operator!=(const FileName& a, const FileName& b);
  64. /*! output operator */
  65. friend std::ostream& operator<<(std::ostream& cout, const FileName& filename);
  66. private:
  67. std::string filename;
  68. };
  69. }