|
OpenXLSX 1.9.1
|
This class encapsulate the Excel concept of Shared Strings. In Excel, instead of havig individual strings in each cell, cells have a reference to an entry in the SharedStrings register. This results in smalle file sizes, as repeated strings are referenced easily. More...
#include <XLSharedStrings.hpp>
Public Member Functions | |
| XLSharedStrings ()=default | |
| XLSharedStrings (XLXmlData *xmlData, XLSharedStringsState *state) | |
| ~XLSharedStrings () | |
| Destructor. | |
| XLSharedStrings (const XLSharedStrings &other)=default | |
| XLSharedStrings (XLSharedStrings &&other) noexcept=default | |
| XLSharedStrings & | operator= (const XLSharedStrings &other)=default |
| XLSharedStrings & | operator= (XLSharedStrings &&other) noexcept=default |
| int32_t | stringCount () const |
| return the amount of shared string entries currently in the cache | |
| int32_t | getStringIndex (std::string_view str) const |
| bool | stringExists (std::string_view str) const |
| const char * | getString (int32_t index) const |
| std::string_view | getStringView (int32_t index) const |
| Get a string view from the list of shared strings. | |
| int32_t | appendString (std::string_view str) const |
| Append a new string to the list of shared strings. | |
| void | reserveStrings (size_t n) const |
| Pre-reserve capacity in the string cache and index for n strings. | |
| size_t | memoryUsageBytes () const noexcept |
| Approximate memory used by the cache and hash index structures. | |
| int32_t | getOrCreateStringIndex (std::string_view str) const |
| Get or create a string index in O(1) time. | |
| void | clearString (int32_t index) const |
| Clear the string at the given index. | |
| void | print (std::basic_ostream< char > &ostr) const |
| print the XML contents of the shared strings document using the underlying XMLNode print function | |
Public Member Functions inherited from OpenXLSX::XLXmlFile | |
| XLXmlFile ()=default | |
| Default constructor. | |
| std::string | xmlData (XLXmlSavingDeclaration savingDeclaration=XLXmlSavingDeclaration{}) const |
| Method for getting the XML data represented by the object. | |
| XLXmlFile (XLXmlData *xmlData) | |
| Constructor. Creates an object based on the xmlData input. | |
| XLXmlFile (const XLXmlFile &other)=default | |
| Copy constructor. Default implementation used. | |
| XLXmlFile (XLXmlFile &&other) noexcept=default | |
| Move constructor. Default implementation used. | |
| ~XLXmlFile ()=default | |
| Destructor. Default implementation used. | |
| bool | valid () const |
| check whether class is linked to a valid XML file | |
| XLXmlFile & | operator= (const XLXmlFile &other)=default |
| The copy assignment operator. The default implementation has been used. | |
| XLXmlFile & | operator= (XLXmlFile &&other) noexcept=default |
| The move assignment operator. The default implementation has been used. | |
| XLDocument & | parentDoc () |
| This function provides access to the parent XLDocument object. | |
| const XLDocument & | parentDoc () const |
| This function provides access to the parent XLDocument object. | |
| XMLDocument & | xmlDocument () |
| This function provides access to the underlying XMLDocument object. | |
| const XMLDocument & | xmlDocument () const |
| This function provides access to the underlying XMLDocument object. | |
| std::string | getXmlPath () const |
| Retrieve the path of the XML data in the .xlsx zip archive via m_xmlData->getXmlPath. | |
Protected Member Functions | |
| int32_t | rewriteXmlFromCache () |
| clear & rewrite the full shared strings XML from the shared strings cache | |
| void | rebuild (const std::vector< int32_t > &indexMap, int32_t newStringCount) |
| Rebuilds the shared string arena and cache using the provided index mapping, keeping only the used strings, and rewrites the XML. | |
Protected Member Functions inherited from OpenXLSX::XLXmlFile | |
| void | setXmlData (std::string_view xmlData) |
| Provide the XML data represented by the object. | |
| std::string | relationshipID () const |
| This function returns the relationship ID (the ID used in the XLRelationships objects) for the object. | |
Friends | |
| class | XLDocument |
Additional Inherited Members | |
Protected Attributes inherited from OpenXLSX::XLXmlFile | |
| XLXmlData * | m_xmlData {nullptr} |
This class encapsulate the Excel concept of Shared Strings. In Excel, instead of havig individual strings in each cell, cells have a reference to an entry in the SharedStrings register. This results in smalle file sizes, as repeated strings are referenced easily.
|
default |
|
explicit |
| xmlData | |
| state | Pointer to the shared strings state |
Constructs a new XLSharedStrings object. Only one (common) object is allowed per XLDocument instance. A filepath to the underlying XML file must be provided.
|
default |
Destructor.
|
default |
| other |
|
defaultnoexcept |
| other |
| int32_t XLSharedStrings::appendString | ( | std::string_view | str | ) | const |
Append a new string to the list of shared strings.
| str | The string to append. |
Append a string by creating a new node in the XML file and adding the string to it. The index to the shared string is returned
| void XLSharedStrings::clearString | ( | int32_t | index | ) | const |
Clear the string at the given index.
| index | The index to clear. |
Clear the string at the given index. This will affect the entire spreadsheet; everywhere the shared string is used, it will be erased.
| int32_t XLSharedStrings::getOrCreateStringIndex | ( | std::string_view | str | ) | const |
Get or create a string index in O(1) time.
| str | The string to look up or add. |
Get or create a string index in O(1) time. This is the optimized path for setting cell values. It avoids the separate stringExists() + getStringIndex()/appendString() pattern.
| const char * XLSharedStrings::getString | ( | int32_t | index | ) | const |
| index |
| int32_t XLSharedStrings::getStringIndex | ( | std::string_view | str | ) | const |
| str |
Look up a string index by the string content. If the string does not exist, the returned index is -1. Optimized to use O(1) hash lookup when available.
| std::string_view XLSharedStrings::getStringView | ( | int32_t | index | ) | const |
Get a string view from the list of shared strings.
| index | The index of the string to get. |
|
noexcept |
Approximate memory used by the cache and hash index structures.
Returns the approximate heap memory used by the string cache vector and the hash index buckets. Does not include the arena itself.
|
default |
| other |
|
defaultnoexcept |
| other |
| void XLSharedStrings::print | ( | std::basic_ostream< char > & | ostr | ) | const |
print the XML contents of the shared strings document using the underlying XMLNode print function
Print the underlying XML using pugixml::xml_node::print
|
protected |
Rebuilds the shared string arena and cache using the provided index mapping, keeping only the used strings, and rewrites the XML.
| indexMap | Mapping from old string indices to new string indices. |
| newStringCount | The number of used strings (including empty string at index 0). |
| void XLSharedStrings::reserveStrings | ( | size_t | n | ) | const |
Pre-reserve capacity in the string cache and index for n strings.
Call before bulk-inserting many strings to avoid incremental reallocation. Does not affect the pugi XML DOM.
| n | Number of strings to reserve capacity for. |
Pre-reserve capacity in the string cache vector and hash index for n strings. Avoids repeated incremental reallocations when bulk-inserting many strings.
|
protected |
clear & rewrite the full shared strings XML from the shared strings cache
|
inline |
return the amount of shared string entries currently in the cache
| bool XLSharedStrings::stringExists | ( | std::string_view | str | ) | const |
| str |
Check if a string exists in the shared strings table. O(1) with hash index.
|
friend |