ExternalProgram.hpp
Go to the documentation of this file.
1 /*
2 
3  This file is part of OpenFLUID software
4  Copyright(c) 2007, INRA - Montpellier SupAgro
5 
6 
7  == GNU General Public License Usage ==
8 
9  OpenFLUID is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  OpenFLUID is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with OpenFLUID. If not, see <http://www.gnu.org/licenses/>.
21 
22 
23  == Other Usage ==
24 
25  Other Usage means a use of OpenFLUID that is inconsistent with the GPL
26  license, and requires a written agreement between You and INRA.
27  Licensees for Other Usage of OpenFLUID may use this file in accordance
28  with the terms contained in the written agreement between You and INRA.
29 
30 */
31 
32 
33 /**
34  @file ExternalProgram.hpp
35 
36  @author Jean-Christophe FABRE <jean-christophe.fabre@inra.fr>
37  */
38 
39 
40 #ifndef __OPENFLUID_UTILS_EXTERNALPROGRAM_HPP__
41 #define __OPENFLUID_UTILS_EXTERNALPROGRAM_HPP__
42 
43 
44 #include <QStringList>
45 
46 #include <openfluid/dllexport.hpp>
47 
48 
49 namespace openfluid { namespace utils {
50 
51 /**
52  Management of external programs
53 */
55 {
56  private:
57 
58  QStringList m_ProgramNames;
59 
60  QString m_FullProgramPath;
61 
62  QStringList m_SearchPaths;
63 
64  bool m_UsePathEnv;
65 
66 
67  public:
68 
69  /**
70  List of pre-registered external programs
71  */
72  enum RegisteredPrograms { CMakeProgram, ZipProgram, SevenZipProgram,
73  GnuplotProgram, GoogleEarthProgram, GccProgram,
74  PdfLatexProgram, BibTexProgram, Latex2HTMLProgram,
75  GitProgram, GrassGisProgram };
76 
77  ExternalProgram() = delete;
78 
79  /**
80  Constructor for a given external programs. Automatically searches for the program at construction
81  @param[in] ProgramNames The possible names of the program to find
82  @param[in] SearchPaths The list of paths to search. Default value is an empty list
83  @param[in] UsePathEnv Enable the use of PATH environment variable to search for the program.
84  Default value is true.
85  */
86  ExternalProgram(const QStringList& ProgramNames,
87  const QStringList& SearchPaths = QStringList(),
88  bool UsePathEnv = true);
89 
90  /**
91  Constructor for a given external programs. Automatically searches for the program at construction
92  @param[in] ProgramName The name of the program to find
93  @param[in] SearchPaths The list of paths to search. Default value is an empty list
94  @param[in] UsePathEnv Enable the use of PATH environment variable to search for the program.
95  Default value is true.
96  */
97  ExternalProgram(const QString& ProgramName,
98  const QStringList& SearchPaths = QStringList(),
99  bool UsePathEnv = true);
100 
101  ~ExternalProgram();
102 
103  /**
104  Returns an ExternalProgram object initialized with the registered program to find
105  @param[in] Prog The registered program to find
106  @param[in] SearchPaths The list of paths to search. Default value is an empty list
107  @param[in] UsePathEnv Enable the use of PATH environment variable to search for the registered program.
108  Default value is true.
109  @return An ExternalProgram object initialized with the registered program to find
110  */
111  static ExternalProgram getRegisteredProgram(RegisteredPrograms Prog,
112  const QStringList& SearchPaths = QStringList(),
113  bool UsePathEnv = true);
114 
115  /**
116  Finds a program using the PATH environment variable
117  @param[in] ProgramNames The list of the potential program names of the program to find
118  @return The full path of the first found program
119  */
120  static QString findUsingPATHEnvVar(const QStringList& ProgramNames);
121 
122  /**
123  Finds a program using a given paths list
124  @param[in] ProgramNames The list of the potential program names of the program to find
125  @param[in] PathsList The list of paths to search
126  @return The full path of the first found program
127  */
128  static QString findUsingPathsList(const QStringList& ProgramNames, const QStringList& PathsList);
129 
130  /**
131  Returns true if the current program has been found
132  @return true if the current program has been found
133  */
134  bool isFound() const
135  { return !m_FullProgramPath.isEmpty(); };
136 
137  /**
138  Searches for the program
139  */
140  void searchForProgram();
141 
142  /**
143  Returns the full path of the program
144  @return the full path of the program if it has been found, otherwise an empty string
145  */
146  QString getFullProgramPath() const
147  { return m_FullProgramPath; };
148 
149 };
150 
151 
152 } } // namespaces
153 
154 #endif /* __OPENFLUID_UTILS_EXTERNALPROGRAM_HPP__ */
Definition: ExternalProgram.hpp:54
bool isFound() const
Definition: ExternalProgram.hpp:134
RegisteredPrograms
Definition: ExternalProgram.hpp:72
Definition: ApplicationException.hpp:47
Definition: ExternalProgram.hpp:74
Definition: ExternalProgram.hpp:72
QString getFullProgramPath() const
Definition: ExternalProgram.hpp:146
#define OPENFLUID_API
Definition: dllexport.hpp:86