TimeTable.hh
5.25 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
/*
* TimeTable.h
*
* Created on: 5 août 2013
* Author: CS
*/
#ifndef TIMETABLE_H_
#define TIMETABLE_H_
#include <string>
#include <vector>
#include <memory>
// Common include modules
#include "OutputFormatTime.hh"
#include "TimeInterval.hh"
#include "ParameterDescription.hh"
#include "log4cxx/logger.h"
namespace TimeTableCatalog {
/**
* TimeTable(TT) definition.
*/
class TimeTable {
public:
/**
* ISO Time format for creation date and interval dates.
*/
enum TIME_FORMAT {
UNKNOWN = 0,
YYYYMMDDThhmmssmsk = 1,
YYYYDOYThhmmssmsk = 2,
YYYYMMDDThhmmss = 3,
YYYYDOYThhmmss = 4,
YYYYMMDDThhmm = 5,
YYYYDOYThhmm = 6
};
TimeTable();
TimeTable(TIME_FORMAT pFormat);
TimeTable(AMDA::OutputFormatTime pFormat);
~TimeTable();
/**
* Creates a new time table as a union of all given time table.
*/
static std::unique_ptr<TimeTable> merge(
const std::vector<TimeTable>& pTimeTableList);
/**
* Creates a new time table as an intersection of all given time tables.
*/
static std::unique_ptr<TimeTable> intersect(
const std::vector<TimeTable>& pTimeTableList);
/**
* Complementary to intersect operation.
*/
static std::unique_ptr<TimeTable> antiintersect(
const std::vector<TimeTable>& pTimeTableList);
/**
* Sorts time intervals according to their start date.
*/
void sort();
/**
* Copies all intervals of a list of time tables into a unique time table.
*/
void group(const std::vector<TimeTable>& pTimeTableList);
/**
* Reads a TT.
*/
void read(const std::string& pPath, const std::string& ptype);
/**
* Writes a TT.
*/
std::string write(const std::string& pPath, const std::string& ptype, const std::string& pName="") const;
/**
* Reads a time table and writes it into another format.
*/
void convert(const std::string& pInPath, const std::string& pInType,
const std::string& pOutPath, const std::string& pName, const std::string& pOutType);
/**
* Unset current TT.
*/
void clear();
/**
* Adds an interval to the TT interval list.
*/
void addInterval(const TimeInterval& pInterval);
/**
* Gets intervals from TT.
*/
const std::vector<TimeInterval>& getIntervals() const {
return _intervals;
}
/**
* Gets last intervals from TT.
*/
TimeInterval * getLastInterval() {
if (_intervals.empty()) {
return NULL;
}
return &(_intervals.back());
}
/**
* Gets number of intervals in TT.
*/
int getIntervalNumber() const;
/**
* Downloads distant timetable file in tmp directory.
*/
static std::string download(const std::string& pPath);
/**
* Retrieve parameter descriptions list
*/
const ParameterDescriptionList& getParameterDescritptions() const {
return _parameterDescritptions;
}
/**
* Retrieve last parameter descriptions
*/
ParameterDescription * getLastParameterDescritption() {
return &_parameterDescritptions.back();
}
/**
* TT metadata name.
*/
std::string _name;
/**
* TT metadata creation date.
*/
double _creationDate;
/**
* TT metadata description
*/
std::vector<std::string> _description;
/**
* TT metadata history
*/
std::string _history;
/**
* TT creation date and interval dates ISO format (with or without msk)
*/
TIME_FORMAT _timeFormat;
/**
* TT creation date and interval dates extented format
*/
AMDA::OutputFormatTime _extTimeFormat;
/**
* ListStartDate => start date of the survey
*/
double _listStartDate;
/**
* ListStopDate => stop date of the survey
*/
double _listStopDate;
/**
* contact
*/
std::string _contact;
/**
* contactID spase contact id
*/
std::string _contactID;
protected:
/**
* Additional parameters descriptions used by Catalog class
* these descriptions are not accessible through the Time table class
*/
ParameterDescriptionList _parameterDescritptions;
private:
/**
* Logger
*/
static log4cxx::LoggerPtr _logger;
/**
* Returns a merged interval list.
*/
static std::unique_ptr<std::vector<TimeInterval>> merge(
const std::vector<TimeInterval>& pTimeIntervalsList);
/**
* Fills an interval list with all non intersections between the two given time tables.
*/
static void antiintersect(const TimeTable& ptt1, const TimeTable& ptt2,
std::vector<TimeInterval>& pIntersetedIntervals);
/**
* Fills an interval list with all intersections between the two given time tables.
*/
static void intersect(const TimeTable& ptt1, const TimeTable& ptt2,
std::vector<TimeInterval>& pIntersetedIntervals);
/**
* Sorts a list of interval according to their start date.
*/
static void sort(std::vector<TimeInterval>& pIntervals);
/**
* TT intervals
*/
std::vector<TimeInterval> _intervals;
};
std::string join(const std::vector<std::string>& pvalues,
const std::string& pseparator);
size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream);
} /* namespace TimeTableCatalog */
#endif /* TIMETABLE_H_ */