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@supagro.inra.fr>
37  */
38 
39 
40 #ifndef __OPENFLUID_UTILS_EXTERNALPROGRAM_HPP__
41 #define __OPENFLUID_UTILS_EXTERNALPROGRAM_HPP__
42 
43 #include <openfluid/dllexport.hpp>
44 
45 #include <QStringList>
46 
47 
48 namespace openfluid { namespace utils {
49 
50 /**
51  Management of external programs
52 */
54 {
55  private:
56 
57  QStringList m_ProgramNames;
58 
59  QString m_FullProgramPath;
60 
61  QStringList m_SearchPaths;
62 
63  bool m_UsePathEnv;
64 
65 
66  public:
67 
68  /**
69  List of pre-registered external programs
70  */
71  enum RegisteredPrograms { CMakeProgram, ZipProgram, SevenZipProgram,
72  GnuplotProgram, GoogleEarthProgram, GccProgram,
73  PdfLatexProgram, BibTexProgram, Latex2HTMLProgram,
74  GitProgram, GrassGisProgram };
75 
76  /**
77  Constructor for a given external programs. Automatically searches for the program at construction
78  @param[in] ProgramNames The possible names of the program to find
79  @param[in] SearchPaths The list of paths to search. Default value is an empty list
80  @param[in] UsePathEnv Enable the use of PATH environment variable to search for the program.
81  Default value is true.
82  */
83  ExternalProgram(const QStringList& ProgramNames,
84  const QStringList& SearchPaths = QStringList(),
85  bool UsePathEnv = true);
86 
87  /**
88  Constructor for a given external programs. Automatically searches for the program at construction
89  @param[in] ProgramName The name of the program to find
90  @param[in] SearchPaths The list of paths to search. Default value is an empty list
91  @param[in] UsePathEnv Enable the use of PATH environment variable to search for the program.
92  Default value is true.
93  */
94  ExternalProgram(const QString& ProgramName,
95  const QStringList& SearchPaths = QStringList(),
96  bool UsePathEnv = true);
97 
98  ~ExternalProgram();
99 
100  /**
101  Returns an ExternalProgram object initialized with the registered program to find
102  @param[in] Prog The registered program to find
103  @param[in] SearchPaths The list of paths to search. Default value is an empty list
104  @param[in] UsePathEnv Enable the use of PATH environment variable to search for the registered program.
105  Default value is true.
106  @return An ExternalProgram object initialized with the registered program to find
107  */
108  static ExternalProgram getRegisteredProgram(RegisteredPrograms Prog,
109  const QStringList& SearchPaths = QStringList(),
110  bool UsePathEnv = true);
111 
112  /**
113  Finds a program using the PATH environment variable
114  @param[in] ProgramNames The list of the potential program names of the program to find
115  @return The full path of the first found program
116  */
117  static QString findUsingPATHEnvVar(const QStringList& ProgramNames);
118 
119  /**
120  Finds a program using a given paths list
121  @param[in] ProgramNames The list of the potential program names of the program to find
122  @param[in] PathsList The list of paths to search
123  @return The full path of the first found program
124  */
125  static QString findUsingPathsList(const QStringList& ProgramNames, const QStringList& PathsList);
126 
127  /**
128  Returns true if the current program has been found
129  @return true if the current program has been found
130  */
131  bool isFound() const
132  { return !m_FullProgramPath.isEmpty(); };
133 
134  /**
135  Searches for the program
136  */
137  void searchForProgram();
138 
139  /**
140  Returns the full path of the program
141  @return the full path of the program if it has been found, otherwise an empty string
142  */
143  QString getFullProgramPath() const
144  { return m_FullProgramPath; };
145 
146 };
147 
148 
149 } } // namespaces
150 
151 #endif /* __OPENFLUID_UTILS_EXTERNALPROGRAM_HPP__ */
Definition: ExternalProgram.hpp:53
RegisteredPrograms
Definition: ExternalProgram.hpp:71
Definition: ExternalProgram.hpp:73
bool isFound() const
Definition: ExternalProgram.hpp:131
QString getFullProgramPath() const
Definition: ExternalProgram.hpp:143
Definition: ExternalProgram.hpp:71
Definition: ApplicationException.hpp:47
#define OPENFLUID_API
Definition: dllexport.hpp:87