OTB  6.7.0
Orfeo Toolbox
otbWrapperApplicationFactory.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2019 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:
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  }
77 
79  {
80 
81  }
82 
86  LightObject::Pointer CreateObject(const char* itkclassname ) override
87  {
88  LightObject::Pointer ret;
89  if ( m_ClassName == itkclassname)
90  ret = TApplication::New().GetPointer();
92 
93  return ret;
94  }
95 
99  std::list<LightObject::Pointer>
100  CreateAllObject(const char* itkclassname) override
101  {
102  const std::string applicationClass("otbWrapperApplication");
103  std::list<LightObject::Pointer> list;
104  if ( m_ClassName == itkclassname ||
105  applicationClass == itkclassname )
106  list.push_back(TApplication::New().GetPointer());
108 
109  return list;
110  }
111 
112 private:
113  ApplicationFactory(const Self &) = delete;
114  void operator =(const Self&) = delete;
115 
116  std::string m_ClassName;
117 };
118 
119 } // end namespace Wrapper
120 } //end namespace otb
121 
122 #if (defined(WIN32) || defined(_WIN32))
123 # define OTB_APP_EXPORT __declspec(dllexport)
124 #else
125 # define OTB_APP_EXPORT
126 #endif
127 
128 #define OTB_APPLICATION_EXPORT( ApplicationType ) \
129  typedef otb::Wrapper::ApplicationFactory<ApplicationType> ApplicationFactoryType; \
130  static ApplicationFactoryType::Pointer staticFactory; \
131  extern "C" \
132  { \
133  OTB_APP_EXPORT itk::ObjectFactoryBase* itkLoad() \
134  { \
135  staticFactory = ApplicationFactoryType::New(); \
136  staticFactory->SetClassName(#ApplicationType); \
137  return staticFactory; \
138  } \
139  }
140 
141 
142 #endif // otbWrapperApplication_h_
const char * GetDescription(void) const override
#define ITK_SOURCE_VERSION
const char * GetITKSourceVersion(void) const override
LightObject::Pointer CreateObject(const char *itkclassname) override
itk::SmartPointer< const Self > ConstPointer
std::list< LightObject::Pointer > CreateAllObject(const char *itkclassname) override