1 #ifndef __UTILITIES_HPP__ 2 #define __UTILITIES_HPP__ 8 #include "system_detection.inl" 10 #if _MSC_VER > 0 && _MSC_VER < 1201 11 #pragma warning( disable: 4786 ) 14 #pragma warning( disable : 4996 ) 45 #if defined(_MSC_VER) || defined(WIN32) 46 #pragma warning( disable: 4251 ) 47 #pragma warning( disable: 4275 ) 48 #ifdef WINUX_DLL_EXPORTS 49 #define WINUX_DLL __declspec(dllexport) 51 #define WINUX_DLL __declspec(dllimport) 54 #define WINUX_API __stdcall 64 #define WINUX_FUNC_DECL(ret) WINUX_DLL ret WINUX_API 65 #define WINUX_FUNC_IMPL(ret) ret WINUX_API 68 #define countof(arr) ( sizeof(arr) / sizeof(arr[0]) ) 72 #if defined(_UNICODE) || defined(UNICODE) 73 #define $T(__x) L##__x 80 #define interface struct 85 #define DISABLE_OBJECT_COPY( clsname ) private:\ 86 clsname( clsname const & ) = delete;\ 87 clsname & operator = ( clsname const & ) = delete; 91 #define IF_PTR(ptr) if ( (ptr) != NULL ) (ptr) 93 #define ASSIGN_PTR(ptr) if ( (ptr) != NULL ) (*(ptr)) 101 #define DEFINE_ATTR_MEMBER( ty, name, memname ) \ 103 ty const & get##name() const { return this->memname; }\ 104 void set##name( ty const & v ) { this->memname = v; }\ 109 #define DEFINE_ATTR_MEMBER_READONLY( ty, name, memname ) \ 111 ty const & get##name() const { return this->memname; }\ 116 #define DEFINE_ATTR_MEMBER_VAL( ty, name, memname ) \ 118 ty get##name() const { return this->memname; }\ 119 void set##name( ty v ) { this->memname = v; }\ 124 #define DEFINE_ATTR_MEMBER_VAL_READONLY( ty, name, memname ) \ 126 ty get##name() const { return this->memname; }\ 131 #define DEFINE_ATTR_METHOD( ty, name, memname ) \ 133 ty const & get##name() const { return this->memname; }\ 134 void set##name( ty const & v ) { this->memname = v; } 137 #define DEFINE_ATTR_METHOD_READONLY( ty, name, memname ) \ 139 ty const & get##name() const { return this->memname; } 142 #define DEFINE_ATTR_METHOD_VAL( ty, name, memname ) \ 144 ty get##name() const { return this->memname; }\ 145 void set##name( ty v ) { this->memname = v; } 148 #define DEFINE_ATTR_METHOD_VAL_READONLY( ty, name, memname ) \ 150 ty get##name() const { return this->memname; } 153 #define DEFINE_ATTR( ty, name, getcode, setcode ) \ 155 ty const & get##name() const { getcode; }\ 156 void set##name( ty const & _VAL_ ) { setcode; } 159 #define DEFINE_ATTR_READONLY( ty, name, getcode ) \ 161 ty const & get##name() const { getcode; } 164 #define DEFINE_ATTR_VAL( ty, name, getcode, setcode ) \ 166 ty get##name() const { getcode; }\ 167 void set##name( ty _VAL_ ) { setcode; } 170 #define DEFINE_ATTR_VAL_READONLY( ty, name, getcode ) \ 172 ty get##name() const { getcode; } 175 #define DEFINE_FUNC_NEWINSTANCE( cls, ret, paramtypes, params ) \ 176 inline static ret * NewInstance##paramtypes \ 178 return new cls##params;\ 182 #define DEFINE_CUSTOM_EVENT(evtname, paramtypes, calledparams) \ 184 using evtname##HandlerFunction = std::function< void paramtypes >; \ 185 void on##evtname##Handler( evtname##HandlerFunction handler ) \ 187 this->_##evtname##Handler = handler; \ 190 evtname##HandlerFunction _##evtname##Handler; \ 191 virtual void on##evtname paramtypes \ 193 if ( this->_##evtname##Handler ) this->_##evtname##Handler calledparams; \ 197 #define DEFINE_CUSTOM_EVENT_RETURN_EX(ret, evtname, paramtypes) \ 199 using evtname##HandlerFunction = std::function< ret paramtypes >; \ 200 void on##evtname##Handler( evtname##HandlerFunction handler ) \ 202 this->_##evtname##Handler = handler; \ 205 evtname##HandlerFunction _##evtname##Handler; \ 206 virtual ret on##evtname paramtypes 210 #define GCC_VERSION_GREAT_THAN(Major,Minor,Patchlevel) \ 211 ( __GNUC__ > Major || ( __GNUC__ == Major && ( __GNUC_MINOR__ > Minor || ( __GNUC_MINOR__ == Minor && __GNUC_PATCHLEVEL__ > Patchlevel ) ) ) ) 235 typedef wchar_t wchar;
236 typedef unsigned long long uint64;
238 typedef long long int64;
242 #if defined(_UNICODE) || defined(UNICODE) 254 template <
typename _ChTy >
255 using XString = std::basic_string< _ChTy, std::char_traits<_ChTy>, std::allocator<_ChTy> >;
263 template <
typename _ChTy >
285 static constexpr
size_t const npos =
static_cast<size_t>(-1);
289 #include "literal_str.inl" 300 template <
typename _ChTy >
304 template < u
int64 n >
struct Bin0 306 enum : uint64 { val = (
Bin0< n / 8 >::val << 1 ) + n % 8 };
310 enum : uint64 { val = 0 };
314 #define BinVal(x) winux::Bin0<0##x>::val 317 template <
typename _Ty >
326 operator ParamTypeRef () {
return _r; }
330 template <
typename _Ty >
337 template <
size_t... _Index >
341 template <
size_t _Num,
typename _IdxSeq = IndexSequence<> >
344 template <
size_t _Num,
size_t... _Index >
347 template <
size_t... _Index >
354 #include "func_traits.inl" 357 #include "func_runable.inl" 360 #include "func_invoker.inl" 363 template <
typename _PfnType, _PfnType pfn >
366 template <
typename... _ArgType >
369 return (*pfn)( std::forward<_ArgType>(arg)... );
374 template <
typename _KTy,
typename _VTy,
typename _Pr,
typename _Alloc >
378 typedef std::map< _KTy, _VTy, _Pr, _Alloc >
MapType;
386 operator MapType & () {
return *_m; }
393 template <
typename _Ty,
typename _Alloc >
405 operator VectorType & () {
return *_a; }
412 template <
typename _KTy,
typename _VTy,
typename _Pr,
typename _Alloc >
419 template <
typename _Ty,
typename _Alloc >
426 template <
typename _TargetCls >
435 template <
typename... _ArgType >
438 this->_create( std::forward<_ArgType>(arg)... );
454 if ( &other !=
this )
461 #ifndef MOVE_SEMANTICS_DISABLED 470 if ( &other !=
this )
484 _TargetCls *
get()
const 489 _TargetCls * operator -> ()
493 _TargetCls
const * operator -> ()
const 498 operator _TargetCls & ()
502 operator _TargetCls
const & ()
const 507 operator bool()
const 509 return _p !=
nullptr;
518 delete (_TargetCls *)_p;
524 template <
typename... _ArgType >
525 void _create( _ArgType&&... arg )
528 _p =
new _TargetCls( std::forward<_ArgType>(arg)... );
535 template <
typename _TargetCls,
size_t _MembersSize >
541 this->_create<sizeof(_TargetCls)>();
544 template <
typename... _ArgType >
547 this->_create<sizeof(_TargetCls)>( std::forward<_ArgType>(arg)... );
557 this->_create<sizeof(_TargetCls)>();
558 *this->
get() = *other.
get();
563 if ( &other !=
this )
565 *this->
get() = *other.
get();
570 #ifndef MOVE_SEMANTICS_DISABLED 573 this->_create<sizeof(_TargetCls)>();
574 *this->
get() = std::move( *other.get() );
579 if ( &other !=
this )
581 *this->
get() = std::move( *other.get() );
589 return reinterpret_cast<_TargetCls*
>((
char*)_block);
591 _TargetCls *
get()
const 593 return reinterpret_cast<_TargetCls*
>((
char*)_block);
596 _TargetCls * operator -> ()
600 _TargetCls
const * operator -> ()
const 605 operator _TargetCls & ()
609 operator _TargetCls
const & ()
const 614 operator bool()
const 616 return _MembersSize >=
sizeof(_TargetCls);
623 this->
get()->~_TargetCls();
627 template <
size_t _TargetClsSize,
typename... _ArgType >
628 void _create( _ArgType&&... arg )
630 static_assert( !( _TargetClsSize > _MembersSize ),
"Error: sizeof(_TargetCls) > _MembersSize, _MembersSize is too small" );
631 new(_block) _TargetCls( std::forward<_ArgType>(arg)... );
634 char _block[_MembersSize];
639 template <
typename _ChTy,
typename = CharTypeConstrain<_ChTy> >
640 inline static size_t StrLen( _ChTy
const * str )
643 while ( str[len] ) len++;
648 template <
typename _Ty >
652 for (
int i = 0; i < sizeof(_Ty); ++i ) v2 |= ( ( v >> i * 8 ) & 0xFFU ) << (
sizeof(_Ty) - 1 - i ) * 8;
657 template <
typename _Ty >
660 for (
size_t k = 0; k < count; k++ )
690 template <
typename _ChTy >
693 size_t n = str1.length() < str2.length() ? str1.length() : str2.length();
694 for (
size_t i = 0; i < n; ++i )
696 int diff = str1[i] - str2[i];
697 if ( diff != 0 )
return diff;
699 return (
int)( str1.length() - str2.length() );
703 template <
typename _ChTy >
706 size_t n = str1.length() < str2.length() ? str1.length() : str2.length();
707 for (
size_t i = 0; i < n; ++i )
709 int diff = tolower(str1[i]) - tolower(str2[i]);
710 if ( diff != 0 )
return diff;
712 return (
int)( str1.length() - str2.length() );
716 template <
typename _Ty >
717 inline static bool ArrayLess( _Ty
const * arr1,
size_t count1, _Ty
const * arr2,
size_t count2 )
719 size_t n = count1 < count2 ? count1 : count2;
721 for ( i = 0; i < n; ++i )
723 if ( arr1[i] != arr2[i] )
break;
727 return arr1[i] < arr2[i];
731 return count1 < count2;
736 template <
typename _Ty >
737 inline static bool ArrayGreater( _Ty
const * arr1,
size_t count1, _Ty
const * arr2,
size_t count2 )
739 size_t n = count1 < count2 ? count1 : count2;
741 for ( i = 0; i < n; ++i )
743 if ( arr1[i] != arr2[i] )
break;
747 return arr1[i] > arr2[i];
751 return count1 > count2;
756 template <
typename _Ty >
757 inline static bool ArrayEqual( _Ty
const * arr1,
size_t count1, _Ty
const * arr2,
size_t count2 )
759 size_t n = count1 < count2 ? count1 : count2;
760 for (
size_t i = 0; i < n; ++i )
762 if ( arr1[i] != arr2[i] )
return false;
764 return count1 == count2;
768 template <
typename _Ty >
769 inline static bool ArrayLess( std::vector<_Ty>
const & arr1, std::vector<_Ty>
const & arr2 )
771 auto p1 = arr1.empty() ?
nullptr : &arr1.front();
772 auto p2 = arr2.empty() ?
nullptr : &arr2.front();
773 return ArrayLess( p1, arr1.size(), p2, arr2.size() );
777 template <
typename _Ty >
778 inline static bool ArrayGreater( std::vector<_Ty>
const & arr1, std::vector<_Ty>
const & arr2 )
780 auto p1 = arr1.empty() ?
nullptr : &arr1.front();
781 auto p2 = arr2.empty() ?
nullptr : &arr2.front();
782 return ArrayGreater( p1, arr1.size(), p2, arr2.size() );
786 template <
typename _Ty >
787 inline static bool ArrayEqual( std::vector<_Ty>
const & arr1, std::vector<_Ty>
const & arr2 )
789 auto p1 = arr1.empty() ?
nullptr : &arr1.front();
790 auto p2 = arr2.empty() ?
nullptr : &arr2.front();
791 return ArrayEqual( p1, arr1.size(), p2, arr2.size() );
806 template <
typename _MAP,
typename _KEY >
807 inline bool isset( _MAP
const & m, _KEY
const & k )
809 return m.find(k) != m.end();
813 template <
typename _Ty >
814 inline std::vector<_Ty>
ToArray( _Ty * arr, uint count )
816 return std::vector<_Ty>( arr, arr + count );
819 template <
typename _Ty, u
int _Count >
820 inline std::vector<_Ty>
ToArray( _Ty (&arr)[_Count] )
822 return std::vector<_Ty>( arr, arr + _Count );
828 template <
typename _Fx,
typename... _ArgType >
831 fn( std::forward<_ArgType>(arg)... );
847 Error(
int errType, AnsiString
const & errStr )
throw() : _errType(errType), _errStr(errStr) { }
850 virtual char const *
what()
const throw() {
return _errStr.c_str(); }
909 static void * Alloc(
size_t size );
910 static void * Realloc(
void * p,
size_t newSize );
911 static void Free(
void * p );
920 Buffer(
void const * buf,
size_t size,
bool isPeek =
false );
925 template <
typename _ChTy >
928 this->_copyConstruct( data.c_str(), data.size() *
sizeof(_ChTy), isPeek );
932 template <
typename _ChTy,
typename = CharTypeConstrain<_ChTy> >
933 Buffer( _ChTy
const * str,
size_t len = npos,
bool isPeek =
false )
935 this->_copyConstruct( str, ( len == npos ? StrLen<_ChTy>(str) *
sizeof(_ChTy) : len *
sizeof(_ChTy) ), isPeek );
947 #ifndef MOVE_SEMANTICS_DISABLED 964 void setBuf(
void const * buf,
size_t size,
size_t capacity,
bool isPeek );
971 void setBuf(
void const * buf,
size_t size,
bool isPeek ) { this->
setBuf( buf, size, size, isPeek ); }
974 void alloc(
size_t capacity,
bool setDataSize =
true );
979 void realloc(
size_t newCapacity );
984 bool peekCopy(
bool copyCapacity =
false );
987 void * detachBuf(
size_t * size =
nullptr );
996 template <
typename _Ty >
997 _Ty *
getBuf()
const {
return reinterpret_cast<_Ty *
>(_buf); }
1000 void *
get()
const {
return _buf; }
1003 template <
typename _Ty >
1004 _Ty *
get()
const {
return reinterpret_cast<_Ty *
>(_buf); }
1010 template <
typename _Ty >
1011 _Ty *
getAt( ssize_t i )
const {
return reinterpret_cast<_Ty *
>(_buf) + i; }
1028 size_t size()
const {
return _dataSize; }
1031 template <
typename _Ty >
1032 size_t size()
const {
return _dataSize /
sizeof(_Ty); }
1035 template <
typename _Ty >
1036 size_t count()
const {
return _dataSize /
sizeof(_Ty); }
1039 void _setSize(
size_t dataSize ) { _dataSize = ( dataSize > _capacity ? _capacity : dataSize ); }
1051 operator bool()
const {
return _buf != NULL; }
1054 template <
typename _ChTy >
1058 AnsiString
toAnsi()
const {
return this->toString<AnsiString::value_type>(); }
1061 UnicodeString
toUnicode()
const {
return this->toString<UnicodeString::value_type>(); }
1067 bool operator != (
Buffer const & other )
const {
return !this->operator == (other); }
1068 bool operator >= (
Buffer const & other )
const {
return !this->operator < (other); }
1069 bool operator <= (
Buffer const & other )
const {
return !this->operator > (other); }
1075 void _copyConstruct(
void const * buf,
size_t size,
bool isPeek );
1086 template <
typename _PodType >
1092 if ( size > 0 ) this->alloc(size);
1096 _PodType *
get()
const {
return reinterpret_cast<_PodType *
>(_buf); }
1098 _PodType * operator -> () {
return reinterpret_cast<_PodType *
>(_buf); }
1099 _PodType
const * operator -> ()
const {
return reinterpret_cast<_PodType *
>(_buf); }
1113 #ifndef MOVE_SEMANTICS_DISABLED 1128 void append(
void const * data,
size_t size );
1134 template <
typename _ChTy >
1138 template <
typename _ChTy,
typename = CharTypeConstrain<_ChTy> >
1141 this->append( (
void const *)str, ( len == npos ? StrLen<_ChTy>(str) : len ) *
sizeof(_ChTy) );
1145 template <
typename _PodType >
1146 void appendType( _PodType
const & data,
size_t size =
sizeof(_PodType) ) { this->append( (
void const *)&data, size ); }
1149 template <
typename _PodType,
size_t _Count >
1150 void appendType( _PodType
const (&data)[_Count] ) { this->append( (
void const *)&data, _Count *
sizeof(data[0]) ); }
1153 template <
typename _PodType >
1156 for (
auto const & e : list )
1158 this->appendType<_PodType>( e,
sizeof(e) );
1163 void erase(
size_t start,
size_t count = (
size_t)-1 );
1196 MixedError(
int errType, AnsiString
const & errStr )
throw() :
Error( errType, errStr ) { }
1203 $a( std::initializer_list<Mixed> && list ) : _list(
std::move(list) )
1211 std::initializer_list< std::pair< Mixed, Mixed > >
_list;
1212 $c( std::initializer_list< std::pair< Mixed, Mixed > > && list ) : _list(
std::move(list) )
1221 bool operator () (
Mixed const & v1,
Mixed const & v2 )
const;
1229 bool operator () (
Mixed const & v1,
Mixed const & v2 )
const;
1240 explicit Collection(
bool caseInsensitive =
false );
1250 template <
typename _KTy,
typename _VTy,
typename _Pr,
typename _Alloc >
1251 explicit Collection( std::map< _KTy, _VTy, _Pr, _Alloc >
const & m,
bool caseInsensitive =
false )
1254 this->assign< _KTy, _VTy, _Pr, _Alloc >( m, caseInsensitive );
1258 template <
typename _KTy,
typename _VTy,
size_t _Count >
1259 explicit Collection( std::pair< _KTy, _VTy > (&pairs)[_Count],
bool caseInsensitive =
false )
1262 this->assign< _KTy, _VTy, _Count >( pairs, caseInsensitive );
1266 explicit Collection(
$c && coll,
bool caseInsensitive =
false );
1269 explicit Collection(
Mixed const & coll,
bool caseInsensitive =
false );
1272 void create(
bool caseInsensitive =
false );
1281 template <
typename _Ty,
typename _Alloc >
1282 size_t getKeys( std::vector< _Ty, _Alloc > * keys )
const 1284 for (
auto it = this->_pKeysArr->begin(); it != this->_pKeysArr->end(); ++it )
1285 keys->push_back(*it);
1286 return keys->size();
1290 template <
typename _KTy,
typename _VTy,
typename _Pr,
typename _Alloc >
1291 size_t getMap( std::map< _KTy, _VTy, _Pr, _Alloc > * m )
const;
1294 bool isEmpty()
const {
return this->getCount() == 0; }
1297 size_t getCount()
const {
return this->_pKeysArr != NULL ? this->_pKeysArr->size() : 0; }
1303 template <
typename _ChTy >
1304 Mixed & operator [] ( _ChTy
const * k ) {
return this->operator [] (
Mixed(k) ); }
1315 MixedMixedPair & getPair(
size_t i );
1317 MixedMixedPair
const & getPair(
size_t i )
const;
1320 void setPair(
size_t i,
Mixed const & k,
Mixed const & v );
1323 void addPair(
Mixed const & k,
Mixed const & v );
1329 void del(
Mixed const & k );
1332 bool has(
Mixed const & k )
const;
1342 MixedMixedMap &
refMap() {
return *this->_pMap; }
1343 MixedMixedMap
const &
refMap()
const {
return *this->_pMap; }
1345 MixedMixedMapI &
refMapI() {
return *this->_pMapI; }
1346 MixedMixedMapI
const &
refMapI()
const {
return *this->_pMapI; }
1349 template <
typename _KTy,
typename _VTy,
typename _Pr,
typename _Alloc >
1350 void assign( std::map< _KTy, _VTy, _Pr, _Alloc >
const & m,
bool caseInsensitive =
false )
1353 &Collection::_fxMap<MixedMixedMap, _KTy, _VTy, _Pr, _Alloc>,
1354 &Collection::_fxMap<MixedMixedMapI, _KTy, _VTy, _Pr, _Alloc>,
1361 template <
typename _KTy,
typename _VTy,
size_t _Count >
1362 void assign( std::pair< _KTy, _VTy > (&pairs)[_Count],
bool caseInsensitive =
false )
1365 &Collection::_fxPairs<MixedMixedMap, _KTy, _VTy, _Count>,
1366 &Collection::_fxPairs<MixedMixedMapI, _KTy, _VTy, _Count>,
1373 void assign(
$c && coll,
bool caseInsensitive =
false )
1376 &Collection::_fxC<MixedMixedMap>,
1377 &Collection::_fxC<MixedMixedMapI>,
1387 memset(
this, 0,
sizeof(*
this) );
1390 void _copyConstruct( Collection
const & other );
1393 bool _addUniqueKey(
Mixed const & k );
1395 template <
typename _MAP,
typename _KTy,
typename _VTy,
typename _Pr,
typename _Alloc >
1396 void _fxMap( _MAP * pMap, std::map< _KTy, _VTy, _Pr, _Alloc >
const & m )
1398 for (
auto it = m.begin(); it != m.end(); ++it )
1400 this->_addUniqueKey(it->first);
1401 (*pMap)[it->first] = it->second;
1405 template <
typename _MAP,
typename _KTy,
typename _VTy,
size_t _Count >
1406 void _fxPairs( _MAP * pMap, std::pair< _KTy, _VTy > (&pairs)[_Count] )
1408 for (
size_t i = 0; i < _Count; ++i )
1410 this->_addUniqueKey(pairs[i].first);
1411 (*pMap)[pairs[i].first] = pairs[i].second;
1415 template <
typename _MAP >
1416 void _fxC( _MAP * pMap,
$c && coll );
1418 template <
typename _Fx1,
typename _Fx2,
typename _Ty >
1419 void _implAssign( _Fx1 fn, _Fx2 fnI, _Ty && m,
bool caseInsensitive );
1422 MixedArray * _pKeysArr;
1428 bool _caseInsensitive;
1443 #ifdef MIXED_REF_NO_EXCEPTION 1444 #define MIXED_REF_TYPE_METHOD( mt, ty, memb, funcname )\ 1445 ty& ref##funcname() { return memb; }\ 1446 ty const& ref##funcname() const { return memb; } 1447 #define MIXED_REF_TYPE_METHOD_OUTER( mt, ty, memb, funcname )\ 1448 template<> inline ty& Mixed::ref<ty>() { return memb; }\ 1449 template<> inline ty const& Mixed::ref<ty>() const { return memb; } 1451 #define MIXED_REF_TYPE_METHOD( mt, ty, memb, funcname )\ 1452 ty& ref##funcname() { if ( this->_type != mt ) throw MixedError( MixedError::meUnexpectedType, "ref"#funcname"(): " + TypeStringA(*this) + " can not be referenced as a "#mt ); return memb; }\ 1453 ty const& ref##funcname() const { if ( this->_type != mt ) throw MixedError( MixedError::meUnexpectedType, "ref"#funcname"(): " + TypeStringA(*this) + " can not be referenced as a "#mt ); return memb; } 1454 #define MIXED_REF_TYPE_METHOD_OUTER( mt, ty, memb, funcname )\ 1455 template<> inline ty& Mixed::ref<ty>() { if ( this->_type != mt ) throw MixedError( MixedError::meUnexpectedType, "ref<"#ty">(): " + TypeStringA(*this) + " can not be referenced as a "#mt ); return memb; }\ 1456 template<> inline ty const& Mixed::ref<ty>() const { if ( this->_type != mt ) throw MixedError( MixedError::meUnexpectedType, "ref<"#ty">(): " + TypeStringA(*this) + " can not be referenced as a "#mt ); return memb; } 1459 #define MIXED_TYPE_ENUM_ITEM( item, nouse1, nouse2, nouse3 ) item, 1460 #define MIXED_TYPE_ENUM_ITEMSTRINGA( item, nouse1, nouse2, nouse3 ) #item, 1461 #define MIXED_TYPE_ENUM_ITEMSTRINGW( item, nouse1, nouse2, nouse3 ) L ## #item, 1463 #define MIXED_TYPE_LIST(funcmacro) \ 1464 funcmacro( MT_BOOLEAN, bool, _boolVal, Bool ) \ 1465 funcmacro( MT_CHAR, char, _chVal, Char ) \ 1466 funcmacro( MT_BYTE, byte, _btVal, Byte ) \ 1467 funcmacro( MT_SHORT, short, _shVal, Short ) \ 1468 funcmacro( MT_USHORT, ushort, _ushVal, UShort ) \ 1469 funcmacro( MT_INT, int, _iVal, Int ) \ 1470 funcmacro( MT_UINT, uint, _uiVal, UInt ) \ 1471 funcmacro( MT_LONG, long, _lVal, Long ) \ 1472 funcmacro( MT_ULONG, ulong, _ulVal, ULong ) \ 1473 funcmacro( MT_INT64, int64, _i64Val, Int64 ) \ 1474 funcmacro( MT_UINT64, uint64, _ui64Val, UInt64 ) \ 1475 funcmacro( MT_FLOAT, float, _fltVal, Float ) \ 1476 funcmacro( MT_DOUBLE, double, _dblVal, Double ) \ 1477 funcmacro( MT_ANSI, AnsiString, *_pStr, Ansi ) \ 1478 funcmacro( MT_UNICODE, UnicodeString, *_pWStr, Unicode ) \ 1479 funcmacro( MT_BINARY, Buffer, *_pBuf, Buffer ) \ 1480 funcmacro( MT_ARRAY, MixedArray, *_pArr, Array ) \ 1481 funcmacro( MT_COLLECTION, Collection, *_pColl, Collection ) 1493 UnicodeString * _pWStr;
1496 Collection * _pColl;
1516 Mixed( std::nullptr_t );
1517 Mixed(
void const * ) =
delete;
1520 Mixed(
bool boolVal );
1521 Mixed(
char chVal );
1522 Mixed( byte btVal );
1523 Mixed(
short shVal );
1524 Mixed( ushort ushVal );
1526 Mixed( uint uiVal );
1528 Mixed( ulong ulVal );
1529 Mixed(
float fltVal );
1530 Mixed( int64 i64Val );
1531 Mixed( uint64 ui64Val );
1532 Mixed(
double dblVal );
1535 Mixed( AnsiString
const & str );
1536 Mixed( UnicodeString
const & str );
1537 Mixed( AnsiString && str );
1538 Mixed( UnicodeString && str );
1539 Mixed(
char const * str,
size_t len = npos );
1540 Mixed( wchar
const * str,
size_t len = npos );
1543 Mixed(
Buffer const & buf );
1544 Mixed(
void const * binaryData,
size_t size,
bool isPeek =
false );
1550 Mixed( Mixed * arr,
size_t count );
1553 template <
typename _Ty,
typename _Alloc >
1554 Mixed( std::vector< _Ty, _Alloc >
const & arr )
1557 this->assign< _Ty, _Alloc >(arr);
1561 template <
typename _Ty,
size_t _Count >
1562 Mixed( _Ty (&arr)[_Count] )
1565 this->assign< _Ty, _Count >(arr);
1569 Mixed( std::initializer_list<Mixed> && list );
1576 template <
typename _KTy,
typename _VTy,
typename _Pr,
typename _Alloc >
1577 Mixed( std::map< _KTy, _VTy, _Pr, _Alloc >
const & m,
bool caseInsensitive =
false )
1580 this->assign< _KTy, _VTy, _Pr, _Alloc >( m, caseInsensitive );
1584 template <
typename _KTy,
typename _VTy,
size_t _Count >
1585 Mixed( std::pair< _KTy, _VTy > (&pairs)[_Count],
bool caseInsensitive =
false )
1588 this->assign< _KTy, _VTy, _Count >( pairs, caseInsensitive );
1592 Mixed(
$c && coll,
bool caseInsensitive =
false );
1595 Mixed( Collection
const & coll,
bool caseInsensitive =
false );
1599 Mixed( Mixed
const & other );
1601 Mixed & operator = ( Mixed
const & other );
1604 Mixed( Mixed && other );
1606 Mixed & operator = ( Mixed && other );
1615 MixedType type()
const {
return this->_type; }
1618 template <
typename _ChTy >
1620 template <
typename _ChTy >
1623 template <
typename _Ty >
1625 template <
typename _Ty >
1626 _Ty
const & ref()
const;
1632 operator
bool() const;
1634 operator byte() const;
1635 operator
short() const;
1636 operator ushort() const;
1637 operator
int() const;
1638 operator uint() const;
1639 operator
long() const;
1640 operator ulong() const;
1641 operator
float() const;
1642 operator int64() const;
1643 operator uint64() const;
1644 operator
double() const;
1645 operator AnsiString() const;
1646 operator UnicodeString() const;
1648 operator MixedArray() const;
1649 operator Collection() const;
1651 bool toBool()
const {
return this->
operator bool(); }
1652 char toChar()
const;
1654 short toShort()
const {
return this->
operator short(); }
1656 int toInt()
const {
return this->
operator int(); }
1658 long toLong()
const {
return this->
operator long(); }
1660 float toFloat()
const {
return this->
operator float(); }
1661 int64 toInt64()
const {
return this->
operator winux::int64(); }
1662 uint64 toUInt64()
const {
return this->
operator winux::uint64(); }
1663 double toDouble()
const {
return this->
operator double(); }
1664 template <
typename _ChTy >
1666 AnsiString toAnsi()
const {
return this->
operator AnsiString(); }
1668 Buffer toBuffer()
const {
return this->
operator Buffer(); }
1669 MixedArray toArray()
const {
return this->
operator MixedArray(); }
1670 Collection toCollection()
const {
return this->
operator Collection(); }
1671 template <
typename _Ty >
1675 bool operator == ( Mixed
const & other )
const;
1676 bool operator < ( Mixed
const & other )
const;
1677 bool operator > ( Mixed
const & other )
const;
1678 bool operator != ( Mixed
const & other )
const {
return !this->operator == (other); }
1679 bool operator >= ( Mixed
const & other )
const {
return !this->operator < (other); }
1680 bool operator <= ( Mixed
const & other )
const {
return !this->operator > (other); }
1683 bool isNull()
const {
return this->_type == MT_NULL; }
1684 bool isNumeric()
const {
return this->_type > MT_NULL && this->_type < MT_ANSI; }
1685 bool isInteger()
const {
return this->isNumeric() && this->_type != MT_FLOAT && this->_type != MT_DOUBLE; }
1686 bool isString()
const {
return this->_type == MT_ANSI || this->_type == MT_UNICODE; }
1687 bool isSequence()
const {
return this->_type >= MT_ANSI && this->_type <= MT_BINARY; }
1688 bool isAnsi()
const {
return this->_type == MT_ANSI; }
1689 bool isUnicode()
const {
return this->_type == MT_UNICODE; }
1690 bool isBinary()
const {
return this->_type == MT_BINARY; }
1691 bool isContainer()
const {
return this->_type == MT_ARRAY || this->_type == MT_COLLECTION; }
1692 bool isArray()
const {
return this->_type == MT_ARRAY; }
1693 bool isCollection()
const {
return this->_type == MT_COLLECTION; }
1697 template <
typename _ChTy >
1698 Mixed & createString();
1700 template <
typename _ChTy >
1703 template <
typename _ChTy >
1707 Mixed & createAnsi( AnsiString
const & str );
1711 Mixed & createUnicode( UnicodeString
const & str );
1715 Mixed & createBuffer(
size_t size = 0 );
1717 Mixed & createArray(
size_t count = 0 );
1719 Mixed & createCollection(
bool caseInsensitive =
false );
1723 void alloc(
size_t size,
bool setDataSize =
true );
1728 bool peekCopy(
bool copyCapacity =
false );
1733 void * getBuf()
const;
1739 template <
typename _Ty,
typename _Alloc >
1740 size_t getArray( std::vector< _Ty, _Alloc > * arr )
const 1743 for (
auto it = this->_pArr->begin(); it != this->_pArr->end(); ++it )
1744 arr->push_back(*it);
1751 template <
typename _KTy,
typename _Alloc >
1752 size_t getKeys( std::vector< _KTy, _Alloc > * keys )
const 1755 return this->_pColl->getKeys(keys);
1761 template <
typename _KTy,
typename _VTy,
typename _Pr,
typename _Alloc >
1762 size_t getMap( std::map< _KTy, _VTy, _Pr, _Alloc > * m )
const 1765 return this->_pColl->getMap(m);
1771 bool isEmpty()
const 1773 switch ( this->_type )
1776 return this->_pStr->empty();
1778 return this->_pWStr->empty();
1780 return this->_pBuf->getSize() == 0;
1782 return this->_pArr->empty();
1784 return this->_pColl->isEmpty();
1793 size_t getSize()
const 1795 switch ( this->_type )
1798 return this->_pStr->size();
1800 return this->_pWStr->size();
1802 return this->_pBuf->getSize();
1811 size_t getCount()
const 1813 switch ( this->_type )
1816 return this->_pArr->size();
1818 return this->_pColl->getCount();
1825 Mixed & operator [] ( Mixed
const & k );
1827 Mixed
const & operator [] ( Mixed
const & k )
const;
1829 template <
typename _ChTy >
1830 Mixed & operator [] ( _ChTy
const * k ) {
return this->operator [] ( Mixed(k) ); }
1832 template <
typename _ChTy >
1833 Mixed
const & operator [] ( _ChTy
const * k )
const {
return this->operator [] ( Mixed(k) ); }
1836 template <
typename _Ty >
1837 _Ty
get( Mixed
const & k, Mixed
const & defval =
mxNull )
const {
return this->
get( k, defval ).to<_Ty>(); }
1840 Mixed
const &
get( Mixed
const & k, Mixed
const & defval =
mxNull )
const;
1843 MixedMixedPair & getPair(
size_t i );
1845 MixedMixedPair
const & getPair(
size_t i )
const;
1848 Mixed & setPair(
size_t i, Mixed
const & k, Mixed
const & v );
1856 if ( _mx->isCollection() ) _mx->_pColl->addPair( k, v );
1861 if ( _mx->isCollection() ) _mx->_pColl->addPair( k, std::move(v) );
1864 operator Mixed & () {
return *_mx; }
1875 if ( this->_type != MT_COLLECTION ) this->createCollection(caseInsensitive);
1880 Mixed & addPair( Mixed
const & k, Mixed
const & v );
1888 if ( _mx->isArray() ) _mx->_pArr->push_back(v);
1893 if ( _mx->isArray() ) _mx->_pArr->push_back( std::move(v) );
1896 operator Mixed & () {
return *_mx; }
1907 if ( this->_type != MT_ARRAY ) this->createArray();
1912 size_t add( Mixed
const & v );
1915 size_t add( Mixed && v );
1918 size_t addUnique( Mixed
const & v );
1921 size_t addUnique( Mixed && v );
1924 void del( Mixed
const & k );
1929 bool has( Mixed
const & ek )
const;
1934 Mixed & merge( Mixed
const & v );
1941 void assign(
bool boolVal );
1942 void assign(
char chVal );
1943 void assign( byte btVal );
1944 void assign(
short shVal );
1945 void assign( ushort ushVal );
1946 void assign(
int iVal );
1947 void assign( uint uiVal );
1948 void assign(
long lVal );
1949 void assign( ulong ulVal );
1950 void assign(
float fltVal );
1951 void assign( int64 i64Val );
1952 void assign( uint64 ui64Val );
1953 void assign(
double dblVal );
1956 void assign( AnsiString
const & str );
1957 void assign( UnicodeString
const & str );
1958 void assign( AnsiString && str );
1959 void assign( UnicodeString && str );
1960 void assign(
char const * str,
size_t len = npos );
1961 void assign( wchar
const * str,
size_t len = npos );
1964 void assign(
Buffer const & buf );
1965 void assign(
void const * binaryData,
size_t size,
bool isPeek =
false );
1966 void assign(
Buffer && buf );
1971 template <
typename _Ty,
typename _Alloc >
1972 void assign( std::vector< _Ty, _Alloc >
const & arr )
1974 if ( this->_type == MT_ARRAY )
1976 this->_pArr->clear();
1977 for (
size_t i = 0; i < arr.size(); ++i )
1979 this->_pArr->push_back(arr[i]);
1985 this->_type = MT_ARRAY;
1987 for (
size_t i = 0; i < arr.size(); ++i )
1989 this->_pArr->at(i) = arr[i];
1995 template <
typename _Ty,
size_t _Count >
1996 void assign( _Ty (&arr)[_Count] )
1998 if ( this->_type == MT_ARRAY )
2000 this->_pArr->clear();
2001 for (
size_t i = 0; i < _Count; ++i )
2003 this->_pArr->push_back(arr[i]);
2009 this->_type = MT_ARRAY;
2011 for (
size_t i = 0; i < _Count; ++i )
2013 this->_pArr->at(i) = arr[i];
2019 void assign( Mixed * arr,
size_t count );
2022 void assign( std::initializer_list<Mixed> && list );
2025 void assign(
$a && arr );
2029 template <
typename _KTy,
typename _VTy,
typename _Pr,
typename _Alloc >
2030 void assign( std::map< _KTy, _VTy, _Pr, _Alloc >
const & m,
bool caseInsensitive =
false )
2032 if ( this->_type == MT_COLLECTION )
2034 this->_pColl->assign( m, caseInsensitive );
2039 this->_type = MT_COLLECTION;
2040 this->_pColl =
new Collection( m, caseInsensitive );
2045 template <
typename _KTy,
typename _VTy,
size_t _Count >
2046 void assign( std::pair< _KTy, _VTy > (&pairs)[_Count],
bool caseInsensitive =
false )
2048 if ( this->_type == MT_COLLECTION )
2050 this->_pColl->assign( pairs, caseInsensitive );
2055 this->_type = MT_COLLECTION;
2056 this->_pColl =
new Collection( pairs, caseInsensitive );
2061 void assign(
$c && coll,
bool caseInsensitive =
false );
2064 void assign( Collection
const & coll,
bool caseInsensitive =
false );
2067 String myJson(
bool autoKeyQuotes =
true, String
const & spacer = $T(
""), String
const & newline = $T(
"") )
const;
2068 String json()
const;
2069 Mixed & json( String
const & jsonStr );
2073 void _zeroInit() { memset(
this, 0,
sizeof(Mixed) ); }
2075 void _copyConstruct( Mixed
const & other );
2077 void _copyAssignment( Mixed
const & other );
2084 return this->refAnsi();
2090 return this->refAnsi();
2096 return this->refUnicode();
2102 return this->refUnicode();
2110 inline
XString<
char> Mixed::toString<
char>()
const {
return this->toAnsi(); }
2117 inline Mixed Mixed::to<Mixed>()
const {
return *
this; }
2119 inline bool Mixed::to<bool>()
const {
return this->
operator bool(); }
2121 inline char Mixed::to<char>()
const {
return this->toChar(); }
2123 inline byte Mixed::to<byte>()
const {
return this->
operator winux::byte(); }
2125 inline short Mixed::to<short>()
const {
return this->
operator short(); }
2127 inline ushort Mixed::to<ushort>()
const {
return this->
operator winux::ushort(); }
2129 inline int Mixed::to<int>()
const {
return this->
operator int(); }
2131 inline uint Mixed::to<uint>()
const {
return this->
operator winux::uint(); }
2133 inline long Mixed::to<long>()
const {
return this->
operator long(); }
2135 inline ulong Mixed::to<ulong>()
const {
return this->
operator winux::ulong(); }
2137 inline float Mixed::to<float>()
const {
return this->
operator float(); }
2139 inline int64 Mixed::to<int64>()
const {
return this->
operator winux::int64(); }
2141 inline uint64 Mixed::to<uint64>()
const {
return this->
operator winux::uint64(); }
2143 inline double Mixed::to<double>()
const {
return this->
operator double(); }
2145 inline AnsiString Mixed::to<AnsiString>()
const {
return this->
operator AnsiString(); }
2147 inline UnicodeString Mixed::to<UnicodeString>()
const {
return this->
operator UnicodeString(); }
2149 inline Buffer Mixed::to<Buffer>()
const {
return this->
operator Buffer(); }
2151 inline MixedArray Mixed::to<MixedArray>()
const {
return this->
operator MixedArray(); }
2153 inline Collection Mixed::to<Collection>()
const {
return this->
operator Collection(); }
2157 inline Mixed & Mixed::createString<char>() {
return this->createAnsi(); }
2160 inline Mixed & Mixed::createString<wchar>() {
return this->createUnicode(); }
2164 inline Mixed & Mixed::createString<char>(
XString<char> const & str ) {
return this->createAnsi(str); }
2167 inline Mixed & Mixed::createString<wchar>(
XString<wchar> const & str ) {
return this->createUnicode(str); }
2171 inline Mixed & Mixed::createString<char>(
XString<char> && str ) {
return this->createAnsi( std::move(str) ); }
2174 inline Mixed & Mixed::createString<wchar>(
XString<wchar> && str ) {
return this->createUnicode( std::move(str) ); }
2177 template <
typename _KTy,
typename _VTy,
typename _Pr,
typename _Alloc >
2180 if ( this->_caseInsensitive )
2182 for (
auto it = this->_pMapI->begin(); it != this->_pMapI->end(); ++it )
2183 (*m)[(_KTy)it->first] = (_VTy)it->second;
2188 for (
auto it = this->_pMap->begin(); it != this->_pMap->end(); ++it )
2189 (*m)[(_KTy)it->first] = (_VTy)it->second;
2194 inline Mixed
const &
Collection::get( Mixed
const & k, Mixed
const & defval = mxNull )
const 2196 if ( this->_caseInsensitive )
2198 if ( this->_pMapI->find(k) != this->_pMapI->end() )
2199 return this->_pMapI->at(k);
2203 if ( this->_pMap->find(k) != this->_pMap->end() )
2204 return this->_pMap->at(k);
2211 return this->_caseInsensitive ? this->_pMapI->find(k) != this->_pMapI->end() : this->_pMap->find(k) != this->_pMap->end();
2214 inline bool Collection::_addUniqueKey( Mixed
const & k )
2216 if ( this->_caseInsensitive )
2218 if ( this->_pMapI->find(k) == this->_pMapI->end() )
2220 this->_pKeysArr->push_back(k);
2226 if ( this->_pMap->find(k) == this->_pMap->end() )
2228 this->_pKeysArr->push_back(k);
2235 template <
typename _MAP >
2236 inline void Collection::_fxC( _MAP * pMap,
$c && coll )
2238 for (
auto & pr : coll._list )
2240 this->_addUniqueKey(pr.first);
2241 (*pMap)[pr.first] = pr.second;
2245 template <
typename _Fx1,
typename _Fx2,
typename _Ty >
2246 inline void Collection::_implAssign( _Fx1 fn, _Fx2 fnI, _Ty && m,
bool caseInsensitive )
2248 if ( this->_pKeysArr && ( this->_pMap || this->_pMapI ) )
2250 this->_pKeysArr->clear();
2252 if ( this->_caseInsensitive )
2255 if ( !caseInsensitive )
2257 this->_caseInsensitive = caseInsensitive;
2258 delete this->_pMapI;
2259 this->_pMapI = NULL;
2261 (this->*fn)( this->_pMap, std::forward<_Ty>(m) );
2265 this->_pMapI->clear();
2266 (this->*fnI)( this->_pMapI, std::forward<_Ty>(m) );
2272 if ( caseInsensitive )
2274 this->_caseInsensitive = caseInsensitive;
2278 (this->*fnI)( this->_pMapI, std::forward<_Ty>(m) );
2282 this->_pMap->clear();
2283 (this->*fn)( this->_pMap, std::forward<_Ty>(m) );
2290 this->_caseInsensitive = caseInsensitive;
2292 if ( this->_caseInsensitive )
2295 (this->*fnI)( this->_pMapI, std::forward<_Ty>(m) );
2300 (this->*fn)( this->_pMap, std::forward<_Ty>(m) );
2314 #endif // __UTILITIES_HPP__
XString< char > AnsiString
XString< char32 > UnicodeString32
#define MIXED_TYPE_ENUM_ITEM(item, nouse1, nouse2, nouse3)
$a(std::initializer_list< Mixed > &&list)
static bool IsLittleEndian()
判断编译环境是否为小端序
XString< wchar > UnicodeString
函数包装,用来将不同调用约定的函数统一包装成默认约定
bool ParseLong(AnsiString const &str, long *lVal)
parse long
void * getBuf() const
暴露缓冲区指针
$c(std::initializer_list< std::pair< Mixed, Mixed > > &&list)
MapAssigner< _KTy, _VTy, _Pr, _Alloc > Assign(std::map< _KTy, _VTy, _Pr, _Alloc > *m)
给容器赋值
Mixed const mxNull
Mixed(MT_NULL)常量对象
AnsiString toAnsi() const
转换到AnsiString
std::map< String, Mixed > StringMixedMap
#define MIXED_REF_TYPE_METHOD(mt, ty, memb, funcname)
PlainMembers(PlainMembers &&other)
std::map< _KTy, _VTy, _Pr, _Alloc > MapType
static int StringCompare(XString< _ChTy > const &str1, XString< _ChTy > const &str2)
字符串比较
Collection(std::map< _KTy, _VTy, _Pr, _Alloc > const &m, bool caseInsensitive=false)
构造函数 用map构造Collection
winux::byte const * begin() const
bool isPeek() const
是否为窥探模式
std::initializer_list< std::pair< Mixed, Mixed > > _list
int VoidReturnInt(_Fx fn, _ArgType &&...arg)
调用一个返回void的函数或函数对象,返回一个数字
static bool ArrayLess(_Ty const *arr1, size_t count1, _Ty const *arr2, size_t count2)
array less
Members(_ArgType &&...arg)
bool ParseUInt(AnsiString const &str, uint *uiVal)
parse uint
UnicodeString const & TypeStringW(Mixed const &v)
输出Mixed类型的字符串表示
bool CollectionGreater(Collection const &coll1, Collection const &coll2)
collection greater
typename CharSpec< typename std::decay< _ChTy >::type >::Type CharTypeConstrain
字符类型约束
数据包,用来表示一些POD结构体用于网络通信。通常这类结构体实际大小 > sizeof(这类结构体) ...
bool ParseDouble(AnsiString const &str, double *dblVal)
parse double
XStringArray< char16 > UnicodeString16Array
std::pair< String, Mixed > StringMixedPair
XStringArray< char16 > Utf16StringArray
bool CollectionLess(Collection const &coll1, Collection const &coll2)
collection less
size_t capacity() const
获取容量大小
XString< _ChTy > toString() const
转换到字符串
MixedArray const & refKeysArray() const
bool ValueIsInArray(StringArray const &arr, String const &val, bool caseInsensitive=false)
判断一个字符串值是否在一个字符串数组里,默认大小写敏感
int MemoryCompareI(void const *buf1, size_t n1, void const *buf2, size_t n2)
内存比较(不区分大小写)
std::map< String, String > StringStringMap
static bool ArrayEqual(_Ty const *arr1, size_t count1, _Ty const *arr2, size_t count2)
array equal
size_t getSize() const
获取数据大小
void appendType(_PodType const (&data)[_Count])
添加数据:POD类型数组
size_t getCount() const
获取Collection元素个数
std::vector< XString< _ChTy > > XStringArray
Buffer(_ChTy const *str, size_t len=npos, bool isPeek=false)
构造函数3 从字符指针创建Buffer,可以指定是否为窥视模式
std::ostream & operator<<(std::ostream &out, ConsoleAttrT< _VarType > const &tr)
bool ParseInt(AnsiString const &str, int *iVal)
parse int
std::vector< _Ty, _Alloc > VectorType
PlainMembers(_ArgType &&...arg)
void assign(std::pair< _KTy, _VTy >(&pairs)[_Count], bool caseInsensitive=false)
用pair[]给Collection赋值
bool ParseBool(AnsiString const &str, bool *boolVal)
parse bool
_Ty * getBuf() const
暴露缓冲区指针
std::map< Mixed, Mixed, MixedLess > MixedMixedMap
bool ParseUInt64(AnsiString const &str, uint64 *ui64Val)
parse uint64
MixedMixedMapI & refMapI()
Members(Members const &other)
XString< char32 > Utf32String
Collection(std::pair< _KTy, _VTy >(&pairs)[_Count], bool caseInsensitive=false)
构造函数 用pair[]构造Collection
std::pair< Mixed const, Mixed > MixedMixedPair
int Random(int n1, int n2)
随机数,随机产生n1~n2的数字. 包括n1,n2本身
static constexpr size_t const npos
非位置,值为-1。
#define MIXED_TYPE_LIST(funcmacro)
ArrayAssigner(VectorType *a)
std::basic_string< _ChTy, std::char_traits< _ChTy >, std::allocator< _ChTy > > XString
XStringArray< char > AnsiStringArray
std::vector< Mixed > MixedArray
size_t getMap(std::map< _KTy, _VTy, _Pr, _Alloc > *m) const
获取映射表,返回键值对个数
缓冲区,表示内存中一块二进制数据(利用malloc/realloc进行内存分配)
static bool IsBigEndian()
判断编译环境是否为大端序
XStringArray< char > Utf8StringArray
void assign(std::map< _KTy, _VTy, _Pr, _Alloc > const &m, bool caseInsensitive=false)
用map给Collection赋值
AnsiString const & TypeStringA(Mixed const &v)
输出Mixed类型的字符串表示
size_t count() const
获取大小
static int BufferCompare(Buffer const &buf1, Buffer const &buf2)
memcmp()
void appendString(_ChTy const *str, size_t len=npos)
添加数据:C串
bool ParseFloat(AnsiString const &str, float *fltVal)
parse float
XString< char > Utf8String
bool isset(_MAP const &m, _KEY const &k)
检测map中是否有该键的值
MixedMixedMap const & refMap() const
void _setSize(size_t dataSize)
设置数据大小,不能超过容量大小(不建议外部调用)
XStringArray< char32 > Utf32StringArray
MixedError(int errType, AnsiString const &errStr)
std::map< Mixed, Mixed, MixedLessI > MixedMixedMapI
size_t getKeys(std::vector< _Ty, _Alloc > *keys) const
获取全部键名,返回键名个数
#define WINUX_FUNC_DECL(ret)
static void InvertByteOrderArray(_Ty *p, size_t count)
反转字节序。_Ty必须是基本数字类型
#define MIXED_REF_TYPE_METHOD_OUTER(mt, ty, memb, funcname)
virtual char const * what() const
bool ParseULong(AnsiString const &str, ulong *ulVal)
parse ulong
Mixed const & get(Mixed const &k, Mixed const &defval) const
取得指定'Key'的元素,不存在则返回默认值
void appendType(std::initializer_list< _PodType > list)
添加数据:POD类型std::initializer_list
bool ParseInt64(AnsiString const &str, int64 *i64Val)
parse int64
unsigned __int64 ulonglong
bool has(Mixed const &k) const
判断键名是否存在
PlainMembers(PlainMembers const &other)
MixedMixedMapI const & refMapI() const
std::vector< _Ty > ToArray(_Ty *arr, uint count)
将C数组转换成vector
void append(Buffer const &data)
添加数据:Buffer对象
void setBuf(void const *buf, size_t size, bool isPeek)
设置缓冲区,当isPeek为false时拷贝数据缓冲区
UnicodeString toUnicode() const
转换到UnicodeString
XStringArray< wchar > UnicodeStringArray
Error(int errType, AnsiString const &errStr)
Plain成员隐藏(By plain block)
XString< char16 > UnicodeString16
virtual int getErrType() const
void assign($c &&coll, bool caseInsensitive=false)
用$c给Collection赋值
static int BufferCompareI(Buffer const &buf1, Buffer const &buf2)
memicmp()
size_t getCapacity() const
获取容量大小
Buffer(XString< _ChTy > const &data, bool isPeek=false)
构造函数2 从一个XString创建Buffer,可以指定是否为窥视模式
MixedMixedMapI * _pMapI
映射表大小写无关
XStringArray< char32 > UnicodeString32Array
int MemoryCompare(void const *buf1, size_t n1, void const *buf2, size_t n2)
内存比较
static FuncTraits< _PfnType >::ReturnType func(_ArgType &&...arg)
bool CollectionEqual(Collection const &coll1, Collection const &coll2)
collection equal
static _Ty InvertByteOrder(_Ty v)
反转字节序。_Ty必须是基本数字类型
_Ty * getAt(ssize_t i) const
暴露缓冲区指定位置指针
std::initializer_list< Mixed > _list
RefParam< _Ty > Ref(_Ty &r)
向模板参数传递引用型参数
std::pair< String, String > StringStringPair
MixedArray & refKeysArray()
bool isEmpty() const
判断容器是否为空
winux::byte * getAt(ssize_t i) const
暴露缓冲区指定位置指针
static int StringCompareI(XString< _ChTy > const &str1, XString< _ChTy > const &str2)
字符串(大小写无关)比较
XStringArray< tchar > StringArray
size_t size() const
获取数据字节大小
static bool ArrayGreater(_Ty const *arr1, size_t count1, _Ty const *arr2, size_t count2)
array greater
void appendType(_PodType const &data, size_t size=sizeof(_PodType))
添加数据:POD类型变量
XString< char16 > Utf16String
static size_t StrLen(_ChTy const *str)
计算字符串长度
void appendString(XString< _ChTy > const &data)
添加数据:XString对象
winux::byte const * end() const
bool getCaseInsensitive() const