All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ExpansibleRasterFactory.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/memory/ExpansibleRasterFactory.cpp
22 
23  \brief This is the concrete factory for In-Memory driver.
24 */
25 
26 // TerraLib
27 #include "../common/StringUtils.h"
28 #include "../common/Translator.h"
29 #include "Exception.h"
30 #include "ExpansibleRaster.h"
32 
33 // STL
34 #include <memory>
35 
36 // Boost
37 #include <boost/lexical_cast.hpp>
38 
39 static std::string sg_expansibleRasterFactoryId("EXPANSIBLE");
40 
42 
44 {
45 }
46 
48 {
50 }
51 
52 void te::mem::ExpansibleRasterFactory::getCreationalParameters(std::vector< std::pair<std::string, std::string> >& params) const
53 {
54  params.push_back(std::pair<std::string, std::string>("MAXMEMPERCENTUSED", "40"));
55  params.push_back(std::pair<std::string, std::string>("MAXNUMBEROFRAMBLOCKS", "1"));
56 }
57 
60 {
61 }
62 
64  const std::vector<te::rst::BandProperty*> bands,
65  const std::map<std::string, std::string>& rinfo,
66  void* h,
67  void (*deleter)(void*))
68 {
69  std::auto_ptr<te::rst::Raster> rasterPtr;
70 
71  if( rinfo.find( "MAXNUMBEROFRAMBLOCKS" ) != rinfo.end() )
72  {
73  unsigned int maxNumberOfRAMBlocks = boost::lexical_cast< unsigned int >( rinfo.find( "MAXNUMBEROFRAMBLOCKS" )->second );
74  rasterPtr.reset( new ExpansibleRaster( g, bands, maxNumberOfRAMBlocks ) );
75  }
76  else if( rinfo.find( "MAXMEMPERCENTUSED" ) != rinfo.end() )
77  {
78  unsigned int maxMemPercentUsed = boost::lexical_cast< unsigned int>( rinfo.find( "MAXMEMPERCENTUSED" )->second );
79  if( maxMemPercentUsed > 100 )
80  {
81  throw Exception(TE_TR("Invalid parameter: MAXMEMPERCENTUSED") );
82  }
83 
84  rasterPtr.reset( new ExpansibleRaster( (unsigned char)maxMemPercentUsed, g, bands ) );
85  }
86  else
87  {
88  rasterPtr.reset( new ExpansibleRaster( 40, g, bands ) );
89  }
90 
91  return rasterPtr.release();
92 }
93 
95 {
96  return new ExpansibleRaster;
97 }
98 
99 std::map<std::string, std::string> te::mem::ExpansibleRasterFactory::getCapabilities() const
100 {
101  return std::map<std::string, std::string>();
102 }
103 
105 {
106  finalize();
107  sm_factoryPointer = new ExpansibleRasterFactory;
108 }
109 
111 {
112  delete sm_factoryPointer;
113  sm_factoryPointer = 0;
114 }
A raster (stored in memory and eventually swapped to disk) where it is possible to dynamically add li...
static void initialize()
It initializes the factory: the singleton instance will be registered in the abstract factory DataSou...
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:347
An exception class for the TerraLib In-Memory Data Access driver.
te::rst::Raster * build()
Concrete factories (derived from this one) must implement this method in order to create objects...
te::rst::Raster * create(te::rst::Grid *g, const std::vector< te::rst::BandProperty * > bands, const std::map< std::string, std::string > &rinfo, void *h=0, void(*deleter)(void *)=0)
This method must be implemented by subclasses (raster drivers).
An abstract class for raster data strucutures.
Definition: Raster.h:71
This is the abstract factory for Rasters.
Definition: RasterFactory.h:44
static std::string sg_expansibleRasterFactoryId("EXPANSIBLE")
void getCreationalParameters(std::vector< std::pair< std::string, std::string > > &params) const
It returns the list of parameters accepted as raster info.
A raster (stored in memory and eventually swapped to disk) where it is possible to dynamically add li...
This is the concrete factory for expansible raster.
const std::string & getType() const
Returns the type (name) of this factory.
A rectified grid is the spatial support for raster data.
Definition: Grid.h:68
static ExpansibleRasterFactory * sm_factoryPointer
std::map< std::string, std::string > getCapabilities() const
It returns a map containing all supported formats.
static void finalize()
It finalizes the factory: the singleton instance will be destroyed and will be unregistered from the ...