OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
FactoryListBase.h
Go to the documentation of this file.
1 //**************************************************************************************************
2 //
3 // License: MIT
4 //
5 // See LICENSE.txt file in the top level directory for more details.
6 //
7 // Description: Class declaration of ossimFactoryListInterface.
8 //
9 //**************************************************************************************************
10 // $Id$
11 #ifndef ossimFactoryListBase_HEADER
12 #define ossimFactoryListBase_HEADER 1
13 #include <vector>
14 #include <ossim/base/ossimString.h>
15 #include <ossim/base/RWLock.h>
16 
17 namespace ossim
18 {
19  template <class T>
21  {
22  public:
23  typedef std::vector<T> FactoryListType;
24  typedef std::vector<ossimString> TypeNameList;
25 
27 
31  void addFactory(T factory)
32  {
33  registerFactory(factory);
34  }
35 
40  bool isFactoryRegistered(T factory)const
41  {
42  if(!factory) return false;
43  ScopeReadLock scopedReadLock(m_rwlock);
44 
45  return findFactory(factory);
46  }
47 
52  void registerFactory(T factory, bool pushToFrontFlag=false)
53  {
54  if(!factory) return;
55  ScopeWriteLock scopedWriteLock(m_rwlock);
56  if(!findFactory(factory))
57  {
58  if (pushToFrontFlag)
59  {
60  m_factoryList.insert(m_factoryList.begin(), factory);
61  }
62  else
63  {
64  m_factoryList.push_back(factory);
65  }
66  }
67  }
71  void unregisterFactory(T factory)
72  {
73  ScopeWriteLock scopedWriteLock(m_rwlock);
74  ossim_uint32 idx = 0;
75  for(idx = 0; idx < m_factoryList.size(); ++idx)
76  {
77  if(factory == m_factoryList[idx])
78  {
79  m_factoryList.erase(m_factoryList.begin() + idx);
80  return;
81  }
82  }
83  }
84 
89  {
90  ScopeWriteLock scopedWriteLock(m_rwlock);
91  m_factoryList.clear();
92  }
93 
97  void registerFactoryToFront(T factory)
98  {
99  ScopeWriteLock scopedWriteLock(m_rwlock);
100  if(!findFactory(factory))
101  {
102  m_factoryList.insert(m_factoryList.begin(), factory);
103  }
104  }
105 
110  void registerFactoryBefore(T factory, T beforeThisFactory)
111  {
112  ScopeWriteLock scopedWriteLock(m_rwlock);
113 
114  if(!findFactory(factory))
115  {
116  ossim_uint32 idx = 0;
117  for(idx = 0; idx < m_factoryList.size(); ++idx)
118  {
119  if(beforeThisFactory == m_factoryList[idx])
120  {
121  m_factoryList.insert(m_factoryList.begin() + idx, factory);
122  return;
123  }
124  }
125  m_factoryList.push_back(factory);
126  }
127  }
128 
129  protected:
133  bool findFactory(T factory)const
134  {
135  if(!factory) return false;
136  ossim_uint32 idx = 0;
137  for(const auto& testFactory:m_factoryList)
138  {
139  if(factory == testFactory)
140  {
141  return true;
142  }
143  }
144  return false;
145  }
146 
149  };
150 }
151 
152 #endif
Code was derived from https://gist.github.com/mshockwave.
Definition: RWLock.h:38
FactoryListType m_factoryList
void unregisterAllFactories()
Will remove all factories from the registry.
This code was derived from https://gist.github.com/mshockwave.
Definition: Barrier.h:8
std::vector< T > FactoryListType
void registerFactoryToFront(T factory)
Inserts the factory to the front of the list.
void registerFactory(T factory, bool pushToFrontFlag=false)
Will register a factory to the factory list.
unsigned int ossim_uint32
bool findFactory(T factory) const
Utility to find a factory in the list.
std::vector< ossimString > TypeNameList
void unregisterFactory(T factory)
Will remove the factory from the registry.
void addFactory(T factory)
This is for backward compatability and calls registerFactory for simple adds.
void registerFactoryBefore(T factory, T beforeThisFactory)
Will insert the factory before the beforeThisFactory.
bool isFactoryRegistered(T factory) const
Public access method to determine if a factory is already registered to this list.