FileWriterASCIIAbstract.hh
8.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
/**
* FileWriterASCIIAbstract.hh
*
* Created on: 21 oct. 2014
* Author: AKKA
*/
#ifndef FILEWRITERASCIIABSTRACT_HH_
#define FILEWRITERASCIIABSTRACT_HH_
#include "FileWriter.hh"
#include "ParamMgr.hh"
#include "DataSetMgr.hh"
#include "InstrumentMgr.hh"
#include "MissionMgr.hh"
#include <fstream>
#include <map>
#include <list>
namespace AMDA {
namespace ParamOutputImpl {
namespace Download {
namespace FileWriter {
using namespace AMDA::Info;
/**
* @class FileWriterASCIIAbstract
* @brief Abstract class use to define a file writer for a ASCII file.
* @details
*/
class FileWriterASCIIAbstract : public FileWriter
{
public:
/*
* @brief Working structure used to define a field for ASCII formats
*/
typedef struct
{
std::string name;
std::string ucd;
std::string unit;
FileDataType type;
int dimSize1;
int dimSize2;
AMDA::Common::ParameterIndexComponentList componentsList;
std::string filePath;
std::fstream* file;
} ASCIIFieldInfo;
/*
* @brief Constructor
*/
FileWriterASCIIAbstract(AMDA::Parameters::ParameterManager& pParameterManager);
/*
* @brief Destructor
*/
virtual ~FileWriterASCIIAbstract(void);
/*
* @overload FileWriter::getExtension - Abstract method to get file format extension
*/
virtual std::string getExtension(void) = 0;
/*
* @brief Abstract method to get fill character to use
*/
virtual std::string getDataFillCharacter(void) = 0;
/*
* @brief Abstract method to get string representation of a Not A Number
*/
virtual std::string getNanString(void) = 0;
/*
* @brief Abstract method to write begin file tag
*/
virtual void writeBeginFile(void) = 0;
/*
* @brief Abstract method to write end file tag
*/
virtual void writeEndFile(void) = 0;
/*
* @brief Abstract method to write begin description tag
*/
virtual void writeBeginGeneralDescription(void) = 0;
/*
* @brief Abstract method to write end description tag
*/
virtual void writeEndGeneralDescription(void) = 0;
/*
* @brief Abstract method to write an error message
*/
virtual void writeErrorInfo(std::string msg) = 0;
/*
* @brief Abstract method to write begin info group tag with a title
*/
virtual void writeBeginInfoGroup(std::string title, int level) = 0;
/*
* @brief Abstract method to write end info group tag
*/
virtual void writeEndInfoGroup(int level) = 0;
/*
* @brief Abstract method to write an info designated by a key and a value
*/
virtual void writeSingleInfo(std::string key, std::string value, int level) = 0;
/*
* @brief Abstract method to write begin info list tag with a title
*/
virtual void writeBeginInfoList(std::string title, int level) = 0;
/*
* @brief Abstract method to write end info list tag
*/
virtual void writeEndInfoList(void) = 0;
/*
* @brief Abstract method to write begin info fields description tag
*/
virtual void writeBeginFieldsDescription(void) = 0;
/*
* @brief Abstract method to write end info fields description tag
*/
virtual void writeEndFieldsDescription(void) = 0;
/*
* @brief Abstract method to write a field description by parameter id
*/
virtual void writeFieldDescription(std::string paramId) = 0;
/*
* @brief Abstract method to write begin data tag
*/
virtual void writeBeginData(void) = 0;
/*
* @brief Abstract method to write end data tag
*/
virtual void writeEndData(void) = 0;
/*
* @brief Abstract method to write a data record
*/
virtual void writeDataRecord(std::string record) = 0;
/*
* @brief Abstract method to get data start tag
*/
virtual std::string getDataStartTag(bool isTimeData) = 0;
/*
* @brief Abstract method to get data stop tag
*/
virtual std::string getDataStopTag(void) = 0;
/*
* @brief Abstract method to get data value separator
*/
virtual std::string getDataValueSeparator(void) = 0;
/*
* @brief Abstract method used to know if data must be trimmed
*/
virtual bool trimData(void) = 0;
/*
* @overload FileWriter::createNewFile - Create a new ASCII file
*/
virtual bool createNewFile(std::string filePath);
/*
* @overload FileWriter::closeFile - Close current opened ASCII file
*/
virtual void closeFile(void);
/*
* @overload FileWriter::addParameter - Add an output parameter in ASCII file
*/
virtual bool addParameter(ParamProperties* paramProp, AMDA::Common::ParameterIndexComponentList& indexList,
FileDataType type, bool isFirstParam, int dim1Size = 1, int dim2Size = 1);
/*
* @overload FileWriter::isInfoInSeparateFile - Function use to know if info must be write in a separate file
*/
virtual bool isInfoInSeparateFile(bool separateInfoFile, bool onlyOneInterval, OutputStructure outputStructure);
/*
* @overload FileWriter::writeError - Write an error message in the ASCII file
*/
virtual bool writeError(std::string msg);
/*
* @overload FileWriter::writeAMDAInfo - Write an AMDA info bloc for ASCII file
*/
virtual bool writeAMDAInfo(std::string version, std::string createdby, std::string acknowledgement);
/*
* @overload FileWriter::writeRequestInfo - Write a request info bloc for ASCII file
*/
virtual bool writeRequestInfo(std::string structure, std::string timeFormat,
int timeResolution, std::string outputParams, std::string ttName);
/*
* @overload FileWriter::writeParamsInfo - Write a parameter info bloc for ASCII file
*/
virtual bool writeParamsInfo(ParamPropertiesList& paramPropertiesList, OutputStructure outputStructure,
std::string currentParamId = "");
virtual bool writeTableParamsInfo(std::vector<std::string> tableParams, int level);
/*
* @overload FileWriter::writeIntervalInfo - Write an interval info bloc for ASCII file
*/
virtual bool writeIntervalInfo(std::string startTime, std::string stopTime);
/*
* @overload FileWriter::writeTimeData - Write a time data in the ASCII file
*/
virtual bool writeTimeData(std::string paramId, double data, OutputFormatTime timeFormat, bool isFirstParam);
/*
* @overload FileWriter::writeFloatData - Write a float data in the ASCII file
*/
virtual bool writeFloatData(std::string paramId, int varIndex, float data, bool precision);
/*
* @overload FileWriter::writeShortData - Write a short data in the ASCII file
*/
virtual bool writeShortData(std::string paramId, int varIndex, short data, bool precision);
/*
* @overload FileWriter::writeIntData - Write a int data in the ASCII file
*/
virtual bool writeIntData(std::string paramId, int varIndex, int data, bool precision);
/*
* @overload FileWriter::writeDoubleData - Write a double data in the ASCII file
*/
virtual bool writeDoubleData(std::string paramId, int varIndex, double data, bool precision);
/*
* @overload FileWriter::writeLongDoubleData - Write a long double data in the ASCII file
*/
virtual bool writeLongDoubleData(std::string paramId, int varIndex, long double data, bool precision);
/*
* @overload FileWriter::writeLogicalData - Write a logical data in the ASCII file
*/
virtual bool writeLogicalData(std::string paramId, int varIndex, AMDA::Parameters::LogicalData data, bool precision);
/*
* @overload FileWriter::goToNextRecord - Prepare ASCII writer to write the next record
*/
virtual bool goToNextRecord(std::string paramId);
/*
* @overload FileWriter::finalize - Finalize ASCII file write.
* This function merge all temporary files in the final resulted file
*/
virtual bool finalize(bool isInfoFile = false);
protected:
/**
* @brief output stream file
*/
std::ofstream _outputFile;
/**
* @brief Map of fields working structure
*/
std::map <std::string, ASCIIFieldInfo> _fieldInfoMap;
private:
/*
* @brief Clean output temporary file used for each output parameters
*/
void cleanTempFiles();
/*
* @brief Add a a parameter info
*/
bool writeParameterInfo(ParamInfoSPtr parameterInfo, int level);
/*
* brief Add a dataset info
*/
bool writeDatasetInfo(DataSetInfoSPtr datasetInfo,
std::set<std::pair<std::string,ParamInfoSPtr>,FileWriter::cmpParamInfoStruct>& baseParamsInfoList);
/*
* brief Add an instrument info
*/
bool writeInstrumentInfo(InstrumentInfoSPtr instrumentInfo,
std::set<std::pair<std::string,ParamInfoSPtr>,FileWriter::cmpParamInfoStruct>& baseParamsInfoList);
/*
* brief Add a mission info
*/
bool writeMissionInfo(MissionInfoSPtr missionInfo,
std::set<std::pair<std::string,ParamInfoSPtr>,FileWriter::cmpParamInfoStruct>& baseParamsInfoList);
/*
* @brief current output file path
*/
std::string _outputFilePath;
/*
* @brief Ordered list of output parameters
*/
std::list<std::string> _outputParamsList;
/*
* @brief Flag to force to not write all info blocs
*/
bool _writeInfo;
};
} /* namespace FileWriter */
} /* namespace Download */
} /* namespace ParamOutputImpl */
} /* namespace AMDA */
#endif /* FILEWRITERASCIIABSTRACT_HH_ */