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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. /// Trim whitespace from a string.
  74. //
  75. // This method removes leading " ", "\t", "\r", and "\n" from the specified string.
  76. //
  77. // \param[in] String is the string to trim.
  78. //
  79. // \returns String with the leading and trailing whitespace removed.
  80. static std::string Trim(std::string String);
  81. /// Store the Verbose mode.
  82. //
  83. // \param[in] Mode stores the Verbose mode.
  84. //
  85. void SetVerbose(bool Mode);
  86. /// Provide verbose output?
  87. //
  88. // \returns true if the application is to provide verbose output.
  89. //
  90. bool Verbose();
  91. /// Store the Explain mode.
  92. //
  93. // \param[in] Mode stores the Explain mode.
  94. //
  95. void SetExplain(bool Mode);
  96. /// Provide an explanation of the actions only?
  97. //
  98. // \returns true if the application is to provide an explanation
  99. // of the actions without executing any commands.
  100. //
  101. bool Explain();
  102. /// Store the Help mode.
  103. //
  104. // \param[in] Mode stores the Help mode.
  105. //
  106. void SetHelp(bool Mode);
  107. /// Provide help?
  108. //
  109. // \returns true if the application is to output a help message.
  110. //
  111. bool Help();
  112. /// Output the end of a verbose output line.
  113. void OutputVerboseEnd();
  114. /// Directory separator.
  115. static const std::string DirectorySeparator;
  116. /// Trim whitespace from a string.
  117. private:
  118. bool VerboseRequested; ///< User requested verbose processing.
  119. bool ExplainRequested; ///< User requested verbose processing but without actually executing the commands.
  120. bool HelpRequested; ///< User requested help.
  121. };
  122. #endif