HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
UT_ZString.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_ZString.h (UT Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __UT_ZString__
12 #define __UT_ZString__
13 
14 #include "UT_StringHolder.h"
15 #include <SYS/SYS_Hash.h>
16 
17 /// Storage to hold compressed data.
18 ///
19 /// This class will take a buffer of data and compress it. You can access the
20 /// raw compressed data using @c compressedString(), or easily get a copy of
21 /// the uncompressed data by calling @c uncompress().
22 ///
23 /// Since @c UT_StringRef can hold binary data, this is a convenient way of
24 /// compressing data that has infrequent access (or possibly never accessed).
25 /// For example: @code
26 /// void *binary_data;
27 /// UT_ZString z(UT_StringRef((const char *)binary_data, binary_size));
28 /// @endcode
29 ///
30 /// @note BLOSC compression typically works best on larger buffers with numeric
31 /// data. It's faster than GZIP compression, but has worse compression.
33 {
34 public:
35  enum Style
36  {
39  BLOSC
40  };
41 
42  static const char *style(Style s);
43  static Style style(const char *s);
44 
45  UT_ZString() = default;
46  UT_ZString(const UT_StringRef &src, Style style=GZIP, int level=9)
47  {
48  compress(src, style, level);
49  }
50 
51  /// Store a string as compressed data, returning the compressed style. If
52  /// no compression is done, the returned style will be NONE.
53  ///
54  /// For GZIP compression, level can be between 1 and 9. 1 is faster, 9 is
55  /// better compression (but can be significantly slower).
56  Style compress(const UT_StringRef &s,
57  Style style=GZIP,
58  int level=1);
59 
60  /// Return the uncompressed contents
61  UT_StringHolder uncompress() const;
62 
63  /// @{
64  /// Member data access
65  const UT_StringHolder &compressedString() const { return myString; }
66  Style compressedStyle() const { return myStyle; }
67  exint originalSize() const { return mySize; }
68  /// @}
69 
70  /// @{
71  /// Standard "string" type operations.
72  int64 getMemoryUsage(bool inclusive) const
73  {
74  int64 mem = inclusive ? sizeof(*this) : 0;
75  return mem += myString.getMemoryUsage(false);
76  }
78  {
79  SYS_HashType h = myString.hash();
80  SYShashCombine(h, mySize);
81  SYShashCombine(h, myStyle);
82  return h;
83  }
84  friend std::size_t hash_value(const UT_ZString &s) { return s.hash(); }
85  bool operator==(const UT_ZString &s) const
86  {
87  return mySize == s.mySize
88  && myStyle == s.myStyle
89  && myString == s.myString;
90  }
91  /// @}
92 
93 private:
94  UT_StringHolder myString;
95  exint mySize = 0;
96  Style myStyle = NONE;
97 };
98 
99 #endif
GLint level
Definition: glcorearb.h:107
std::size_t SYS_HashType
Define the type for hash values.
Definition: SYS_Hash.h:19
Style compressedStyle() const
Definition: UT_ZString.h:66
#define UT_API
Definition: UT_API.h:12
SYS_HashType hash() const
Definition: UT_ZString.h:77
long long int64
Definition: SYS_Types.h:106
int64 exint
Definition: SYS_Types.h:115
const UT_StringHolder & compressedString() const
Definition: UT_ZString.h:65
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2001
bool operator==(const UT_ZString &s) const
Definition: UT_ZString.h:85
UT_ZString(const UT_StringRef &src, Style style=GZIP, int level=9)
Definition: UT_ZString.h:46
exint originalSize() const
Definition: UT_ZString.h:67
friend std::size_t hash_value(const UT_ZString &s)
Definition: UT_ZString.h:84
GLenum src
Definition: glcorearb.h:1792
int64 getMemoryUsage(bool inclusive) const
Definition: UT_ZString.h:72