Orfeo Toolbox  4.2
otbVectorDataIOFactory.cxx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ORFEO Toolbox
4  Language: C++
5  Date: $Date$
6  Version: $Revision$
7 
8 
9  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
10  See OTBCopyright.txt for details.
11 
12 
13  This software is distributed WITHOUT ANY WARRANTY; without even
14  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  PURPOSE. See the above copyright notices for more information.
16 
17 =========================================================================*/
18 
19 #include "otbVectorDataIOFactory.h"
22 #include "itkObjectFactoryBase.h"
23 #include "itkMutexLock.h"
24 #include "itkMutexLockHolder.h"
25 
26 namespace otb
27 {
28 
32 ::CreateVectorDataIO(const char* path, FileModeType mode)
33 {
34  RegisterBuiltInFactories();
35 
36  std::string baseclassID = std::string("otbVectorDataIOBase");
37 
38  std::list<VectorDataIOBasePointerType> possibleVectorDataIO;
39  std::list<itk::LightObject::Pointer> allobjects =
40  itk::ObjectFactoryBase::CreateAllInstance(baseclassID.c_str());
41  for (std::list<itk::LightObject::Pointer>::iterator i = allobjects.begin();
42  i != allobjects.end(); ++i)
43  {
44  VectorDataIOBaseType * io = dynamic_cast<VectorDataIOBaseType*>(i->GetPointer());
45  if (io)
46  {
47  possibleVectorDataIO.push_back(io);
48  }
49  else
50  {
51  itkGenericExceptionMacro(<< "Error VectorDataIO factory did not return an VectorDataIOBase: "
52  << (*i)->GetNameOfClass());
53  }
54  }
55  for (std::list<VectorDataIOBasePointerType>::iterator k = possibleVectorDataIO.begin();
56  k != possibleVectorDataIO.end(); ++k)
57  {
58  if (mode == ReadMode)
59  {
60  if ((*k)->CanReadFile(path))
61  {
62  return *k;
63  }
64  }
65  else if (mode == WriteMode)
66  {
67  if ((*k)->CanWriteFile(path))
68  {
69  return *k;
70  }
71 
72  }
73  }
74  return 0;
75 }
76 
77 void
80 {
81  static bool firstTime = true;
82 
83  static itk::SimpleMutexLock mutex;
84  {
85  // This helper class makes sure the Mutex is unlocked
86  // in the event an exception is thrown.
88  if (firstTime)
89  {
92  firstTime = false;
93  }
94  }
95 }
96 
97 } // end namespace otb
98 

Generated at Sat Aug 30 2014 16:31:48 for Orfeo Toolbox with doxygen 1.8.3.1