| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/logging.h" |
| 6 #include "base/win/enum_variant.h" |
| 7 |
| 8 namespace base { |
| 9 namespace win { |
| 10 |
| 11 EnumVariant::EnumVariant(unsigned long count) |
| 12 : count_(count) { |
| 13 items_.reset(new VARIANT[count_]); |
| 14 current_index_ = 0; |
| 15 ref_count_ = 1; |
| 16 } |
| 17 |
| 18 EnumVariant::~EnumVariant() { |
| 19 } |
| 20 |
| 21 VARIANT* EnumVariant::ItemAt(unsigned long index) { |
| 22 DCHECK(index < count_); |
| 23 return &items_[index]; |
| 24 } |
| 25 |
| 26 ULONG STDMETHODCALLTYPE EnumVariant::AddRef() { |
| 27 return InterlockedIncrement(&ref_count_); |
| 28 } |
| 29 |
| 30 ULONG STDMETHODCALLTYPE EnumVariant::Release() { |
| 31 ULONG ref_count = InterlockedDecrement(&ref_count_); |
| 32 if (ref_count == 0) |
| 33 delete this; |
| 34 return ref_count; |
| 35 } |
| 36 |
| 37 STDMETHODIMP EnumVariant::QueryInterface(REFIID riid, void** ppv) { |
| 38 if (riid == IID_IUnknown || |
| 39 riid == IID_IEnumVARIANT) { |
| 40 *ppv = this; |
| 41 AddRef(); |
| 42 return S_OK; |
| 43 } |
| 44 |
| 45 *ppv = NULL; |
| 46 return E_NOINTERFACE; |
| 47 } |
| 48 |
| 49 STDMETHODIMP EnumVariant::Next(ULONG requested_count, |
| 50 VARIANT* out_elements, |
| 51 ULONG* out_elements_received) { |
| 52 unsigned long count = requested_count; |
| 53 if (current_index_ + count > count_) |
| 54 count = count_ - current_index_; |
| 55 |
| 56 for (unsigned long i = 0; i < count; ++i) |
| 57 out_elements[i] = items_[current_index_ + i]; |
| 58 current_index_ += count; |
| 59 *out_elements_received = count; |
| 60 |
| 61 return (count == requested_count ? S_OK : S_FALSE); |
| 62 } |
| 63 |
| 64 STDMETHODIMP EnumVariant::Skip(ULONG skip_count) { |
| 65 unsigned long count = skip_count; |
| 66 if (current_index_ + count > count_) |
| 67 count = count_ - current_index_; |
| 68 |
| 69 current_index_ += count; |
| 70 return (count == skip_count ? S_OK : S_FALSE); |
| 71 } |
| 72 |
| 73 STDMETHODIMP EnumVariant::Reset() { |
| 74 current_index_ = 0; |
| 75 return S_OK; |
| 76 } |
| 77 |
| 78 STDMETHODIMP EnumVariant::Clone(IEnumVARIANT** out_cloned_object) { |
| 79 EnumVariant* other = new EnumVariant(count_); |
| 80 for (unsigned long i = 0; i < count_; ++i) |
| 81 *other->ItemAt(i) = items_[i]; |
| 82 *out_cloned_object = other; |
| 83 return S_OK; |
| 84 } |
| 85 |
| 86 } // namespace win |
| 87 } // namespace base |
| OLD | NEW |