1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "nsAlgorithm.h"
10 CEnumFormatEtc::CEnumFormatEtc() :
16 // Constructor used by Clone()
17 CEnumFormatEtc::CEnumFormatEtc(nsTArray
<FormatEtc
>& aArray
) :
21 // a deep copy, calls FormatEtc's copy constructor on each
22 mFormatList
.AppendElements(aArray
);
25 CEnumFormatEtc::~CEnumFormatEtc()
32 CEnumFormatEtc::QueryInterface(REFIID riid
, LPVOID
*ppv
)
36 if (IsEqualIID(riid
, IID_IUnknown
) ||
37 IsEqualIID(riid
, IID_IEnumFORMATETC
))
43 // AddRef any interface we'll return.
44 ((LPUNKNOWN
)*ppv
)->AddRef();
49 CEnumFormatEtc::AddRef()
52 NS_LOG_ADDREF(this, mRefCnt
, "CEnumFormatEtc",sizeof(*this));
57 CEnumFormatEtc::Release()
61 refReturn
= --mRefCnt
;
62 NS_LOG_RELEASE(this, mRefCnt
, "CEnumFormatEtc");
70 /* IEnumFORMATETC impl. */
73 CEnumFormatEtc::Next(ULONG aMaxToFetch
, FORMATETC
*aResult
, ULONG
*aNumFetched
)
75 // If the method retrieves the number of items requested, the return
76 // value is S_OK. Otherwise, it is S_FALSE.
81 // aNumFetched can be null if aMaxToFetch is 1
82 if (!aNumFetched
&& aMaxToFetch
> 1)
88 // We're done walking the list
89 if (mCurrentIdx
>= mFormatList
.Length())
92 uint32_t left
= mFormatList
.Length() - mCurrentIdx
;
97 uint32_t count
= std::min(static_cast<uint32_t>(aMaxToFetch
), left
);
101 // Copy out to aResult
102 mFormatList
[mCurrentIdx
++].CopyOut(&aResult
[idx
++]);
113 CEnumFormatEtc::Skip(ULONG aSkipNum
)
115 // If the method skips the number of items requested, the return value is S_OK.
116 // Otherwise, it is S_FALSE.
118 if ((mCurrentIdx
+ aSkipNum
) >= mFormatList
.Length())
121 mCurrentIdx
+= aSkipNum
;
127 CEnumFormatEtc::Reset(void)
134 CEnumFormatEtc::Clone(LPENUMFORMATETC
*aResult
)
136 // Must return a new IEnumFORMATETC interface with the same iterative state.
141 CEnumFormatEtc
* pEnumObj
= new CEnumFormatEtc(mFormatList
);
144 return E_OUTOFMEMORY
;
147 pEnumObj
->SetIndex(mCurrentIdx
);
157 CEnumFormatEtc::AddFormatEtc(LPFORMATETC aFormat
)
161 FormatEtc
* etc
= mFormatList
.AppendElement();
162 // Make a copy of aFormat
164 etc
->CopyIn(aFormat
);
170 CEnumFormatEtc::SetIndex(uint32_t aIdx
)