react-native-nitro-xlsx 0.2.6 → 0.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -8
- package/cpp/HybridNitroXlsx.cpp +25 -1
- package/cpp/HybridXlsxCellFormat.cpp +46 -146
- package/cpp/HybridXlsxCellFormat.hpp +9 -41
- package/cpp/HybridXlsxConditionalFormat.cpp +4 -1
- package/cpp/HybridXlsxConditionalFormats.cpp +5 -1
- package/cpp/HybridXlsxWorkbook.cpp +38 -8
- package/cpp/HybridXlsxWorkbook.hpp +10 -1
- package/cpp/HybridXlsxWorksheet.cpp +422 -141
- package/cpp/HybridXlsxWorksheet.hpp +4 -1
- package/cpp/XlsxCacheDir.cpp +25 -2
- package/cpp/XlsxCacheDir.hpp +3 -1
- package/cpp/XlsxCellStyle.hpp +360 -0
- package/cpp/XlsxJson.cpp +29 -8
- package/package.json +1 -1
- package/scripts/sync-openxlsx-headers.sh +34 -0
- package/src/__mocks__/react-native-nitro-modules.ts +523 -20
- package/src/__tests__/index.test.ts +124 -16
- package/src/index.ts +13 -13
- package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/IZipArchive.hpp +361 -0
- package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/OpenXLSX-Exports.hpp +12 -0
- package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLCell.hpp +367 -0
- package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLCellIterator.hpp +252 -0
- package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLCellRange.hpp +223 -0
- package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLCellReference.hpp +317 -0
- package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLCellValue.hpp +793 -0
- package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLColor.hpp +232 -0
- package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLColumn.hpp +159 -0
- package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLCommandQuery.hpp +228 -0
- package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLComments.hpp +270 -0
- package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLConstants.hpp +18 -0
- package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLContentTypes.hpp +264 -0
- package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLDateTime.hpp +175 -0
- package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLDocument.hpp +505 -0
- package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLDrawing.hpp +452 -0
- package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLException.hpp +161 -0
- package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLFormula.hpp +375 -0
- package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLIterator.hpp +40 -0
- package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLMergeCells.hpp +216 -0
- package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLProperties.hpp +348 -0
- package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLRelationships.hpp +348 -0
- package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLRow.hpp +721 -0
- package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLRowData.hpp +488 -0
- package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLSharedStrings.hpp +204 -0
- package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLSheet.hpp +1640 -0
- package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLStyles.hpp +2390 -0
- package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLTables.hpp +132 -0
- package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLWorkbook.hpp +404 -0
- package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLXmlData.hpp +283 -0
- package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLXmlFile.hpp +194 -0
- package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLXmlParser.hpp +282 -0
- package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLXmlParserForwardDeclarations.hpp +85 -0
- package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/XLZipArchive.hpp +232 -0
- package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/detail/LibZip.hpp +447 -0
- package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/detail/OpenXLSXFileSystemTools.hpp +207 -0
- package/thirdparty/OpenXLSX/OpenXLSX/headers/OpenXLSX/detail/Zippy.hpp +1375 -0
- package/thirdparty/README.md +7 -3
|
@@ -18,32 +18,124 @@ import {
|
|
|
18
18
|
} from '../index';
|
|
19
19
|
|
|
20
20
|
describe('NitroXlsx', () => {
|
|
21
|
+
beforeEach(() => {
|
|
22
|
+
jest.clearAllMocks();
|
|
23
|
+
});
|
|
24
|
+
|
|
21
25
|
it('should export NitroXlsx object', () => {
|
|
22
26
|
expect(NitroXlsx).toBeDefined();
|
|
23
27
|
expect(typeof NitroXlsx).toBe('object');
|
|
24
28
|
});
|
|
25
29
|
|
|
26
|
-
it('
|
|
27
|
-
|
|
28
|
-
expect(typeof
|
|
30
|
+
it('createWorkbook returns a workbook implementing the spec surface', () => {
|
|
31
|
+
const wb = NitroXlsx.createWorkbook();
|
|
32
|
+
expect(typeof wb.addWorksheet).toBe('function');
|
|
33
|
+
expect(typeof wb.getBuffer).toBe('function');
|
|
34
|
+
expect(typeof wb.toJSON).toBe('function');
|
|
35
|
+
expect(wb.getWorksheetCount()).toBe(0);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('addWorksheet registers the sheet and forwards its argument', () => {
|
|
39
|
+
const wb = NitroXlsx.createWorkbook();
|
|
40
|
+
const ws = wb.addWorksheet('Data');
|
|
41
|
+
expect(ws.getName()).toBe('Data');
|
|
42
|
+
expect(wb.getWorksheetCount()).toBe(1);
|
|
43
|
+
expect(wb.getWorksheet(0)).toBe(ws);
|
|
44
|
+
expect(jest.mocked(wb.addWorksheet).mock.calls[0]).toEqual(['Data']);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('worksheet write/read methods round-trip cell values', () => {
|
|
48
|
+
const ws = NitroXlsx.createWorkbook().addWorksheet('Data');
|
|
49
|
+
ws.writeNumber(1, 2, 3.5);
|
|
50
|
+
expect(ws.getCellValue(1, 2)).toBe(3.5);
|
|
51
|
+
expect(ws.getCellType(1, 2)).toBe('number');
|
|
52
|
+
ws.writeString(0, 0, 'Hello');
|
|
53
|
+
expect(ws.getCellString(0, 0)).toBe('Hello');
|
|
54
|
+
ws.writeFormula(3, 3, 'A1+B1');
|
|
55
|
+
expect(ws.hasFormula(3, 3)).toBe(true);
|
|
56
|
+
expect(ws.formula(3, 3)).toBe('A1+B1');
|
|
57
|
+
expect(ws.getCellValue(9, 9)).toBeNull();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('getBuffer resolves an ArrayBuffer', async () => {
|
|
61
|
+
const wb = NitroXlsx.createWorkbook();
|
|
62
|
+
await expect(wb.getBuffer()).resolves.toBeInstanceOf(ArrayBuffer);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('toJSON returns rows keyed by sheet name', () => {
|
|
66
|
+
const wb = NitroXlsx.createWorkbook();
|
|
67
|
+
const ws = wb.addWorksheet('Data');
|
|
68
|
+
ws.writeString(0, 0, 'Hello');
|
|
69
|
+
ws.writeNumber(0, 1, 42);
|
|
70
|
+
expect(wb.toJSON()).toEqual({ Data: [{ '0': 'Hello', '1': 42 }] });
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('openWorkbook forwards the path and returns a workbook', () => {
|
|
74
|
+
const wb = NitroXlsx.openWorkbook('/tmp/report.xlsx');
|
|
75
|
+
expect(jest.mocked(NitroXlsx.openWorkbook).mock.calls[0]).toEqual(['/tmp/report.xlsx']);
|
|
76
|
+
expect(typeof wb.addWorksheet).toBe('function');
|
|
77
|
+
expect(wb.getWorksheetCount()).toBe(0);
|
|
29
78
|
});
|
|
30
79
|
|
|
31
|
-
it('
|
|
32
|
-
|
|
33
|
-
|
|
80
|
+
it('openWorkbookFromBuffer forwards the buffer', () => {
|
|
81
|
+
const buffer = new ArrayBuffer(16);
|
|
82
|
+
NitroXlsx.openWorkbookFromBuffer(buffer);
|
|
83
|
+
expect(jest.mocked(NitroXlsx.openWorkbookFromBuffer).mock.calls[0]?.[0]).toBe(buffer);
|
|
34
84
|
});
|
|
35
85
|
|
|
36
|
-
it('
|
|
37
|
-
|
|
38
|
-
|
|
86
|
+
it('fromJSON forwards the sheet rows and returns a workbook', () => {
|
|
87
|
+
const data = { Sheet1: [{ Name: 'Alice', Age: 30 }] };
|
|
88
|
+
const wb = NitroXlsx.fromJSON(data);
|
|
89
|
+
expect(jest.mocked(NitroXlsx.fromJSON).mock.calls[0]).toEqual([data]);
|
|
90
|
+
expect(typeof wb.addWorksheet).toBe('function');
|
|
39
91
|
});
|
|
40
92
|
|
|
41
|
-
it('
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
93
|
+
it('sheet lookup, rename, clone and delete follow the native contract', () => {
|
|
94
|
+
const wb = NitroXlsx.createWorkbook();
|
|
95
|
+
const ws = wb.addWorksheet('Data');
|
|
96
|
+
wb.updateSheetName('Data', 'Raw');
|
|
97
|
+
expect(ws.getName()).toBe('Raw');
|
|
98
|
+
const copy = wb.clone('Raw', 'Copy');
|
|
99
|
+
expect(copy.getName()).toBe('Copy');
|
|
100
|
+
expect(wb.getWorksheetCount()).toBe(2);
|
|
101
|
+
wb.deleteSheet('Copy');
|
|
102
|
+
expect(wb.getWorksheetCount()).toBe(1);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('lookup misses throw native-style errors parseable by XlsxError.from', () => {
|
|
106
|
+
expect.assertions(2);
|
|
107
|
+
const wb = NitroXlsx.createWorkbook();
|
|
108
|
+
try {
|
|
109
|
+
wb.getWorksheetByName('missing');
|
|
110
|
+
} catch (e) {
|
|
111
|
+
const err = XlsxError.from(e);
|
|
112
|
+
expect(err.code).toBe('SHEET_NOT_FOUND');
|
|
113
|
+
expect(err.message).toContain('missing');
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('cell format setters update the read-back getters', () => {
|
|
118
|
+
const fmt = NitroXlsx.createWorkbook().addCellFormat();
|
|
119
|
+
fmt.setBold();
|
|
120
|
+
expect(fmt.getIsBold()).toBe(true);
|
|
121
|
+
fmt.setNumFormat('0.00%');
|
|
122
|
+
expect(fmt.getNumFormat()).toBe('0.00%');
|
|
123
|
+
fmt.setFontSize(14);
|
|
124
|
+
expect(fmt.getFontSize()).toBe(14);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('conditional formats create rules and round-trip rule edits', () => {
|
|
128
|
+
const ws = NitroXlsx.createWorkbook().addWorksheet('Data');
|
|
129
|
+
const cfs = ws.getConditionalFormats();
|
|
130
|
+
const cf = cfs.create('A1:A5');
|
|
131
|
+
expect(cf.getSqref()).toBe('A1:A5');
|
|
132
|
+
expect(cfs.getCount()).toBe(1);
|
|
133
|
+
const rule = cf.createRule();
|
|
134
|
+
expect(rule).toBe(0);
|
|
135
|
+
cf.setRuleType(rule, 1);
|
|
136
|
+
cf.setRuleFormula(rule, 0, 'A1>5');
|
|
137
|
+
expect(cf.getRuleType(rule)).toBe(1);
|
|
138
|
+
expect(cf.getRuleFormula(rule, 0)).toBe('A1>5');
|
|
47
139
|
});
|
|
48
140
|
});
|
|
49
141
|
|
|
@@ -137,9 +229,18 @@ describe('Constants', () => {
|
|
|
137
229
|
expect(NumFormat.NUMBER).toBe(1);
|
|
138
230
|
expect(NumFormat.CURRENCY).toBe(5);
|
|
139
231
|
expect(NumFormat.PERCENT).toBe(9);
|
|
140
|
-
expect(NumFormat.
|
|
232
|
+
expect(NumFormat.SCIENTIFIC).toBe(11);
|
|
233
|
+
expect(NumFormat.FRACTION_1).toBe(12);
|
|
234
|
+
expect(NumFormat.DATE_1).toBe(14);
|
|
235
|
+
expect(NumFormat.TIME_1).toBe(18);
|
|
236
|
+
expect(NumFormat.DATETIME).toBe(22);
|
|
141
237
|
expect(NumFormat.TEXT).toBe(49);
|
|
142
238
|
});
|
|
239
|
+
|
|
240
|
+
it('should not expose nonexistent built-in numFmtIds', () => {
|
|
241
|
+
expect('SCIENTIFIC_2' in NumFormat).toBe(false);
|
|
242
|
+
expect('DATE_5' in NumFormat).toBe(false);
|
|
243
|
+
});
|
|
143
244
|
});
|
|
144
245
|
|
|
145
246
|
describe('CfType', () => {
|
|
@@ -198,6 +299,13 @@ describe('XlsxError', () => {
|
|
|
198
299
|
expect(err.message).toContain('Worksheet not found: Foo');
|
|
199
300
|
});
|
|
200
301
|
|
|
302
|
+
it('should parse native INVALID_ARGUMENT errors', () => {
|
|
303
|
+
const native = new Error('writeNumber: INVALID_ARGUMENT: bad arg');
|
|
304
|
+
const err = XlsxError.from(native);
|
|
305
|
+
expect(err.code).toBe('INVALID_ARGUMENT');
|
|
306
|
+
expect(err.message).toContain('bad arg');
|
|
307
|
+
});
|
|
308
|
+
|
|
201
309
|
it('should wrap unknown errors with INTERNAL_ERROR', () => {
|
|
202
310
|
const err = XlsxError.from(new Error('something odd'));
|
|
203
311
|
expect(err.code).toBe('INTERNAL_ERROR');
|
package/src/index.ts
CHANGED
|
@@ -265,7 +265,9 @@ export const Colors = {
|
|
|
265
265
|
FUCHSIA: 0xFF00FF,
|
|
266
266
|
} as const
|
|
267
267
|
|
|
268
|
-
// Built-in number format indices
|
|
268
|
+
// Built-in number format indices (ECMA-376 §18.8.30 numFmtId values).
|
|
269
|
+
// Note: ids 5-8 are locale-dependent currency variants; 14-22 are locale-dependent
|
|
270
|
+
// date/time formats. There is no second built-in scientific format (11 is the only one).
|
|
269
271
|
export const NumFormat = {
|
|
270
272
|
GENERAL: 0,
|
|
271
273
|
NUMBER: 1,
|
|
@@ -279,18 +281,16 @@ export const NumFormat = {
|
|
|
279
281
|
PERCENT: 9,
|
|
280
282
|
PERCENT_2: 10,
|
|
281
283
|
SCIENTIFIC: 11,
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
TIME_3: 22,
|
|
293
|
-
TIME_4: 23,
|
|
284
|
+
FRACTION_1: 12,
|
|
285
|
+
FRACTION_2: 13,
|
|
286
|
+
DATE_1: 14,
|
|
287
|
+
DATE_2: 15,
|
|
288
|
+
DATE_3: 16,
|
|
289
|
+
DATE_4: 17,
|
|
290
|
+
TIME_1: 18,
|
|
291
|
+
TIME_2: 19,
|
|
292
|
+
TIME_3: 20,
|
|
293
|
+
TIME_4: 21,
|
|
294
294
|
DATETIME: 22,
|
|
295
295
|
TEXT: 49,
|
|
296
296
|
} as const
|
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
/*
|
|
2
|
+
|
|
3
|
+
____ ____ ___ ____ ____ ____ ___
|
|
4
|
+
6MMMMb `MM( )M' `MM' 6MMMMb\`MM( )M'
|
|
5
|
+
8P Y8 `MM. d' MM 6M' ` `MM. d'
|
|
6
|
+
6M Mb __ ____ ____ ___ __ `MM. d' MM MM `MM. d'
|
|
7
|
+
MM MM `M6MMMMb 6MMMMb `MM 6MMb `MM. d' MM YM. `MM. d'
|
|
8
|
+
MM MM MM' `Mb 6M' `Mb MMM9 `Mb `MMd MM YMMMMb `MMd
|
|
9
|
+
MM MM MM MM MM MM MM' MM dMM. MM `Mb dMM.
|
|
10
|
+
MM MM MM MM MMMMMMMM MM MM d'`MM. MM MM d'`MM.
|
|
11
|
+
YM M9 MM MM MM MM MM d' `MM. MM MM d' `MM.
|
|
12
|
+
8b d8 MM. ,M9 YM d9 MM MM d' `MM. MM / L ,M9 d' `MM.
|
|
13
|
+
YMMMM9 MMYMMM9 YMMMM9 _MM_ _MM_M(_ _)MM_ _MMMMMMM MYMMMM9 _M(_ _)MM_
|
|
14
|
+
MM
|
|
15
|
+
MM
|
|
16
|
+
_MM_
|
|
17
|
+
|
|
18
|
+
Copyright (c) 2022, Kenneth Troldal Balslev
|
|
19
|
+
|
|
20
|
+
All rights reserved.
|
|
21
|
+
|
|
22
|
+
Redistribution and use in source and binary forms, with or without
|
|
23
|
+
modification, are permitted provided that the following conditions are met:
|
|
24
|
+
- Redistributions of source code must retain the above copyright
|
|
25
|
+
notice, this list of conditions and the following disclaimer.
|
|
26
|
+
- Redistributions in binary form must reproduce the above copyright
|
|
27
|
+
notice, this list of conditions and the following disclaimer in the
|
|
28
|
+
documentation and/or other materials provided with the distribution.
|
|
29
|
+
- Neither the name of the author nor the
|
|
30
|
+
names of any contributors may be used to endorse or promote products
|
|
31
|
+
derived from this software without specific prior written permission.
|
|
32
|
+
|
|
33
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
34
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
35
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
36
|
+
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
|
37
|
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
38
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
39
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
40
|
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
41
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
42
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
43
|
+
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
#ifndef OPENXLSX_IZIPARCHIVE_HPP
|
|
47
|
+
#define OPENXLSX_IZIPARCHIVE_HPP
|
|
48
|
+
|
|
49
|
+
#ifdef _MSC_VER // conditionally enable MSVC specific pragmas to avoid other compilers warning about unknown pragmas
|
|
50
|
+
# pragma warning(push)
|
|
51
|
+
# pragma warning(disable : 4251)
|
|
52
|
+
# pragma warning(disable : 4275)
|
|
53
|
+
#endif // _MSC_VER
|
|
54
|
+
|
|
55
|
+
// ===== OpenXLSX Includes ===== //
|
|
56
|
+
#include "OpenXLSX-Exports.hpp"
|
|
57
|
+
|
|
58
|
+
#include <memory>
|
|
59
|
+
#include <string>
|
|
60
|
+
|
|
61
|
+
namespace OpenXLSX
|
|
62
|
+
{
|
|
63
|
+
/**
|
|
64
|
+
* @brief This class functions as a wrapper around any class that provides the necessary functionality for
|
|
65
|
+
* a zip archive.
|
|
66
|
+
* @details This class works by applying 'type erasure'. This enables the use of objects of any class, the only
|
|
67
|
+
* requirement being that it provides the right interface. No inheritance from a base class is needed.
|
|
68
|
+
*/
|
|
69
|
+
class OPENXLSX_EXPORT IZipArchive
|
|
70
|
+
{
|
|
71
|
+
public:
|
|
72
|
+
/**
|
|
73
|
+
* @brief Default constructor
|
|
74
|
+
*/
|
|
75
|
+
IZipArchive() : m_zipArchive() {} // NOLINT
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* @brief Constructor, taking the target object as an argument.
|
|
79
|
+
* @tparam T The type of the target object (will be auto deducted)
|
|
80
|
+
* @param x The target object
|
|
81
|
+
* @note This method is deliberately not marked 'explicit', because as a templated constructor, it should be able
|
|
82
|
+
* to take any type as an argument. However, only objects that satisfy the required interface can be used.
|
|
83
|
+
*/
|
|
84
|
+
template<typename T>
|
|
85
|
+
IZipArchive(const T& zipArchive) : m_zipArchive { std::make_unique<Model<T>>(zipArchive) } {} // NOLINT
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* @brief Copy constructor
|
|
89
|
+
* @param other
|
|
90
|
+
*/
|
|
91
|
+
IZipArchive(const IZipArchive& other) : m_zipArchive(other.m_zipArchive ? other.m_zipArchive->clone() : nullptr) {}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @brief Move constructor
|
|
95
|
+
* @param other
|
|
96
|
+
*/
|
|
97
|
+
IZipArchive(IZipArchive&& other) noexcept = default;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* @brief Destructor
|
|
101
|
+
*/
|
|
102
|
+
~IZipArchive() = default;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* @brief
|
|
106
|
+
* @tparam T
|
|
107
|
+
* @param x
|
|
108
|
+
* @return
|
|
109
|
+
*/
|
|
110
|
+
template<typename T>
|
|
111
|
+
inline IZipArchive& operator=(const T& zipArchive)
|
|
112
|
+
{
|
|
113
|
+
m_zipArchive = std::make_unique<Model<T>>(zipArchive);
|
|
114
|
+
return *this;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* @brief copy assignment shall be disabled until a use case is found
|
|
119
|
+
* @param other
|
|
120
|
+
* @return
|
|
121
|
+
*/
|
|
122
|
+
inline IZipArchive& operator=(const IZipArchive& other) = delete;
|
|
123
|
+
// inline IZipArchive& operator=(const IZipArchive& other)
|
|
124
|
+
// {
|
|
125
|
+
// IZipArchive copy(other);
|
|
126
|
+
// *this = std::move(copy);
|
|
127
|
+
// return *this;
|
|
128
|
+
// }
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* @brief
|
|
132
|
+
* @param other
|
|
133
|
+
* @return
|
|
134
|
+
*/
|
|
135
|
+
inline IZipArchive& operator=(IZipArchive&& other) noexcept = default;
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* @brief
|
|
139
|
+
* @return
|
|
140
|
+
*/
|
|
141
|
+
inline explicit operator bool() const
|
|
142
|
+
{
|
|
143
|
+
return isValid();
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
inline bool isValid() const {
|
|
147
|
+
return m_zipArchive->isValid();
|
|
148
|
+
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
inline bool isOpen() const {
|
|
152
|
+
return m_zipArchive->isOpen();
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
inline void open(const std::string& fileName) {
|
|
156
|
+
m_zipArchive->open(fileName);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
inline void close() const {
|
|
160
|
+
m_zipArchive->close();
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
inline void save(const std::string& path) {
|
|
164
|
+
m_zipArchive->save(path);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
inline void addEntry(const std::string& name, const std::string& data) {
|
|
168
|
+
m_zipArchive->addEntry(name, data);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
inline void addEntryAndCommit(const std::string& name, const std::string& data) {
|
|
172
|
+
m_zipArchive->addEntryAndCommit(name, data);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
inline void deleteEntry(const std::string& entryName) {
|
|
176
|
+
m_zipArchive->deleteEntry(entryName);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
inline std::string getEntry(const std::string& name) {
|
|
180
|
+
return m_zipArchive->getEntry(name);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
inline bool hasEntry(const std::string& entryName) const {
|
|
184
|
+
return m_zipArchive->hasEntry(entryName);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
private:
|
|
188
|
+
/**
|
|
189
|
+
* @brief
|
|
190
|
+
*/
|
|
191
|
+
struct Concept
|
|
192
|
+
{
|
|
193
|
+
public:
|
|
194
|
+
/**
|
|
195
|
+
* @brief
|
|
196
|
+
*/
|
|
197
|
+
Concept() = default;
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* @brief
|
|
201
|
+
*/
|
|
202
|
+
Concept(const Concept&) = default;
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* @brief
|
|
206
|
+
*/
|
|
207
|
+
Concept(Concept&&) noexcept = default;
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* @brief
|
|
211
|
+
*/
|
|
212
|
+
virtual ~Concept() = default;
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* @brief
|
|
216
|
+
* @return
|
|
217
|
+
*/
|
|
218
|
+
inline Concept& operator=(const Concept&) = default;
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* @brief
|
|
222
|
+
* @return
|
|
223
|
+
*/
|
|
224
|
+
inline Concept& operator=(Concept&&) noexcept = default;
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* @brief
|
|
228
|
+
* @return
|
|
229
|
+
*/
|
|
230
|
+
inline virtual std::unique_ptr<Concept> clone() const = 0;
|
|
231
|
+
|
|
232
|
+
inline virtual bool isValid() const = 0;
|
|
233
|
+
|
|
234
|
+
inline virtual bool isOpen() const = 0;
|
|
235
|
+
|
|
236
|
+
inline virtual void open(const std::string& fileName) = 0;
|
|
237
|
+
|
|
238
|
+
inline virtual void close() = 0;
|
|
239
|
+
|
|
240
|
+
inline virtual void save (const std::string& path) = 0;
|
|
241
|
+
|
|
242
|
+
inline virtual void addEntry(const std::string& name, const std::string& data) = 0;
|
|
243
|
+
|
|
244
|
+
inline virtual void addEntryAndCommit(const std::string& name, const std::string& data) = 0;
|
|
245
|
+
|
|
246
|
+
inline virtual void deleteEntry(const std::string& entryName) = 0;
|
|
247
|
+
|
|
248
|
+
inline virtual std::string getEntry(const std::string& name) = 0;
|
|
249
|
+
|
|
250
|
+
inline virtual bool hasEntry(const std::string& entryName) const = 0;
|
|
251
|
+
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* @brief
|
|
256
|
+
* @tparam T
|
|
257
|
+
*/
|
|
258
|
+
template<typename T>
|
|
259
|
+
struct Model : Concept
|
|
260
|
+
{
|
|
261
|
+
public:
|
|
262
|
+
/**
|
|
263
|
+
* @brief
|
|
264
|
+
* @param x
|
|
265
|
+
*/
|
|
266
|
+
explicit Model(const T& x) : ZipType(x) {}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* @brief
|
|
270
|
+
* @param other
|
|
271
|
+
*/
|
|
272
|
+
Model(const Model& other) = default;
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* @brief
|
|
276
|
+
* @param other
|
|
277
|
+
*/
|
|
278
|
+
Model(Model&& other) noexcept = default;
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* @brief
|
|
282
|
+
*/
|
|
283
|
+
~Model() override = default;
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* @brief
|
|
287
|
+
* @param other
|
|
288
|
+
* @return
|
|
289
|
+
*/
|
|
290
|
+
inline Model& operator=(const Model& other) = default;
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* @brief
|
|
294
|
+
* @param other
|
|
295
|
+
* @return
|
|
296
|
+
*/
|
|
297
|
+
inline Model& operator=(Model&& other) noexcept = default;
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* @brief
|
|
301
|
+
* @return
|
|
302
|
+
*/
|
|
303
|
+
inline std::unique_ptr<Concept> clone() const override
|
|
304
|
+
{
|
|
305
|
+
return std::make_unique<Model<T>>(ZipType);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
inline bool isValid() const override {
|
|
309
|
+
return ZipType.isValid();
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
inline bool isOpen() const override {
|
|
313
|
+
return ZipType.isOpen();
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
inline void open(const std::string& fileName) override {
|
|
317
|
+
ZipType.open(fileName);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
inline void close() override {
|
|
321
|
+
ZipType.close();
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
inline void save(const std::string& path) override {
|
|
325
|
+
ZipType.save(path);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
inline void addEntry(const std::string& name, const std::string& data) override {
|
|
329
|
+
ZipType.addEntry(name, data);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
inline void addEntryAndCommit(const std::string& name, const std::string& data) override {
|
|
333
|
+
ZipType.addEntryAndCommit(name, data);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
inline void deleteEntry(const std::string& entryName) override {
|
|
337
|
+
ZipType.deleteEntry(entryName);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
inline std::string getEntry(const std::string& name) override {
|
|
341
|
+
return ZipType.getEntry(name);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
inline bool hasEntry(const std::string& entryName) const override {
|
|
345
|
+
return ZipType.hasEntry(entryName);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
private:
|
|
349
|
+
T ZipType;
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
std::unique_ptr<Concept> m_zipArchive;
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
} // namespace OpenXLSX
|
|
356
|
+
|
|
357
|
+
#ifdef _MSC_VER // conditionally enable MSVC specific pragmas to avoid other compilers warning about unknown pragmas
|
|
358
|
+
# pragma warning(pop)
|
|
359
|
+
#endif // _MSC_VER
|
|
360
|
+
|
|
361
|
+
#endif // OPENXLSX_IZIPARCHIVE_HPP
|