Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. // \file filesystem.hpp
  2. //
  3. // Copyright (C) 2015 MicroNeil Research Corporation.
  4. //
  5. // This program is part of the MicroNeil Research Open Library Project. For
  6. // more information go to http://www.microneil.com/OpenLibrary/index.html
  7. //
  8. // This program is free software; you can redistribute it and/or modify it
  9. // under the terms of the GNU General Public License as published by the
  10. // Free Software Foundation; either version 2 of the License, or (at your
  11. // option) any later version.
  12. //
  13. // This program is distributed in the hope that it will be useful, but WITHOUT
  14. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  16. // more details.
  17. //
  18. // You should have received a copy of the GNU General Public License along with
  19. // this program; if not, write to the Free Software Foundation, Inc., 59 Temple
  20. // Place, Suite 330, Boston, MA 02111-1307 USA
  21. //==============================================================================
  22. /*
  23. \brief The filesystem module provides classes to access the filesystem.
  24. */
  25. #ifndef FILESYSTEM_HPP
  26. #define FILESYSTEM_HPP
  27. #include <ctime>
  28. #include <string>
  29. namespace CodeDweller {
  30. /** Abstracts OS specifics for identifying a file and provides
  31. access to meta data.
  32. */
  33. class FileReference {
  34. public:
  35. /** Initialize with the name of the file.
  36. @param[in] fileName is the name of the file.
  37. */
  38. FileReference(std::string fileName);
  39. /** Return timestamp.
  40. @returns the epoch modification time for file when
  41. FileReference was created or last refreshed, or zero if the
  42. file doesn't exist.
  43. */
  44. time_t ModTimestamp() const;
  45. /** Get the file size.
  46. @returns the size of file when FileReference was created or
  47. last refreshed, or 0 if the file doesn't exist.
  48. */
  49. long Size() const;
  50. /** Get full path.
  51. @returns a fully referenced path to the file.
  52. */
  53. std:: string FullPath() const;
  54. /** Refreshes the FileReference object with the current data on the file
  55. system.
  56. */
  57. void refresh();
  58. /** Check if the file exists.
  59. @returns true if the file reference name exists in the file
  60. system, false otherwise.
  61. @throws std::runtime_error if an error occurs.
  62. */
  63. bool exists() const;
  64. /** Check if the file is a directory.
  65. @returns true if the name provided on construction resulted in
  66. finding a directory not a file, and false otherwise or if the
  67. file doesn't exist.
  68. */
  69. bool isDirectory() const;
  70. private:
  71. /// Return text for the most recent error.
  72. //
  73. // \returns Human-readable description of the most recent error.
  74. //
  75. static std::string getErrorText();
  76. /** Name provided to constructor. */
  77. std::string name;
  78. /** Full path. */
  79. std::string path;
  80. /** Timestamp. */
  81. time_t modTimestamp;
  82. /** Size in bytes. */
  83. long size_bytes;
  84. /** True if the file exists, false otherwise. */
  85. bool fileExists;
  86. /** True if the file is a directory, false otherwise. */
  87. bool fileIsDirectory;
  88. };
  89. }
  90. #endif // FILESYSTEM_HPP