20#ifndef GEODE_CACHEABLESTRING_H_
21#define GEODE_CACHEABLESTRING_H_
24#include "internal/DSCode.hpp"
25#include "internal/DataSerializablePrimitive.hpp"
26#include "internal/geode_globals.hpp"
32using internal::DSCode;
39 :
public internal::DataSerializablePrimitive,
44 mutable int m_hashcode;
47 inline explicit CacheableString(DSCode type = DSCode::CacheableASCIIString)
48 : m_str(), m_type(type), m_hashcode(0) {}
54 : m_str(std::move(value)), m_hashcode(0) {
55 bool ascii = isAscii(m_str);
57 m_type = m_str.length() > (std::numeric_limits<uint16_t>::max)()
58 ? ascii ? DSCode::CacheableASCIIStringHuge
59 : DSCode::CacheableStringHuge
60 : ascii ? DSCode::CacheableASCIIString
61 : DSCode::CacheableString;
69 void toData(
DataOutput& output)
const override;
73 DSCode getDsCode()
const override {
return m_type; }
93 inline static std::shared_ptr<CacheableString> create(
94 const std::string& value) {
95 return std::make_shared<CacheableString>(value);
98 inline static std::shared_ptr<CacheableString> create(std::string&& value) {
99 return std::make_shared<CacheableString>(std::move(value));
102 static std::shared_ptr<CacheableString> create(
const std::u16string& value);
104 static std::shared_ptr<CacheableString> create(std::u16string&& value);
106 static std::shared_ptr<CacheableString> create(
const std::u32string& value);
108 static std::shared_ptr<CacheableString> create(std::u32string&& value);
110 inline static std::shared_ptr<CacheableString> create(
111 const std::wstring& value) {
112 return std::make_shared<CacheableString>(
113 std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>,
wchar_t>{}
117 inline static std::shared_ptr<CacheableString> create(std::wstring&& value) {
118 return std::make_shared<CacheableString>(
119 std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>,
wchar_t>{}
120 .to_bytes(std::move(value)));
124 inline std::string::size_type
length()
const {
return m_str.length(); }
126 inline const std::string& value()
const {
return m_str; }
133 static bool isAscii(
const std::string& str);
138 return CacheableString::create(value);
143 std::u16string value) {
144 return CacheableString::create(value);
149 std::u32string value) {
150 return CacheableString::create(value);
155 return CacheableString::create(value);
160 return CacheableString::create(value);
165 return CacheableString::create(value);
170 return CacheableString::create(value);
175 return CacheableString::create(value);
180 return CacheableString::create(value);
185 return CacheableString::create(value);
190 return CacheableString::create(value);
195 return CacheableString::create(value);
200 const char16_t* value) {
201 return CacheableString::create(value);
206 return CacheableString::create(value);
211 return CacheableString::create(value);
216 return CacheableString::create(value);
221 const char32_t* value) {
222 return CacheableString::create(value);
227 return CacheableString::create(value);
231 return CacheableString::create(value);
236 return CacheableString::create(value);
241 const wchar_t* value) {
242 return CacheableString::create(value);
247 return CacheableString::create(value);
252 return CacheableString::create(value);
257 return CacheableString::create(value);
267struct hash<apache::geode::client::CacheableString>
268 : hash<apache::geode::client::CacheableKey> {};
Represents a cacheable key.
Definition: CacheableKey.hpp:40
static std::shared_ptr< CacheableKey > create(_T value)
Factory method that creates the key type that matches the type of value.
Implement a immutable C string wrapper that can serve as a distributable key object for caching as we...
Definition: CacheableString.hpp:40
virtual std::string toString() const override
Display this object as 'string', which depends on the implementation in the subclasses.
static std::shared_ptr< Serializable > createUTFDeserializable()
creation function for wide strings
virtual int32_t hashcode() const override
return the hashcode for this key.
static std::shared_ptr< Serializable > createUTFDeserializableHuge()
creation function for wide strings > 64K length in UTF8 encoding
static std::shared_ptr< Serializable > createDeserializableHuge()
creation function for strings > 64K length
std::string::size_type length() const
Return the length of the contained string.
Definition: CacheableString.hpp:124
static std::shared_ptr< Serializable > createDeserializable()
creation function for strings
virtual bool operator==(const CacheableKey &other) const override
return true if this key matches other.
virtual size_t objectSize() const override
return the size in bytes of the instance being serialized.
Provide operations for reading primitive data values, byte arrays, strings, Serializable objects from...
Definition: DataInput.hpp:59
Provide operations for writing primitive data values, byte arrays, strings, Serializable objects to a...
Definition: DataOutput.hpp:48
static std::shared_ptr< Serializable > create(_T value)
Factory method that creates the Serializable object that matches the type of value.