Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

Utility.hpp 4.5KB

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