17 #define const_self (static_cast<const std::decay<decltype(*this)>::type&>(*this)) 25 #define const_this (&const_cast_self) 33 #define const_cast_self (const_cast<std::decay<decltype(*this)>::type&>(*this)) 41 #define const_cast_this (&const_cast_self) 51 if (!(x)) utl::abort(__FILE__, __LINE__, "assertion failed: " #x) 59 #define ABORT() utl::abort(__FILE__, __LINE__) 67 #define DIE(text) utl::die(__FILE__, __LINE__, text) 88 #define UTL_ANONYMOUS_VARIABLE(str) UTL_CONCATENATE(str, __COUNTER__) 90 #define UTL_ANONYMOUS_VARIABLE(str) UTL_CONCATENATE(str, __LINE__) 99 #define UTL_CONCATENATE_IMPL(a, b) a##b 107 #define UTL_CONCATENATE(a, b) UTL_CONCATENATE_IMPL(a, b) 115 #define likely(x) __builtin_expect(!!(x), 1) 121 #define unlikely(x) __builtin_expect(!!(x), 0) 129 #define UTL_PRINT(x) cout << #x " = " << x << endl 135 #define ASSERTD ASSERT 136 #define ASSERTFNZ(x) ASSERT(x == 0) 137 #define ASSERTFNP(x) ASSERT(x != 0) 142 #define ASSERTFNZ(x) x 143 #define ASSERTFNP(x) x 145 #define INLINE inline 194 #define UTL_INSTANTIATE_TPL(className, T) \ 195 UTL_CLASS_IMPL_NAME_TPL(className, T) \ 196 template class className<T>; \ 197 template class utl::TRunTimeClass<className<T>>; \ 198 template class utl::TConcreteRunTimeClass<className<T>>; 206 #define UTL_INSTANTIATE_TPL2(className, T1, T2) \ 207 UTL_CLASS_IMPL_NAME_TPL2(className, T1, T2) \ 208 template class className<T1, T2>; \ 209 template class utl::TRunTimeClass<className<T1, T2>>; \ 210 template class utl::TConcreteRunTimeClass<className<T1, T2>>; 219 #define UTL_INSTANTIATE_TPLxTPL2(className, TC, T1, T2) \ 220 UTL_CLASS_IMPL_NAME_TPLxTPL2(className, TC, T1, T2) template class className<TC<T1, T2>>; \ 221 template class utl::TRunTimeClass<className<TC<T1, T2>>>; \ 222 template class utl::TConcreteRunTimeClass<className<TC<T1, T2>>>; 231 #define UTL_EINTR_LOOP(SyscallFn) \ 236 if ((err >= 0) || (errno != EINTR)) break; \ 245 #define UTL_MAIN(appName) \ 246 int main(int argc, char** argv) \ 248 appName* theApp = new appName; \ 252 res = theApp->run(argc, argv); \ 254 catch (utl::Exception & ex) \ 256 ex.dump(utl::cerr); \ 257 ex.setObject(nullptr); \ 269 #if defined(DEBUG) && UTL_HOST_OS != UTL_OS_MINGW 270 #define UTL_MAIN_RL(appName) \ 271 int main(int argc, char** argv) \ 273 appName* theApp = new appName; \ 277 res = theApp->run(argc, argv); \ 279 catch (utl::Exception & ex) \ 281 ex.dump(utl::cerr); \ 282 ex.setObject(nullptr); \ 285 utl::memReportLeaks(false); \ 289 #define UTL_MAIN_RL(appName) UTL_MAIN(appName) 301 #define for_each_ln(head, var_type, var_name) \ 303 for (const ListNode* __ln = head; (__ln != nullptr) && !__ln->isSentinelTail(); \ 304 __ln = __ln->next()) \ 306 utl::Object* __lnPtr = __ln->get(); \ 307 ASSERTD(__lnPtr->isA(var_type)); \ 308 var_type& var_name = *(var_type*)__lnPtr; 319 #define for_each_sln(head, var_type, var_name) \ 321 for (const SlistNode* __ln = head; (__ln != nullptr) && !__ln->isSentinelTail(); \ 322 __ln = __ln->next()) \ 324 utl::Object* __lnPtr = __ln->get(); \ 325 ASSERTD(__lnPtr->isA(var_type)); \ 326 var_type& var_name = *(var_type*)__lnPtr; 334 #define for_each_end \ 344 #define UTL_CLASS_NO_COMPARE \ 346 virtual int compare(const utl::Object&) const \ 358 #define UTL_CLASS_NO_COPY \ 360 virtual void copy(const utl::Object&) \ 371 #define UTL_CLASS_NO_KEY(className) \ 373 virtual const utl::Object& getKey() const \ 384 #define UTL_CLASS_NO_SERIALIZE \ 386 virtual void serialize(utl::Stream&, uint_t, uint_t) \ 397 #define UTL_CLASS_NO_VCLONE \ 399 virtual void vclone(const utl::Object&) \ 410 #define UTL_CLASS_TYPE(className) \ 412 typedef className thisType; 420 #define UTL_CLASS_TYPE_TPL2(className, T1, T2) \ 422 typedef className<T1, T2> thisType; 430 #define UTL_CLASS_SUPER(baseClassName) \ 432 typedef baseClassName super; 440 #define UTL_CLASS_SUPER_TPL2(baseClassName, T1, T2) \ 442 typedef baseClassName<T1, T2> super; 451 #define UTL_CLASS_SUPER_TPL2_TPLxTPL2(baseClassName, T, T1, T2) \ 453 typedef baseClassName<T<T1, T2>> super; 461 #define UTL_CLASS_CONSTRUCT(className) \ 474 #define UTL_CLASS_COPYCONSTRUCT(className) \ 476 className(const thisType& rhs) \ 488 #define UTL_CLASS_MOVECONSTRUCT(className) \ 490 className(thisType&& rhs) noexcept \ 503 #define UTL_SAFE_DEINIT \ 506 DIE("unexpected exception during object destruction"); \ 510 #define UTL_SAFE_DEINIT deInit(); 519 #define UTL_CLASS_DESTRUCT(className) \ 521 virtual ~className() \ 532 #define UTL_CLASS_DEFID \ 547 #define UTL_CLASS_DECL_CREATE \ 549 virtual thisType* create() const; 557 #define UTL_CLASS_DECL_CLONE \ 559 virtual thisType* clone() const; 567 #define UTL_CLASS_EQUALS(rhsClassName) \ 569 thisType& operator=(const rhsClassName& rhs) \ 581 #define UTL_CLASS_EQUALS_MOVE \ 583 thisType& operator=(thisType&& rhs) noexcept \ 595 #define UTL_CLASS_POINTER \ 597 operator thisType*() \ 608 #define UTL_CLASS_CONSTPOINTER \ 610 operator const thisType*() const \ 614 operator const thisType*() \ 625 #define UTL_CLASS_SERIALIZE(className) \ 626 inline void serialize(className& object, Stream& stream, uint_t io, \ 627 uint_t mode = utl::ser_default) \ 629 object.serialize(stream, io, mode); \ 638 #define UTL_TYPE_NO_SERIALIZE(typeName) \ 639 inline void serialize(typeName&, Stream&, uint_t, uint_t) \ 650 #define UTL_CLASS_DECL_ABC(DC, BC) \ 652 UTL_CLASS_SUPER(BC) \ 653 UTL_CLASS_DECL_RTTI_ABC(DC) \ 654 UTL_CLASS_CONSTRUCT(DC) \ 655 UTL_CLASS_DESTRUCT(DC) \ 656 UTL_CLASS_DECL_CREATE \ 657 UTL_CLASS_DECL_CLONE \ 658 UTL_CLASS_EQUALS(DC) \ 659 UTL_CLASS_EQUALS_MOVE \ 661 UTL_CLASS_CONSTPOINTER 669 #define UTL_CLASS_DECL_CMN(DC) \ 670 UTL_CLASS_CONSTRUCT(DC) \ 671 UTL_CLASS_COPYCONSTRUCT(DC) \ 672 UTL_CLASS_MOVECONSTRUCT(DC) \ 673 UTL_CLASS_DESTRUCT(DC) \ 674 UTL_CLASS_DECL_CREATE \ 675 UTL_CLASS_DECL_CLONE \ 676 UTL_CLASS_EQUALS(utl::Object) \ 677 UTL_CLASS_EQUALS(thisType) \ 678 UTL_CLASS_EQUALS_MOVE \ 680 UTL_CLASS_CONSTPOINTER 688 #define UTL_CLASS_DECL(DC, BC) \ 690 UTL_CLASS_SUPER(BC) \ 691 UTL_CLASS_DECL_RTTI(DC) \ 692 UTL_CLASS_DECL_CMN(DC) 701 #define UTL_CLASS_DECL_NT_TPL2(DC, BC, T1, T2) \ 703 UTL_CLASS_SUPER_TPL2(BC, T1, T2) \ 704 UTL_CLASS_DECL_RTTI(DC) \ 705 UTL_CLASS_DECL_CMN(DC) 713 #define UTL_CLASS_DECL_TPL(DC, T, BC) \ 714 UTL_CLASS_TYPE(DC<T>) \ 715 UTL_CLASS_SUPER(BC) \ 716 UTL_CLASS_DECL_RTTI_TPL(DC, T) \ 717 UTL_CLASS_DECL_CMN(DC) 726 #define UTL_CLASS_DECL_TPL2(DC, T1, T2, BC) \ 727 UTL_CLASS_TYPE_TPL2(DC, T1, T2) \ 728 UTL_CLASS_SUPER(BC) \ 729 UTL_CLASS_DECL_RTTI_TPL2(DC, T1, T2) \ 730 UTL_CLASS_DECL_CMN(DC) 739 #define UTL_CLASS_DECL_TPL2_TPL2(DC, DC_T1, DC_T2, BC, BC_T1, BC_T2) \ 740 UTL_CLASS_TYPE_TPL2(DC, DC_T1, DC_T2) \ 741 UTL_CLASS_SUPER_TPL2(BC, BC_T1, BC_T2) \ 742 UTL_CLASS_DECL_RTTI_TPL2(DC, DC_T1, DC_T2) \ 743 UTL_CLASS_DECL_CMN(DC) 753 #define UTL_CLASS_DECL_TPL2_TPLxTPL2(DC, DC_T1, DC_T2, BC, BC_BT, BC_T1, BC_T2) \ 755 UTL_CLASS_TYPE_TPL2(DC, DC_T1, DC_T2) \ 756 UTL_CLASS_SUPER_TPL2_TPLxTPL2(BC, BC_BT, BC_T1, BC_T2); \ 757 UTL_CLASS_DECL_RTTI_TPL2(DC, DC_T1, DC_T2) \ 758 UTL_CLASS_DECL_CMN(DC) 766 #define UTL_CLASS_IMPL_CREATE_ABC(className) \ 767 className* className::create() const \ 779 #define UTL_CLASS_IMPL_CREATE(className) \ 780 className* className::create() const \ 782 return new className(); \ 791 #define UTL_CLASS_IMPL_CREATE_TPL(className, T) \ 793 className<T>* className<T>::create() const \ 795 return new className<T>(); \ 804 #define UTL_CLASS_IMPL_CREATE_TPL2(className, T1, T2) \ 805 template <class T1, class T2> \ 806 className<T1, T2>* className<T1, T2>::create() const \ 808 return new className<T1, T2>(); \ 817 #define UTL_CLASS_IMPL_CLONE_ABC(className) \ 818 className* className::clone() const \ 830 #define UTL_CLASS_IMPL_CLONE(className) \ 831 className* className::clone() const \ 833 auto object = new className(); \ 834 object->vclone(*this); \ 844 #define UTL_CLASS_IMPL_CLONE_TPL(className, T) \ 846 className<T>* className<T>::clone() const \ 848 auto object = new className<T>(); \ 849 object->vclone(*this); \ 859 #define UTL_CLASS_IMPL_CLONE_TPL2(className, T1, T2) \ 860 template <class T1, class T2> \ 861 className<T1, T2>* className<T1, T2>::clone() const \ 863 auto object = new className<T1, T2>(); \ 864 object->vclone(*this); \ 874 #define UTL_CLASS_IMPL_ABC(className) \ 875 UTL_CLASS_IMPL_NAME(className) \ 876 UTL_CLASS_IMPL_RTTI_ABC(className) \ 877 UTL_CLASS_IMPL_CREATE_ABC(className) \ 878 UTL_CLASS_IMPL_CLONE_ABC(className) \ 879 template const className& utl::cast<className>(const utl::Object&); \ 880 template className& utl::cast<className>(utl::Object&); \ 881 template const className* utl::cast<className>(const utl::Object*); \ 882 template className* utl::cast<className>(utl::Object*); 890 #define UTL_CLASS_IMPL(className) \ 891 UTL_CLASS_IMPL_NAME(className) \ 892 UTL_CLASS_IMPL_RTTI(className) \ 893 UTL_CLASS_IMPL_CREATE(className) \ 894 UTL_CLASS_IMPL_CLONE(className) \ 895 template const className& utl::cast<className>(const utl::Object&); \ 896 template className& utl::cast<className>(utl::Object&); \ 897 template const className* utl::cast<className>(const utl::Object*); \ 898 template className* utl::cast<className>(utl::Object*); 906 #define UTL_CLASS_IMPL_TPL(className, T) \ 907 UTL_CLASS_IMPL_RTTI_TPL(className, T) \ 908 UTL_CLASS_IMPL_CREATE_TPL(className, T) \ 909 UTL_CLASS_IMPL_CLONE_TPL(className, T) 917 #define UTL_CLASS_IMPL_TPL2(className, T1, T2) \ 918 UTL_CLASS_IMPL_RTTI_TPL2(className, T1, T2) \ 919 UTL_CLASS_IMPL_CREATE_TPL2(className, T1, T2) \ 920 UTL_CLASS_IMPL_CLONE_TPL2(className, T1, T2)