// Utility.hpp // // Copyright (C) 2011 ARM Research Labs, LLC. // See www.armresearch.com for the copyright terms. // // This file defines the interface used by the configuration utilities. // #ifndef Utilityhpp_included #define Utilityhpp_included #include #include /// Base class for the Sniffer configuration. // // This class provides capability common to the configuration classes. // ////////////////////////////////////////////////////////////////////////////////////////////////////////// class Utility { public: /// Default constructor. Utility(); /// Check whether a file exists. // // \param[in] File is the name of the file. // // \returns true if the file exists, false otherwise. // bool FileExists(std::string File); /// Read last part of a file. // // \param[in] File is the name of the file. // // \param[in] Size is the number of bytes from the end to start reading. // // \returns contents of the end of the file if the file exists, "" otherwise. // std::string ReadLastPartOfFile(std::string File, long Size); /// Copy a file. // // \param[in] From is the name of the source file. // // \param[in] To is the name of the destination file. // void Copy(std::string From, std::string To); /// Set the owner and group of the specified file. // // This function sets the owner and group of the specified file to the // value specified in Utility.cpp. // // \param[in] File is the specified file. // // \see SNFUserName. // // \see SNFGroupName. // void SetOwnerGroup(std::string File); /// Set the mode of a file. // // This function sets the mode of the specified file. If an error // occurs, an exception is thrown. // // \param[in] File is the specified file. // // \param[in] is the mode. // void SetMode(std::string File, mode_t mode); /// Create a directory. // // This function creates the specified directory. If an error // occurs, an exception is thrown. // // \param[in] Dir is the directory to create. // void MkDir(std::string &Dir); /// Check for a specified string at the beginning of a line. // // This function checks for the specified string at the beginning of a // line. Leading whitespace in the line is ignored. // // \param[in] Line is the line. // // \param[in] SearchString is the string to check for. // static bool CheckForString(std::string Line, std::string SearchString); /// Replace an XML attribute. // // Replace the specified XML element attribute with the specified value. // // \param[in, out] Content is the XML content containing the element. // // \param[in] ElementName is the name of the XML element. // // \param[in] AttributeName is the name of the XML attribute. // // \param[in] AttributeValue is the new value of the XML attribute. // static void ReplaceXmlAttribute(std::string *Content, std::string ElementName, std::string AttributeName, std::string AttributeValue); /// Trim whitespace from a string. // // This method removes leading " ", "\t", "\r", and "\n" from the specified string. // // \param[in] String is the string to trim. // // \returns String with the leading and trailing whitespace removed. static std::string Trim(std::string String); /// Store the Debug mode. // // \param[in] Mode stores the Debug mode. // void SetDebug(bool Mode); /// Provide debug output? // // \returns true if the application is to provide debug output. // bool Debug(); /// Store the Verbose mode. // // \param[in] Mode stores the Verbose mode. // void SetVerbose(bool Mode); /// Provide verbose output? // // \returns true if the application is to provide verbose output. // bool Verbose(); /// Store the Explain mode. // // \param[in] Mode stores the Explain mode. // void SetExplain(bool Mode); /// Provide an explanation of the actions only? // // \returns true if the application is to provide an explanation // of the actions without executing any commands. // bool Explain(); /// Store the Help mode. // // \param[in] Mode stores the Help mode. // void SetHelp(bool Mode); /// Provide help? // // \returns true if the application is to output a help message. // bool Help(); /// Output the end of a verbose output line. void OutputVerboseEnd(); /// Directory separator. static const std::string DirectorySeparator; private: bool DebugRequested; ///< User requested debug output. bool VerboseRequested; ///< User requested verbose processing. bool ExplainRequested; ///< User requested verbose processing but without actually executing the commands. bool HelpRequested; ///< User requested help. }; #endif