1#ifndef OPENXLSX_XLSHAREDSTRINGS_HPP
2#define OPENXLSX_XLSHAREDSTRINGS_HPP
6# pragma warning(disable : 4251)
7# pragma warning(disable : 4275)
14#include <shared_mutex>
16#include <ankerl/unordered_dense.h>
19#include "OpenXLSX-Exports.hpp"
29 auto operator()(std::string_view str)
const noexcept -> uint64_t {
30 return ankerl::unordered_dense::hash<std::string_view>{}(str);
35 template<
typename Key,
typename Value>
36 using FlatHashMap = ankerl::unordered_dense::map<Key, Value, StringViewHash, std::equal_to<>>;
43 std::vector<std::string_view>
cache{};
45 std::unique_ptr<std::shared_mutex>
mutex{std::make_unique<std::shared_mutex>()};
55 class XLSharedStrings;
126 if (!m_state)
return 0;
127 if (m_state->mutex) {
128 std::shared_lock<std::shared_mutex> lock(*m_state->mutex);
129 return static_cast<int32_t
>(m_state->cache.size());
131 return static_cast<int32_t
>(m_state->cache.size());
139 int32_t getStringIndex(std::string_view str)
const;
146 bool stringExists(std::string_view str)
const;
153 const char* getString(int32_t index)
const;
160 std::string_view getStringView(int32_t index)
const;
167 int32_t appendString(std::string_view str)
const;
175 void reserveStrings(
size_t n)
const;
181 size_t memoryUsageBytes() const noexcept;
189 int32_t getOrCreateStringIndex(
std::string_view str) const;
198 void clearString(int32_t index) const;
203 void print(
std::basic_ostream<
char>& ostr) const;
210 int32_t rewriteXmlFromCache();
218 void rebuild(const
std::vector<int32_t>& indexMap, int32_t newStringCount);
228 mutable bool m_domDirty{
false};
XLXmlData * xmlData
Definition XLDocument.cpp:1422
This class encapsulates the concept of an excel file. It is different from the XLWorkbook,...
Definition XLDocument.hpp:82
This class encapsulate the Excel concept of Shared Strings. In Excel, instead of havig individual str...
Definition XLSharedStrings.hpp:67
XLSharedStrings & operator=(XLSharedStrings &&other) noexcept=default
~XLSharedStrings()
Destructor.
XLSharedStrings(const XLSharedStrings &other)=default
XLSharedStrings()=default
XLSharedStrings(XLSharedStrings &&other) noexcept=default
int32_t stringCount() const
return the amount of shared string entries currently in the cache
Definition XLSharedStrings.hpp:124
XLSharedStrings & operator=(const XLSharedStrings &other)=default
String memory pool (Arena Allocator) with block recycling.
Definition XLStringArena.hpp:23
void clear() noexcept
Recycle all blocks for reuse without freeing heap memory.
Definition XLStringArena.hpp:76
The XLXmlData class encapsulates the properties and behaviour of the .xml files in an ....
Definition XLXmlData.hpp:29
The XLXmlFile class provides an interface for derived classes to use. It functions as an ancestor to ...
Definition XLXmlFile.hpp:42
Definition IZipArchive.hpp:18
const XLSharedStrings XLSharedStringsDefaulted
Definition XLSharedStrings.cpp:16
ankerl::unordered_dense::map< Key, Value, StringViewHash, std::equal_to<> > FlatHashMap
Definition XLSharedStrings.hpp:36
std::reference_wrapper< const XLSharedStrings > XLSharedStringsRef
Definition XLSharedStrings.hpp:56
constexpr size_t XLMaxSharedStrings
Definition XLSharedStrings.hpp:38
Definition XLCellIterator.hpp:121
Definition XLSharedStrings.hpp:27
void is_transparent
Definition XLSharedStrings.hpp:28
auto operator()(std::string_view str) const noexcept -> uint64_t
Definition XLSharedStrings.hpp:29
Definition XLSharedStrings.hpp:41
XLStringArena arena
Definition XLSharedStrings.hpp:42
void clear()
Definition XLSharedStrings.hpp:47
std::unique_ptr< std::shared_mutex > mutex
Definition XLSharedStrings.hpp:45
std::vector< std::string_view > cache
Definition XLSharedStrings.hpp:43
FlatHashMap< std::string_view, int32_t > index
Definition XLSharedStrings.hpp:44