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 "../core/translator/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 
46 {
48 }
49 
50 void te::mem::ExpansibleRasterFactory::getCreationalParameters(std::vector< std::pair<std::string, std::string> >& params) const
51 {
52  params.push_back(std::pair<std::string, std::string>("MAXMEMPERCENTUSED", "40"));
53  params.push_back(std::pair<std::string, std::string>("MAXNUMBEROFRAMBLOCKS", "1"));
54 }
55 
58 {
59 }
60 
62  const std::vector<te::rst::BandProperty*> bands,
63  const std::map<std::string, std::string>& rinfo,
64  void* h, //NOLINT
65  void (*deleter)(void*)) //NOLINT
66 {
67  std::unique_ptr<te::rst::Raster> rasterPtr;
68 
69  if( rinfo.find( "MAXNUMBEROFRAMBLOCKS" ) != rinfo.end() )
70  {
71  unsigned int maxNumberOfRAMBlocks = boost::lexical_cast< unsigned int >( rinfo.find( "MAXNUMBEROFRAMBLOCKS" )->second );
72  rasterPtr.reset( new ExpansibleRaster( g, bands, maxNumberOfRAMBlocks ) );
73  }
74  else if( rinfo.find( "MAXMEMPERCENTUSED" ) != rinfo.end() )
75  {
76  unsigned int maxMemPercentUsed = boost::lexical_cast< unsigned int>( rinfo.find( "MAXMEMPERCENTUSED" )->second );
77  if( maxMemPercentUsed > 100 )
78  {
79  throw Exception(TE_TR("Invalid parameter: MAXMEMPERCENTUSED") );
80  }
81 
82  rasterPtr.reset( new ExpansibleRaster( (unsigned char)maxMemPercentUsed, g, bands ) );
83  }
84  else
85  {
86  rasterPtr.reset( new ExpansibleRaster( 40, g, bands ) );
87  }
88 
89  return rasterPtr.release();
90 }
91 
93 {
94  return new ExpansibleRaster;
95 }
96 
97 std::map<std::string, std::string> te::mem::ExpansibleRasterFactory::getCapabilities() const
98 {
99  return std::map<std::string, std::string>();
100 }
101 
103 {
104  finalize();
106 }
107 
109 {
110  delete sm_factoryPointer;
111  sm_factoryPointer = nullptr;
112 }
A raster (stored in memory and eventually swapped to disk) where it is possible to dynamically add li...
Base exception class for plugin module.
An exception class for the TerraLib In-Memory Data Access driver.
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:242
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.
This is the abstract factory for Rasters.
URI C++ Library.
Definition: Attributes.h:37
list bands
Definition: compose.py:2
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: raster/Grid.h:68
static ExpansibleRasterFactory * sm_factoryPointer
std::map< std::string, std::string > getCapabilities() const
It returns a map<string, string> containing all supported formats.
static void finalize()
It finalizes the factory: the singleton instance will be destroyed and will be unregistered from the ...