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"
30 auto operator()(std::string_view str)
const noexcept -> uint64_t {
31 return ankerl::unordered_dense::hash<std::string_view>{}(str);
36 template<
typename Key,
typename Value>
37 using FlatHashMap = ankerl::unordered_dense::map<Key, Value, StringViewHash, std::equal_to<>>;
44 std::vector<std::string_view>
cache{};
46 std::unique_ptr<std::shared_mutex>
mutex{std::make_unique<std::shared_mutex>()};
56 class XLSharedStrings;
127 if (!m_state)
return 0;
128 if (m_state->mutex) {
129 std::shared_lock<std::shared_mutex> lock(*m_state->mutex);
130 return static_cast<int32_t
>(m_state->cache.size());
132 return static_cast<int32_t
>(m_state->cache.size());
140 int32_t getStringIndex(std::string_view str)
const;
147 bool stringExists(std::string_view str)
const;
154 const char* getString(int32_t index)
const;
161 std::string_view getStringView(int32_t index)
const;
168 int32_t appendString(std::string_view str)
const;
176 void reserveStrings(
size_t n)
const;
182 size_t memoryUsageBytes() const noexcept;
190 int32_t getOrCreateStringIndex(
std::string_view str) const;
199 void clearString(int32_t index) const;
204 void print(
std::basic_ostream<
char>& ostr) const;
211 int32_t rewriteXmlFromCache();
226 void rebuild(const
std::vector<int32_t>& indexMap, int32_t newStringCount);
236 mutable bool m_domDirty{
false};
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:68
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:125
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:68
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:17
ankerl::unordered_dense::map< Key, Value, StringViewHash, std::equal_to<> > FlatHashMap
Definition XLSharedStrings.hpp:37
std::reference_wrapper< const XLSharedStrings > XLSharedStringsRef
Definition XLSharedStrings.hpp:57
constexpr size_t XLMaxSharedStrings
Definition XLSharedStrings.hpp:39
Definition XLCellIterator.hpp:121
Definition XLSharedStrings.hpp:28
void is_transparent
Definition XLSharedStrings.hpp:29
auto operator()(std::string_view str) const noexcept -> uint64_t
Definition XLSharedStrings.hpp:30
Auto-managed malloc memory for Zero-Copy serialization.
Definition XLXmlData.hpp:26
Definition XLSharedStrings.hpp:42
XLStringArena arena
Definition XLSharedStrings.hpp:43
void clear()
Definition XLSharedStrings.hpp:48
std::unique_ptr< std::shared_mutex > mutex
Definition XLSharedStrings.hpp:46
std::vector< std::string_view > cache
Definition XLSharedStrings.hpp:44
FlatHashMap< std::string_view, int32_t > index
Definition XLSharedStrings.hpp:45