summaryrefslogtreecommitdiffstats
path: root/base/win/enum_variant.h
blob: 82f8750c2a0ce10717adb4be5132cdc039d63984 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef BASE_WIN_ENUM_VARIANT_H_
#define BASE_WIN_ENUM_VARIANT_H_

#include <unknwn.h>

#include "base/memory/scoped_ptr.h"
#include "base/win/iunknown_impl.h"

namespace base {
namespace win {

// A simple implementation of IEnumVARIANT.
class BASE_EXPORT EnumVariant
  : public IEnumVARIANT,
    public IUnknownImpl {
 public:
  // The constructor allocates an array of size |count|. Then use
  // ItemAt to set the value of each item in the array to initialize it.
  explicit EnumVariant(unsigned long count);

  // Returns a mutable pointer to the item at position |index|.
  VARIANT* ItemAt(unsigned long index);

  // IUnknown.
  ULONG STDMETHODCALLTYPE AddRef() OVERRIDE;
  ULONG STDMETHODCALLTYPE Release() OVERRIDE;
  STDMETHODIMP QueryInterface(REFIID riid, void** ppv) OVERRIDE;

  // IEnumVARIANT.
  STDMETHODIMP Next(ULONG requested_count,
                    VARIANT* out_elements,
                    ULONG* out_elements_received);
  STDMETHODIMP Skip(ULONG skip_count);
  STDMETHODIMP Reset();
  STDMETHODIMP Clone(IEnumVARIANT** out_cloned_object);

 private:
  ~EnumVariant();

  scoped_ptr<VARIANT[]> items_;
  unsigned long count_;
  unsigned long current_index_;
};

}  // namespace win
}  // namespace base

#endif  // BASE_WIN_ENUM_VARIANT_H_