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"
35 using internal::DSCode;
42 :
public internal::DataSerializablePrimitive,
47 mutable int m_hashcode;
50 inline explicit CacheableString(DSCode type = DSCode::CacheableASCIIString)
51 : m_str(), m_type(type), m_hashcode(0) {}
57 : m_str(std::move(value)), m_hashcode(0) {
58 bool ascii = isAscii(m_str);
61 m_str.length() > std::numeric_limits<uint16_t>::max()
62 ? ascii ? DSCode::CacheableASCIIStringHuge
63 : DSCode::CacheableStringHuge
64 : ascii ? DSCode::CacheableASCIIString : DSCode::CacheableString;
72 void toData(
DataOutput& output)
const override;
76 DSCode getDsCode()
const override {
return m_type; }
96 inline static std::shared_ptr<CacheableString> create(
97 const std::string& value) {
98 return std::make_shared<CacheableString>(value);
101 inline static std::shared_ptr<CacheableString> create(std::string&& value) {
102 return std::make_shared<CacheableString>(std::move(value));
105 static std::shared_ptr<CacheableString> create(
const std::u16string& value);
107 static std::shared_ptr<CacheableString> create(std::u16string&& value);
109 static std::shared_ptr<CacheableString> create(
const std::u32string& value);
111 static std::shared_ptr<CacheableString> create(std::u32string&& value);
113 inline static std::shared_ptr<CacheableString> create(
114 const std::wstring& value) {
115 return std::make_shared<CacheableString>(
116 std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>,
wchar_t>{}
120 inline static std::shared_ptr<CacheableString> create(std::wstring&& value) {
121 return std::make_shared<CacheableString>(
122 std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>,
wchar_t>{}
123 .to_bytes(std::move(value)));
127 inline std::string::size_type
length()
const {
return m_str.length(); }
129 inline const std::string& value()
const {
return m_str; }
136 static bool isAscii(
const std::string& str);
141 return CacheableString::create(value);
146 std::u16string value) {
147 return CacheableString::create(value);
152 std::u32string value) {
153 return CacheableString::create(value);
158 return CacheableString::create(value);
163 return CacheableString::create(value);
168 return CacheableString::create(value);
173 return CacheableString::create(value);
178 return CacheableString::create(value);
183 return CacheableString::create(value);
188 return CacheableString::create(value);
193 return CacheableString::create(value);
198 return CacheableString::create(value);
203 const char16_t* value) {
204 return CacheableString::create(value);
209 return CacheableString::create(value);
214 return CacheableString::create(value);
219 return CacheableString::create(value);
224 const char32_t* value) {
225 return CacheableString::create(value);
230 return CacheableString::create(value);
234 return CacheableString::create(value);
239 return CacheableString::create(value);
244 const wchar_t* value) {
245 return CacheableString::create(value);
250 return CacheableString::create(value);
255 return CacheableString::create(value);
260 return CacheableString::create(value);
270 struct hash<apache::geode::client::CacheableString>
271 : hash<apache::geode::client::CacheableKey> {};
275 #endif // GEODE_CACHEABLESTRING_H_