SLikeNet 0.1.3

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
StringCompressor.h
Go to the documentation of this file.
1 /*
2 * Original work: Copyright (c) 2014, Oculus VR, Inc.
3 * All rights reserved.
4 *
5 * This source code is licensed under the BSD-style license found in the
6 * RakNet License.txt file in the licenses directory of this source tree. An additional grant
7 * of patent rights can be found in the RakNet Patents.txt file in the same directory.
8 *
9 *
10 * Modified work: Copyright (c) 2017, SLikeSoft UG (haftungsbeschränkt)
11 *
12 * This source code was modified by SLikeSoft. Modifications are licensed under the MIT-style
13 * license found in the license.txt file in the root directory of this source tree.
14 */
15
19
20
21
22 #ifndef __STRING_COMPRESSOR_H
23 #define __STRING_COMPRESSOR_H
24
25 #include "Export.h"
26 #include "DS_Map.h"
27 #include "memoryoverride.h"
28 #include "NativeTypes.h"
29
30 #ifdef _STD_STRING_COMPRESSOR
31 #include <string>
32 #endif
33
35 namespace SLNet
36 {
37 class BitStream;
38 class RakString;
39 };
40
41
42 namespace SLNet
43 {
45 class HuffmanEncodingTree;
46
51 class RAK_DLL_EXPORT StringCompressor
52 {
53 public:
54
55 // Destructor
56 ~StringCompressor();
57
61 static StringCompressor* Instance(void);
62
68 void GenerateTreeFromStrings( unsigned char *input, unsigned inputLength, uint8_t languageId );
69
75 void EncodeString( const char *input, int maxCharsToWrite, SLNet::BitStream *output, uint8_t languageId=0 );
76
82 bool DecodeString( char *output, int maxCharsToWrite, SLNet::BitStream *input, uint8_t languageId=0 );
83
84 #ifdef _CSTRING_COMPRESSOR
85 void EncodeString( const CString &input, int maxCharsToWrite, SLNet::BitStream *output, uint8_t languageId=0 );
86 bool DecodeString( CString &output, int maxCharsToWrite, SLNet::BitStream *input, uint8_t languageId=0 );
87 #endif
88
89 #ifdef _STD_STRING_COMPRESSOR
90 void EncodeString( const std::string &input, int maxCharsToWrite, SLNet::BitStream *output, uint8_t languageId=0 );
91 bool DecodeString( std::string *output, int maxCharsToWrite, SLNet::BitStream *input, uint8_t languageId=0 );
92 #endif
93
94 void EncodeString( const SLNet::RakString *input, int maxCharsToWrite, SLNet::BitStream *output, uint8_t languageId=0 );
95 bool DecodeString(SLNet::RakString *output, int maxCharsToWrite, SLNet::BitStream *input, uint8_t languageId=0 );
96
98 static void AddReference(void);
99
101 static void RemoveReference(void);
102
103 StringCompressor();
104
105 private:
106
108 static StringCompressor *instance;
109
111 DataStructures::Map<int, HuffmanEncodingTree *> huffmanEncodingTrees;
112
113 static int referenceCount;
114 };
115
116 } // namespace SLNet
117
118 #endif