VirtualBox

source: vbox/trunk/include/VBox/com/mtlist.h@ 36659

Last change on this file since 36659 was 36659, checked in by vboxsync, 14 years ago

com/list: do r71131 right

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.3 KB
Line 
1/* $Id: mtlist.h 36659 2011-04-12 15:53:44Z vboxsync $ */
2/** @file
3 * MS COM / XPCOM Abstraction Layer - Thread-safe list classes declaration.
4 */
5
6/*
7 * Copyright (C) 2011 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27#ifndef ___VBox_com_mtlist_h
28#define ___VBox_com_mtlist_h
29
30#include <VBox/com/string.h>
31#include <iprt/cpp/mtlist.h>
32
33/**
34 * Specialized thread-safe list class for using with com::Utf8Str.
35 *
36 * The class offers methods for importing com::SafeArray's of com::Bstr's.
37 */
38template <>
39class RTCMTList<Utf8Str>: public RTCListBase<Utf8Str, Utf8Str*, true>
40{
41 /* Traits */
42 typedef Utf8Str T;
43 typedef T *ITYPE;
44 static const bool MT = true;
45 typedef RTCListBase<T, ITYPE, MT> BASE;
46
47public:
48 /**
49 * Creates a new list.
50 *
51 * This preallocates @a cCapacity elements within the list.
52 *
53 * @param cCapacitiy The initial capacity the list has.
54 * @throws std::bad_alloc
55 */
56 RTCMTList(size_t cCapacity = BASE::DefaultCapacity)
57 : BASE(cCapacity) {}
58
59 /**
60 * Creates a copy of another list.
61 *
62 * The other list will be fully copied and the capacity will be the same as
63 * the size of the other list. The com::Bstr's are silently converted to
64 * com::Utf8Str's.
65 *
66 * @param other The list to copy.
67 * @throws std::bad_alloc
68 */
69 RTCMTList(ComSafeArrayIn(IN_BSTR, other))
70 {
71 com::SafeArray<IN_BSTR> sfaOther(ComSafeArrayInArg(other));
72 realloc_grow(sfaOther.size());
73 m_cSize = sfaOther.size();
74 for (size_t i = 0; i < m_cSize; ++i)
75 RTCListHelper<T, ITYPE>::set(m_pArray, i, T(sfaOther[i]));
76 }
77
78 /**
79 * Creates a copy of another list.
80 *
81 * The other list will be fully copied and the capacity will be the same as
82 * the size of the other list. The com::Bstr's are silently converted to
83 * com::Utf8Str's.
84 *
85 * @param other The list to copy.
86 * @throws std::bad_alloc
87 */
88 RTCMTList(const com::SafeArray<IN_BSTR> &other)
89 {
90 realloc_grow(other.size());
91 m_cSize = other.size();
92 for (size_t i = 0; i < m_cSize; ++i)
93 RTCListHelper<T, ITYPE>::set(m_pArray, i, T(other[i]));
94 }
95
96 /**
97 * Copy the items of the other list into this list. All previous items of
98 * this list are deleted.
99 *
100 * @param other The list to copy.
101 * @return a reference to this list.
102 * @throws std::bad_alloc
103 */
104 RTCListBase<T, ITYPE, MT> &operator=(const com::SafeArray<IN_BSTR> &other)
105 {
106 m_guard.enterWrite();
107 /* Values cleanup */
108 RTCListHelper<T, ITYPE>::eraseRange(m_pArray, 0, m_cSize);
109
110 /* Copy */
111 if (other.size() != m_cCapacity)
112 realloc_grow(other.size());
113 m_cSize = other.size();
114 for (size_t i = 0; i < other.size(); ++i)
115 RTCListHelper<T, ITYPE>::set(m_pArray, i, T(other[i]));
116 m_guard.leaveWrite();
117
118 return *this;
119 }
120
121 /**
122 * Implicit conversion to a RTCString list.
123 *
124 * This allows the usage of the RTCString::join method with this list type.
125 *
126 * @return a converted const reference to this list.
127 */
128 operator const RTCMTList<RTCString, RTCString*>&()
129 {
130 return *reinterpret_cast<RTCMTList<RTCString, RTCString*> *>(this);
131 }
132
133 /* Define our own new and delete. */
134 RTMEMEF_NEW_AND_DELETE_OPERATORS();
135};
136
137#endif /* !___VBox_com_mtlist_h */
138
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette