nidas v1.2.3
AsciiSscanf.h
Go to the documentation of this file.
1// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 4; -*-
2// vim: set shiftwidth=4 softtabstop=4 expandtab:
3/*
4 ********************************************************************
5 ** NIDAS: NCAR In-situ Data Acquistion Software
6 **
7 ** 2004, Copyright University Corporation for Atmospheric Research
8 **
9 ** This program is free software; you can redistribute it and/or modify
10 ** it under the terms of the GNU General Public License as published by
11 ** the Free Software Foundation; either version 2 of the License, or
12 ** (at your option) any later version.
13 **
14 ** This program is distributed in the hope that it will be useful,
15 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ** GNU General Public License for more details.
18 **
19 ** The LICENSE.txt file accompanying this software contains
20 ** a copy of the GNU General Public License. If it is not found,
21 ** write to the Free Software Foundation, Inc.,
22 ** 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 **
24 ********************************************************************
25*/
26
27#ifndef NIDAS_CORE_ASCIISSCANF_H
28#define NIDAS_CORE_ASCIISSCANF_H
29
30/*
31 * flex reads AsciiSscanf.ll and creates AsciiSscanf.cc, and that contains
32 * the implementation for three classes: the public class AsciiSscanf
33 * defined in this header, the private lexer implementation class
34 * SscanfFlexLexer, and a subclass of SscanfFlexLexer called
35 * AsciiSscanfAdapter. The public class refers to the adapter class only
36 * by pointer, so the flex implementation does not need to be exposed in
37 * this public header file. The AsciiSscanfAdapter class extends
38 * SscanfFlexLexer to tie the flex implementation into the AsciiSscanf
39 * class. The friend declaration allows the adapter to manipulate private
40 * members of the AsciiSscanf class during parsing.
41 */
42
43
44#include "Sample.h"
46
47#include <vector>
48
49namespace nidas { namespace core {
50
51class AsciiSscanfAdapter;
52class SampleTag;
53
63public:
64
66
67 virtual ~AsciiSscanf();
68
70
87 void setFormat(const std::string& val);
88
89 const std::string& getFormat() const { return _format; }
90
92
93 const SampleTag* getSampleTag() const { return _sampleTag; }
94
96
105 int sscanf(const char* input, float* output, int nout) throw();
106
107 int getNumberOfFields() const { return _fields.size(); }
108
113
118 struct FormatField {
120 int size;
122 };
123
124private:
125
131 std::string _format;
132
137 char* _charfmt;
138
143
148
152 std::vector<FormatField*> _fields;
153
158
163
171 char** _bufptrs;
172
178
180
183
186
187 friend class AsciiSscanfAdapter;
188};
189
190}} // namespace nidas namespace core
191
192#endif
Class providing sscanf functionality for parsing ASCII data.
Definition AsciiSscanf.h:62
char ** _bufptrs
Pointers into the local buffer for each field in the format string.
Definition AsciiSscanf.h:171
AsciiSscanf & operator=(const AsciiSscanf &)
No assignment.
bool _allFloats
Are all fields floats?
Definition AsciiSscanf.h:157
std::vector< FormatField * > _fields
Information scanned from each field.
Definition AsciiSscanf.h:152
int sscanf(const char *input, float *output, int nout)
scan input, storing up to nout number of values into output, as floats.
const SampleTag * getSampleTag() const
Definition AsciiSscanf.h:93
std::string _format
scanf format that we scan to count the number and type of % converters.
Definition AsciiSscanf.h:131
SampleTag * _sampleTag
A scanner may produce dsm samples.
Definition AsciiSscanf.h:177
friend class AsciiSscanfAdapter
Definition AsciiSscanf.h:187
AsciiSscanf(const AsciiSscanf &)
No copying.
int _lexpos
Current lexical scanner position.
Definition AsciiSscanf.h:142
struct FormatField * _currentField
Pointer to current FormatField that we are scanning.
Definition AsciiSscanf.h:147
char * _charfmt
Same scanf format, converted to character for quick use by sscanf.
Definition AsciiSscanf.h:137
char * _databuf0
A local buffer to store results of sscanf.
Definition AsciiSscanf.h:162
SampleTag * getSampleTag()
Definition AsciiSscanf.h:95
void setSampleTag(SampleTag *val)
Definition AsciiSscanf.h:91
int getNumberOfFields() const
Definition AsciiSscanf.h:107
void setFormat(const std::string &val)
Set the format to be used to sscanf samples.
AsciiSscanfAdapter * _lexer
Definition AsciiSscanf.h:179
const std::string & getFormat() const
Definition AsciiSscanf.h:89
const int MAX_OUTPUT_VALUES
Maximum number of fields that we can scan.
Definition AsciiSscanf.h:112
fieldtype
Definition AsciiSscanf.h:69
@ USHORT
Definition AsciiSscanf.h:69
@ SHORT
Definition AsciiSscanf.h:69
@ FLOAT
Definition AsciiSscanf.h:69
@ UNKNOWN
Definition AsciiSscanf.h:69
@ ULONG
Definition AsciiSscanf.h:69
@ LONG
Definition AsciiSscanf.h:69
@ INT
Definition AsciiSscanf.h:69
@ DOUBLE
Definition AsciiSscanf.h:69
@ UINT
Definition AsciiSscanf.h:69
@ CHAR
Definition AsciiSscanf.h:69
Class describing a group of variables that are sampled and handled together.
Definition SampleTag.h:88
Sample * getSample(sampleType type, unsigned int len)
A convienence method for getting a sample of an enumerated type from a pool.
Definition Sample.cc:70
Root namespace for the NCAR In-Situ Data Acquisition Software.
Definition A2DConverter.h:31
Information we determine from each conversion field in the sscanf format.
Definition AsciiSscanf.h:118
enum fieldtype type
Definition AsciiSscanf.h:119
int size
Definition AsciiSscanf.h:120
int length
Definition AsciiSscanf.h:121