diff options
Diffstat (limited to 'include/VBox/com/list.h')
-rw-r--r-- | include/VBox/com/list.h | 46 |
1 files changed, 26 insertions, 20 deletions
diff --git a/include/VBox/com/list.h b/include/VBox/com/list.h index 11a137b5..5ecf4f16 100644 --- a/include/VBox/com/list.h +++ b/include/VBox/com/list.h @@ -4,7 +4,7 @@ */ /* - * Copyright (C) 2011 Oracle Corporation + * Copyright (C) 2011-2013 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; @@ -29,8 +29,10 @@ #include <VBox/com/ptr.h> #include <VBox/com/string.h> +#include <VBox/com/array.h> #include <iprt/cpp/list.h> + /** * Specialized list class for using with com::ComPtr<C> * @@ -54,8 +56,8 @@ public: * @param cCapacitiy The initial capacity the list has. * @throws std::bad_alloc */ - RTCList(size_t cCapacity = BASE::DefaultCapacity) - : BASE(cCapacity) {} + RTCList(size_t cCapacity = BASE::kDefaultCapacity) + : BASE(cCapacity) {} /* Define our own new and delete. */ RTMEMEF_NEW_AND_DELETE_OPERATORS(); @@ -84,8 +86,8 @@ public: * @param cCapacitiy The initial capacity the list has. * @throws std::bad_alloc */ - RTCList(size_t cCapacity = BASE::DefaultCapacity) - : BASE(cCapacity) {} + RTCList(size_t cCapacity = BASE::kDefaultCapacity) + : BASE(cCapacity) {} /* Define our own new and delete. */ RTMEMEF_NEW_AND_DELETE_OPERATORS(); @@ -97,10 +99,10 @@ public: * The class offers methods for importing com::SafeArray's of com::Bstr's. */ template <> -class RTCList<Utf8Str>: public RTCListBase<Utf8Str, Utf8Str*, false> +class RTCList<com::Utf8Str>: public RTCListBase<com::Utf8Str, com::Utf8Str*, false> { /* Traits */ - typedef Utf8Str T; + typedef com::Utf8Str T; typedef T *ITYPE; static const bool MT = false; typedef RTCListBase<T, ITYPE, MT> BASE; @@ -114,8 +116,8 @@ public: * @param cCapacitiy The initial capacity the list has. * @throws std::bad_alloc */ - RTCList(size_t cCapacity = BASE::DefaultCapacity) - : BASE(cCapacity) {} + RTCList(size_t cCapacity = BASE::kDefaultCapacity) + : BASE(cCapacity) {} /** * Creates a copy of another list. @@ -130,9 +132,10 @@ public: RTCList(ComSafeArrayIn(IN_BSTR, other)) { com::SafeArray<IN_BSTR> sfaOther(ComSafeArrayInArg(other)); - realloc(sfaOther.size()); - m_cSize = sfaOther.size(); - for (size_t i = 0; i < m_cSize; ++i) + size_t const cElementsOther = sfaOther.size(); + resizeArray(cElementsOther); + m_cElements = cElementsOther; + for (size_t i = 0; i < cElementsOther; ++i) RTCListHelper<T, ITYPE>::set(m_pArray, i, T(sfaOther[i])); } @@ -147,9 +150,9 @@ public: * @throws std::bad_alloc */ RTCList(const com::SafeArray<IN_BSTR> &other) - : BASE(other.size()) + : BASE(other.size()) { - for (size_t i = 0; i < m_cSize; ++i) + for (size_t i = 0; i < m_cElements; ++i) RTCListHelper<T, ITYPE>::set(m_pArray, i, T(other[i])); } @@ -164,16 +167,19 @@ public: RTCListBase<T, ITYPE, MT> &operator=(const com::SafeArray<IN_BSTR> &other) { m_guard.enterWrite(); + /* Values cleanup */ - RTCListHelper<T, ITYPE>::eraseRange(m_pArray, 0, m_cSize); + RTCListHelper<T, ITYPE>::eraseRange(m_pArray, 0, m_cElements); + /* Copy */ - if (other.size() != m_cCapacity) - realloc_no_elements_clean(other.size()); - m_cSize = other.size(); - for (size_t i = 0; i < other.size(); ++i) + size_t cElementsOther = other.size(); + if (cElementsOther != m_cCapacity) + resizeArrayNoErase(cElementsOther); + m_cElements = cElementsOther; + for (size_t i = 0; i < cElementsOther; ++i) RTCListHelper<T, ITYPE>::set(m_pArray, i, T(other[i])); - m_guard.leaveWrite(); + m_guard.leaveWrite(); return *this; } |