Documentation for OpenFLUID 2.2.2
Loading...
Searching...
No Matches
ExternalProgram.hpp
Go to the documentation of this file.
1/*
2
3 This file is part of OpenFLUID software
4 Copyright(c) 2021-2026, INRAE
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 <string>
45#include <vector>
46
48
49
50namespace openfluid { namespace utils {
51
52/**
53 Management of external programs
54*/
56{
57 private:
58
59 std::vector<std::string> m_ProgramNames;
60
61 std::string m_FullProgramPath;
62
63 std::vector<std::string> m_SearchPaths;
64
65 bool m_UsePathEnv;
66
67
68 public:
69
70 /**
71 List of pre-registered external programs
72 */
73 enum class RegisteredPrograms { CMake, CTest, Zip, SevenZip,
74 Gnuplot, GoogleEarth, Gcc,
75 Pandoc, PdfLatex, BibTex, Latex2HTML,
76 Git, GrassGis, R, Rscript };
77
78 ExternalProgram() = delete;
79
80 /**
81 Constructor for a given external programs. Automatically searches for the program at construction
82 @param[in] ProgramNames The possible names of the program to find
83 @param[in] SearchPaths The list of paths to search. Default value is an empty list
84 @param[in] UsePathEnv Enable the use of PATH environment variable to search for the program.
85 Default value is true.
86 */
87 ExternalProgram(const std::vector<std::string>& ProgramNames,
88 const std::vector<std::string>& SearchPaths = std::vector<std::string>(),
89 bool UsePathEnv = true);
90
91 /**
92 Constructor for a given external programs. Automatically searches for the program at construction
93 @param[in] ProgramName The name of the program to find
94 @param[in] SearchPaths The list of paths to search. Default value is an empty list
95 @param[in] UsePathEnv Enable the use of PATH environment variable to search for the program.
96 Default value is true.
97 */
98 ExternalProgram(const std::string& ProgramName,
99 const std::vector<std::string>& SearchPaths = std::vector<std::string>(),
100 bool UsePathEnv = true);
101
103
104 /**
105 Returns an ExternalProgram object initialized with the registered program to find
106 @param[in] Prog The registered program to find
107 @param[in] SearchPaths The list of paths to search. Default value is an empty list
108 @param[in] UsePathEnv Enable the use of PATH environment variable to search for the registered program.
109 Default value is true.
110 @return An ExternalProgram object initialized with the registered program to find
111 */
113 const std::vector<std::string>& SearchPaths = std::vector<std::string>(),
114 bool UsePathEnv = true);
115
116 /**
117 Finds a program using the PATH environment variable
118 @param[in] ProgramNames The list of the potential program names of the program to find
119 @return The full path of the first found program
120 */
121 static std::string findUsingPATHEnvVar(const std::vector<std::string>& ProgramNames);
122
123 /**
124 Finds a program using a given paths list
125 @param[in] ProgramNames The list of the potential program names of the program to find
126 @param[in] PathsList The list of paths to search
127 @return The full path of the first found program
128 */
129 static std::string findUsingPathsList(const std::vector<std::string>& ProgramNames,
130 const std::vector<std::string>& PathsList);
131
132 /**
133 Returns true if the current program has been found
134 @return true if the current program has been found
135 */
136 bool isFound() const
137 {
138 return !m_FullProgramPath.empty();
139 };
140
141 /**
142 Searches for the program
143 */
145
146 /**
147 Returns the full path of the program
148 @return the full path of the program if it has been found, otherwise an empty string
149 */
150 std::string getFullProgramPath() const
151 {
152 return m_FullProgramPath;
153 };
154
155};
156
157
158} } // namespaces
159
160#endif /* __OPENFLUID_UTILS_EXTERNALPROGRAM_HPP__ */
Definition ExternalProgram.hpp:56
std::string getFullProgramPath() const
Definition ExternalProgram.hpp:150
RegisteredPrograms
Definition ExternalProgram.hpp:73
bool isFound() const
Definition ExternalProgram.hpp:136
ExternalProgram(const std::vector< std::string > &ProgramNames, const std::vector< std::string > &SearchPaths=std::vector< std::string >(), bool UsePathEnv=true)
static std::string findUsingPATHEnvVar(const std::vector< std::string > &ProgramNames)
static ExternalProgram getRegisteredProgram(RegisteredPrograms Prog, const std::vector< std::string > &SearchPaths=std::vector< std::string >(), bool UsePathEnv=true)
ExternalProgram(const std::string &ProgramName, const std::vector< std::string > &SearchPaths=std::vector< std::string >(), bool UsePathEnv=true)
static std::string findUsingPathsList(const std::vector< std::string > &ProgramNames, const std::vector< std::string > &PathsList)
#define OPENFLUID_API
Definition dllexport.hpp:86
Definition ApplicationException.hpp:47