OpenXLSX 1.12.1
Modern C++ Excel Library (Fork of OpenXLSX by Kenneth Troldal Balslev)
Loading...
Searching...
No Matches
XLSharedStringTable.hpp
Go to the documentation of this file.
1/*
2 * OpenXLSX-NX - Modern High-Performance C++ Excel Library
3 *
4 * Original work Copyright (c) 2018-2025, Kenneth Troldal Balslev and OpenXLSX contributors
5 * Modified work Copyright (c) 2026, Curry Tang and OpenXLSX-NX contributors
6 *
7 * Distributed under the BSD 3-Clause License.
8 * See LICENSE.md in the project root or https://opensource.org/licenses/BSD-3-Clause
9 */
10
11#ifndef OPENXLSX_XLSHAREDSTRINGTABLE_HPP
12#define OPENXLSX_XLSHAREDSTRINGTABLE_HPP
13
14#ifdef _MSC_VER
15# pragma warning(push)
16# pragma warning(disable : 4251)
17# pragma warning(disable : 4275)
18#endif
19
34
35#include "OpenXLSX-Exports.hpp"
36
37#include <cstdint>
38#include <string>
39#include <string_view>
40#include <unordered_map>
41#include <vector>
42
43namespace OpenXLSX
44{
50 class OPENXLSX_EXPORT XLSharedStringTable
51 {
52 public:
53 virtual ~XLSharedStringTable() = default;
54
56 [[nodiscard]] virtual int32_t stringCount() const = 0;
57
62 [[nodiscard]] virtual int32_t getStringIndex(std::string_view str) const = 0;
63
65 [[nodiscard]] virtual bool stringExists(std::string_view str) const = 0;
66
71 [[nodiscard]] virtual const char* getString(int32_t index) const = 0;
72
77 [[nodiscard]] virtual std::string_view getStringView(int32_t index) const = 0;
78 };
79
85 class OPENXLSX_EXPORT XLMapSharedStringTable final : public XLSharedStringTable
86 {
87 public:
89
91 explicit XLMapSharedStringTable(std::vector<std::string> strings);
92
94 int32_t append(std::string_view str);
95
96 void clear();
97
98 [[nodiscard]] int32_t stringCount() const override;
99 [[nodiscard]] int32_t getStringIndex(std::string_view str) const override;
100 [[nodiscard]] bool stringExists(std::string_view str) const override;
101 [[nodiscard]] const char* getString(int32_t index) const override;
102 [[nodiscard]] std::string_view getStringView(int32_t index) const override;
103
104 private:
105 std::vector<std::string> m_strings;
106 std::unordered_map<std::string, int32_t> m_index;
107 };
108
109} // namespace OpenXLSX
110
111#ifdef _MSC_VER
112# pragma warning(pop)
113#endif
114
115#endif // OPENXLSX_XLSHAREDSTRINGTABLE_HPP
int32_t getStringIndex(std::string_view str) const override
Look up an existing string's index.
Definition XLSharedStringTable.cpp:40
std::string_view getStringView(int32_t index) const override
Resolve an SST index to a string_view into the arena/cache.
Definition XLSharedStringTable.cpp:57
int32_t append(std::string_view str)
Append a string and return its index (duplicates reuse the existing index).
Definition XLSharedStringTable.cpp:21
const char * getString(int32_t index) const override
Resolve an SST index to a null-terminated C string.
Definition XLSharedStringTable.cpp:51
int32_t stringCount() const override
Definition XLSharedStringTable.cpp:38
bool stringExists(std::string_view str) const override
Definition XLSharedStringTable.cpp:46
void clear()
Definition XLSharedStringTable.cpp:32
Abstract read-only view of the workbook shared string table.
Definition XLSharedStringTable.hpp:51
virtual ~XLSharedStringTable()=default
virtual const char * getString(int32_t index) const =0
Resolve an SST index to a null-terminated C string.
virtual int32_t stringCount() const =0
virtual int32_t getStringIndex(std::string_view str) const =0
Look up an existing string's index.
virtual std::string_view getStringView(int32_t index) const =0
Resolve an SST index to a string_view into the arena/cache.
virtual bool stringExists(std::string_view str) const =0
Definition IXLCellProvider.hpp:24