OTB  9.0.0
Orfeo Toolbox
otbWrapperCommandLineLauncher.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2022 Centre National d'Etudes Spatiales (CNES)
3  *
4  * This file is part of Orfeo Toolbox
5  *
6  * https://www.orfeo-toolbox.org/
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #ifndef otbWrapperCommandLineLauncher_h
22 #define otbWrapperCommandLineLauncher_h
23 
24 
25 #include "otbWrapperApplication.h"
26 #include "otbWrapperParameter.h"
27 #include "itksys/SystemTools.hxx"
29 
30 #include "itkStdStreamLogOutput.h"
31 
33 
34 #include "itkCommand.h"
35 
36 #include <vector>
37 #include <string>
38 
39 namespace otb
40 {
41 namespace Wrapper
42 {
43 
57 class ITK_ABI_EXPORT CommandLineLauncher : public itk::Object
58 {
59 public:
62  typedef itk::Object Superclass;
63  typedef itk::SmartPointer<Self> Pointer;
64  typedef itk::SmartPointer<const Self> ConstPointer;
65 
67  itkNewMacro(Self);
68 
70  itkTypeMacro(CommandLineLauncher, itk::Object);
71 
74  typedef enum { OKPARAM, MISSINGMANDATORYPARAMETER, MISSINGPARAMETERVALUE, WRONGPARAMETERVALUE, INVALIDNUMBEROFVALUE, DEFAULT } ParamResultType;
75 
77  typedef std::vector<StandardOneLineFilterWatcher<>*> WatcherListType;
78 
80  typedef itk::MemberCommand<Self> AddProcessCommandType;
81 
86  bool Load();
87 
89  bool Load(const std::vector<std::string>& vexp);
90 
95  bool Execute();
96 
102  bool ExecuteAndWriteOutput();
103 
108  bool BeforeExecute();
109 
111  void DisplayHelp(bool longHelp = false);
112 
114  void LoadTestEnv();
115 
116 protected:
119 
121  ~CommandLineLauncher() override;
122 
126  bool LoadPath();
127 
133  bool LoadApplication();
134 
139  CommandLineLauncher::ParamResultType LoadParameters();
140 
142  std::string DisplayParameterHelp(const Parameter::Pointer& param, const std::string paramKey, bool longHelp = false);
143 
145  bool CheckUnicity();
146 
148  bool CheckParametersPrefix();
149 
151  bool CheckKeyValidity(std::string& key);
152 
154  void DisplayOutputParameters();
155 
157  void LinkWatchers(itk::Object* caller, const itk::EventObject& event);
158 
160  void DeleteWatcherList();
161 
163  unsigned int GetMaxKeySize() const;
164 
165 private:
167  bool CheckMissingMandatoryParameter(const std::string& paramKey) const;
168 
170  void CheckUnusedParameter(const std::string& paramKey) const;
171 
174  bool CheckOutputPathsValidity(const std::string& paramKey) const;
175 
176  CommandLineLauncher(const CommandLineLauncher&) = delete;
177  void operator=(const CommandLineLauncher&) = delete;
178 
182  bool ExecuteAndWriteOutputNoCatch();
183 
184 
185  std::string m_Path;
186 
188  // std::string m_Expression;
189  std::vector<std::string> m_VExpression;
191 
193 
194  itk::StdStreamLogOutput::Pointer m_LogOutput;
195 
196  AddProcessCommandType::Pointer m_AddProcessCommand;
198 
199 }; // end class
200 
201 } // end namespace Wrapper
202 } // end namespace otb
203 
204 #endif // otbWrapperCommandLineLauncher_h_
otb::Wrapper::CommandLineLauncher::m_WatcherList
WatcherListType m_WatcherList
Definition: otbWrapperCommandLineLauncher.h:192
otb::Wrapper::CommandLineLauncher::m_VExpression
std::vector< std::string > m_VExpression
Definition: otbWrapperCommandLineLauncher.h:189
otb::Wrapper::Application::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbWrapperApplication.h:82
otb::Wrapper::CommandLineLauncher::m_Path
std::string m_Path
Definition: otbWrapperCommandLineLauncher.h:185
LoadTestEnv
void LoadTestEnv()
Definition: otbTestMain.h:61
otbWrapperApplication.h
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::Wrapper::CommandLineLauncher::m_AddProcessCommand
AddProcessCommandType::Pointer m_AddProcessCommand
Definition: otbWrapperCommandLineLauncher.h:196
otb::Wrapper::CommandLineLauncher::m_Parser
CommandLineParser::Pointer m_Parser
Definition: otbWrapperCommandLineLauncher.h:190
otb::Wrapper::CommandLineLauncher::m_ReportProgress
bool m_ReportProgress
Definition: otbWrapperCommandLineLauncher.h:197
otb::Wrapper::CommandLineLauncher::Superclass
itk::Object Superclass
Definition: otbWrapperCommandLineLauncher.h:62
otb::Wrapper::CommandLineLauncher::Self
CommandLineLauncher Self
Definition: otbWrapperCommandLineLauncher.h:61
otb::Wrapper::CommandLineLauncher::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbWrapperCommandLineLauncher.h:64
otb::Wrapper::CommandLineLauncher::WatcherListType
std::vector< StandardOneLineFilterWatcher<> * > WatcherListType
Definition: otbWrapperCommandLineLauncher.h:77
otb::Wrapper::CommandLineParser::ParseResultType
ParseResultType
Definition: otbWrapperCommandLineParser.h:59
otb::Wrapper::Parameter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbWrapperParameter.h:55
otb::Wrapper::CommandLineLauncher::ParamResultType
ParamResultType
Definition: otbWrapperCommandLineLauncher.h:74
otb::Wrapper::CommandLineLauncher::m_LogOutput
itk::StdStreamLogOutput::Pointer m_LogOutput
Definition: otbWrapperCommandLineLauncher.h:194
otb::vexp
Definition: otbParserXPlugins.h:699
otb::Wrapper::CommandLineLauncher::m_Application
Application::Pointer m_Application
Definition: otbWrapperCommandLineLauncher.h:187
otb::Wrapper::CommandLineLauncher::AddProcessCommandType
itk::MemberCommand< Self > AddProcessCommandType
Definition: otbWrapperCommandLineLauncher.h:80
otbWrapperCommandLineParser.h
otb::Wrapper::CommandLineLauncher::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbWrapperCommandLineLauncher.h:63
otb::Wrapper::CommandLineLauncher::WRONGPARAMETERVALUE
@ WRONGPARAMETERVALUE
Definition: otbWrapperCommandLineLauncher.h:74
otbStandardOneLineFilterWatcher.h
otbWrapperParameter.h
otb::Wrapper::CommandLineLauncher
This class check the validity of a command line application.
Definition: otbWrapperCommandLineLauncher.h:57
otb::Wrapper::CommandLineParser::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbWrapperCommandLineParser.h:49
otb::Wrapper::CommandLineLauncher::ParseResultType
CommandLineParser::ParseResultType ParseResultType
Definition: otbWrapperCommandLineLauncher.h:70