Skylicht Engine
Loading...
Searching...
No Matches
CXMLSpreadsheet.h
1/*
2!@
3MIT License
4
5Copyright (c) 2020 Skylicht Technology CO., LTD
6
7Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
8(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
9merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
10subject to the following conditions:
11
12The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
20This file is part of the "Skylicht Engine".
21https://github.com/skylicht-lab/skylicht-engine
22!#
23*/
24
25#pragma once
26
27#include "Serializable/CObjectSerializable.h"
28
29namespace Skylicht
30{
38 class SKYLICHT_API CXMLSpreadsheet
39 {
40 public:
44 struct SCell
45 {
47 u32 Row;
49 u32 Col;
51 EPropertyDataType Type;
53 std::string Value;
55 std::wstring UnicodeValue;
61 long Time;
74
79 {
80 Row = 0;
81 Col = 0;
82 Type = String;
83 NumberInt = 0;
84 NumberFloat = 0.0f;
85 Time = 0;
86 TimeYear = 0;
87 TimeMonth = 0;
88 TimeDay = 0;
89 TimeHour = 0;
90 TimeMin = 0;
91 TimeSec = 0;
92 }
93 };
94
98 struct SRow
99 {
101 u32 Index;
103 std::vector<SCell*> Cells;
104
109 {
110 for (SCell* c : Cells)
111 {
112 delete c;
113 }
114 Cells.clear();
115 }
116 };
117
121 struct SSheet
122 {
128 std::string Name;
130 std::wstring NameUnicode;
132 std::vector<SRow*> Rows;
133
138 {
139 clear();
140 }
141
145 void clear()
146 {
147 for (SRow* r : Rows)
148 {
149 delete r;
150 }
151 Rows.clear();
152 }
153 };
154
155 protected:
156 std::vector<SSheet*> m_sheets;
157
158 public:
163
168
174 bool open(const char* file);
175
181 bool open(io::IXMLReader* xmlReader);
182
188 bool openCSV(const char* file);
189
194 inline u32 getSheetCount()
195 {
196 return (u32)m_sheets.size();
197 }
198
205 {
206 return m_sheets[i];
207 }
208
215 {
216 return m_sheets[i];
217 }
218
226 SCell* getCell(SSheet* sheet, u32 row, u32 col);
227
234 SCell* getCell(SSheet* sheet, const char* cellName);
235
245 std::list<SCell*> getRange(SSheet* sheet, u32 fromRow, u32 fromCol, u32 toRow, u32 toCol);
246
254 std::list<SCell*> getRange(SSheet* sheet, const char* from, const char* to);
255
263 bool convertCellName(const char* cellName, u32& row, u32& col);
264
268 void clear();
269
270 protected:
271
279 bool splitCsvLine(const std::string& line, char delimiter, std::vector<std::string>& cells);
280
287 bool combineLine(std::vector<std::string>& cols, std::vector<std::string>& cells);
288 };
289}
virtual ~CXMLSpreadsheet()
Destroy the spreadsheet and all loaded data.
std::list< SCell * > getRange(SSheet *sheet, u32 fromRow, u32 fromCol, u32 toRow, u32 toCol)
Get all cells inside a rectangular range.
SCell * getCell(SSheet *sheet, const char *cellName)
Find a cell by spreadsheet cell name.
SSheet * operator[](int i)
Get a sheet by index.
Definition CXMLSpreadsheet.h:214
bool splitCsvLine(const std::string &line, char delimiter, std::vector< std::string > &cells)
Split one CSV line into cell strings.
void clear()
Clear all loaded sheets and data.
bool open(io::IXMLReader *xmlReader)
Load spreadsheet data from an existing XML reader.
SSheet * getSheet(int i)
Get a sheet by index.
Definition CXMLSpreadsheet.h:204
std::list< SCell * > getRange(SSheet *sheet, const char *from, const char *to)
Get all cells inside a named rectangular range.
bool convertCellName(const char *cellName, u32 &row, u32 &col)
Convert a spreadsheet cell name into row and column indexes.
SCell * getCell(SSheet *sheet, u32 row, u32 col)
Find a cell by row and column.
u32 getSheetCount()
Get the number of loaded sheets.
Definition CXMLSpreadsheet.h:194
bool open(const char *file)
Load spreadsheet data from an XML file.
CXMLSpreadsheet()
Construct an empty spreadsheet.
bool openCSV(const char *file)
Load spreadsheet data from a CSV file.
bool combineLine(std::vector< std::string > &cols, std::vector< std::string > &cells)
Combine parsed columns with continuation cells for multi-line CSV fields.
Everything in the Skylicht Engine. You can start by looking at the topics.
Definition AudioDebugLog.h:29
One spreadsheet cell.
Definition CXMLSpreadsheet.h:45
u32 Col
One-based column index from the source document.
Definition CXMLSpreadsheet.h:49
u32 Row
One-based row index from the source document.
Definition CXMLSpreadsheet.h:47
int TimeMonth
Time month component.
Definition CXMLSpreadsheet.h:65
float NumberFloat
Floating-point numeric value.
Definition CXMLSpreadsheet.h:59
int NumberInt
Integer numeric value.
Definition CXMLSpreadsheet.h:57
int TimeDay
Time day component.
Definition CXMLSpreadsheet.h:67
EPropertyDataType Type
Serialized property type of this cell.
Definition CXMLSpreadsheet.h:51
int TimeYear
Time year component.
Definition CXMLSpreadsheet.h:63
long Time
Time value represented as seconds.
Definition CXMLSpreadsheet.h:61
SCell()
Construct an empty string cell.
Definition CXMLSpreadsheet.h:78
int TimeHour
Time hour component.
Definition CXMLSpreadsheet.h:69
std::string Value
Narrow string value.
Definition CXMLSpreadsheet.h:53
int TimeSec
Time second component.
Definition CXMLSpreadsheet.h:73
std::wstring UnicodeValue
Unicode string value.
Definition CXMLSpreadsheet.h:55
int TimeMin
Time minute component.
Definition CXMLSpreadsheet.h:71
One spreadsheet row that owns its cells.
Definition CXMLSpreadsheet.h:99
u32 Index
Row index from the source document.
Definition CXMLSpreadsheet.h:101
~SRow()
Destroy all cells in the row.
Definition CXMLSpreadsheet.h:108
std::vector< SCell * > Cells
Cells contained in this row.
Definition CXMLSpreadsheet.h:103
One spreadsheet sheet that owns its rows.
Definition CXMLSpreadsheet.h:122
int NumRow
Declared number of rows.
Definition CXMLSpreadsheet.h:124
int NumCol
Declared number of columns.
Definition CXMLSpreadsheet.h:126
std::string Name
Sheet name as narrow text.
Definition CXMLSpreadsheet.h:128
void clear()
Remove and delete all rows.
Definition CXMLSpreadsheet.h:145
std::wstring NameUnicode
Sheet name as Unicode text.
Definition CXMLSpreadsheet.h:130
~SSheet()
Destroy all rows in the sheet.
Definition CXMLSpreadsheet.h:137
std::vector< SRow * > Rows
Rows contained in the sheet.
Definition CXMLSpreadsheet.h:132