OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimInfoFactoryRegistry.cpp
Go to the documentation of this file.
1 //---
2 //
3 // License: MIT
4 //
5 // Author: David Burken
6 //
7 // Description: Class definition of registry (singleton) for info factories.
8 //
9 //---
10 // $Id$
11 
19 
20 #include <algorithm> /* for std::find */
21 
23 
25 {
26  m_factoryList.clear();
27 }
28 
30 {
31  if ( !m_instance )
32  {
34  }
35  return m_instance;
36 }
37 
40 {
41  if (factory)
42  {
43  m_mutex.lock();
44  m_factoryList.push_back(factory);
45  m_mutex.unlock();
46  }
47 }
48 
51 {
52  if (factory)
53  {
54  m_mutex.lock();
55  m_factoryList.insert( m_factoryList.begin(), factory );
56  m_mutex.unlock();
57  }
58 }
59 
62 {
63  m_mutex.lock();
64  std::vector<ossimInfoFactoryInterface*>::iterator i =
65  std::find(m_factoryList.begin(), m_factoryList.end(), factory);
66 
67  if( i != m_factoryList.end() )
68  {
69  m_factoryList.erase(i);
70  }
71  m_mutex.unlock();
72 }
73 
74 std::shared_ptr<ossimInfoBase> ossimInfoFactoryRegistry::create(
75  const ossimFilename& file) const
76 {
77  std::shared_ptr<ossimInfoBase> result(0);
78 
79  std::shared_ptr<ossim::istream> str = ossim::StreamFactoryRegistry::instance()->
80  createIstream( file.c_str(), std::ios_base::in|std::ios_base::binary );
81  if ( str )
82  {
83  std::string connectionString = file.c_str();
84  result = create( str, connectionString );
85  str.reset();
86  }
87 
88  if(!result)
89  {
90  std::vector<ossimInfoFactoryInterface*>::const_iterator i =
91  m_factoryList.begin();
92 
93  while ( i != m_factoryList.end() )
94  {
95  result = (*i)->create( file );
96  if ( result )
97  {
98  break;
99  }
100  ++i;
101  }
102  }
103 
104  return result;
105 }
106 
107 std::shared_ptr<ossimInfoBase> ossimInfoFactoryRegistry::create(
108  std::shared_ptr<ossim::istream>& str,
109  const std::string& connectionString) const
110 {
111  std::shared_ptr<ossimInfoBase> result(0);
112  if ( str )
113  {
114  std::vector<ossimInfoFactoryInterface*>::const_iterator i =
115  m_factoryList.begin();
116 
117  while ( i != m_factoryList.end() )
118  {
119  result = (*i)->create(str, connectionString);
120  if ( result )
121  {
122  break;
123  }
124  str->clear();
125  str->seekg(0);
126  ++i;
127  }
128  }
129  return result;
130 }
131 
134  : m_factoryList(),
135  m_mutex()
136 {
138 }
139 
142  const ossimInfoFactoryRegistry& /* obj */)
143 {}
144 
147  const ossimInfoFactoryRegistry& /* rhs */ )
148 {
149  return *this;
150 }
void unregisterFactory(ossimInfoFactoryInterface *factory)
Method to remove a factory from the registry.
static StreamFactoryRegistry * instance()
std::vector< ossimInfoFactoryInterface * > m_factoryList
std::shared_ptr< ossimInfoBase > create(const ossimFilename &file) const
Create method.
void registerFactoryToFront(ossimInfoFactoryInterface *factory)
Adds factory to the front of the registry.
static ossimInfoFactory * instance()
static ossimInfoFactoryRegistry * instance()
instance method
ossimInfoFactoryRegistry()
Hidden from use default constructor.
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string&#39;s contents...
Definition: ossimString.h:396
static ossimInfoFactoryRegistry * m_instance
const ossimInfoFactoryRegistry & operator=(const ossimInfoFactoryRegistry &rhs)
hidden from use assignment operator
void registerFactory(ossimInfoFactoryInterface *factory)
Method to add factory to registry.