Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. // \param[in] File is the name of the file.
  24. //
  25. // \returns true if the file exists, false otherwise.
  26. //
  27. bool FileExists(std::string File);
  28. /// Read last part of a file.
  29. //
  30. // \param[in] File is the name of the file.
  31. //
  32. // \param[in] Size is the number of bytes from the end to start reading.
  33. //
  34. // \returns contents of the end of the file if the file exists, "" otherwise.
  35. //
  36. std::string ReadLastPartOfFile(std::string File, long Size);
  37. /// Copy a file.
  38. //
  39. // \param[in] From is the name of the source file.
  40. //
  41. // \param[in] To is the name of the destination file.
  42. //
  43. void Copy(std::string From, std::string To);
  44. /// Set the owner and group of the specified file.
  45. //
  46. // This function sets the owner and group of the specified file to the
  47. // value specified in Utility.cpp.
  48. //
  49. // \param[in] File is the specified file.
  50. //
  51. // \see SNFUserName.
  52. //
  53. // \see SNFGroupName.
  54. //
  55. void SetOwnerGroup(std::string File);
  56. /// Set the mode of a file.
  57. //
  58. // This function sets the mode of the specified file. If an error
  59. // occurs, an exception is thrown.
  60. //
  61. // \param[in] File is the specified file.
  62. //
  63. // \param[in] is the mode.
  64. //
  65. void SetMode(std::string File, mode_t mode);
  66. /// Create a directory.
  67. //
  68. // This function creates the specified directory. If an error
  69. // occurs, an exception is thrown.
  70. //
  71. // \param[in] Dir is the directory to create.
  72. //
  73. void MkDir(std::string &Dir);
  74. /// Check for a specified string at the beginning of a line.
  75. //
  76. // This function checks for the specified string at the beginning of a
  77. // line. Leading whitespace in the line is ignored.
  78. //
  79. // \param[in] Line is the line.
  80. //
  81. // \param[in] SearchString is the string to check for.
  82. //
  83. static bool CheckForString(std::string Line, std::string SearchString);
  84. /// Replace an XML attribute.
  85. //
  86. // Replace the specified XML element attribute with the specified value.
  87. //
  88. // \param[in, out] Content is the XML content containing the element.
  89. //
  90. // \param[in] ElementName is the name of the XML element.
  91. //
  92. // \param[in] AttributeName is the name of the XML attribute.
  93. //
  94. // \param[in] AttributeValue is the new value of the XML attribute.
  95. //
  96. static void ReplaceXmlAttribute(std::string *Content, std::string ElementName, std::string AttributeName, std::string AttributeValue);
  97. /// Trim whitespace from a string.
  98. //
  99. // This method removes leading " ", "\t", "\r", and "\n" from the specified string.
  100. //
  101. // \param[in] String is the string to trim.
  102. //
  103. // \returns String with the leading and trailing whitespace removed.
  104. static std::string Trim(std::string String);
  105. /// Store the Debug mode.
  106. //
  107. // \param[in] Mode stores the Debug mode.
  108. //
  109. void SetDebug(bool Mode);
  110. /// Provide debug output?
  111. //
  112. // \returns true if the application is to provide debug output.
  113. //
  114. bool Debug();
  115. /// Store the Verbose mode.
  116. //
  117. // \param[in] Mode stores the Verbose mode.
  118. //
  119. void SetVerbose(bool Mode);
  120. /// Provide verbose output?
  121. //
  122. // \returns true if the application is to provide verbose output.
  123. //
  124. bool Verbose();
  125. /// Store the Explain mode.
  126. //
  127. // \param[in] Mode stores the Explain mode.
  128. //
  129. void SetExplain(bool Mode);
  130. /// Provide an explanation of the actions only?
  131. //
  132. // \returns true if the application is to provide an explanation
  133. // of the actions without executing any commands.
  134. //
  135. bool Explain();
  136. /// Store the Help mode.
  137. //
  138. // \param[in] Mode stores the Help mode.
  139. //
  140. void SetHelp(bool Mode);
  141. /// Provide help?
  142. //
  143. // \returns true if the application is to output a help message.
  144. //
  145. bool Help();
  146. /// Output the end of a verbose output line.
  147. void OutputVerboseEnd();
  148. /// Directory separator.
  149. static const std::string DirectorySeparator;
  150. private:
  151. bool DebugRequested; ///< User requested debug output.
  152. bool VerboseRequested; ///< User requested verbose processing.
  153. bool ExplainRequested; ///< User requested verbose processing but without actually executing the commands.
  154. bool HelpRequested; ///< User requested help.
  155. };
  156. #endif