Warning, file /include/unicode/char16ptr.h was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007 #ifndef __CHAR16PTR_H__
0008 #define __CHAR16PTR_H__
0009
0010 #include "unicode/utypes.h"
0011
0012 #if U_SHOW_CPLUSPLUS_API
0013
0014 #include <cstddef>
0015
0016
0017
0018
0019
0020
0021
0022
0023 U_NAMESPACE_BEGIN
0024
0025
0026
0027
0028
0029
0030 #ifdef U_ALIASING_BARRIER
0031
0032 #elif (defined(__clang__) || defined(__GNUC__)) && U_PLATFORM != U_PF_BROWSER_NATIVE_CLIENT
0033 # define U_ALIASING_BARRIER(ptr) asm volatile("" : : "rm"(ptr) : "memory")
0034 #elif defined(U_IN_DOXYGEN)
0035 # define U_ALIASING_BARRIER(ptr)
0036 #endif
0037
0038
0039
0040
0041
0042 class U_COMMON_API Char16Ptr final {
0043 public:
0044
0045
0046
0047
0048
0049 inline Char16Ptr(char16_t *p);
0050 #if !U_CHAR16_IS_TYPEDEF
0051
0052
0053
0054
0055
0056 inline Char16Ptr(uint16_t *p);
0057 #endif
0058 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
0059
0060
0061
0062
0063
0064
0065 inline Char16Ptr(wchar_t *p);
0066 #endif
0067
0068
0069
0070
0071
0072 inline Char16Ptr(std::nullptr_t p);
0073
0074
0075
0076
0077 inline ~Char16Ptr();
0078
0079
0080
0081
0082
0083
0084 inline char16_t *get() const;
0085
0086
0087
0088
0089
0090 inline operator char16_t *() const { return get(); }
0091
0092 private:
0093 Char16Ptr() = delete;
0094
0095 #ifdef U_ALIASING_BARRIER
0096 template<typename T> static char16_t *cast(T *t) {
0097 U_ALIASING_BARRIER(t);
0098 return reinterpret_cast<char16_t *>(t);
0099 }
0100
0101 char16_t *p_;
0102 #else
0103 union {
0104 char16_t *cp;
0105 uint16_t *up;
0106 wchar_t *wp;
0107 } u_;
0108 #endif
0109 };
0110
0111
0112 #ifdef U_ALIASING_BARRIER
0113
0114 Char16Ptr::Char16Ptr(char16_t *p) : p_(p) {}
0115 #if !U_CHAR16_IS_TYPEDEF
0116 Char16Ptr::Char16Ptr(uint16_t *p) : p_(cast(p)) {}
0117 #endif
0118 #if U_SIZEOF_WCHAR_T==2
0119 Char16Ptr::Char16Ptr(wchar_t *p) : p_(cast(p)) {}
0120 #endif
0121 Char16Ptr::Char16Ptr(std::nullptr_t p) : p_(p) {}
0122 Char16Ptr::~Char16Ptr() {
0123 U_ALIASING_BARRIER(p_);
0124 }
0125
0126 char16_t *Char16Ptr::get() const { return p_; }
0127
0128 #else
0129
0130 Char16Ptr::Char16Ptr(char16_t *p) { u_.cp = p; }
0131 #if !U_CHAR16_IS_TYPEDEF
0132 Char16Ptr::Char16Ptr(uint16_t *p) { u_.up = p; }
0133 #endif
0134 #if U_SIZEOF_WCHAR_T==2
0135 Char16Ptr::Char16Ptr(wchar_t *p) { u_.wp = p; }
0136 #endif
0137 Char16Ptr::Char16Ptr(std::nullptr_t p) { u_.cp = p; }
0138 Char16Ptr::~Char16Ptr() {}
0139
0140 char16_t *Char16Ptr::get() const { return u_.cp; }
0141
0142 #endif
0143
0144
0145
0146
0147
0148
0149 class U_COMMON_API ConstChar16Ptr final {
0150 public:
0151
0152
0153
0154
0155
0156 inline ConstChar16Ptr(const char16_t *p);
0157 #if !U_CHAR16_IS_TYPEDEF
0158
0159
0160
0161
0162
0163 inline ConstChar16Ptr(const uint16_t *p);
0164 #endif
0165 #if U_SIZEOF_WCHAR_T==2 || defined(U_IN_DOXYGEN)
0166
0167
0168
0169
0170
0171
0172 inline ConstChar16Ptr(const wchar_t *p);
0173 #endif
0174
0175
0176
0177
0178
0179 inline ConstChar16Ptr(const std::nullptr_t p);
0180
0181
0182
0183
0184
0185 inline ~ConstChar16Ptr();
0186
0187
0188
0189
0190
0191
0192 inline const char16_t *get() const;
0193
0194
0195
0196
0197
0198 inline operator const char16_t *() const { return get(); }
0199
0200 private:
0201 ConstChar16Ptr() = delete;
0202
0203 #ifdef U_ALIASING_BARRIER
0204 template<typename T> static const char16_t *cast(const T *t) {
0205 U_ALIASING_BARRIER(t);
0206 return reinterpret_cast<const char16_t *>(t);
0207 }
0208
0209 const char16_t *p_;
0210 #else
0211 union {
0212 const char16_t *cp;
0213 const uint16_t *up;
0214 const wchar_t *wp;
0215 } u_;
0216 #endif
0217 };
0218
0219
0220 #ifdef U_ALIASING_BARRIER
0221
0222 ConstChar16Ptr::ConstChar16Ptr(const char16_t *p) : p_(p) {}
0223 #if !U_CHAR16_IS_TYPEDEF
0224 ConstChar16Ptr::ConstChar16Ptr(const uint16_t *p) : p_(cast(p)) {}
0225 #endif
0226 #if U_SIZEOF_WCHAR_T==2
0227 ConstChar16Ptr::ConstChar16Ptr(const wchar_t *p) : p_(cast(p)) {}
0228 #endif
0229 ConstChar16Ptr::ConstChar16Ptr(const std::nullptr_t p) : p_(p) {}
0230 ConstChar16Ptr::~ConstChar16Ptr() {
0231 U_ALIASING_BARRIER(p_);
0232 }
0233
0234 const char16_t *ConstChar16Ptr::get() const { return p_; }
0235
0236 #else
0237
0238 ConstChar16Ptr::ConstChar16Ptr(const char16_t *p) { u_.cp = p; }
0239 #if !U_CHAR16_IS_TYPEDEF
0240 ConstChar16Ptr::ConstChar16Ptr(const uint16_t *p) { u_.up = p; }
0241 #endif
0242 #if U_SIZEOF_WCHAR_T==2
0243 ConstChar16Ptr::ConstChar16Ptr(const wchar_t *p) { u_.wp = p; }
0244 #endif
0245 ConstChar16Ptr::ConstChar16Ptr(const std::nullptr_t p) { u_.cp = p; }
0246 ConstChar16Ptr::~ConstChar16Ptr() {}
0247
0248 const char16_t *ConstChar16Ptr::get() const { return u_.cp; }
0249
0250 #endif
0251
0252
0253
0254
0255
0256
0257
0258
0259
0260 inline const UChar *toUCharPtr(const char16_t *p) {
0261 #ifdef U_ALIASING_BARRIER
0262 U_ALIASING_BARRIER(p);
0263 #endif
0264 return reinterpret_cast<const UChar *>(p);
0265 }
0266
0267
0268
0269
0270
0271
0272
0273
0274 inline UChar *toUCharPtr(char16_t *p) {
0275 #ifdef U_ALIASING_BARRIER
0276 U_ALIASING_BARRIER(p);
0277 #endif
0278 return reinterpret_cast<UChar *>(p);
0279 }
0280
0281
0282
0283
0284
0285
0286
0287
0288 inline const OldUChar *toOldUCharPtr(const char16_t *p) {
0289 #ifdef U_ALIASING_BARRIER
0290 U_ALIASING_BARRIER(p);
0291 #endif
0292 return reinterpret_cast<const OldUChar *>(p);
0293 }
0294
0295
0296
0297
0298
0299
0300
0301
0302 inline OldUChar *toOldUCharPtr(char16_t *p) {
0303 #ifdef U_ALIASING_BARRIER
0304 U_ALIASING_BARRIER(p);
0305 #endif
0306 return reinterpret_cast<OldUChar *>(p);
0307 }
0308
0309 U_NAMESPACE_END
0310
0311 #endif
0312
0313 #endif