HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_ZString Class Reference

#include <UT_ZString.h>

Public Types

enum  Style { NONE, GZIP, BLOSC }
 

Public Member Functions

 UT_ZString ()=default
 
 UT_ZString (const UT_StringRef &src, Style style=GZIP, int level=9)
 Take an uncompressed string and store the compressed result. More...
 
 UT_ZString (const UT_StringRef &src, Style style, const UT::source_is_compressed &, exint original_size, bool force_compressed=false)
 
void clear ()
 Clear storage and reset values. More...
 
Style compress (const UT_StringRef &s, Style style=GZIP, int level=1)
 
UT_StringHolder uncompress () const
 Return the uncompressed contents. More...
 
void setCompressedData (const UT_StringHolder &z, Style s, exint original_size, bool force_compressed=false)
 Set the class to hold an already compressed string. More...
 
SYS_FORCE_INLINE bool isstring () const
 The z-string has a string if the original size is non-zero. More...
 
SYS_FORCE_INLINE SYS_SAFE_BOOL operator bool () const
 Test whether the string is defined or not. More...
 
const UT_StringHoldercompressedString () const
 
Style compressedStyle () const
 
exint originalSize () const
 

Static Public Member Functions

static const char * style (Style s)
 Map the enum to a string. More...
 
static Style style (const char *s)
 Map the string to an enum value. More...
 
int64 getMemoryUsage (bool inclusive) const
 
SYS_HashType hash () const
 
bool operator== (const UT_ZString &s) const
 
std::size_t hash_value (const UT_ZString &s)
 

Detailed Description

Storage to hold compressed data.

This class will take a buffer of data and compress it. You can access the raw compressed data using compressedString(), or easily get a copy of the uncompressed data by calling uncompress().

Since UT_StringRef can hold binary data, this is a convenient way of compressing data that has infrequent access (or possibly never accessed). For example:

void *binary_data;
UT_ZString z(UT_StringRef((const char *)binary_data, binary_size));
Note
BLOSC compression typically works best on larger buffers with numeric data. It's faster than GZIP compression, but has worse compression.

Definition at line 38 of file UT_ZString.h.

Member Enumeration Documentation

Enumerator
NONE 
GZIP 
BLOSC 

Definition at line 41 of file UT_ZString.h.

Constructor & Destructor Documentation

UT_ZString::UT_ZString ( )
default
UT_ZString::UT_ZString ( const UT_StringRef src,
Style  style = GZIP,
int  level = 9 
)
inline

Take an uncompressed string and store the compressed result.

Definition at line 56 of file UT_ZString.h.

UT_ZString::UT_ZString ( const UT_StringRef src,
Style  style,
const UT::source_is_compressed ,
exint  original_size,
bool  force_compressed = false 
)
inline

Set the compressed data given the original style. If the original_size == src.length() then we assume the string is uncompressed (unless the force_compressed flag is true).

This matches the semantics of compress() (which stores the uncompressed string if the compression results in a larger buffer).

Definition at line 66 of file UT_ZString.h.

Member Function Documentation

void UT_ZString::clear ( void  )
inline

Clear storage and reset values.

Definition at line 75 of file UT_ZString.h.

Style UT_ZString::compress ( const UT_StringRef s,
Style  style = GZIP,
int  level = 1 
)

Store a string as compressed data, returning the compressed style. If no compression is done, the returned style will be NONE.

For GZIP compression, level can be between 1 and 9. 1 is faster, 9 is better compression (but can be significantly slower).

const UT_StringHolder& UT_ZString::compressedString ( ) const
inline

Member data access

Definition at line 101 of file UT_ZString.h.

Style UT_ZString::compressedStyle ( ) const
inline

Member data access

Definition at line 102 of file UT_ZString.h.

int64 UT_ZString::getMemoryUsage ( bool  inclusive) const
inline

Standard "string" type operations.

Definition at line 116 of file UT_ZString.h.

SYS_HashType UT_ZString::hash ( void  ) const
inline

Standard "string" type operations.

Definition at line 121 of file UT_ZString.h.

SYS_FORCE_INLINE bool UT_ZString::isstring ( ) const
inline

The z-string has a string if the original size is non-zero.

Definition at line 108 of file UT_ZString.h.

SYS_FORCE_INLINE SYS_SAFE_BOOL UT_ZString::operator bool ( ) const
inline

Test whether the string is defined or not.

Definition at line 112 of file UT_ZString.h.

bool UT_ZString::operator== ( const UT_ZString s) const
inline

Standard "string" type operations.

Definition at line 129 of file UT_ZString.h.

exint UT_ZString::originalSize ( ) const
inline

Member data access

Definition at line 103 of file UT_ZString.h.

void UT_ZString::setCompressedData ( const UT_StringHolder z,
Style  s,
exint  original_size,
bool  force_compressed = false 
)

Set the class to hold an already compressed string.

static const char* UT_ZString::style ( Style  s)
static

Map the enum to a string.

static Style UT_ZString::style ( const char *  s)
static

Map the string to an enum value.

UT_StringHolder UT_ZString::uncompress ( ) const

Return the uncompressed contents.

Friends And Related Function Documentation

std::size_t hash_value ( const UT_ZString s)
friend

Standard "string" type operations.

Definition at line 128 of file UT_ZString.h.


The documentation for this class was generated from the following file: