OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimImageWriterFactoryRegistry.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 // Copyright (C) 2000 ImageLinks Inc.
3 //
4 // License: LGPL
5 //
6 // See LICENSE.txt file in the top level directory for more details.
7 //
8 // Author: Frank Warmerdam (warmerda@home.com)
9 //
10 //*******************************************************************
11 // $Id: ossimImageWriterFactoryRegistry.cpp 22865 2014-08-06 11:17:03Z gpotts $
12 
16 #include <ossim/base/ossimCommon.h>
20 #include <ossim/base/ossimString.h>
22 #include <algorithm>
23 #include <iterator>
24 #include <ostream>
25 
26 //ossimImageWriterFactoryRegistry* ossimImageWriterFactoryRegistry::theInstance = NULL;
27 
29 {
30 }
31 
33 {
35  static bool initInst = false;
36  if(!initInst)
37  {
40  initInst = true;
41  }
42 
43  return &inst;
44 // if(!theInstance)
45 // {
46 // theInstance = new ossimImageWriterFactoryRegistry;
47 // }
48 
49 // return theInstance;
50 }
51 
52 
54 {
56  if(writer)
57  {
58  writer->setFilename(filename);
59  }
60 
61  return writer;
62 }
63 
65  const char *prefix)const
66 {
67  return createObjectFromRegistry(kwl, prefix);
68 }
69 
71 {
72  return createObjectFromRegistry(typeName);
73 }
74 
75 void ossimImageWriterFactoryRegistry::getTypeNameList(std::vector<ossimString>& typeList)const
76 {
78 }
79 
81 {
82  ossimImageFileWriter *writer = NULL;
84  getImageFileWritersBySuffix(result, fileExtension);
85  if(!result.empty())
86  {
87  writer = result[0].release();
88  result.clear();
89  }
90  return writer;
91 }
92 
94  const char *prefix)const
95 {
96  // let's see if we ned to return an object based on extension.
97  // this is specified by the type to be a generic
98  // ossimImageFileWriter
99  //
100  ossimString type = kwl.find(prefix, ossimKeywordNames::TYPE_KW);
101 
102  if(type == "ossimImageFileWriter")
103  {
104  ossimFilename filename = kwl.find(prefix, ossimKeywordNames::FILENAME_KW);
105 
106  if((filename != "")&&
107  (filename.ext() != ""))
108  {
109  ossimImageFileWriter* writer = createWriterFromExtension(filename.ext());
110 
111  if(writer)
112  {
113  writer->setFilename(filename);
114  }
115  return writer;
116  }
117  }
118 
119  vector<ossimImageWriterFactoryBase*>::const_iterator factories;
120  ossimImageFileWriter *result = NULL;
121 
122  factories = m_factoryList.begin();
123  while(factories != m_factoryList.end())
124  {
125  result = (*factories)->createWriter(kwl, prefix);
126  if(result)
127  {
128  return result;
129  }
130  ++factories;
131  }
132 
133  return result;
134 }
135 
137 {
138  vector<ossimImageWriterFactoryBase*>::const_iterator factories;
139  ossimImageFileWriter *result = NULL;
140 
141  factories = m_factoryList.begin();
142  while(factories != m_factoryList.end())
143  {
144  result = (*factories)->createWriter(typeName);
145  if(result)
146  {
147  return result;
148  }
149  ++factories;
150  }
151 
152  return result;
153 }
154 
155 
156 void ossimImageWriterFactoryRegistry::getImageTypeList(std::vector<ossimString>& typeList)const
157 {
158  vector<ossimString> result;
159  vector<ossimImageWriterFactoryBase*>::const_iterator iter = m_factoryList.begin();
160 
161  while(iter != m_factoryList.end())
162  {
163  result.clear();
164  (*iter)->getImageTypeList(result);
165 
166  // now append to the end of the typeList.
167  typeList.insert(typeList.end(),
168  result.begin(),
169  result.end());
170  ++iter;
171  }
172 }
173 
175  const ossimString& ext)const
176 {
178  vector<ossimImageWriterFactoryBase*>::const_iterator iter = m_factoryList.begin();
179 
180  while(iter != m_factoryList.end())
181  {
182  result.clear();
183  (*iter)->getImageFileWritersBySuffix(tempResult, ext);
184 
185  // now append to the end of the typeList.
186  result.insert(result.end(),
187  tempResult.begin(),
188  tempResult.end());
189  ++iter;
190  }
191 
192 }
193 
195  const ossimString& mimeType)const
196 {
198  vector<ossimImageWriterFactoryBase*>::const_iterator iter = m_factoryList.begin();
199 
200  while(iter != m_factoryList.end())
201  {
202  result.clear();
203  (*iter)->getImageFileWritersByMimeType(tempResult, mimeType);
204 
205  // now append to the end of the typeList.
206  result.insert(result.end(),
207  tempResult.begin(),
208  tempResult.end());
209  ++iter;
210  }
211 }
212 
214  std::ostream& out)const
215 {
216  std::vector<ossimString> outputType;
217 
218  this->getImageTypeList(outputType);
219  std::copy(outputType.begin(),
220  outputType.end(),
221  std::ostream_iterator<ossimString>(out, "\n"));
222  out << std::endl;
223  return out;
224 }
225 
227 {
228  // Loop through factories:
229  vector<ossimImageWriterFactoryBase*>::const_iterator factoryIter = m_factoryList.begin();
230  while( factoryIter != m_factoryList.end() )
231  {
232  out << "factory: " << (*factoryIter)->getClassName() << "\n\n";
233 
234  // Loop through writer classes in factory.
235  std::vector<ossimString> typeNames;
236  (*factoryIter)->getTypeNameList(typeNames);
237  std::vector<ossimString>::const_iterator typeNamesIter = typeNames.begin();
238  while (typeNamesIter != typeNames.end())
239  {
240  ossimRefPtr<ossimImageFileWriter> writer = (*factoryIter)->createWriter(*typeNamesIter);
241  if ( writer.valid() )
242  {
243  out << "writer:\n" << writer->getClassName() << "\n";
244 
245  // Loop through writer types, e.g. tiff_tiled_band_separate
246  std::vector<ossimString> imageTypeList;
247  writer->getImageTypeList(imageTypeList);
248  std::vector<ossimString>::const_iterator imageTypeListIter = imageTypeList.begin();
249  out << "\ntypes:\n";
250  while ( imageTypeListIter != imageTypeList.end() )
251  {
252  out << (*imageTypeListIter) << "\n";
253  ++imageTypeListIter;
254  }
255 
256  // Loop through writer properties:
257  std::vector<ossimString> propNames;
258  writer->getPropertyNames(propNames);
259  if ( propNames.size() )
260  {
261  out << "\nproperties:\n";
263  std::vector<ossimString>::const_iterator p = propNames.begin();
264  while ( p != propNames.end() )
265  {
266  out << " " << (*p) << "\n";
267  prop = writer->getProperty( *p );
268  if ( prop.valid() )
269  {
270  ossimStringProperty* stringProp =
271  dynamic_cast<ossimStringProperty*>(prop.get());
272  if ( stringProp )
273  {
274  if ( stringProp->getConstraints().size() )
275  {
276  out << " constraints:\n";
277  std::vector<ossimString>::const_iterator strPropIter =
278  stringProp->getConstraints().begin();
279  while( strPropIter != stringProp->getConstraints().end() )
280  {
281  out << " " << (*strPropIter) << "\n";
282  ++strPropIter;
283  }
284  }
285  }
286  }
287 
288  ++p;
289  }
290  out << "\n";
291  }
292  }
293  ++typeNamesIter;
294  }
295 
296  ++factoryIter;
297  }
298  return out;
299 }
300 
301 extern "C"
302 {
304  {
306  }
307 }
308 
310  :
312 {
313 }
314 
316 {
317 }
void operator=(const ossimImageWriterFactoryRegistry &)
ossimImageFileWriter * createWriterFromExtension(const ossimString &fileExtension) const
static ossimImageWriterFactory * instance()
Represents serializable keyword/value map.
bool valid() const
Definition: ossimRefPtr.h:75
const char * find(const char *key) const
virtual void getImageFileWritersBySuffix(ossimImageWriterFactoryBase::ImageFileWriterList &result, const ossimString &ext) const
static ossimImageWriterFactoryRegistry * instance()
static ossimObjectFactoryRegistry * instance()
ossimObject * createObject(const ossimKeywordlist &kwl, const char *prefix=0) const
virtual ossimString getClassName() const
Definition: ossimObject.cpp:64
void * ossimImageWriterFactoryRegistryGetInstance()
Pure virtual base class for image file writers.
const std::vector< ossimString > & getConstraints() const
virtual void getPropertyNames(std::vector< ossimString > &propertyNames) const
std::ostream & printWriterProps(std::ostream &out) const
Prints list of writers from getImageTypeList.
static const char * TYPE_KW
virtual void getImageTypeList(std::vector< ossimString > &imageTypeList) const =0
void getImageTypeList(std::vector<ossimString>& imageTypeList)const
static ossimString downcase(const ossimString &aString)
Definition: ossimString.cpp:48
virtual ossimRefPtr< ossimProperty > getProperty(const ossimString &name) const
void registerFactory(T *factory, bool pushToFrontFlag=false)
Will register a factory to the factory list.
virtual void getImageFileWritersByMimeType(ossimImageWriterFactoryBase::ImageFileWriterList &result, const ossimString &mimeType) const
virtual void setFilename(const ossimFilename &file)
std::vector< ossimRefPtr< ossimImageFileWriter > > ImageFileWriterList
ossimImageFileWriter * createWriter(const ossimFilename &filename) const
ossimString ext() const
std::ostream & printImageTypeList(std::ostream &out) const
Prints list of writers from getImageTypeList.
void getAllTypeNamesFromRegistry(std::vector< ossimString > &typeList) const
Will add all object types the factories can allocate.
virtual void getTypeNameList(std::vector< ossimString > &typeList) const
getTypeNameList.
ossimObject * createObjectFromRegistry(const ossimString &typeName) const
This is the base object return for all objects in the system.
static const char * FILENAME_KW
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23
virtual void getImageTypeList(std::vector< ossimString > &imageTypeList) const
getImageTypeList.