openModeller  Version 1.5.0
RasterFactory.cpp
Go to the documentation of this file.
1 
32 
33 #include <algorithm>
34 #include <string>
35 using std::string;
36 
38 
39 /****************/
40 /*** instance ***/
43 {
44  static RasterFactory _instance;
45 
46  if ( ! _initiated ) {
47 
48 #ifdef TERRALIB_FOUND
50 #endif
51 
53 
54  _initiated = true;
55  }
56 
57  return _instance;
58 }
59 
60 /***********************/
61 /*** register driver ***/
62 bool
63 RasterFactory::registerDriver( const string& driverId, CreateRasterCallback builder )
64 {
65  return _drivers.insert( DriversMap::value_type( driverId, builder ) ).second;
66 }
67 
68 /*************************/
69 /*** unregister driver ***/
70 bool
71 RasterFactory::unregisterDriver( const string& driverId )
72 {
73  return _drivers.erase( driverId ) != 0;
74 }
75 
76 /**************/
77 /*** create ***/
78 Raster*
79 RasterFactory::create( const string& source, int categ )
80 {
81  // Another Raster Lib
82  int i = source.find( ">" );
83 
84  if ( i != -1 ) {
85 
86  string driver_id = source.substr( 0, i );
87 
88  DriversMap::const_iterator i = _drivers.find( driver_id );
89 
90  if ( i != _drivers.end() ) {
91 
92  Raster* r = (i->second)();
93  r->createRaster( source, categ );
94  return r;
95  }
96  }
97 
98  #ifdef CURL_FOUND
99  // Check if name starts with http://, https:// or ftp://
100  if ( source.size() > 6 ) {
101 
102  string lower_source;
103  transform( source.begin(), source.end(), std::back_inserter(lower_source), ::tolower );
104 
105  if ( lower_source.compare( 0, 7, "http://" ) == 0 ||
106  lower_source.compare( 0, 8, "https://" ) == 0 ||
107  lower_source.compare( 0, 6, "ftp://" ) == 0 ) {
108 
109  Raster* r = new RemoteRaster();
110  r->createRaster( source, categ );
111  return r;
112  }
113  }
114  #endif
115 
116  // Default: GDAL Raster Lib
117  Raster* r = new GdalRaster();
118  r->createRaster( source, categ );
119  return r;
120 }
121 
122 
123 #ifdef MPI_FOUND
124 /**************/
125 /*** create ***/
126 Raster*
127 RasterFactory::create( const string& output_file_source, const string& source, const MapFormat& format )
128 {
129  // Another Raster Lib
130  int i = source.find( ">" );
131 
132  if ( i != -1 ) {
133 
134  string driver_id = source.substr( 0, i );
135 
136  DriversMap::const_iterator i = _drivers.find( driver_id );
137 
138  if ( i != _drivers.end() ) {
139 
140  Raster* r = (i->second)();
141  r->createRaster( output_file_source, source, format );
142  return r;
143  }
144  }
145 
146  #ifdef CURL_FOUND
147  // Check if name starts with http://, https:// or ftp://
148  if ( source.size() > 6 ) {
149 
150  string lower_source;
151  transform( source.begin(), source.end(), std::back_inserter(lower_source), ::tolower );
152 
153  if ( lower_source.compare( 0, 7, "http://" ) == 0 ||
154  lower_source.compare( 0, 8, "https://" ) == 0 ||
155  lower_source.compare( 0, 6, "ftp://" ) == 0 ) {
156 
157  Raster* r = new RemoteRaster();
158  r->createRaster( output_file_source, source, format );
159  return r;
160  }
161  }
162  #endif
163 
164  // Default: GDAL Raster Lib
165  Raster* r = new GdalRaster();
166  r->createRaster( output_file_source, source, format );
167  return r;
168 }
169 #else
170 /**************/
171 /*** create ***/
172 Raster*
173 RasterFactory::create( const string& source, const MapFormat& format )
174 {
175  // Another Raster Lib
176  int i = source.find( ">" );
177 
178  if ( i != -1 ) {
179 
180  string driver_id = source.substr( 0, i );
181 
182  DriversMap::const_iterator i = _drivers.find( driver_id );
183 
184  if ( i != _drivers.end() ) {
185 
186  Raster* r = (i->second)();
187  r->createRaster( source, format );
188  return r;
189  }
190  }
191 
192  #ifdef CURL_FOUND
193  // Check if name starts with http://, https:// or ftp://
194  if ( source.size() > 6 ) {
195 
196  string lower_source;
197  transform( source.begin(), source.end(), std::back_inserter(lower_source), ::tolower );
198 
199  if ( lower_source.compare( 0, 7, "http://" ) == 0 ||
200  lower_source.compare( 0, 8, "https://" ) == 0 ||
201  lower_source.compare( 0, 6, "ftp://" ) == 0 ) {
202 
203  Raster* r = new RemoteRaster();
204  r->createRaster( source, format );
205  return r;
206  }
207  }
208  #endif
209 
210  // Default: GDAL Raster Lib
211  Raster* r = new GdalRaster();
212  r->createRaster( source, format );
213  return r;
214 }
215 #endif
static Raster * CreateRasterCallback()
Return a new instance of TerralibRaster.
A common interface to rasters.
Definition: Raster.hh:44
Build a Raster.
static Raster * CreateRasterCallback()
bool unregisterDriver(const string &driverId)
Unregister a Raster.
static RasterFactory & instance()
DriversMap _drivers
Map of Rasters and identifiers.
bool registerDriver(const string &driverId, CreateRasterCallback builder)
Raster * create(const string &source, int categ=0)
static bool _initiated
virtual void createRaster(const std::string &source, int categ=0)=0