]> Creatis software - crea.git/blobdiff - lib/creaDevManagerLib/CDMUtilities.h
Feature #1711 CreaDevManager application implementation
[crea.git] / lib / creaDevManagerLib / CDMUtilities.h
index 4b18fcb2ec6e26e30e510bdc528fc3e5f3051aee..e245450c831aaed17ad39616d0ffdab7881b8e4e 100644 (file)
@@ -36,6 +36,7 @@
 #define CDMUTILITIES_H_
 
 #include<iostream>
+#include<vector>
 #include<cstddef>
 
 namespace CDMUtilities
@@ -43,22 +44,22 @@ namespace CDMUtilities
   /**
    * Path slash
    */
-  #ifdef _WIN32
-    // ------ Windows
-    static std::string SLASH = "\\";
-  #elif __APPLE__
-    // ------ Apple
-    static std::string SLASH = "/";
-  #else
-    static std::string SLASH = "/";
-  #endif
+#ifdef _WIN32
+  // ------ Windows
+  static std::string SLASH = "\\";
+#elif __APPLE__
+  // ------ Apple
+  static std::string SLASH = "/";
+#else
+  static std::string SLASH = "/";
+#endif
 
   /**
    * Text editor program
    */
 #ifdef _WIN32
   // ------ Windows
-  //TODO: implementation for windows
+  static std::string TEXT_EDITOR = "notepad";
 #elif __APPLE__
   // ------ Apple
   //TODO: implementation for apple
@@ -71,7 +72,7 @@ namespace CDMUtilities
    */
 #ifdef _WIN32
   // ------ Windows
-  //TODO: implementation for windows
+  static std::string FILE_EXPLORER = "explorer";
 #elif __APPLE__
   // ------ Apple
   //TODO: implementation for apple
@@ -82,16 +83,15 @@ namespace CDMUtilities
   /**
    * Terminal program
    */
-  #ifdef _WIN32
-    // ------ Windows
-    //TODO: implementation for windows
-  #elif __APPLE__
-    // ------ Apple
-    //TODO: implementation for apple
-  #else
-    static std::string TERMINAL = "gnome-terminal";
-  #endif
-
+#ifdef _WIN32
+  // ------ Windows
+  static std::string TERMINAL = "start cmd.exe";
+#elif __APPLE__
+  // ------ Apple
+  //TODO: implementation for apple
+#else
+  static std::string TERMINAL = "gnome-terminal";
+#endif
 
   /**
    * Structure that handles the split method for c++
@@ -170,6 +170,61 @@ namespace CDMUtilities
    * @return True if the class was successfully created.
    */
   bool createEmptyClass(const std::string& name, const std::string& path);
+  /**
+   * Creates a string replacing each \ by double \ .
+   * @param line String to stringify.
+   * @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<std::string> 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<cmdType,cmdValue> syntaxElement;
+
+  /**
+   * Type definition for describing a CMakeLists file content
+   */
+  typedef std::vector<syntaxElement> 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);
+
+  /**
+   * 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_ */