-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpreadSheet.cpp
More file actions
129 lines (106 loc) · 2.38 KB
/
Copy pathSpreadSheet.cpp
File metadata and controls
129 lines (106 loc) · 2.38 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
#include "SpreadSheet.h"
#include <algorithm>
#include "IOCSV.h"
using namespace std;
SpreadSheet::SpreadSheet()
{
type = ST_Count;
for(int i = 0; i < ST_Count; i++)
{
SpreadSheetTypes thisType = (SpreadSheetTypes)i;
if(!isSupported(thisType)) continue;
if(type == ST_Count)
{ type = thisType;
// Add children
children[thisType] = new IOCSV();
}
}
}
SpreadSheet::~SpreadSheet()
{
for(auto it = children.begin(); it != children.end(); it++)
delete it->second;
}
int SpreadSheet::test()
{
return current()->test();
}
#include <QDebug>
int SpreadSheet::init(const char *fileName)
{
std::string ext = fileName;
ext = ext.substr(ext.length() - 3, 3);
std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower);
ext = "*." + ext;
for(auto it = children.begin(); it != children.end(); it++)
if(it->second->extensions().contains(ext.c_str()))
{
type = it->first;
break;
}
return current()->init(fileName);
}
int SpreadSheet::open(const char *fileName)
{
return current()->open(fileName);
}
string SpreadSheet::read(int nRow, int nColumn)
{
return current()->read(nRow, nColumn);
}
Date SpreadSheet::readTimeStamp(int nRow)
{
return current()->readTimeStamp(nRow);
}
int SpreadSheet::searchDateRow(const Date &searchedDate)
{
return current()->searchDateRow(searchedDate);
}
Date *SpreadSheet::getFirstDate()
{
return current()->getFirstDate();
}
Date *SpreadSheet::getLastDate()
{
return current()->getLastDate();
}
int SpreadSheet::getTimeStep()
{
return current()->getTimeStep();
}
QStringList SpreadSheet::extensions() const
{
QStringList res;
for(auto it = children.begin(); it != children.end(); it++)
{
IOSpreadSheet *child = it->second;
QStringList subRes = child->extensions();
for(int j = 0; j < subRes.size(); j++)
res << subRes[j];
}
return res;
}
void SpreadSheet::readTimeData()
{
current()->readTimeData();
}
int SpreadSheet::searchExcelRow(int searchedNumber, int startRow, int column)
{
return current()->searchExcelRow(searchedNumber, startRow, column);
}
IOSpreadSheet *SpreadSheet::current()
{
return children[type];
}
bool SpreadSheet::isSupported(SpreadSheet::SpreadSheetTypes type) const
{
switch(type)
{
case ST_Excel:
return false;
case ST_CSV:
return true;
default:
return false;
}
}