nidas v1.2.3
SampleInputHeader.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 ** 2005, 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_SAMPLEFILEHEADER_H
28#define NIDAS_CORE_SAMPLEFILEHEADER_H
29
30#include "IOStream.h"
31#include "SampleOutput.h"
33
34namespace nidas { namespace core {
35
37{
38public:
39
41
47
53
55
63 void read(IOStream* iostream);
64
74 bool parse(IOStream* iostream);
75
79 int getLength() const { return _size; }
80
84 std::string toString() const;
85
89 size_t write(SampleOutput* output) const;
90
94 size_t write(IOStream* iostream) const;
95
96 void setArchiveVersion(const std::string& val) { _archiveVersion = val; }
97 const std::string& getArchiveVersion() const { return _archiveVersion; }
98
99 void setSoftwareVersion(const std::string& val) { _softwareVersion = val; }
100 const std::string& getSoftwareVersion() const { return _softwareVersion; }
101
102 void setProjectName(const std::string& val) { _projectName = val; }
103 const std::string& getProjectName() const { return _projectName; }
104
105 void setSystemName(const std::string& val) { _systemName = val; }
106 const std::string& getSystemName() const { return _systemName; }
107
108 void setConfigName(const std::string& val) { _configName = val; }
109 const std::string& getConfigName() const { return _configName; }
110
111 void setConfigVersion(const std::string& val) { _configVersion = val; }
112 const std::string& getConfigVersion() const { return _configVersion; }
113
114protected:
115
119 bool parseMagic(IOStream* iostream);
120
124 bool parseTag(IOStream* iostream);
125
129 bool parseValue(IOStream* iostream);
130
131private:
132
133 // Set method that does nothing.
134 void setDummyString(const std::string&) { }
135
136 const std::string& getDummyString() const { return _dummy; }
137
138 struct headerField {
139
140 /* a tag in the file header */
141 const char* tag;
142
144
145 /* ptr to setXXX member function for setting an attribute of this
146 * class, based on the value of the tag from the IOStream.
147 */
148 void (SampleInputHeader::* setFunc)(const std::string&);
149
150 /* ptr to getXXX member function for getting an attribute of this
151 * class, in order to write the value of the tag to the IOStream.
152 */
153 const std::string& (SampleInputHeader::* getFunc)() const;
154
156
157 };
158
159 static const struct headerField headers[];
160
161 std::string _archiveVersion;
162
163 std::string _softwareVersion;
164
165 std::string _projectName;
166
167 std::string _systemName;
168
169 std::string _configName;
170
171 std::string _configVersion;
172
173 std::string _dummy;
174
182 static const char* magicStrings[];
183
184 static const int _nmagic;
185
187
189
190 static const int _ntags;
191
193
195
201 int _size;
202
203 static const int HEADER_BUF_LEN;
204
205 char* _buf;
206
207 char* _headPtr;
208
210
211};
212
213}} // namespace nidas namespace core
214
215#endif
A base class for buffering data.
Definition IOStream.h:41
Definition SampleInputHeader.h:37
SampleInputHeader & operator=(const SampleInputHeader &)
Assignment operator.
Definition SampleInputHeader.cc:124
SampleInputHeader()
Definition SampleInputHeader.cc:82
int getLength() const
Get length in bytes of the header.
Definition SampleInputHeader.h:79
int _endTag
Definition SampleInputHeader.h:192
std::string _systemName
Definition SampleInputHeader.h:167
const std::string & getConfigName() const
Definition SampleInputHeader.h:109
static const int HEADER_BUF_LEN
Definition SampleInputHeader.h:203
void setSystemName(const std::string &val)
Definition SampleInputHeader.h:105
static const int _ntags
Definition SampleInputHeader.h:190
std::string toString() const
Render the header in string form.
Definition SampleInputHeader.cc:331
void setProjectName(const std::string &val)
Definition SampleInputHeader.h:102
const std::string & getDummyString() const
Definition SampleInputHeader.h:136
void setConfigName(const std::string &val)
Definition SampleInputHeader.h:108
parseStage
Definition SampleInputHeader.h:209
@ PARSE_VALUE
Definition SampleInputHeader.h:209
@ PARSE_TAG
Definition SampleInputHeader.h:209
@ PARSE_START
Definition SampleInputHeader.h:209
@ PARSE_MAGIC
Definition SampleInputHeader.h:209
@ PARSE_DONE
Definition SampleInputHeader.h:209
void setDummyString(const std::string &)
Definition SampleInputHeader.h:134
const std::string & getConfigVersion() const
Definition SampleInputHeader.h:112
std::string _softwareVersion
Definition SampleInputHeader.h:163
std::string _archiveVersion
Definition SampleInputHeader.h:161
bool parseValue(IOStream *iostream)
Definition SampleInputHeader.cc:297
static const int _nmagic
Definition SampleInputHeader.h:184
bool parse(IOStream *iostream)
Parse the current contents of the IOStream for the SampleInputHeader.
Definition SampleInputHeader.cc:154
void read(IOStream *iostream)
Read IOStream until the SampleInputHeader has been fully read.
Definition SampleInputHeader.cc:180
void setConfigVersion(const std::string &val)
Definition SampleInputHeader.h:111
std::string _dummy
Definition SampleInputHeader.h:173
char * _buf
Definition SampleInputHeader.h:205
bool parseTag(IOStream *iostream)
Definition SampleInputHeader.cc:240
const std::string & getProjectName() const
Definition SampleInputHeader.h:103
static const struct headerField headers[]
Definition SampleInputHeader.h:159
void setArchiveVersion(const std::string &val)
Definition SampleInputHeader.h:96
static const char * magicStrings[]
Strings that can occur as the magic value at the beginning of a sample file.
Definition SampleInputHeader.h:182
const std::string & getArchiveVersion() const
Definition SampleInputHeader.h:97
void setSoftwareVersion(const std::string &val)
Definition SampleInputHeader.h:99
int _imagic
Definition SampleInputHeader.h:188
const std::string & getSoftwareVersion() const
Definition SampleInputHeader.h:100
int _tagMatch
Definition SampleInputHeader.h:194
int _size
Size in bytes of the header.
Definition SampleInputHeader.h:201
enum nidas::core::SampleInputHeader::parseStage _stage
std::string _configName
Definition SampleInputHeader.h:169
bool parseMagic(IOStream *iostream)
Definition SampleInputHeader.cc:195
int _minMagicLen
Definition SampleInputHeader.h:186
char * _headPtr
Definition SampleInputHeader.h:207
std::string _configVersion
Definition SampleInputHeader.h:171
std::string _projectName
Definition SampleInputHeader.h:165
const std::string & getSystemName() const
Definition SampleInputHeader.h:106
size_t write(SampleOutput *output) const
Definition SampleInputHeader.cc:357
~SampleInputHeader()
Definition SampleInputHeader.cc:146
Interface of an output stream of samples.
Definition SampleOutput.h:49
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
Definition SampleInputHeader.h:138
void(SampleInputHeader::* setFunc)(const std::string &)
Definition SampleInputHeader.h:148
int taglen
Definition SampleInputHeader.h:143
bool obsolete
Definition SampleInputHeader.h:155
const std::string &(SampleInputHeader::* getFunc)() const
Definition SampleInputHeader.h:153
const char * tag
Definition SampleInputHeader.h:141