OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
ossim::StreamFactoryRegistry Class Reference

This is a generic stream registry. More...

#include <ossimStreamFactoryRegistry.h>

Inheritance diagram for ossim::StreamFactoryRegistry:
ossim::StreamFactoryBase

Classes

class  BufferInfo
 This is an internal class used to store the buffer information loaded from the preferences. More...
 

Public Member Functions

virtual ~StreamFactoryRegistry ()
 
void registerFactory (StreamFactoryBase *factory)
 Registers a stream factory. More...
 
void unregisterFactory (StreamFactoryBase *factory)
 Removes a factory from the registry. More...
 
virtual std::shared_ptr< ossim::istreamcreateIstream (const std::string &connectionString, const ossimKeywordlist &options=ossimKeywordlist(), std::ios_base::openmode mode=std::ios_base::in|std::ios_base::binary) const
 Will try to creates an istream interface to the connectionString passed in. More...
 
virtual std::shared_ptr< ossim::ostreamcreateOstream (const std::string &connectionString, const ossimKeywordlist &options=ossimKeywordlist(), std::ios_base::openmode mode=std::ios_base::out|std::ios_base::binary) const
 Will try to creates an ostream interface to the connectionString passed in. More...
 
virtual std::shared_ptr< ossim::iostreamcreateIOstream (const std::string &connectionString, const ossimKeywordlist &options=ossimKeywordlist(), std::ios_base::openmode mode=std::ios_base::in|std::ios_base::out|std::ios_base::binary) const
 Will try to creates an iostream interface to the connectionString passed in. More...
 
bool exists (const std::string &connectionString) const
 Methods to test if connection exists. More...
 
virtual bool exists (const std::string &connectionString, bool &continueFlag) const
 Methods to test if connection exists. More...
 
void loadPreferences ()
 This will load the buffer information from the preferences. More...
 
- Public Member Functions inherited from ossim::StreamFactoryBase
virtual ~StreamFactoryBase ()
 

Static Public Member Functions

static StreamFactoryRegistryinstance ()
 

Protected Member Functions

 StreamFactoryRegistry ()
 

Private Member Functions

 StreamFactoryRegistry (const StreamFactoryRegistry &)
 copy constructor hidden from use More...
 
bool getBufferInfo (BufferInfo &bufferInfo, const ossimString &connectionString) const
 

Private Attributes

std::vector< StreamFactoryBase * > m_factoryList
 
std::vector< BufferInfom_bufferInfoList
 
ossimRegExp m_patternMatcher
 
std::mutex m_mutex
 

Static Private Attributes

static StreamFactoryRegistrym_instance = 0
 

Detailed Description

This is a generic stream registry.

We could try to create streams for http, https, s3 protocols as well as local file. We have also exposed an exists for supporting exists() calls for different stream types.

We have added support for Buffered reads. You can enable buffered reads to be block boundary. If it's not block then it will use a pubsetbuf for a buffered I/O It will read the

See also
ossimPreferences for the prefix key ossim.stream.factory.registry.istream.buffer[0-9]+ Example key list:
ossim.stream.factory.registry.istream.buffer1.enabled: false
ossim.stream.factory.registry.istream.buffer1.includePattern: ^/
ossim.stream.factory.registry.istream.buffer1.enableBlocked: true
ossim.stream.factory.registry.istream.buffer1.size: 65536

The includePattern keyword is a regular expression. Examples:

Local file example:

ossimString connectionString = "/data/foo.ntf"
std::shared_ptr<ossim::istream> in = ossim::StreamFactoryRegistry::instance()->createIstream(connectionString);
if(in)
{
std::vector<char> buf(1024)
in->seekg(0);
in->read(&buf.front(), buf.size());
}

S3 file example:

ossimString connectionString = "s3://foo-bucket/path/foo.ntf"
std::shared_ptr<ossim::istream> in = ossim::StreamFactoryRegistry::instance()->createIstream(connectionString);
if(in)
{
std::vector<char> buf(1024)
in->seekg(0);
in->read(&buf.front(), buf.size());
}

https or https file example:

ossimString connectionString = "https://foo-host/path/foo.ntf"
std::shared_ptr<ossim::istream> in = ossim::StreamFactoryRegistry::instance()->createIstream(connectionString);
if(in)
{
std::vector<char> buf(1024)
in->seekg(0);
in->read(&buf.front(), buf.size());
}

Definition at line 84 of file ossimStreamFactoryRegistry.h.

Constructor & Destructor Documentation

◆ ~StreamFactoryRegistry()

ossim::StreamFactoryRegistry::~StreamFactoryRegistry ( )
virtual

Definition at line 31 of file ossimStreamFactoryRegistry.cpp.

32 {
33 }

◆ StreamFactoryRegistry() [1/2]

ossim::StreamFactoryRegistry::StreamFactoryRegistry ( )
protected

Definition at line 26 of file ossimStreamFactoryRegistry.cpp.

27 {
28 }

◆ StreamFactoryRegistry() [2/2]

ossim::StreamFactoryRegistry::StreamFactoryRegistry ( const StreamFactoryRegistry )
private

copy constructor hidden from use

Member Function Documentation

◆ createIOstream()

std::shared_ptr< ossim::iostream > ossim::StreamFactoryRegistry::createIOstream ( const std::string &  connectionString,
const ossimKeywordlist options = ossimKeywordlist(),
std::ios_base::openmode  mode = std::ios_base::in|std::ios_base::out|std::ios_base::binary 
) const
virtual

Will try to creates an iostream interface to the connectionString passed in.

Parameters
connectionStringIs the connection string used to create the stream
optionsIf a stream is found then this holds specific options for the stream. Defaults to empty options
modeIs the mode to be used. Defaults to a binary output stream.
Returns
A shared pointer to an ostream if successful.

Implements ossim::StreamFactoryBase.

Definition at line 200 of file ossimStreamFactoryRegistry.cpp.

204 {
205  std::shared_ptr<ossim::iostream> result(0);
206  return result;
207 }

◆ createIstream()

std::shared_ptr< ossim::istream > ossim::StreamFactoryRegistry::createIstream ( const std::string &  connectionString,
const ossimKeywordlist options = ossimKeywordlist(),
std::ios_base::openmode  mode = std::ios_base::in|std::ios_base::binary 
) const
virtual

Will try to creates an istream interface to the connectionString passed in.

Parameters
connectionStringIs the connection string used to create a stream. Possible examples: s3://<bucket>/path or /data/foo.tif or https://<host>/<path>
optionsIf a stream is found then this holds specific options for the stream. Defaults to empty options
modeIs the mode to be used. Defaults to a binary input stream.
Returns
A shared pointer to an istream if successful.

Implements ossim::StreamFactoryBase.

Definition at line 148 of file ossimStreamFactoryRegistry.cpp.

Referenced by ossimSrtmSupportData::computeMinMaxTemplate(), ossimImageHandler::initVertices(), ossimImageHandler::loadMetaData(), ossimTiffInfo::open(), and ossimNitfTileSource::open().

152 {
153  std::shared_ptr<ossim::istream> result(0);
154  if(traceDebug())
155  {
157  << "ossim::StreamFactoryRegistry::createIstream: ....... entered: "<< connectionString << "\n";
158  }
159 
160  ossim_uint32 i = 0;
161  for(i = 0; (i < m_factoryList.size())&&(!result); ++i)
162  {
163  result = m_factoryList[i]->createIstream(connectionString, options, openMode);
164 
165  if(result)
166  {
167  BufferInfo bufferInfo;
168  if(getBufferInfo(bufferInfo, connectionString))
169  {
170  if(bufferInfo.m_enableBlocked)
171  {
172  result = std::make_shared<ossim::BlockIStream>(result, bufferInfo.m_size);
173  }
174  else
175  {
176  result = std::make_shared<ossimBufferedInputStream>(result, bufferInfo.m_size);
177  }
178  }
179  }
180  }
181 
182  if(traceDebug())
183  {
185  << "ossim::StreamFactoryRegistry::createIstream: ....... leaving!\n";
186  }
187 
188  return result;
189 }
unsigned int ossim_uint32
bool getBufferInfo(BufferInfo &bufferInfo, const ossimString &connectionString) const
std::vector< StreamFactoryBase * > m_factoryList
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)

◆ createOstream()

std::shared_ptr< ossim::ostream > ossim::StreamFactoryRegistry::createOstream ( const std::string &  connectionString,
const ossimKeywordlist options = ossimKeywordlist(),
std::ios_base::openmode  mode = std::ios_base::out|std::ios_base::binary 
) const
virtual

Will try to creates an ostream interface to the connectionString passed in.

Parameters
connectionStringIs the connection string used to create the stream
optionsIf a stream is found then this holds specific options for the stream. Defaults to empty options
modeIs the mode to be used. Defaults to a binary output stream.
Returns
A shared pointer to an ostream if successful.

Implements ossim::StreamFactoryBase.

Definition at line 191 of file ossimStreamFactoryRegistry.cpp.

195 {
196  std::shared_ptr<ossim::ostream> result(0);
197  return result;
198 }

◆ exists() [1/2]

bool ossim::StreamFactoryRegistry::exists ( const std::string &  connectionString) const

Methods to test if connection exists.

Returns
true on success, false, if not.

Definition at line 209 of file ossimStreamFactoryRegistry.cpp.

Referenced by ossimFilename::exists().

210 {
211  bool continueFlag = true;
212  return exists( connectionString, continueFlag );
213 }
bool exists(const std::string &connectionString) const
Methods to test if connection exists.

◆ exists() [2/2]

bool ossim::StreamFactoryRegistry::exists ( const std::string &  connectionString,
bool &  continueFlag 
) const
virtual

Methods to test if connection exists.

Parameters
connectionString
continueFlagInitializes by this, if set to true, indicates factory handles file/url and no more factory checks are necessary.
Returns
true on success, false, if not.

Implements ossim::StreamFactoryBase.

Definition at line 215 of file ossimStreamFactoryRegistry.cpp.

217 {
218  if(traceDebug())
219  {
221  << "ossim::StreamFactoryRegistry::exists: ....... entered: "<< connectionString << "\n";
222  }
223  bool result = false;
224  for(auto factory:m_factoryList)
225  {
226 
227  result = factory->exists( connectionString, continueFlag );
228  if ( ( result == true ) || (continueFlag == false ) ) break;
229  }
230 
231  if(traceDebug())
232  {
234  << "ossim::StreamFactoryRegistry::createIstream: ....... leaving!\n";
235  }
236  return result;
237 }
std::vector< StreamFactoryBase * > m_factoryList
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)

◆ getBufferInfo()

bool ossim::StreamFactoryRegistry::getBufferInfo ( BufferInfo bufferInfo,
const ossimString connectionString 
) const
private
Parameters
bufferInfoHolds the result of the first buffer info matching the connection string
connecitonStringThe connection string

Definition at line 120 of file ossimStreamFactoryRegistry.cpp.

References ossimString::c_str().

122 {
123  bool result = false;
124 
125  for(std::vector<BufferInfo>::const_iterator iter = m_bufferInfoList.begin();
126  iter != m_bufferInfoList.end();
127  ++iter)
128  {
129  if(iter->m_enabled)
130  {
131  m_patternMatcher.compile(iter->m_pattern);
133  {
134  if(m_patternMatcher.find(connectionString.c_str()))
135  {
136  bufferInfo = *iter;
137  result = true;
138  break;
139  }
140  }
141  }
142  }
143 
144  return result;
145 }
std::vector< BufferInfo > m_bufferInfoList
void compile(const char *)
bool is_valid() const
Definition: ossimRegExp.h:232
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
bool find(const char *)

◆ instance()

ossim::StreamFactoryRegistry * ossim::StreamFactoryRegistry::instance ( )
static

Definition at line 35 of file ossimStreamFactoryRegistry.cpp.

Referenced by ossimSrtmSupportData::computeMinMaxTemplate(), ossimInfoFactoryRegistry::create(), ossimFilename::exists(), ossimFilename::fileSize(), for(), ossimNitfFile::getNewDataExtensionSegment(), ossimNitfFile::getNewImageHeader(), ossimNitfFile::getNewLabelHeader(), ossimNitfFile::getNewSymbolHeader(), ossimNitfFile::getNewTextHeader(), ossimAuxXmlSupportData::getProjection(), ossimMultiResLevelHistogram::importHistogram(), ossimInit::initializeDefaultFactories(), ossimImageHandler::initVertices(), ossimApplanixEOFile::isEOFile(), ossimSensorModelFactory::isNitf(), ossimImageHandler::loadMetaData(), ossimNitfInfo::open(), ossimDemInfo::open(), ossimCcfInfo::open(), ossimInfoBase::open(), ossimDemHeader::open(), ossimTiffInfo::open(), ossimNitfTileSource::open(), ossimDtedHandler::open(), ossimFfRevb::ossimFfRevb(), ossimFfRevc::ossimFfRevc(), ossimSharedLibraryFinalize(), ossimSharedLibraryInitialize(), ossimCcfHead::parseCcfHeader(), ossimApplanixEOFile::parseFile(), ossimKeywordlist::parseFile(), and ossimApplanixEOFile::parseHeader().

36 {
37  // because of the loadPreferences for this factory and the fact that
38  // create stream could be recursive the lock and unlock are
39  // a little different here. We will unlock as quickly as we can
40  // After the unlock then call load preferences
41  m_instanceMutex.lock();
42  if(!m_instance)
43  {
46  m_instanceMutex.unlock();
48  }
49  else
50  {
51  m_instanceMutex.unlock();
52  }
53 
54  return m_instance;
55 }
static StreamFactoryRegistry * m_instance
void registerFactory(StreamFactoryBase *factory)
Registers a stream factory.
static StreamFactory * instance()
This is a generic stream registry.
void loadPreferences()
This will load the buffer information from the preferences.

◆ loadPreferences()

void ossim::StreamFactoryRegistry::loadPreferences ( )

This will load the buffer information from the preferences.

Definition at line 57 of file ossimStreamFactoryRegistry.cpp.

58 {
59  if(traceDebug())
60  {
62  << "ossim::StreamFactoryRegistry::loadPreferences: ....... entered!\n";
63  }
64  std::vector<ossimString> sortedList;
66  .getSortedList(sortedList, ISTREAM_BUFFER_KW);
67  if(sortedList.size())
68  {
69  m_bufferInfoList.resize(sortedList.size());
70  }
71  else
72  {
73  m_bufferInfoList.clear();
74  }
75  ossim_uint32 idx=0;
76  for(std::vector<ossimString>::const_iterator iter = sortedList.begin();
77  iter!=sortedList.end();
78  ++iter,++idx)
79  {
80  ossimString prefix = *iter;
81  ossimString bufferIStreamEnabled = ossimPreferences::instance()->findPreference(prefix+".enabled");
82  ossimString bufferIStreamBlockEnabled = ossimPreferences::instance()->findPreference(prefix+".enableBlocked");
83  ossimString bufferIStreamIncludePattern = ossimPreferences::instance()->findPreference(prefix+".includePattern");
84  ossimString bufferIStreamSize = ossimPreferences::instance()->findPreference(prefix+".size");
85 
86  if(!bufferIStreamSize.empty())
87  {
88  m_bufferInfoList[idx].m_size = bufferIStreamSize.toUInt64();
89  }
90  if(!bufferIStreamEnabled.empty())
91  {
92  m_bufferInfoList[idx].m_enabled = bufferIStreamEnabled.toBool();
93  }
94  if(!bufferIStreamBlockEnabled.empty())
95  {
96  m_bufferInfoList[idx].m_enableBlocked = bufferIStreamBlockEnabled.toBool();
97  }
98  if(!bufferIStreamIncludePattern.empty())
99  {
100  m_bufferInfoList[idx].m_pattern = bufferIStreamIncludePattern;
101  }
102  if(traceDebug())
103  {
105  << "ossim::StreamFactoryRegistry adding BufferInfo: \n"
106  << "enabled: " << ossimString::toString(m_bufferInfoList[idx].m_enabled)<< "\n"
107  << "enableBlocked: " << ossimString::toString(m_bufferInfoList[idx].m_enableBlocked)<< "\n"
108  << "size: " << m_bufferInfoList[idx].m_size << "\n"
109  << "pattern: " << m_bufferInfoList[idx].m_pattern << "\n";
110  }
111 
112  }
113  if(traceDebug())
114  {
116  << "ossim::StreamFactoryRegistry::loadPreferences: ....... leaving!\n";
117  }
118 }
const ossimKeywordlist & preferencesKWL() const
static ossimString toString(bool aValue)
Numeric to string methods.
std::vector< BufferInfo > m_bufferInfoList
const char * findPreference(const char *key) const
bool toBool() const
String to numeric methods.
unsigned int ossim_uint32
static ossimPreferences * instance()
void getSortedList(std::vector< ossimString > &prefixValues, const ossimString &prefixKey) const
This return the sorted keys if you have a list.
ossim_uint64 toUInt64() const
bool empty() const
Definition: ossimString.h:411
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)

◆ registerFactory()

void ossim::StreamFactoryRegistry::registerFactory ( ossim::StreamFactoryBase factory)

Registers a stream factory.

This allows for a pluggable stream Please see ossim-plugins and look at curl, aws for example stream definitions.

Parameters
factoryTo be added to the registry

Definition at line 239 of file ossimStreamFactoryRegistry.cpp.

240 {
241  std::vector<ossim::StreamFactoryBase*>::iterator iter = std::find(
242  m_factoryList.begin(), m_factoryList.end(), factory);
243  if(iter == m_factoryList.end())
244  {
245  m_factoryList.push_back(factory);
246  }
247 }
std::vector< StreamFactoryBase * > m_factoryList

◆ unregisterFactory()

void ossim::StreamFactoryRegistry::unregisterFactory ( StreamFactoryBase factory)

Removes a factory from the registry.

Parameters
factoryTo be removed from the registry

Definition at line 249 of file ossimStreamFactoryRegistry.cpp.

250 {
251  // std::lock_guard<std::mutex> lock(m_factoryListMutex);
252  std::vector<ossim::StreamFactoryBase*>::iterator iter = std::find(
253  m_factoryList.begin(), m_factoryList.end(), factory);
254  if(iter != m_factoryList.end())
255  {
256  m_factoryList.erase( iter );
257  }
258 }
std::vector< StreamFactoryBase * > m_factoryList

Member Data Documentation

◆ m_bufferInfoList

std::vector<BufferInfo> ossim::StreamFactoryRegistry::m_bufferInfoList
private

Definition at line 215 of file ossimStreamFactoryRegistry.h.

◆ m_factoryList

std::vector<StreamFactoryBase*> ossim::StreamFactoryRegistry::m_factoryList
private

Definition at line 214 of file ossimStreamFactoryRegistry.h.

◆ m_instance

ossim::StreamFactoryRegistry * ossim::StreamFactoryRegistry::m_instance = 0
staticprivate

Definition at line 216 of file ossimStreamFactoryRegistry.h.

◆ m_mutex

std::mutex ossim::StreamFactoryRegistry::m_mutex
mutableprivate

Definition at line 218 of file ossimStreamFactoryRegistry.h.

◆ m_patternMatcher

ossimRegExp ossim::StreamFactoryRegistry::m_patternMatcher
mutableprivate

Definition at line 217 of file ossimStreamFactoryRegistry.h.


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