11#ifndef OPENXLSX_XLSHAREDSTRINGS_HPP
12#define OPENXLSX_XLSHAREDSTRINGS_HPP
16# pragma warning(disable : 4251)
17# pragma warning(disable : 4275)
24#include <shared_mutex>
26#include <ankerl/unordered_dense.h>
29#include "OpenXLSX-Exports.hpp"
40 auto operator()(std::string_view str)
const noexcept -> uint64_t {
41 return ankerl::unordered_dense::hash<std::string_view>{}(str);
46 template<
typename Key,
typename Value>
47 using FlatHashMap = ankerl::unordered_dense::map<Key, Value, StringViewHash, std::equal_to<>>;
54 std::vector<std::string_view>
cache{};
56 std::unique_ptr<std::shared_mutex>
mutex{std::make_unique<std::shared_mutex>()};
66 class XLSharedStrings;
137 if (!m_state)
return 0;
138 if (m_state->mutex) {
139 std::shared_lock<std::shared_mutex> lock(*m_state->mutex);
140 return static_cast<int32_t
>(m_state->cache.size());
142 return static_cast<int32_t
>(m_state->cache.size());
150 int32_t getStringIndex(std::string_view str)
const;
157 bool stringExists(std::string_view str)
const;
164 const char* getString(int32_t index)
const;
171 std::string_view getStringView(int32_t index)
const;
178 int32_t appendString(std::string_view str)
const;
186 void reserveStrings(
size_t n)
const;
192 size_t memoryUsageBytes() const noexcept;
200 int32_t getOrCreateStringIndex(
std::string_view str) const;
209 void clearString(int32_t index) const;
214 void print(
std::basic_ostream<
char>& ostr) const;
221 int32_t rewriteXmlFromCache();
236 void rebuild(const
std::vector<int32_t>& indexMap, int32_t newStringCount);
246 mutable bool m_domDirty{
false};
This class encapsulate the Excel concept of Shared Strings. In Excel, instead of havig individual str...
Definition XLSharedStrings.hpp:78
XLSharedStrings & operator=(XLSharedStrings &&other) noexcept=default
~XLSharedStrings()
Destructor.
XLSharedStrings(const XLSharedStrings &other)=default
XLSharedStrings()=default
friend class XLDocument
Definition XLSharedStrings.hpp:80
XLSharedStrings(XLSharedStrings &&other) noexcept=default
int32_t stringCount() const
return the amount of shared string entries currently in the cache
Definition XLSharedStrings.hpp:135
XLSharedStrings & operator=(const XLSharedStrings &other)=default
String memory pool (Arena Allocator) with block recycling.
Definition XLStringArena.hpp:33
The XLXmlData class encapsulates the properties and behaviour of the .xml files in an ....
Definition XLXmlData.hpp:79
std::string xmlData(XLXmlSavingDeclaration savingDeclaration=XLXmlSavingDeclaration{}) const
Method for getting the XML data represented by the object.
Definition XLXmlFile.cpp:49
XLXmlFile()=default
Default constructor.
Definition IXLCellProvider.hpp:24
ankerl::unordered_dense::map< Key, Value, StringViewHash, std::equal_to<> > FlatHashMap
Definition XLSharedStrings.hpp:47
const XLSharedStrings XLSharedStringsDefaulted
Definition XLSharedStrings.cpp:27
std::reference_wrapper< const XLSharedStrings > XLSharedStringsRef
Definition XLSharedStrings.hpp:67
constexpr size_t XLMaxSharedStrings
Definition XLSharedStrings.hpp:49
Definition XLCellIterator.hpp:131
Definition XLSharedStrings.hpp:38
void is_transparent
Definition XLSharedStrings.hpp:39
auto operator()(std::string_view str) const noexcept -> uint64_t
Definition XLSharedStrings.hpp:40
Auto-managed malloc memory for Zero-Copy serialization.
Definition XLXmlData.hpp:37
Definition XLSharedStrings.hpp:52
XLStringArena arena
Definition XLSharedStrings.hpp:53
void clear()
Definition XLSharedStrings.hpp:58
std::unique_ptr< std::shared_mutex > mutex
Definition XLSharedStrings.hpp:56
std::vector< std::string_view > cache
Definition XLSharedStrings.hpp:54
FlatHashMap< std::string_view, int32_t > index
Definition XLSharedStrings.hpp:55