OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
ossimFactoryListInterface< T, NativeType > Class Template Reference

The is a factory list interface that allows registries to be accessed in a common way. More...

#include <ossimFactoryListInterface.h>

Public Types

typedef std::vector< T * > FactoryListType
 
typedef T FactoryType
 
typedef NativeType NativeReturnType
 

Public Member Functions

 ossimFactoryListInterface ()
 
void addFactory (T *factory)
 This is for backward compatability and calls registerFactory for simple adds. More...
 
bool isFactoryRegistered (T *factory) const
 Public access method to determine if a factory is already registered to this list. More...
 
void registerFactory (T *factory, bool pushToFrontFlag=false)
 Will register a factory to the factory list. More...
 
void unregisterFactory (T *factory)
 Will remove the factory from the registry. More...
 
void unregisterFactory (const ossimString &factoryTypeName)
 Will remove the factory from the registry by name. More...
 
void unregisterAllFactories ()
 Will remove all factories from the registry. More...
 
void registerFactoryToFront (T *factory)
 Inserts the factory to the front of the list. More...
 
void registerFactoryBefore (T *factory, T *beforeThisFactory)
 Will insert the factory before the beforeThisFactory. More...
 
void getAllTypeNamesFromRegistry (std::vector< ossimString > &typeList) const
 Will add all object types the factories can allocate. More...
 
ossimObjectcreateObjectFromRegistry (const ossimString &typeName) const
 This is the base object return for all objects in the system. More...
 
ossimObjectcreateObjectFromRegistry (const ossimKeywordlist &kwl, const char *prefix=0) const
 This is the base object return for all objects in the system. More...
 
NativeType * createNativeObjectFromRegistry (const ossimString &typeName) const
 This is a helper method that calls the createObject and makes sure that the returned object is of the NativeType base type this registry supports. More...
 
NativeType * createNativeObjectFromRegistry (const ossimKeywordlist &kwl, const char *prefix=0) const
 This is a helper method that calls the createObject and makes sure that the returned object is of the NativeType base type this registry supports. More...
 

Protected Member Functions

bool findFactory (T *factory) const
 Utility to find a factory in the list. More...
 

Protected Attributes

std::mutex m_factoryListMutex
 
FactoryListType m_factoryList
 

Detailed Description

template<class T, class NativeType>
class ossimFactoryListInterface< T, NativeType >

The is a factory list interface that allows registries to be accessed in a common way.

This is typically used by the Registries. The registries derive from this interface so that it will have the ability to give access to others to add to it's registry:

Pseudo Code:

someRegistry::instance()->addFactory(someFactory::instance());

Definition at line 33 of file ossimFactoryListInterface.h.

Member Typedef Documentation

◆ FactoryListType

template<class T, class NativeType>
typedef std::vector<T*> ossimFactoryListInterface< T, NativeType >::FactoryListType

Definition at line 36 of file ossimFactoryListInterface.h.

◆ FactoryType

template<class T, class NativeType>
typedef T ossimFactoryListInterface< T, NativeType >::FactoryType

Definition at line 37 of file ossimFactoryListInterface.h.

◆ NativeReturnType

template<class T, class NativeType>
typedef NativeType ossimFactoryListInterface< T, NativeType >::NativeReturnType

Definition at line 38 of file ossimFactoryListInterface.h.

Constructor & Destructor Documentation

◆ ossimFactoryListInterface()

template<class T, class NativeType>
ossimFactoryListInterface< T, NativeType >::ossimFactoryListInterface ( )
inline

Definition at line 40 of file ossimFactoryListInterface.h.

40 {}

Member Function Documentation

◆ addFactory()

template<class T, class NativeType>
void ossimFactoryListInterface< T, NativeType >::addFactory ( T *  factory)
inline

This is for backward compatability and calls registerFactory for simple adds.

Definition at line 45 of file ossimFactoryListInterface.h.

Referenced by ossimInit::initializeDefaultFactories().

46  {
47  registerFactory(factory);
48  }
void registerFactory(T *factory, bool pushToFrontFlag=false)
Will register a factory to the factory list.

◆ createNativeObjectFromRegistry() [1/2]

template<class T , class NativeType >
NativeType * ossimFactoryListInterface< T, NativeType >::createNativeObjectFromRegistry ( const ossimString typeName) const

This is a helper method that calls the createObject and makes sure that the returned object is of the NativeType base type this registry supports.

Definition at line 261 of file ossimFactoryListInterface.h.

Referenced by ossimProjectionFactoryRegistry::createProjection(), and ossim2dTo2dTransformRegistry::createTransform().

262 {
263  NativeType* result = 0;
264  ossimRefPtr<ossimObject> tempObject = createObjectFromRegistry(typeName);
265  if(tempObject.valid())
266  {
267  result = dynamic_cast<NativeType*>(tempObject.get());
268  if(result)
269  {
270  tempObject.release();
271  }
272  }
273 
274  return result;
275 }
bool valid() const
Definition: ossimRefPtr.h:75
T * release()
Definition: ossimRefPtr.h:93
ossimObject * createObjectFromRegistry(const ossimString &typeName) const
This is the base object return for all objects in the system.

◆ createNativeObjectFromRegistry() [2/2]

template<class T , class NativeType >
NativeType * ossimFactoryListInterface< T, NativeType >::createNativeObjectFromRegistry ( const ossimKeywordlist kwl,
const char *  prefix = 0 
) const

This is a helper method that calls the createObject and makes sure that the returned object is of the NativeType base type this registry supports.

Parameters
kwlis a state keywordlist allowing one to instantiate an object defined by a set of name value pairs. It will use the type keyword to create an object of the defined type and then load the state.

Definition at line 278 of file ossimFactoryListInterface.h.

280 {
281  NativeType* result = 0;
282  ossimRefPtr<ossimObject> tempObject = createObjectFromRegistry(kwl, prefix);
283  if(tempObject.valid())
284  {
285  result = dynamic_cast<NativeType*>(tempObject.get());
286  if(result)
287  {
288  tempObject.release();
289  }
290  }
291 
292  return result;
293 }
bool valid() const
Definition: ossimRefPtr.h:75
T * release()
Definition: ossimRefPtr.h:93
ossimObject * createObjectFromRegistry(const ossimString &typeName) const
This is the base object return for all objects in the system.

◆ createObjectFromRegistry() [1/2]

template<class T , class NativeType >
ossimObject * ossimFactoryListInterface< T, NativeType >::createObjectFromRegistry ( const ossimString typeName) const

This is the base object return for all objects in the system.

This is used for backward compatability.

Definition at line 234 of file ossimFactoryListInterface.h.

Referenced by ossimWebRequestFactoryRegistry::createObject(), ossimObjectFactoryRegistry::createObject(), ossim2dTo2dTransformRegistry::createObject(), and ossimProjectionFactoryRegistry::createObject().

235 {
236  //std::lock_guard<std::mutex> lock(m_factoryListMutex);
237  ossimObject* result = 0;
238  ossim_uint32 idx = 0;
239  for(;((idx<m_factoryList.size())&&!result); ++idx)
240  {
241  result = m_factoryList[idx]->createObject(typeName);
242  }
243  return result;
244 }
unsigned int ossim_uint32

◆ createObjectFromRegistry() [2/2]

template<class T , class NativeType >
ossimObject * ossimFactoryListInterface< T, NativeType >::createObjectFromRegistry ( const ossimKeywordlist kwl,
const char *  prefix = 0 
) const

This is the base object return for all objects in the system.

This is used for backward compatability.

Definition at line 247 of file ossimFactoryListInterface.h.

249 {
250  // std::lock_guard<std::mutex> lock(m_factoryListMutex);
251  ossimObject* result = 0;
252  ossim_uint32 idx = 0;
253  for(;((idx<m_factoryList.size())&&!result); ++idx)
254  {
255  result = m_factoryList[idx]->createObject(kwl, prefix);
256  }
257  return result;
258 }
unsigned int ossim_uint32

◆ findFactory()

template<class T, class NativeType>
bool ossimFactoryListInterface< T, NativeType >::findFactory ( T *  factory) const
inlineprotected

Utility to find a factory in the list.

Definition at line 205 of file ossimFactoryListInterface.h.

Referenced by ossimFactoryListInterface< ossimProjectionFactoryBase, ossimProjection >::isFactoryRegistered(), ossimFactoryListInterface< ossimProjectionFactoryBase, ossimProjection >::registerFactory(), ossimFactoryListInterface< ossimProjectionFactoryBase, ossimProjection >::registerFactoryBefore(), and ossimFactoryListInterface< ossimProjectionFactoryBase, ossimProjection >::registerFactoryToFront().

206  {
207  if(!factory) return false;
208  ossim_uint32 idx = 0;
209  for(;idx < m_factoryList.size();++idx)
210  {
211  if(m_factoryList[idx] == factory)
212  {
213  return true;
214  }
215  }
216 
217  return false;
218  }
unsigned int ossim_uint32

◆ getAllTypeNamesFromRegistry()

template<class T , class NativeType >
void ossimFactoryListInterface< T, NativeType >::getAllTypeNamesFromRegistry ( std::vector< ossimString > &  typeList) const

Will add all object types the factories can allocate.

Typically a list of classnames are returned

Definition at line 224 of file ossimFactoryListInterface.h.

Referenced by ossimElevationDatabaseRegistry::getTypeNameList(), ossimObjectFactoryRegistry::getTypeNameList(), ossimWebRequestFactoryRegistry::getTypeNameList(), ossimImageGeometryRegistry::getTypeNameList(), ossimProjectionFactoryRegistry::getTypeNameList(), and ossim2dTo2dTransformRegistry::getTypeNameList().

225 {
226  //std::lock_guard<std::mutex> lock(m_factoryListMutex);
227  ossim_uint32 idx = 0;
228  for(; idx<m_factoryList.size(); ++idx)
229  {
230  m_factoryList[idx]->getTypeNameList(typeList);
231  }
232 }
unsigned int ossim_uint32

◆ isFactoryRegistered()

template<class T, class NativeType>
bool ossimFactoryListInterface< T, NativeType >::isFactoryRegistered ( T *  factory) const
inline

Public access method to determine if a factory is already registered to this list.

Definition at line 54 of file ossimFactoryListInterface.h.

55  {
56  if(!factory) return false;
57  std::lock_guard<std::mutex> lock(m_factoryListMutex);
58 
59  return findFactory(factory);
60  }
bool findFactory(T *factory) const
Utility to find a factory in the list.

◆ registerFactory()

template<class T, class NativeType>
void ossimFactoryListInterface< T, NativeType >::registerFactory ( T *  factory,
bool  pushToFrontFlag = false 
)
inline

Will register a factory to the factory list.

Will append the passed in factory if not already registered to the list.

Definition at line 66 of file ossimFactoryListInterface.h.

Referenced by ossimFactoryListInterface< ossimProjectionFactoryBase, ossimProjection >::addFactory(), ossimInit::initializeDefaultFactories(), ossimCodecFactoryRegistry::instance(), ossimElevationDatabaseRegistry::instance(), ossimImageGeometryRegistry::instance(), ossimImageWriterFactory::instance(), ossim2dTo2dTransformRegistry::instance(), ossimImageWriterFactoryRegistry::instance(), ossimOverviewBuilderFactoryRegistry::instance(), ossimImageHandlerRegistry::ossimImageHandlerRegistry(), ossimImageMetaDataWriterRegistry::ossimImageMetaDataWriterRegistry(), ossimProjectionFactoryRegistry::ossimProjectionFactoryRegistry(), and ossimSharedLibraryInitialize().

67  {
68  if(!factory) return;
69  std::lock_guard<std::mutex> lock(m_factoryListMutex);
70  if(!findFactory(factory))
71  {
72  if (pushToFrontFlag)
73  {
74  m_factoryList.insert(m_factoryList.begin(), factory);
75  }
76  else
77  {
78  m_factoryList.push_back(factory);
79  }
80  }
81  }
bool findFactory(T *factory) const
Utility to find a factory in the list.

◆ registerFactoryBefore()

template<class T, class NativeType>
void ossimFactoryListInterface< T, NativeType >::registerFactoryBefore ( T *  factory,
T *  beforeThisFactory 
)
inline

Will insert the factory before the beforeThisFactory.

If not found it will do a simple append.

Definition at line 146 of file ossimFactoryListInterface.h.

147  {
148  std::lock_guard<std::mutex> lock(m_factoryListMutex);
149  if(!findFactory(factory))
150  {
151  ossim_uint32 idx = 0;
152  for(idx = 0; idx < m_factoryList.size(); ++idx)
153  {
154  if(beforeThisFactory == m_factoryList[idx])
155  {
156  m_factoryList.insert(m_factoryList.begin() + idx, factory);
157  return;
158  }
159  }
160  m_factoryList.push_back(factory);
161  }
162  }
unsigned int ossim_uint32
bool findFactory(T *factory) const
Utility to find a factory in the list.

◆ registerFactoryToFront()

template<class T, class NativeType>
void ossimFactoryListInterface< T, NativeType >::registerFactoryToFront ( T *  factory)
inline

Inserts the factory to the front of the list.

Definition at line 133 of file ossimFactoryListInterface.h.

Referenced by ossimSharedLibraryInitialize().

134  {
135  std::lock_guard<std::mutex> lock(m_factoryListMutex);
136  if(!findFactory(factory))
137  {
138  m_factoryList.insert(m_factoryList.begin(), factory);
139  }
140  }
bool findFactory(T *factory) const
Utility to find a factory in the list.

◆ unregisterAllFactories()

template<class T, class NativeType>
void ossimFactoryListInterface< T, NativeType >::unregisterAllFactories ( )
inline

Will remove all factories from the registry.

Definition at line 124 of file ossimFactoryListInterface.h.

125  {
126  std::lock_guard<std::mutex> lock(m_factoryListMutex);
127  m_factoryList.clear();
128  }

◆ unregisterFactory() [1/2]

template<class T, class NativeType>
void ossimFactoryListInterface< T, NativeType >::unregisterFactory ( T *  factory)
inline

◆ unregisterFactory() [2/2]

template<class T, class NativeType>
void ossimFactoryListInterface< T, NativeType >::unregisterFactory ( const ossimString factoryTypeName)
inline

Will remove the factory from the registry by name.

Parameters
factoryTypeNameThe class name of the factory, (e.g. "ossimCsmProjectionFactory")

Definition at line 103 of file ossimFactoryListInterface.h.

104  {
105  std::lock_guard<std::mutex> lock(m_factoryListMutex);
106  ossim_uint32 idx = 0;
107  for(idx = 0; idx < m_factoryList.size(); ++idx)
108  {
109  if (m_factoryList[idx])
110  {
111  ossimString mangledName (typeid(*(m_factoryList[idx])).name());
112  if (mangledName.contains(factoryTypeName))
113  {
114  m_factoryList.erase(m_factoryList.begin() + idx);
115  return;
116  }
117  }
118  }
119  }
unsigned int ossim_uint32

Member Data Documentation

◆ m_factoryList

template<class T, class NativeType>
FactoryListType ossimFactoryListInterface< T, NativeType >::m_factoryList
protected

◆ m_factoryListMutex

template<class T, class NativeType>
std::mutex ossimFactoryListInterface< T, NativeType >::m_factoryListMutex
mutableprotected

The documentation for this class was generated from the following file: