nidas  v1.2-1520
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 
34 namespace nidas { namespace core {
35 
37 {
38 public:
39 
41 
47 
53 
55 
61  void read(IOStream* iostream) throw(nidas::util::IOException);
62 
70  bool parse(IOStream* iostream) throw(nidas::util::ParseException);
71 
75  int getLength() const { return _size; }
76 
80  std::string toString() const;
81 
82  size_t write(SampleOutput* output) const throw(nidas::util::IOException);
83 
84  size_t write(IOStream* iostream) const throw(nidas::util::IOException);
85 
86  void setArchiveVersion(const std::string& val) { _archiveVersion = val; }
87  const std::string& getArchiveVersion() const { return _archiveVersion; }
88 
89  void setSoftwareVersion(const std::string& val) { _softwareVersion = val; }
90  const std::string& getSoftwareVersion() const { return _softwareVersion; }
91 
92  void setProjectName(const std::string& val) { _projectName = val; }
93  const std::string& getProjectName() const { return _projectName; }
94 
95  void setSystemName(const std::string& val) { _systemName = val; }
96  const std::string& getSystemName() const { return _systemName; }
97 
98  void setConfigName(const std::string& val) { _configName = val; }
99  const std::string& getConfigName() const { return _configName; }
100 
101  void setConfigVersion(const std::string& val) { _configVersion = val; }
102  const std::string& getConfigVersion() const { return _configVersion; }
103 
104 protected:
105 
106  bool parseMagic(IOStream* iostream) throw(nidas::util::ParseException);
107 
108  bool parseTag(IOStream* iostream) throw(nidas::util::ParseException);
109 
110  bool parseValue(IOStream* iostream) throw(nidas::util::ParseException);
111 
112 private:
113 
114  // Set method that does nothing.
115  void setDummyString(const std::string&) { }
116 
117  const std::string& getDummyString() const { return _dummy; }
118 
119  struct headerField {
120 
121  /* a tag in the file header */
122  const char* tag;
123 
124  int taglen;
125 
126  /* ptr to setXXX member function for setting an attribute of this
127  * class, based on the value of the tag from the IOStream.
128  */
129  void (SampleInputHeader::* setFunc)(const std::string&);
130 
131  /* ptr to getXXX member function for getting an attribute of this
132  * class, in order to write the value of the tag to the IOStream.
133  */
134  const std::string& (SampleInputHeader::* getFunc)() const;
135 
136  bool obsolete;
137 
138  };
139 
140  static const struct headerField headers[];
141 
142  std::string _archiveVersion;
143 
144  std::string _softwareVersion;
145 
146  std::string _projectName;
147 
148  std::string _systemName;
149 
150  std::string _configName;
151 
152  std::string _configVersion;
153 
154  std::string _dummy;
155 
163  static const char* magicStrings[];
164 
165  static const int _nmagic;
166 
168 
169  int _imagic;
170 
171  static const int _ntags;
172 
173  int _endTag;
174 
176 
182  int _size;
183 
184  static const int HEADER_BUF_LEN;
185 
186  char* _buf;
187 
188  char* _headPtr;
189 
191 
192 };
193 
194 }} // namespace nidas namespace core
195 
196 #endif
int getLength() const
Get length in bytes of the header.
Definition: SampleInputHeader.h:75
A base class for buffering data.
Definition: IOStream.h:41
SampleInputHeader & operator=(const SampleInputHeader &)
Assignment operator.
Definition: SampleInputHeader.cc:124
const std::string & getSoftwareVersion() const
Definition: SampleInputHeader.h:90
void(SampleInputHeader::* setFunc)(const std::string &)
Definition: SampleInputHeader.h:129
Definition: SampleInputHeader.h:190
static const int _nmagic
Definition: SampleInputHeader.h:165
Definition: SampleInputHeader.h:119
bool parseMagic(IOStream *iostream)
Definition: SampleInputHeader.cc:197
void setConfigVersion(const std::string &val)
Definition: SampleInputHeader.h:101
int _size
Size in bytes of the header.
Definition: SampleInputHeader.h:182
std::string _dummy
Definition: SampleInputHeader.h:154
Interface of an output stream of samples.
Definition: SampleOutput.h:47
size_t write(SampleOutput *output) const
Definition: SampleInputHeader.cc:362
std::string _softwareVersion
Definition: SampleInputHeader.h:144
const char * tag
Definition: SampleInputHeader.h:122
std::string _archiveVersion
Definition: SampleInputHeader.h:142
Definition: SampleInputHeader.h:190
char * _headPtr
Definition: SampleInputHeader.h:188
parseStage
Definition: SampleInputHeader.h:190
static const char * magicStrings[]
Strings that can occur as the magic value at the beginning of a sample file.
Definition: SampleInputHeader.h:163
Definition: SampleInputHeader.h:190
static const int HEADER_BUF_LEN
Definition: SampleInputHeader.h:184
const std::string & getArchiveVersion() const
Definition: SampleInputHeader.h:87
std::string _configName
Definition: SampleInputHeader.h:150
void setConfigName(const std::string &val)
Definition: SampleInputHeader.h:98
Definition: SampleInputHeader.h:36
std::string _systemName
Definition: SampleInputHeader.h:148
int _tagMatch
Definition: SampleInputHeader.h:175
int _endTag
Definition: SampleInputHeader.h:173
void read(IOStream *iostream)
Read IOStream until the SampleInputHeader has been fully read.
Definition: SampleInputHeader.cc:181
int _imagic
Definition: SampleInputHeader.h:169
char * _buf
Definition: SampleInputHeader.h:186
const std::string &(SampleInputHeader::* getFunc)() const
Definition: SampleInputHeader.h:134
bool obsolete
Definition: SampleInputHeader.h:136
const std::string & getSystemName() const
Definition: SampleInputHeader.h:96
std::string _projectName
Definition: SampleInputHeader.h:146
void setDummyString(const std::string &)
Definition: SampleInputHeader.h:115
std::string _configVersion
Definition: SampleInputHeader.h:152
SampleInputHeader()
Definition: SampleInputHeader.cc:82
bool parseTag(IOStream *iostream)
Definition: SampleInputHeader.cc:243
Definition: SampleInputHeader.h:190
void setSystemName(const std::string &val)
Definition: SampleInputHeader.h:95
const std::string & getProjectName() const
Definition: SampleInputHeader.h:93
const std::string & getConfigVersion() const
Definition: SampleInputHeader.h:102
void setArchiveVersion(const std::string &val)
Definition: SampleInputHeader.h:86
void setSoftwareVersion(const std::string &val)
Definition: SampleInputHeader.h:89
static const int _ntags
Definition: SampleInputHeader.h:171
Definition: IOException.h:37
enum nidas::core::SampleInputHeader::parseStage _stage
Definition: SampleInputHeader.h:190
std::string toString() const
Render the header in string form.
Definition: SampleInputHeader.cc:336
~SampleInputHeader()
Definition: SampleInputHeader.cc:146
bool parse(IOStream *iostream)
Parse the current contents of the IOStream for the SampleInputHeader.
Definition: SampleInputHeader.cc:154
static struct headerField headers[]
Definition: SampleInputHeader.h:140
const std::string & getDummyString() const
Definition: SampleInputHeader.h:117
int _minMagicLen
Definition: SampleInputHeader.h:167
void setProjectName(const std::string &val)
Definition: SampleInputHeader.h:92
int taglen
Definition: SampleInputHeader.h:124
const std::string & getConfigName() const
Definition: SampleInputHeader.h:99
bool parseValue(IOStream *iostream)
Definition: SampleInputHeader.cc:301
Definition: ParseException.h:36