]> Creatis software - crea.git/blob - lib/creaDevManagerLib/CDMUtilities.h
Feature #1711 CreaDevManager application implementation
[crea.git] / lib / creaDevManagerLib / CDMUtilities.h
1 /*
2 # ---------------------------------------------------------------------
3 #
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 #                        pour la Sant�)
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 #
10 #  This software is governed by the CeCILL-B license under French law and
11 #  abiding by the rules of distribution of free software. You can  use,
12 #  modify and/ or redistribute the software under the terms of the CeCILL-B
13 #  license as circulated by CEA, CNRS and INRIA at the following URL
14 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 #  or in the file LICENSE.txt.
16 #
17 #  As a counterpart to the access to the source code and  rights to copy,
18 #  modify and redistribute granted by the license, users are provided only
19 #  with a limited warranty  and the software's author,  the holder of the
20 #  economic rights,  and the successive licensors  have only  limited
21 #  liability.
22 #
23 #  The fact that you are presently reading this means that you have had
24 #  knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------
26  */
27
28 /*
29  * CDMUtilities.h
30  *
31  *  Created on: Nov 23, 2012
32  *      Author: Daniel Felipe Gonzalez Obando
33  */
34
35 #ifndef CDMUTILITIES_H_
36 #define CDMUTILITIES_H_
37
38 #include<iostream>
39 #include<cstddef>
40
41 namespace CDMUtilities
42 {
43   /**
44    * Path slash
45    */
46 #ifdef _WIN32
47   // ------ Windows
48   static std::string SLASH = "\\";
49 #elif __APPLE__
50   // ------ Apple
51   static std::string SLASH = "/";
52 #else
53   static std::string SLASH = "/";
54 #endif
55
56   /**
57    * Text editor program
58    */
59 #ifdef _WIN32
60   // ------ Windows
61   static std::string TEXT_EDITOR = "notepad";
62 #elif __APPLE__
63   // ------ Apple
64   //TODO: implementation for apple
65 #else
66   static std::string TEXT_EDITOR = "gedit";
67 #endif
68
69   /**
70    * File explorer program
71    */
72 #ifdef _WIN32
73   // ------ Windows
74   static std::string FILE_EXPLORER = "explorer";
75 #elif __APPLE__
76   // ------ Apple
77   //TODO: implementation for apple
78 #else
79   static std::string FILE_EXPLORER = "nautilus";
80 #endif
81
82   /**
83    * Terminal program
84    */
85 #ifdef _WIN32
86   // ------ Windows
87   static std::string TERMINAL = "start cmd.exe";
88 #elif __APPLE__
89   // ------ Apple
90   //TODO: implementation for apple
91 #else
92   static std::string TERMINAL = "gnome-terminal";
93 #endif
94
95   /**
96    * Structure that handles the split method for c++
97    * It calls the split method to split a string given certain delimiters.
98    */
99   struct splitter
100   {
101     /**
102      * Enum to allow or not empty resulting strings after performing splits.
103      */
104     enum empties_t { empties_ok, no_empties };
105     /**
106      * Method to split a string given a set of delimiter characters.
107      * @param result Resulting container.
108      * @param s String to be splitted.
109      * @param delimiters Delimiter characters to split the string.
110      * @param empties Either allow or not empty resulting strings after performing split.
111      * @return Resulting container.
112      */
113     template <typename Container>
114     static Container& split
115     (
116         Container& result,
117         const typename Container::value_type& s,
118         const typename Container::value_type& delimiters,
119         empties_t empties = empties_ok
120     );
121   };
122
123   /**
124    * Fixes a given path to avoid double slash directories
125    * @param path Unfixed path.
126    * @return Fixed path.
127    */
128   const std::string fixPath(const std::string& path);
129
130   /**
131    * Opens the default text editor. If a file is given, then it tries to open the given file.
132    * @param file Full path to the file.
133    * @return True if there was an error on the execution of the operation.
134    */
135   int openTextEditor(const std::string& file = "");
136   /**
137    * Opens the system file explorer on the given file path
138    * @param file Path of the desired folder to open.
139    * @return True if there was an error on the execution of the operation.
140    */
141   int openFileExplorer(const std::string& file = "");
142   /**
143    * Opens a file with a given command.
144    * @param file Full path of the file to open.
145    * @param command Command to execute the file with.
146    * @return True if there was an error on the execution of the operation.
147    */
148   int openFileWithCommand(const std::string& file, const std::string& command);
149   /**
150    * Opens the BBTK Graphical Editor
151    * @return True if there was an error on the execution of the operation.
152    */
153   int openBBEditor();
154   /**
155    * Opens the minitools or the creaTools
156    * @return True if there was an error on the execution of the operation.
157    */
158   int openCreaToolsTools();
159   /**
160    * Open a command line interpreter and executes the given command if any.
161    * @param command Command to execute.
162    * @return True if there was an error on the execution of the operation.
163    */
164   int openTerminal(const std::string& command = "");
165   /**
166    * Creates a blank class(.h and .cpp files).
167    * @param name Name of the new class.
168    * @param path Path where the class is to be created.
169    * @return True if the class was successfully created.
170    */
171   bool createEmptyClass(const std::string& name, const std::string& path);
172   /**
173    * Creates a string replacing each \ by double \ .
174    * @param line String to stringify.
175    * @return line stringified.
176    */
177   std::string stringify(const std::string& line);
178 };
179
180 #endif /* CDMUTILITIES_H_ */