| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef BASE_SCOPED_VARIANT_WIN_H_ | 5 #ifndef BASE_SCOPED_VARIANT_WIN_H_ |
| 6 #define BASE_SCOPED_VARIANT_WIN_H_ | 6 #define BASE_SCOPED_VARIANT_WIN_H_ |
| 7 | 7 |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 #include <oleauto.h> | 9 #include <oleauto.h> |
| 10 | 10 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 // be transferred | 33 // be transferred |
| 34 explicit ScopedVariant(const wchar_t* str); | 34 explicit ScopedVariant(const wchar_t* str); |
| 35 | 35 |
| 36 // Creates a new VT_BSTR variant of a specified length. | 36 // Creates a new VT_BSTR variant of a specified length. |
| 37 explicit ScopedVariant(const wchar_t* str, UINT length); | 37 explicit ScopedVariant(const wchar_t* str, UINT length); |
| 38 | 38 |
| 39 // Creates a new integral type variant and assigns the value to | 39 // Creates a new integral type variant and assigns the value to |
| 40 // VARIANT.lVal (32 bit sized field). | 40 // VARIANT.lVal (32 bit sized field). |
| 41 explicit ScopedVariant(int value, VARTYPE vt = VT_I4); | 41 explicit ScopedVariant(int value, VARTYPE vt = VT_I4); |
| 42 | 42 |
| 43 // VT_DISPATCH |
| 44 explicit ScopedVariant(IDispatch* dispatch); |
| 45 |
| 46 // VT_UNKNOWN |
| 47 explicit ScopedVariant(IUnknown* unknown); |
| 48 |
| 49 // Copies the variant. |
| 50 explicit ScopedVariant(const VARIANT& var); |
| 51 |
| 43 ~ScopedVariant(); | 52 ~ScopedVariant(); |
| 44 | 53 |
| 45 inline VARTYPE type() const { | 54 inline VARTYPE type() const { |
| 46 return var_.vt; | 55 return var_.vt; |
| 47 } | 56 } |
| 48 | 57 |
| 49 // Give ScopedVariant ownership over an already allocated VARIANT. | 58 // Give ScopedVariant ownership over an already allocated VARIANT. |
| 50 void Reset(const VARIANT& var = kEmptyVariant); | 59 void Reset(const VARIANT& var = kEmptyVariant); |
| 51 | 60 |
| 52 // Releases ownership of the VARIANT to the caller. | 61 // Releases ownership of the VARIANT to the caller. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 76 void Set(int16 i16); | 85 void Set(int16 i16); |
| 77 void Set(uint16 ui16); | 86 void Set(uint16 ui16); |
| 78 void Set(int32 i32); | 87 void Set(int32 i32); |
| 79 void Set(uint32 ui32); | 88 void Set(uint32 ui32); |
| 80 void Set(int64 i64); | 89 void Set(int64 i64); |
| 81 void Set(uint64 ui64); | 90 void Set(uint64 ui64); |
| 82 void Set(float r32); | 91 void Set(float r32); |
| 83 void Set(double r64); | 92 void Set(double r64); |
| 84 void Set(bool b); | 93 void Set(bool b); |
| 85 | 94 |
| 95 // Creates a copy of |var| and assigns as this instance's value. |
| 96 // Note that this is different from the Reset() method that's used to |
| 97 // free the current value and assume ownership. |
| 98 void Set(const VARIANT& var); |
| 99 |
| 86 // COM object setters | 100 // COM object setters |
| 87 void Set(IDispatch* disp); | 101 void Set(IDispatch* disp); |
| 88 void Set(IUnknown* unk); | 102 void Set(IUnknown* unk); |
| 89 | 103 |
| 90 // SAFEARRAY support | 104 // SAFEARRAY support |
| 91 void Set(SAFEARRAY* array); | 105 void Set(SAFEARRAY* array); |
| 92 | 106 |
| 93 // Special setter for DATE since DATE is a double and we already have | 107 // Special setter for DATE since DATE is a double and we already have |
| 94 // a setter for double. | 108 // a setter for double. |
| 95 void SetDate(DATE date); | 109 void SetDate(DATE date); |
| 96 | 110 |
| 97 // Allows const access to the contained variant without DCHECKs etc. | 111 // Allows const access to the contained variant without DCHECKs etc. |
| 98 // This support is necessary for the V_XYZ (e.g. V_BSTR) set of macros to | 112 // This support is necessary for the V_XYZ (e.g. V_BSTR) set of macros to |
| 99 // work properly but still doesn't allow modifications since we want control | 113 // work properly but still doesn't allow modifications since we want control |
| 100 // over that. | 114 // over that. |
| 101 const VARIANT* operator&() const { | 115 const VARIANT* operator&() const { |
| 102 return &var_; | 116 return &var_; |
| 103 } | 117 } |
| 104 | 118 |
| 119 // Like other scoped classes (e.g scoped_refptr, ScopedComPtr, ScopedBstr) |
| 120 // we support the assignment operator for the type we wrap. |
| 121 ScopedVariant& operator=(const VARIANT& var); |
| 122 |
| 105 // A hack to pass a pointer to the variant where the accepting | 123 // A hack to pass a pointer to the variant where the accepting |
| 106 // function treats the variant as an input-only, read-only value | 124 // function treats the variant as an input-only, read-only value |
| 107 // but the function prototype requires a non const variant pointer. | 125 // but the function prototype requires a non const variant pointer. |
| 108 // There's no DCHECK or anything here. Callers must know what they're doing. | 126 // There's no DCHECK or anything here. Callers must know what they're doing. |
| 109 VARIANT* AsInput() const { | 127 VARIANT* AsInput() const { |
| 110 // The nature of this function is const, so we declare | 128 // The nature of this function is const, so we declare |
| 111 // it as such and cast away the constness here. | 129 // it as such and cast away the constness here. |
| 112 return const_cast<VARIANT*>(&var_); | 130 return const_cast<VARIANT*>(&var_); |
| 113 } | 131 } |
| 114 | 132 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 126 | 144 |
| 127 private: | 145 private: |
| 128 // Comparison operators for ScopedVariant are not supported at this point. | 146 // Comparison operators for ScopedVariant are not supported at this point. |
| 129 // Use the Compare method instead. | 147 // Use the Compare method instead. |
| 130 bool operator==(const ScopedVariant& var) const; | 148 bool operator==(const ScopedVariant& var) const; |
| 131 bool operator!=(const ScopedVariant& var) const; | 149 bool operator!=(const ScopedVariant& var) const; |
| 132 DISALLOW_COPY_AND_ASSIGN(ScopedVariant); | 150 DISALLOW_COPY_AND_ASSIGN(ScopedVariant); |
| 133 }; | 151 }; |
| 134 | 152 |
| 135 #endif // BASE_SCOPED_VARIANT_WIN_H_ | 153 #endif // BASE_SCOPED_VARIANT_WIN_H_ |
| OLD | NEW |