1 //
2 // This file is part of the SDTS++ toolkit, written by the U.S.
3 // Geological Survey.  It is experimental software, written to support
4 // USGS research and cartographic data production.
5 //
6 // SDTS++ is public domain software.  It may be freely copied,
7 // distributed, and modified.  The USGS welcomes user feedback, but makes
8 // no committment to any level of support for this code.  See the SDTS
9 // web site at http://mcmcweb.er.usgs.gov/sdts for more information,
10 // including points of contact.
11 //
12 #ifndef INCLUDED_SIO_8211CONVERTER_H
13 #define INCLUDED_SIO_8211CONVERTER_H
14 
15 
16 #ifndef INCLUDED_SIO_BUFFER_H
17 #include <sdts++/io/sio_Buffer.h>
18 #endif
19 
20 #ifndef INCLUDED_SIO_CONVERTER_H
21 #include <sdts++/io/sio_Converter.h>
22 #endif
23 
24 /**
25    A Converter converts between an SDTS subfield and 'raw' data.
26 
27    \note
28 
29     Niether the fixed or variable make() functions set the subfield
30     mnemonic or the subfield name.
31 
32     \todo XXX consider singleton pattern to access static instances for all supported types
33 
34  */
35 class sio_8211Converter : public sio_Converter
36 {
37    public:
38 
39       ///
sio_8211Converter()40       sio_8211Converter() {}
41 
42       ///
43       virtual ~sio_8211Converter();
44 
45 
46 
47       /// Fixed width subfields
48       /** Returns the length of the data actually converted. This may be
49           different than 'length' if an error occured. */
50       virtual long makeFixedSubfield(sc_Subfield& subfield,
51                                      char const* data,
52                                      long bitLength) const = 0;
53 
54 #ifdef VECTOR_ITERATOR_POINTER_NOT_EQUIVALENT
makeFixedSubfield(sc_Subfield & subfield,std::vector<char>::const_iterator & data,long bitLength)55       long makeFixedSubfield(sc_Subfield& subfield,
56                                      std::vector<char>::const_iterator & data,
57                                      long bitLength) const
58         {
59           return makeFixedSubfield( subfield, &data[0], bitLength );
60         }
61 #endif
62 
63       /// Variable width subfields
64       /** Returns the length of the data converted. This does not__ included
65           the delimiter (if any).*/
66       virtual long makeVarSubfield(sc_Subfield& subfield,
67                                    char const* data,
68                                    long maxLength,
69                                    char delimiter) const;
70 
71 #ifdef VECTOR_ITERATOR_POINTER_NOT_EQUIVALENT
makeVarSubfield(sc_Subfield & subfield,std::vector<char>::const_iterator & data,long maxLength,char delimiter)72       long makeVarSubfield(sc_Subfield& subfield,
73                                    std::vector<char>::const_iterator & data,
74                                    long maxLength,
75                                    char delimiter) const
76         {
77           return makeVarSubfield( subfield, &data[0], maxLength, delimiter );
78         }
79 #endif
80 
81       /// Adds a "null field" (adds an end-of-field character) to the buffer.
82       virtual long addEmptySubfield(sio_Buffer& buffer) const;
83 
84 
85       /// Adds a subfield, encoded in 8211 format, to the buffer
86       virtual long addSubfield(sc_Subfield const& subf,
87                                sio_Buffer& buffer) const = 0;
88 
89       /** Like addSubfield(), but for fixed length subfields.  Will not
90        be implemented for binary fields, obviously.
91       */
92       virtual long addFixedSubfield(sc_Subfield const& subf,
93                                     long length,
94                                     sio_Buffer& buffer) const = 0;
95 
96    protected:
97 
98       /** Determines the length of a variable length subfield in 'data'
99        delimited by 'delimiter'.
100       */
101       long findVariableSubfieldLength(char const* data,
102                                       long maxLength,
103                                       char delimiter) const;
104 
105 }; // sio_8211Converter
106 
107 
108 /// Converter for 8211 'A' data
109 class sio_8211Converter_A : public sio_8211Converter
110 {
111    public:
112 
sio_8211Converter_A()113       sio_8211Converter_A() {}
114 
115       long makeFixedSubfield(sc_Subfield& subfield,
116                              char const* data,
117                              long length) const;
118 
119       long addSubfield(sc_Subfield const& subf,
120                        sio_Buffer& buffer) const;
121 
122       long addFixedSubfield(sc_Subfield const& subf,
123                             long length,
124                             sio_Buffer& buffer) const;
125 }; // sio_8211DConverter_A
126 
127 
128 
129 /// Converter for 8211 'I' data
130 class sio_8211Converter_I : public sio_8211Converter
131 {
132    public:
133 
sio_8211Converter_I()134       sio_8211Converter_I() {}
135 
136       long makeFixedSubfield(sc_Subfield& subfield,
137                              char const* data,
138                              long length) const;
139 
140       long addSubfield(sc_Subfield const& subf,
141                        sio_Buffer& buffer) const;
142 
143       long addFixedSubfield(sc_Subfield const& subf,
144                             long length,
145                             sio_Buffer& buffer) const;
146 }; // class sio_8211Converter_I
147 
148 
149 
150 /// Converter for 8211 'R' data
151 class sio_8211Converter_R : public sio_8211Converter
152 {
153    public:
154 
sio_8211Converter_R()155       sio_8211Converter_R() {}
156 
157       long makeFixedSubfield(sc_Subfield& subfield,
158                              char const* data,
159                              long length) const;
160 
161       long addSubfield(sc_Subfield const& subf,
162                        sio_Buffer& buffer) const;
163 
164       long addFixedSubfield(sc_Subfield const& subf,
165                             long length,
166                             sio_Buffer& buffer) const;
167 }; // class sio_8211Converter_R
168 
169 
170 
171 // Converter for 8211 'S' data
172 class sio_8211Converter_S : public sio_8211Converter
173 {
174    public:
175 
sio_8211Converter_S()176       sio_8211Converter_S() {}
177 
178       long makeFixedSubfield(sc_Subfield& subfield,
179                              char const* data,
180                              long length) const;
181 
182       long addSubfield(sc_Subfield const& subf,
183                        sio_Buffer& buffer) const;
184 
185       long addFixedSubfield(sc_Subfield const& subf,
186                             long length,
187                             sio_Buffer& buffer) const;
188 
189 }; // class sio_8211Converter_S
190 
191 
192 
193 /// Converter for 8111 'C' data
194 class sio_8211Converter_C : public sio_8211Converter
195 {
196    public:
197 
sio_8211Converter_C()198       sio_8211Converter_C() {}
199 
200       long makeFixedSubfield(sc_Subfield& subfield,
201                              char const* data,
202                              long length) const;
203 
204       long addSubfield(sc_Subfield const& subf,
205                        sio_Buffer& buffer) const;
206 
207       long addFixedSubfield(sc_Subfield const& subf,
208                             long length,
209                             sio_Buffer& buffer) const;
210 
211 }; // class sio_8211Converter_C
212 
213 
214 
215 /// Converter for 8211 eight bit signed integer data
216 class sio_8211Converter_BI8 : public sio_8211Converter
217 {
218    public:
sio_8211Converter_BI8()219       sio_8211Converter_BI8() {}
220 
221       long makeFixedSubfield(sc_Subfield& subfield,
222                              char const* data,
223                              long bitLength) const;
224 
225       long addSubfield(sc_Subfield const& subfield,
226                        sio_Buffer& buffer) const;
227 
addFixedSubfield(sc_Subfield const & subf,long length,sio_Buffer & buffer)228       long addFixedSubfield(sc_Subfield const& subf,
229                             long length,
230                             sio_Buffer& buffer) const
231       { return addSubfield( subf, buffer ); }
232 
233 }; // class sio_8211Converter_BI8
234 
235 
236 
237 /// Converter for 8211 sixteen bit signed integers
238 class sio_8211Converter_BI16 : public sio_8211Converter
239 {
240    public:
sio_8211Converter_BI16()241       sio_8211Converter_BI16() {}
242 
243       long makeFixedSubfield(sc_Subfield& subfield,
244                              char const* data,
245                              long bitLength) const;
246 
247       long addSubfield(sc_Subfield const& subfield,
248                        sio_Buffer& buffer) const;
249 
addFixedSubfield(sc_Subfield const & subf,long length,sio_Buffer & buffer)250       long addFixedSubfield(sc_Subfield const& subf,
251                             long length,
252                             sio_Buffer& buffer) const
253       { return addSubfield( subf, buffer ); }
254 
255 }; // class sio_8211Converter_BI16
256 
257 
258 
259 /// Converter for 8211 24 bit signed integers
260 class sio_8211Converter_BI24 : public sio_8211Converter
261 {
262    public:
sio_8211Converter_BI24()263       sio_8211Converter_BI24() {}
264 
265       long makeFixedSubfield(sc_Subfield& subfield,
266                              char const* data,
267                              long bitLength) const;
268 
269       long addSubfield(sc_Subfield const& subfield,
270                        sio_Buffer& buffer) const;
271 
addFixedSubfield(sc_Subfield const & subf,long length,sio_Buffer & buffer)272       long addFixedSubfield(sc_Subfield const& subf,
273                             long length,
274                             sio_Buffer& buffer) const
275       { return addSubfield( subf, buffer ); }
276 
277 }; // class sio_8211Converter_BI24
278 
279 
280 
281 /// Converter for 32 bit signed integers
282 class sio_8211Converter_BI32 : public sio_8211Converter
283 {
284    public:
sio_8211Converter_BI32()285       sio_8211Converter_BI32() {}
286 
287       long makeFixedSubfield(sc_Subfield& subfield,
288                              char const* data,
289                              long bitLength) const;
290 
291       long addSubfield(sc_Subfield const& subfield,
292                        sio_Buffer& buffer) const;
293 
addFixedSubfield(sc_Subfield const & subf,long length,sio_Buffer & buffer)294       long addFixedSubfield(sc_Subfield const& subf,
295                             long length,
296                             sio_Buffer& buffer) const
297       { return addSubfield( subf, buffer ); }
298 
299 }; // class sio_8211Converter_BI32
300 
301 
302 
303 /// Converter for eight bit unsigned integers
304 class sio_8211Converter_BUI8 : public sio_8211Converter
305 {
306    public:
sio_8211Converter_BUI8()307       sio_8211Converter_BUI8() {}
308 
309       long makeFixedSubfield(sc_Subfield& subfield,
310                              char const* data,
311                              long bitLength) const;
312 
313       long addSubfield(sc_Subfield const& subfield,
314                        sio_Buffer& buffer) const;
315 
addFixedSubfield(sc_Subfield const & subf,long length,sio_Buffer & buffer)316       long addFixedSubfield(sc_Subfield const& subf,
317                             long length,
318                             sio_Buffer& buffer) const
319       { return addSubfield( subf, buffer ); }
320 
321 }; // class sio_8211Converter_BUI8
322 
323 
324 
325 /// Converter for sixteen bit unsigned integers
326 class sio_8211Converter_BUI16 : public sio_8211Converter
327 {
328    public:
sio_8211Converter_BUI16()329       sio_8211Converter_BUI16() {}
330 
331       long makeFixedSubfield(sc_Subfield& subfield,
332                              char const* data,
333                              long bitLength) const;
334 
335       long addSubfield(sc_Subfield const& subfield,
336                        sio_Buffer& buffer) const;
337 
addFixedSubfield(sc_Subfield const & subf,long length,sio_Buffer & buffer)338       long addFixedSubfield(sc_Subfield const& subf,
339                             long length,
340                             sio_Buffer& buffer) const
341       { return addSubfield( subf, buffer ); }
342 
343 }; // class sio_8211Converter_BUI16
344 
345 
346 
347 /// Converter for 24 bit unsigned integers
348 class sio_8211Converter_BUI24 : public sio_8211Converter
349 {
350    public:
sio_8211Converter_BUI24()351       sio_8211Converter_BUI24() {}
352 
353       long makeFixedSubfield(sc_Subfield& subfield,
354                              char const* data,
355                              long bitLength) const;
356 
357       long addSubfield(sc_Subfield const& subfield,
358                        sio_Buffer& buffer) const;
359 
addFixedSubfield(sc_Subfield const & subf,long length,sio_Buffer & buffer)360       long addFixedSubfield(sc_Subfield const& subf,
361                             long length,
362                             sio_Buffer& buffer) const
363       { return addSubfield( subf, buffer ); }
364 
365 }; // class sio_8211Converter_BUI24
366 
367 
368 
369 /// Converter for 32 bit unsigned integers
370 class sio_8211Converter_BUI32 : public sio_8211Converter
371 {
372    public:
sio_8211Converter_BUI32()373       sio_8211Converter_BUI32() {}
374 
375       long makeFixedSubfield(sc_Subfield& subfield,
376                              char const* data,
377                              long bitLength) const;
378 
379       long addSubfield(sc_Subfield const& subfield,
380                        sio_Buffer& buffer) const;
381 
addFixedSubfield(sc_Subfield const & subf,long length,sio_Buffer & buffer)382       long addFixedSubfield(sc_Subfield const& subf,
383                             long length,
384                             sio_Buffer& buffer) const
385       { return addSubfield( subf, buffer ); }
386 
387 }; // class sio_8211Converter_BUI32
388 
389 
390 /// Converter for 32 bit floating point numbers
391 class sio_8211Converter_BFP32 : public sio_8211Converter
392 {
393    public:
sio_8211Converter_BFP32()394       sio_8211Converter_BFP32() {}
395 
396       long makeFixedSubfield(sc_Subfield& subfield,
397                              char const* data,
398                              long bitLength) const;
399 
400       long addSubfield(sc_Subfield const& subfield,
401                        sio_Buffer& buffer) const;
402 
addFixedSubfield(sc_Subfield const & subf,long length,sio_Buffer & buffer)403       long addFixedSubfield(sc_Subfield const& subf,
404                             long length,
405                             sio_Buffer& buffer) const
406       { return addSubfield( subf, buffer ); }
407 
408 }; // class sio_8211Converter_BFP32
409 
410 
411 /// Converter for 64 bit floating point numbers
412 class sio_8211Converter_BFP64 : public sio_8211Converter
413 {
414    public:
sio_8211Converter_BFP64()415       sio_8211Converter_BFP64() {}
416 
417       long makeFixedSubfield(sc_Subfield& subfield,
418                              char const* data,
419                              long bitLength) const;
420 
421       long addSubfield(sc_Subfield const& subfield,
422                        sio_Buffer& buffer) const;
423 
addFixedSubfield(sc_Subfield const & subf,long length,sio_Buffer & buffer)424       long addFixedSubfield(sc_Subfield const& subf,
425                             long length,
426                             sio_Buffer& buffer) const
427       { return addSubfield( subf, buffer ); }
428 
429 }; // class sio_8211Converter_BFP64
430 
431 #endif
432