X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;ds=sidebyside;f=lib%2FcreaDevManagerLib%2FCDMUtilities.h;h=2ba3250a6a954fcfb1ae8d900a7ae22cb2af7a66;hb=b5874457abda388b3501cdfa57476de7c006c4ea;hp=5430aea2a9c97d770162aeb1ca398783eccf660c;hpb=157fdd70097efc81cb9bcd3a3b19392b8a144655;p=crea.git diff --git a/lib/creaDevManagerLib/CDMUtilities.h b/lib/creaDevManagerLib/CDMUtilities.h index 5430aea..2ba3250 100644 --- a/lib/creaDevManagerLib/CDMUtilities.h +++ b/lib/creaDevManagerLib/CDMUtilities.h @@ -36,6 +36,7 @@ #define CDMUTILITIES_H_ #include +#include #include namespace CDMUtilities @@ -62,6 +63,7 @@ namespace CDMUtilities #elif __APPLE__ // ------ Apple //TODO: implementation for apple + static std::string TEXT_EDITOR = "open -e"; #else static std::string TEXT_EDITOR = "gedit"; #endif @@ -75,6 +77,7 @@ namespace CDMUtilities #elif __APPLE__ // ------ Apple //TODO: implementation for apple + static std::string FILE_EXPLORER = "open "; #else static std::string FILE_EXPLORER = "nautilus"; #endif @@ -88,10 +91,20 @@ namespace CDMUtilities #elif __APPLE__ // ------ Apple //TODO: implementation for apple + static std::string TERMINAL = "open -a Terminal "; #else static std::string TERMINAL = "gnome-terminal"; #endif + +//EED 10/07/2013 +//#ifndef _WIN32 + /** + * Build Command + */ + static std::string BUILD_COMMAND = "make"; +//#endif + /** * Structure that handles the split method for c++ * It calls the split method to split a string given certain delimiters. @@ -117,7 +130,29 @@ namespace CDMUtilities const typename Container::value_type& s, const typename Container::value_type& delimiters, empties_t empties = empties_ok - ); + ) + { + result.clear(); + size_t current; + size_t next = -1; + do + { + if (empties == no_empties) + { + next = s.find_first_not_of(delimiters, next + 1); + if (next == Container::value_type::npos) + { + break; + } + next -= 1; + } + current = next + 1; + next = s.find_first_of(delimiters, current); + result.push_back(s.substr(current, next - current)); + } + while (next != Container::value_type::npos); + return result; + } }; /** @@ -143,9 +178,10 @@ namespace CDMUtilities * Opens a file with a given command. * @param file Full path of the file to open. * @param command Command to execute the file with. + * @param parameters Parameters to open file. * @return True if there was an error on the execution of the operation. */ - int openFileWithCommand(const std::string& file, const std::string& command); + int openFileWithCommand(const std::string& file, const std::string& command, const std::string& parameters = ""); /** * Opens the BBTK Graphical Editor * @return True if there was an error on the execution of the operation. @@ -175,6 +211,62 @@ namespace CDMUtilities * @return line stringified. */ std::string stringify(const std::string& line); + + //CMakeLists file handling + /** + * Type definition for the value of a syntax element for CMakeLists files + */ + typedef std::vector cmdValue; + + /** + * Type definition for the type of a syntax element for CMakeLists files + */ + typedef std::string cmdType; + + /** + * Type definition for syntax elements of a CMakeLists file + */ + typedef std::pair syntaxElement; + + /** + * Type definition for describing a CMakeLists file content + */ + typedef std::vector CMLFile; + + /** + * Reads a file as string and returns the read data. + * @param file_path Full path of the CMakeLists file. + * @return A string with the contents of the given file. + */ + std::string readFile(const std::string& file_path); + /** + * Writes the given string into a file and returns whether the operation is successful. + * @param file_path Full path of the CMakeLists file. + * @param st string to write. + * @return True if the operation was successful. + */ + bool writeFile(const std::string& file_path, const std::string& st); + + /** + * Reads a CMakeLists file and returns the read data. + * @param file_path Full path of the CMakeLists file. + * @return A CMLFile with the contents of the given file. + */ + CMLFile readCMLFile(const std::string& file_path); + + /** + * Writes the given data into specified CMakeLists file. + * @param file_path Full path of the CMakeLists file. + * @param data CMakeLists data. + * @return True if the operation was successful. + */ + bool writeCMLFile(const std::string& file_path, const CMLFile& data); + + /** + * @param st Strips all space character at the beginning and at the end of the string. + */ + void normalizeStr(std::string& st); + }; #endif /* CDMUTILITIES_H_ */