nidas  v1.2-1520
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 
49 namespace nidas { namespace core {
50 
51 class AsciiSscanfAdapter;
52 class SampleTag;
53 
62 class AsciiSscanf {
63 public:
64 
65  AsciiSscanf();
66 
67  virtual ~AsciiSscanf();
68 
70 
85  void setFormat(const std::string& val) throw(nidas::util::ParseException);
86 
87  const std::string& getFormat() const { return _format; }
88 
89  void setSampleTag(SampleTag* val) { _sampleTag = val; }
90 
91  const SampleTag* getSampleTag() const { return _sampleTag; }
92 
94 
103  int sscanf(const char* input, float* output, int nout) throw();
104 
105  int getNumberOfFields() const { return _fields.size(); }
106 
110  const int MAX_OUTPUT_VALUES;
111 
116  struct FormatField {
118  int size;
119  int length;
120  };
121 
122 private:
123 
129  std::string _format;
130 
135  char* _charfmt;
136 
140  int _lexpos;
141 
146 
150  std::vector<FormatField*> _fields;
151 
156 
160  char* _databuf0;
161 
169  char** _bufptrs;
170 
176 
178 
180  AsciiSscanf(const AsciiSscanf& );
181 
183  AsciiSscanf & operator=(const AsciiSscanf& );
184 
185  friend class AsciiSscanfAdapter;
186 };
187 
188 }} // namespace nidas namespace core
189 
190 #endif
void setSampleTag(SampleTag *val)
Definition: AsciiSscanf.h:89
Definition: AsciiSscanf.h:69
SampleTag * _sampleTag
A scanner may produce dsm samples.
Definition: AsciiSscanf.h:175
void setFormat(const std::string &val)
Set the format to be used to sscanf samples.
Definition: AsciiSscanf.ll:183
std::string _format
scanf format that we scan to count the number and type of % converters.
Definition: AsciiSscanf.h:129
char * _charfmt
Same scanf format, converted to character for quick use by sscanf.
Definition: AsciiSscanf.h:135
virtual ~AsciiSscanf()
Definition: AsciiSscanf.ll:161
Definition: AsciiSscanf.h:69
Definition: AsciiSscanf.h:69
Definition: AsciiSscanf.h:69
Class providing sscanf functionality for parsing ASCII data.
Definition: AsciiSscanf.h:62
SampleTag * getSampleTag()
Definition: AsciiSscanf.h:93
const std::string & getFormat() const
Definition: AsciiSscanf.h:87
int getNumberOfFields() const
Definition: AsciiSscanf.h:105
int sscanf(const char *input, float *output, int nout)
scan input, storing up to nout number of values into output, as floats.
Definition: AsciiSscanf.ll:291
const int MAX_OUTPUT_VALUES
Maximum number of fields that we can scan.
Definition: AsciiSscanf.h:110
AsciiSscanf()
Definition: AsciiSscanf.ll:148
char * _databuf0
A local buffer to store results of sscanf.
Definition: AsciiSscanf.h:160
int _lexpos
Current lexical scanner position.
Definition: AsciiSscanf.h:140
const SampleTag * getSampleTag() const
Definition: AsciiSscanf.h:91
Information we determine from each conversion field in the sscanf format.
Definition: AsciiSscanf.h:116
AsciiSscanfAdapter * _lexer
Definition: AsciiSscanf.h:177
int size
Definition: AsciiSscanf.h:118
bool _allFloats
Are all fields floats?
Definition: AsciiSscanf.h:155
Definition: AsciiSscanf.h:69
std::vector< FormatField * > _fields
Information scanned from each field.
Definition: AsciiSscanf.h:150
Definition: AsciiSscanf.h:69
AsciiSscanf & operator=(const AsciiSscanf &)
No assignment.
Definition: AsciiSscanf.h:69
Definition: AsciiSscanf.h:69
Class describing a group of variables that are sampled and handled together.
Definition: SampleTag.h:87
Definition: AsciiSscanf.h:69
friend class AsciiSscanfAdapter
Definition: AsciiSscanf.h:185
int length
Definition: AsciiSscanf.h:119
char ** _bufptrs
Pointers into the local buffer for each field in the format string.
Definition: AsciiSscanf.h:169
enum fieldtype type
Definition: AsciiSscanf.h:117
Definition: AsciiSscanf.h:69
fieldtype
Definition: AsciiSscanf.h:69
struct FormatField * _currentField
Pointer to current FormatField that we are scanning.
Definition: AsciiSscanf.h:145
Definition: ParseException.h:36