You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Utility.hpp 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. // Utility.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 configuration utilities.
  7. //
  8. #ifndef Utilityhpp_included
  9. #define Utilityhpp_included
  10. #include <sys/stat.h>
  11. #include <string>
  12. /// Base class for the Sniffer configuration.
  13. //
  14. // This class provides capability common to the configuration classes.
  15. //
  16. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  17. class Utility {
  18. public:
  19. /// Default constructor.
  20. Utility();
  21. /// Check whether a file exists.
  22. //
  23. // \returns true if the file exists, false otherwise.
  24. //
  25. bool FileExists(std::string File);
  26. /// Copy a file.
  27. //
  28. // \param[in] From is the name of the source file.
  29. //
  30. // \param[in] To is the name of the destination file.
  31. //
  32. void Copy(std::string From, std::string To);
  33. /// Set the owner and group of the specified file.
  34. //
  35. // This function sets the owner and group of the specified file to the
  36. // value specified in Utility.cpp.
  37. //
  38. // \param[in] File is the specified file.
  39. //
  40. // \see SNFUserName.
  41. //
  42. // \see SNFGroupName.
  43. //
  44. void SetOwnerGroup(std::string &File);
  45. /// Set the mode of a file.
  46. //
  47. // This function sets the mode of the specified file. If an error
  48. // occurs, an exception is thrown.
  49. //
  50. // \param[in] File is the specified file.
  51. //
  52. // \param[in] is the mode.
  53. //
  54. void SetMode(std::string &File, mode_t mode);
  55. /// Create a directory.
  56. //
  57. // This function creates the specified directory. If an error
  58. // occurs, an exception is thrown.
  59. //
  60. // \param[in] Dir is the directory to create.
  61. //
  62. void MkDir(std::string &Dir);
  63. /// Check for a specified string at the beginning of a line.
  64. //
  65. // This function checks for the specified string at the beginning of a
  66. // line. Leading whitespace in the line is ignored.
  67. //
  68. // \param[in] Line is the line.
  69. //
  70. // \param[in] SearchString is the string to check for.
  71. //
  72. static bool CheckForString(std::string Line, std::string SearchString);
  73. /// Store the Verbose mode.
  74. //
  75. // \param[in] Mode stores the Verbose mode.
  76. //
  77. void SetVerbose(bool Mode);
  78. /// Provide verbose output?
  79. //
  80. // \returns true if the application is to provide verbose output.
  81. //
  82. bool Verbose();
  83. /// Store the Explain mode.
  84. //
  85. // \param[in] Mode stores the Explain mode.
  86. //
  87. void SetExplain(bool Mode);
  88. /// Provide an explanation of the actions only?
  89. //
  90. // \returns true if the application is to provide an explanation
  91. // of the actions without executing any commands.
  92. //
  93. bool Explain();
  94. /// Store the Help mode.
  95. //
  96. // \param[in] Mode stores the Help mode.
  97. //
  98. void SetHelp(bool Mode);
  99. /// Provide help?
  100. //
  101. // \returns true if the application is to output a help message.
  102. //
  103. bool Help();
  104. /// Output the end of a verbose output line.
  105. void OutputVerboseEnd();
  106. /// Directory separator.
  107. static const std::string DirectorySeparator;
  108. private:
  109. bool VerboseRequested; ///< User requested verbose processing.
  110. bool ExplainRequested; ///< User requested verbose processing but without actually executing the commands.
  111. bool HelpRequested; ///< User requested help.
  112. };
  113. #endif