rasdaman API
convertor.hh
Go to the documentation of this file.
1 /*
2 * This file is part of rasdaman community.
3 *
4 * Rasdaman community is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * Rasdaman community is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with rasdaman community. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
18 rasdaman GmbH.
19 *
20 * For more information please see <http://www.rasdaman.org>
21 * or contact Peter Baumann via <baumann@rasdaman.com>.
22 /
36 #ifndef _R_CONVERTOR_
37 #define _R_CONVERTOR_
38 
39 #include <stdlib.h>
40 
41 #include "raslib/error.hh"
42 #include "raslib/minterval.hh"
43 #include "raslib/type.hh"
44 #include "raslib/mddtypes.hh"
45 #include "raslib/storageman.hh"
46 //#include "conversion/memfs.h"
47 
48 
49 
50 // Declare to avoid including memfs.h (and with that tiffio.h)
51 struct memFSContext;
52 
53 class r_Parse_Params;
54 
55 
56 typedef struct r_convDesc
57 {
58  const char *src; // pointer to source data
59  char *dest; // pointer to destination data
60  r_Minterval srcInterv; // dimensions of source data
61  r_Minterval destInterv; // dimensions of destination data
62  int baseType; // shortcut to src basetype
63  const r_Type *srcType; // basetypes of src data
64  r_Type *destType; // basetypes of dest data
65 } r_convDesc;
66 
67 
68 
69 //@ManMemo: Module {\bf conversion}
70 
71 
72 /*@Doc:
73  Conversion classes from and to data exchange formats. Can also be used for
74  tile compression of special MDD types (= images)
75 
76  \begin{itemize}
77  \item
78  the member function convertTo() performs the conversion MDD -> DEF
79  \item
80  the member function convertFrom() performs the conversion DEF -> MDD
81  \item
82  the r_convDesc reference returned from this call is only valid while
83  the convertor object is.
84  \item
85  after successful execution the returned r_convDesc structure contains
86  the following information:
87  \begin{itemize}
88  \item
89  dest: pointer to converted data, allocated by the configured heap
90  storage object which will use malloc() by default (see
91  set_storage_handler()); must be deallocated by the caller.
92  \item
93  destInterv: r_Minterval describing the converted object's domain.
94  \item
95  destType: pointer to an r_Type object describing the converted
96  object's type; must be deallocated by the caller.
97  \end{itemize}
98  \item
99  on failure an exception is thrown.
100  \end{itemize}
101 
102  The member function convertTo() receives a parameter string as argument
103  which is NULL for default parameters. The format of the string is such
104  that it can be parsed by r_Parse_Params. The params member variable is
105  initialized to NULL in this class. Derived classes that wish to add
106  parameters must first check whether params is NULL and create a new
107  object if so, then add their parameters. This makes it possible to
108  accumulate parameters over all class hierarchies.
109 */
110 
112 {
113 public:
115  r_Convertor( void );
117  r_Convertor( const char *src, const r_Minterval &interv, const r_Type *tp,
118  bool fullTypes=false) throw(r_Error);
120  r_Convertor( const char *src, const r_Minterval &interv, int type ) throw(r_Error);
146  virtual ~r_Convertor( void );
148 
149  //@Man: Interface
151  virtual r_convDesc &convertTo( const char *options=NULL ) throw(r_Error) = 0;
152 
154  virtual r_convDesc &convertFrom( const char *options=NULL ) throw(r_Error) = 0;
155 
157  virtual r_Convertor *clone( void ) const = 0;
158 
160  virtual const char *get_name( void ) const = 0;
161  virtual r_Data_Format get_data_format( void ) const = 0;
162 
164  void set_storage_handler( const r_Storage_Man &newStore );
165 
167  const r_Storage_Man& get_storage_handler( ) const;
168 
169 
172  {
173  // undefined type
175  // Shortcut for the three important base types r_Boolean, r_Char and RGBPixel
179  // More generic types for HDF
190  // shortcut for structures
192  };
193 
195  typedef struct convert_string_s
196  {
197  const char *key;
198  int id;
201 
203  static std::string type_to_string( int ctype ) throw(r_Error);
204 
206  static r_Type *get_external_type( int ctype ) throw(r_Error);
207 
209  static convert_type_e get_internal_type( const r_Type* type, bool fullTypes=false ) throw(r_Error);
210 
211 protected:
213  void initShare( const char *src, const r_Minterval &interv );
214 
217 
219  template <class baseType>
220  void applyColorScheme();
221 
224 
227 
230 };
231 
233 std::ostream& operator<<(std::ostream& os, r_Convertor::convert_type_e& cte);
234 
235 /*@Doc:
236  Abstract base class for all memory-to-memory conversion classes,
237  uses memfs for of data with unknown size at the time of creation.
238 */
239 
241 {
242 public:
244  r_Convert_Memory( const char *src, const r_Minterval &interv, const r_Type *tp,
245  int fullTypes=0) throw(r_Error);
247  r_Convert_Memory( const char *src, const r_Minterval &interv, int type ) throw(r_Error);
249  virtual ~r_Convert_Memory( void );
250 
251 
252 protected:
254  void initMemory( void ) throw(r_Error);
255 
258  void *handle;
259 };
260 
261 #endif
r_convDesc desc
conversion context
Definition: convertor.hh:223
void applyColorScheme()
convert unsupported type to rgb by applying the default color scheme
Definition: convertor.hh:178
Definition: convertor.hh:182
Definition: error.hh:88
Definition: type.hh:56
virtual r_convDesc & convertFrom(const char *options=NULL)=0
convert DEF to array
Definition: convertor.hh:185
Definition: storageman.hh:56
static std::string type_to_string(int ctype)
get a string representation of the internal type
void * handle
Definition: convertor.hh:258
r_Storage_Man mystore
storage manager
Definition: convertor.hh:229
static convert_type_e get_internal_type(const r_Type *type, bool fullTypes=false)
get a internal type from a r_Type
Definition: convertor.hh:174
virtual ~r_Convertor(void)
destructor
memFSContext * memFS
variables
Definition: convertor.hh:257
Definition: convertor.hh:111
virtual r_convDesc & convertTo(const char *options=NULL)=0
convert array to DEF
Definition: convertor.hh:189
Definition: convertor.hh:195
Definition: convertor.hh:177
bool destroySrc
true if we should free the src area (in case the input was converted to rgb)
Definition: convertor.hh:216
Definition: convertor.hh:188
r_Data_Format
Definition: mddtypes.hh:133
virtual r_Data_Format get_data_format(void) const =0
virtual r_Convertor * clone(void) const =0
cloning
Definition: convertor.hh:186
Definition: convertor.hh:183
Definition: parseparams.hh:44
r_Parse_Params * params
parameter parser
Definition: convertor.hh:226
Definition: convertor.hh:180
Definition: convertor.hh:181
Definition: convertor.hh:187
r_Convertor(void)
default constructor (should not be used)
static r_Type * get_external_type(int ctype)
get a r_Type from an internal type
int id
Definition: convertor.hh:198
Definition: convertor.hh:240
convert_type_e
base type shortcuts
Definition: convertor.hh:171
Definition: memfs.h:48
virtual const char * get_name(void) const =0
identification
Definition: convertor.hh:191
Definition: convertor.hh:176
Definition: convertor.hh:56
const r_Storage_Man & get_storage_handler() const
get storage handler, default is malloc/free
void initShare(const char *src, const r_Minterval &interv)
initialize internal structures
struct r_Convertor::convert_string_s convert_string_t
Definition: convertor.hh:184
Definition: minterval.hh:249
void set_storage_handler(const r_Storage_Man &newStore)
set storage handler, default is malloc/free
const char * key
Definition: convertor.hh:197