Changeset 36508 in vbox for trunk/include/iprt/cpp
- Timestamp:
- Apr 1, 2011 3:03:59 PM (14 years ago)
- Location:
- trunk/include/iprt/cpp
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/cpp/autores.h
r36499 r36508 4 4 5 5 /* 6 * Copyright (C) 2008 Oracle Corporation6 * Copyright (C) 2008-2011 Oracle Corporation 7 7 * 8 8 * This file is part of VirtualBox Open Source Edition (OSE), as … … 31 31 32 32 /** 33 * @addtogroup grp_rt_cpp_util34 * @{35 */36 37 /**38 33 * A simple class used to prevent copying and assignment. 39 34 * 40 35 * Inherit from this class in order to prevent automatic generation 41 36 * of the copy constructor and assignment operator in your class. 37 * 38 * @todo Functionality duplicated by iprt::non_copyable. grr! 39 * 40 * @addtogroup grp_rt_cpp_util 42 41 */ 43 42 class RTCNonCopyable … … 51 50 }; 52 51 53 /** @} */ 54 55 /** 56 * @defgroup grp_rt_cpp_autores C++ Resource Management 52 53 /** @defgroup grp_rt_cpp_autores C++ Resource Management 57 54 * @ingroup grp_rt_cpp 58 55 * @{ … … 85 82 */ 86 83 template <class T> 87 inline void RTAutoResDestruct(T a Handle)84 inline void RTAutoResDestruct(T a_h) 88 85 { 89 86 AssertFatalMsgFailed(("Unspecialized template!\n")); 90 NOREF(a Handle);87 NOREF(a_h); 91 88 } 92 89 -
trunk/include/iprt/cpp/exception.h
r36499 r36508 4 4 5 5 /* 6 * Copyright (C) 2006-201 0Oracle Corporation6 * Copyright (C) 2006-2011 Oracle Corporation 7 7 * 8 8 * This file is part of VirtualBox Open Source Edition (OSE), as … … 32 32 { 33 33 34 /** 35 * @defgroup grp_rt_cpp_exceptions C++ Exceptions 34 /** @defgroup grp_rt_cpp_exceptions C++ Exceptions 36 35 * @ingroup grp_rt_cpp 37 36 * @{ -
trunk/include/iprt/cpp/list.h
r36500 r36508 29 29 #include <iprt/cpp/meta.h> 30 30 #include <iprt/mem.h> 31 #include <iprt/string.h> /* for memcpy */ 31 32 32 33 #include <new> /* For std::bad_alloc */ … … 35 36 { 36 37 37 /** 38 * @defgroup grp_rt_cpp_list C++ List support 38 /** @defgroup grp_rt_cpp_list C++ List support 39 39 * @ingroup grp_rt_cpp 40 40 * … … 312 312 { 313 313 /* Prevent self assignment */ 314 if (this == &other) return *this; 314 if (this == &other) 315 return *this; 316 315 317 /* Values cleanup */ 316 318 ListHelper<T, list_type>::eraseRange(m_pArray, 0, m_cSize); 319 317 320 /* Copy */ 318 321 if (other.m_cSize != m_cCapacity) … … 520 523 521 524 /** 522 525 * Generic realloc, which does some kind of boundary checking. 523 526 */ 524 527 void realloc(size_t cNewSize) … … 527 530 if (cNewSize == m_cCapacity) 528 531 return; 532 529 533 /* If we get smaller we have to delete some of the objects at the end 530 534 of the list. */ … … 535 539 m_cSize -= m_cSize - cNewSize; 536 540 } 541 537 542 /* If we get zero we delete the array it self. */ 538 543 if ( cNewSize == 0 … … 543 548 } 544 549 m_cCapacity = cNewSize; 550 545 551 /* Resize the array. */ 546 552 if (cNewSize > 0) … … 549 555 if (!m_pArray) 550 556 { 557 /** @todo you leak memory. */ 551 558 m_cCapacity = 0; 552 559 m_cSize = 0; 553 560 #ifdef RT_EXCEPTIONS_ENABLED 554 561 throw std::bad_alloc(); 555 #endif /* RT_EXCEPTIONS_ENABLED */562 #endif 556 563 } 557 564 } … … 570 577 if (!m_pArray) 571 578 { 579 /** @todo you leak memory. */ 572 580 m_cCapacity = 0; 573 581 m_cSize = 0; 574 582 #ifdef RT_EXCEPTIONS_ENABLED 575 583 throw std::bad_alloc(); 576 #endif /* RT_EXCEPTIONS_ENABLED */584 #endif 577 585 } 578 586 } … … 604 612 */ 605 613 template <class T, typename TYPE = typename if_<(sizeof(T) > sizeof(void*)), T*, T>::result> 606 class list : public ListBase<T, TYPE> {};614 class list : public ListBase<T, TYPE> {}; 607 615 608 616 /** … … 628 636 } /* namespace iprt */ 629 637 630 #endif /* ___iprt_cpp_list_h */631 638 #endif /* !___iprt_cpp_list_h */ 639 -
trunk/include/iprt/cpp/lock.h
r36499 r36508 4 4 5 5 /* 6 * Copyright (C) 2007 Oracle Corporation6 * Copyright (C) 2007-2011 Oracle Corporation 7 7 * 8 8 * This file is part of VirtualBox Open Source Edition (OSE), as … … 34 34 RT_C_DECLS_BEGIN 35 35 36 /** 37 * @defgroup grp_rt_cpp_lock C++ Scope-based Locking 36 /** @defgroup grp_rt_cpp_lock C++ Scope-based Locking 38 37 * @ingroup grp_rt_cpp 39 38 * @{ … … 53 52 class RTLockMtx 54 53 { 55 54 friend class RTLock; 56 55 57 58 56 private: 57 RTCRITSECT mMtx; 59 58 60 61 62 59 public: 60 RTLockMtx() 61 { 63 62 #ifdef RT_LOCK_STRICT_ORDER 64 65 66 63 RTCritSectInitEx(&mMtx, 0 /*fFlags*/, 64 RTLockValidatorClassCreateUnique(RT_SRC_POS, NULL), 65 RTLOCKVAL_SUB_CLASS_NONE, NULL); 67 66 #else 68 67 RTCritSectInit(&mMtx); 69 68 #endif 70 69 } 71 70 72 73 74 71 /** Use to when creating locks that belongs in the same "class". */ 72 RTLockMtx(RT_SRC_POS_DECL, uint32_t uSubClass = RTLOCKVAL_SUB_CLASS_NONE) 73 { 75 74 #ifdef RT_LOCK_STRICT_ORDER 76 77 78 75 RTCritSectInitEx(&mMtx, 0 /*fFlags*/, 76 RTLockValidatorClassForSrcPos(RT_SRC_POS_ARGS, NULL), 77 uSubClass, NULL); 79 78 #else 80 81 82 79 NOREF(uSubClass); 80 RTCritSectInit(&mMtx); 81 RT_SRC_POS_NOREF(); 83 82 #endif 84 83 } 85 84 86 87 88 89 85 ~RTLockMtx() 86 { 87 RTCritSectDelete(&mMtx); 88 } 90 89 91 92 93 94 95 96 97 90 // lock() and unlock() are private so that only 91 // friend RTLock can access them 92 private: 93 inline void lock() 94 { 95 RTCritSectEnter(&mMtx); 96 } 98 97 99 100 101 102 98 inline void unlock() 99 { 100 RTCritSectLeave(&mMtx); 101 } 103 102 }; 104 103 … … 129 128 class RTLock 130 129 { 131 132 133 130 private: 131 RTLockMtx &mMtx; 132 bool mfLocked; 134 133 135 public: 136 RTLock(RTLockMtx &aMtx) 137 : mMtx(aMtx) 134 public: 135 RTLock(RTLockMtx &aMtx) 136 : mMtx(aMtx) 137 { 138 mMtx.lock(); 139 mfLocked = true; 140 } 141 142 ~RTLock() 143 { 144 if (mfLocked) 145 mMtx.unlock(); 146 } 147 148 inline void release() 149 { 150 if (mfLocked) 138 151 { 139 mMtx. lock();140 mfLocked = true;152 mMtx.unlock(); 153 mfLocked = false; 141 154 } 142 143 ~RTLock() 144 { 145 if (mfLocked) 146 mMtx.unlock(); 147 } 148 149 inline void release() 150 { 151 if (mfLocked) 152 { 153 mMtx.unlock(); 154 mfLocked = false; 155 } 156 } 155 } 157 156 }; 158 157 -
trunk/include/iprt/cpp/meta.h
r36500 r36508 30 30 { 31 31 32 /** 33 * @defgroup grp_rt_cpp_meta C++ Meta programming utilities 32 /** @defgroup grp_rt_cpp_meta C++ Meta programming utilities 34 33 * @ingroup grp_rt_cpp 35 34 * @{ -
trunk/include/iprt/cpp/ministring.h
r36501 r36508 4 4 5 5 /* 6 * Copyright (C) 2007-20 09Oracle Corporation6 * Copyright (C) 2007-2011 Oracle Corporation 7 7 * 8 8 * This file is part of VirtualBox Open Source Edition (OSE), as … … 37 37 { 38 38 39 /** 40 * @defgroup grp_rt_cpp_string C++ String support 39 /** @defgroup grp_rt_cpp_string C++ String support 41 40 * @ingroup grp_rt_cpp 42 41 * @{ 43 42 */ 44 43 45 /** 46 * @brief Mini C++ string class. 44 /** @brief Mini C++ string class. 47 45 * 48 46 * "MiniString" is a small C++ string class that does not depend on anything … … 825 823 * Splits a string separated by strSep into its parts. 826 824 * 827 * @param strSepThe separator to search for.828 * @param modeHow should empty parts be handled.825 * @param a_rstrSep The separator to search for. 826 * @param a_enmMode How should empty parts be handled. 829 827 * @returns separated strings as string list. 830 828 */ 831 iprt::list<iprt::MiniString, iprt::MiniString*> split(const iprt::MiniString &strSep, SplitMode mode = RemoveEmptyParts); 829 iprt::list<iprt::MiniString, iprt::MiniString *> split(const iprt::MiniString &a_rstrSep, 830 SplitMode a_enmMode = RemoveEmptyParts); 832 831 833 832 /** 834 833 * Joins a list of strings together using the provided separator. 835 834 * 836 * @param listThe list to join.837 * @param strSepThe separator used for joining.835 * @param a_rList The list to join. 836 * @param a_rstrSep The separator used for joining. 838 837 * @returns joined string. 839 838 */ 840 static iprt::MiniString join(const iprt::list<iprt::MiniString, iprt::MiniString*> &list, const iprt::MiniString &strSep = ""); 841 839 static iprt::MiniString join(const iprt::list<iprt::MiniString, iprt::MiniString *> &a_rList, 840 const iprt::MiniString &a_rstrSep = ""); 841 842 842 protected: 843 843 … … 919 919 } /* namespace iprt */ 920 920 921 /** 922 * @addtogroup grp_rt_cpp_string 921 /** @addtogroup grp_rt_cpp_string 923 922 * @{ 924 923 */ 925 924 926 925 /** 926 * Concatenate two strings. 927 * 928 * @param a_rstr1 String one. 929 * @param a_rstr2 String two. 930 * @returns the concatenate string. 931 * 927 932 * @relates iprt::MiniString 928 * 933 */ 934 RTDECL(const iprt::MiniString) operator+(const iprt::MiniString &a_rstr1, const iprt::MiniString &a_rstr2); 935 936 /** 929 937 * Concatenate two strings. 930 938 * 931 * @param oneString one.932 * @param otherString two.939 * @param a_rstr1 String one. 940 * @param a_psz2 String two. 933 941 * @returns the concatenate string. 942 * 943 * @relates iprt::MiniString 934 944 */ 935 RTDECL(const iprt::MiniString) operator+(const iprt::MiniString & one, const iprt::MiniString &other);945 RTDECL(const iprt::MiniString) operator+(const iprt::MiniString &a_rstr1, const char *a_psz2); 936 946 937 947 /** 948 * Concatenate two strings. 949 * 950 * @param a_psz1 String one. 951 * @param a_rstr2 String two. 952 * @returns the concatenate string. 953 * 938 954 * @relates iprt::MiniString 939 *940 * Concatenate two strings.941 *942 * @param one String one.943 * @param pcszOther String two.944 * @returns the concatenate string.945 955 */ 946 RTDECL(const iprt::MiniString) operator+(const iprt::MiniString &one, const char *pcszOther); 947 948 /** 949 * @relates iprt::MiniString 950 * 951 * Concatenate two strings. 952 * 953 * @param pcszOne String one. 954 * @param other String two. 955 * @returns the concatenate string. 956 */ 957 RTDECL(const iprt::MiniString) operator+(const char *pcszOne, const iprt::MiniString &other); 956 RTDECL(const iprt::MiniString) operator+(const char *a_psz1, const iprt::MiniString &a_rstr2); 958 957 959 958 /** @} */ -
trunk/include/iprt/cpp/utils.h
r36499 r36508 4 4 5 5 /* 6 * Copyright (C) 2006-20 07Oracle Corporation6 * Copyright (C) 2006-2011 Oracle Corporation 7 7 * 8 8 * This file is part of VirtualBox Open Source Edition (OSE), as … … 27 27 #define ___iprt_cpputils_h 28 28 29 /** 30 * @defgroup grp_rt_cpp IPRT C++ support 31 * @ingroup grp_rt 32 */ 29 /** @defgroup grp_rt_cpp IPRT C++ APIs */ 33 30 34 /** 35 * @defgroup grp_rt_cpp_util C++ Utilitis 31 /** @defgroup grp_rt_cpp_util C++ Utilities 36 32 * @ingroup grp_rt_cpp 37 33 * @{ … … 41 37 * Shortcut to |const_cast<C &>()| that automatically derives the correct 42 38 * type (class) for the const_cast template's argument from its own argument. 39 * 43 40 * Can be used to temporarily cancel the |const| modifier on the left-hand side 44 41 * of assignment expressions, like this: 45 42 * @code 46 * const Class that;43 * const Class That; 47 44 * ... 48 * unconst (that) = some_value;45 * unconst(That) = SomeValue; 49 46 * @endcode 50 47 */ 51 48 template <class C> 52 inline C& unconst(const C &that) { return const_cast<C&>(that); } 49 inline C &unconst(const C &that) 50 { 51 return const_cast<C &>(that); 52 } 53 53 54 54 … … 56 56 * Shortcut to |const_cast<C *>()| that automatically derives the correct 57 57 * type (class) for the const_cast template's argument from its own argument. 58 * 58 59 * Can be used to temporarily cancel the |const| modifier on the left-hand side 59 60 * of assignment expressions, like this: 60 61 * @code 61 * const Class * that;62 * const Class *pThat; 62 63 * ... 63 * unconst (that) = some_value;64 * unconst(pThat) = SomeValue; 64 65 * @endcode 65 66 */ 66 67 template <class C> 67 inline C* unconst(const C *that) { return const_cast<C*>(that); } 68 inline C *unconst(const C *that) 69 { 70 return const_cast<C *>(that); 71 } 68 72 69 73 /** @} */ … … 73 77 74 78 /** 79 * A simple class used to prevent copying and assignment. 80 * 81 * Inherit from this class in order to prevent automatic generation of the copy 82 * constructor and assignment operator in your class. 83 * 75 84 * @ingroup grp_rt_cpp_util 76 * @{ 77 */ 78 79 /** 80 * A simple class used to prevent copying and assignment. Inherit from this 81 * class in order to prevent automatic generation of the copy constructor 82 * and assignment operator in your class. 85 * @todo Functionality duplicated by RTCNonCopyable. grr! 83 86 */ 84 87 class non_copyable … … 88 91 ~non_copyable() {} 89 92 private: 90 non_copyable(non_copyable const &);91 non_copyable const &operator=(non_copyable const &);93 non_copyable(non_copyable const &); 94 non_copyable const &operator=(non_copyable const &); 92 95 }; 93 96 94 /** @}*/97 } /* namespace iprt */ 95 98 96 } // namespace iprt 99 #endif 97 100 98 #endif // ___iprt_cpputils_h99 -
trunk/include/iprt/cpp/xml.h
r36499 r36508 36 36 #include <iprt/cpp/exception.h> 37 37 38 /** 39 * @defgroup grp_rt_cpp_xml C++ XML support 38 /** @defgroup grp_rt_cpp_xml C++ XML support 40 39 * @ingroup grp_rt_cpp 41 40 * @{ … … 747 746 748 747 #endif /* !___iprt_xml_h */ 748
Note:
See TracChangeset
for help on using the changeset viewer.