OTB  9.0.0
Orfeo Toolbox
otbWrapperApplicationFactory.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 otbWrapperApplicationFactory_h
22 #define otbWrapperApplicationFactory_h
23 
25 #include "itkVersion.h"
26 #include <string>
27 
28 namespace otb
29 {
30 namespace Wrapper
31 {
32 
33 template <class TApplication>
34 class ITK_ABI_EXPORT ApplicationFactory : public ApplicationFactoryBase
35 {
36 public:
40  typedef itk::SmartPointer<Self> Pointer;
41  typedef itk::SmartPointer<const Self> ConstPointer;
42 
44  const char* GetITKSourceVersion(void) const override
45  {
46  return ITK_SOURCE_VERSION;
47  }
48 
49  const char* GetDescription(void) const override
50  {
51  return "ApplicationFactory";
52  }
53 
55  itkFactorylessNewMacro(Self);
56 
59 
60  void SetClassName(const char* name)
61  {
62  // remove namespace, only keep class name
63  std::string tmpName(name);
64  std::string::size_type pos = tmpName.rfind("::");
65  if (pos != std::string::npos)
66  {
67  tmpName = tmpName.substr(pos + 2);
68  }
69  m_ClassName.assign(tmpName);
70  }
71 
72 protected:
74  {
75  }
76 
78  {
79  }
80 
84  LightObject::Pointer CreateObject(const char* itkclassname) override
85  {
86  LightObject::Pointer ret;
87  if (m_ClassName == itkclassname)
88  ret = TApplication::New().GetPointer();
90 
91  return ret;
92  }
93 
97  std::list<LightObject::Pointer> CreateAllObject(const char* itkclassname) override
98  {
99  const std::string applicationClass("otbWrapperApplication");
100  std::list<LightObject::Pointer> list;
101  if (m_ClassName == itkclassname || applicationClass == itkclassname)
102  list.push_back(TApplication::New().GetPointer());
104 
105  return list;
106  }
107 
108 private:
109  ApplicationFactory(const Self&) = delete;
110  void operator=(const Self&) = delete;
111 
112  std::string m_ClassName;
113 };
114 
115 } // end namespace Wrapper
116 } // end namespace otb
117 
118 #if (defined(WIN32) || defined(_WIN32))
119 #define OTB_APP_EXPORT __declspec(dllexport)
120 #else
121 #define OTB_APP_EXPORT
122 #endif
123 
124 #define OTB_APPLICATION_EXPORT(ApplicationType) \
125  typedef otb::Wrapper::ApplicationFactory<ApplicationType> ApplicationFactoryType; \
126  static ApplicationFactoryType::Pointer staticFactory; \
127  extern "C" { \
128  OTB_APP_EXPORT itk::ObjectFactoryBase* itkLoad() \
129  { \
130  staticFactory = ApplicationFactoryType::New(); \
131  staticFactory->SetClassName(#ApplicationType); \
132  return staticFactory; \
133  } \
134  }
135 
136 
137 #endif // otbWrapperApplication_h_
otb::Wrapper::ApplicationFactory::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbWrapperApplicationFactory.h:41
otb::Wrapper::ApplicationFactory::ApplicationFactory
ApplicationFactory()
Definition: otbWrapperApplicationFactory.h:73
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::Wrapper::ApplicationFactory::CreateObject
LightObject::Pointer CreateObject(const char *itkclassname) override
Definition: otbWrapperApplicationFactory.h:84
otb::Wrapper::ApplicationFactory::CreateAllObject
std::list< LightObject::Pointer > CreateAllObject(const char *itkclassname) override
Definition: otbWrapperApplicationFactory.h:97
otb::Wrapper::ApplicationFactory
Definition: otbWrapperApplicationFactory.h:34
otb::Wrapper::ApplicationFactory::GetITKSourceVersion
const char * GetITKSourceVersion(void) const override
Definition: otbWrapperApplicationFactory.h:44
otb::Wrapper::ApplicationFactory::Superclass
ApplicationFactoryBase Superclass
Definition: otbWrapperApplicationFactory.h:39
otb::Wrapper::ApplicationFactory::Self
ApplicationFactory Self
Definition: otbWrapperApplicationFactory.h:38
otb::Wrapper::ApplicationFactory::SetClassName
void SetClassName(const char *name)
Definition: otbWrapperApplicationFactory.h:60
otbWrapperApplicationFactoryBase.h
otb::Wrapper::ApplicationFactory::m_ClassName
std::string m_ClassName
Definition: otbWrapperApplicationFactory.h:112
otb::Wrapper::ApplicationFactoryBase
Definition: otbWrapperApplicationFactoryBase.h:33
otb::Wrapper::ApplicationFactory::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbWrapperApplicationFactory.h:40
otb::Wrapper::ApplicationFactory::~ApplicationFactory
~ApplicationFactory() override
Definition: otbWrapperApplicationFactory.h:77
otb::Wrapper::ApplicationFactory::GetDescription
const char * GetDescription(void) const override
Definition: otbWrapperApplicationFactory.h:49