選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

FileBackup.hpp 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // FileBackup.hpp
  2. //
  3. // Copyright (C) 2011 ARM Research Labs, LLC.
  4. // See www.armresearch.com for the copyright terms.
  5. //
  6. // This file defines the interface used by the FileBackup class.
  7. //
  8. #ifndef FileBackuphpp_included
  9. #define FileBackuphpp_included
  10. #include <string>
  11. #include <map>
  12. /// FileBackup class.
  13. //
  14. // This class provides capability to manage the backup and restore of
  15. // disk files.
  16. //
  17. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  18. class FileBackup {
  19. public:
  20. /// Create a backup of the specified file.
  21. //
  22. // This method creates a backup of the specified file The name of
  23. // the link is the name of the file appended by the BackupSuffix
  24. // data member.
  25. //
  26. // The file can be restored from the backup by RestoreFromBackup.
  27. //
  28. // \param[in] File is the file name to create a backup for.
  29. //
  30. // \throws std::runtime_error if an error is encountered.
  31. //
  32. // \see RestoreAllFilesFromBackup().
  33. //
  34. void CreateBackupFile(std::string File);
  35. /// Remove the backups of all the specified files.
  36. //
  37. // This method removes the backup of the files specified by the
  38. // CreateBackup() method.
  39. //
  40. // \throws std::runtime_error if an error is encountered.
  41. //
  42. void RemoveAllBackupFiles();
  43. /// Restore the all the specified files from the backup.
  44. //
  45. // This method restores the backup of the files specified by the
  46. // CreateBackupFile() method.
  47. //
  48. // \throws std::runtime_error if an error is encountered.
  49. //
  50. // \see CreateBackupFile().
  51. //
  52. void RestoreAllFilesFromBackup();
  53. /// Get the name of the backup file.
  54. //
  55. // \param[in] File is the name of the file to back up.
  56. //
  57. // \returns the name of the backup file.
  58. //
  59. static std::string GetBackupFileName(std::string File);
  60. /// Check if a file exists.
  61. //
  62. // \returns true if the file exists, false otherwise.
  63. //
  64. static bool FileExists(std::string File);
  65. private:
  66. /// Copy a file.
  67. //
  68. // \param[in] From is the name of the file to copy from.
  69. //
  70. // \param[in] To is the name of the file to copy to.
  71. //
  72. // \throws runtime_error in case of error.
  73. //
  74. void CopyFile(std::string From, std::string To);
  75. /// Suffix to append to the file name to obtain the backup file
  76. /// name.
  77. static const std::string BackupSuffix;
  78. /// Typedef for container of names of files.
  79. //
  80. // The key is the name of the file to back up. The value is true
  81. // if the file to back up exists, false otherwise.
  82. typedef std::map<std::string, bool> FilenameContainer;
  83. /// Container of files that have backups.
  84. FilenameContainer OriginalFileExists;
  85. };
  86. #endif