bump product version to 6.3.0.0.beta1
[LibreOffice.git] / extensions / test / ole / OleConverterVar1 / smartarray.h
blob424fdb9c45e278ce360735205b23e8ee90946d01
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #ifndef INCLUDED_EXTENSIONS_TEST_OLE_OLECONVERTERVAR1_SMARTARRAY_H
20 #define INCLUDED_EXTENSIONS_TEST_OLE_OLECONVERTERVAR1_SMARTARRAY_H
23 template< class sourceType>
24 class SmartArray
26 SAFEARRAY *m_array;
27 public:
29 SmartArray( sourceType * parParams, int count, VARTYPE destVartype): m_array(NULL)
31 HRESULT hr= S_OK;
32 SAFEARRAYBOUND rgsabound[1];
33 rgsabound[0].cElements= count;
34 rgsabound[0].lLbound= 0;
35 m_array= SafeArrayCreate( destVartype, 1, rgsabound);
36 SafeArrayLock( m_array);
38 void* pData;
39 if( m_array && (SUCCEEDED( SafeArrayAccessData( m_array, (void**)&pData)) ) )
42 for( int i=0; i< count; i++)
44 CComVariant varSource( parParams[i]);
45 switch (destVartype)
47 case VT_I1:
49 char* p= (char*) pData;
50 if( SUCCEEDED( hr= varSource.ChangeType( destVartype)))
51 p[i]= V_I1( &varSource);
52 break;
54 case VT_I2:
56 short* p= (short*) pData;
57 if( SUCCEEDED( hr=varSource.ChangeType( destVartype)))
58 p[i]= V_I2( &varSource);
59 break;
61 case VT_UI2:
63 unsigned short* p= (unsigned short*) pData;
64 if( SUCCEEDED( hr=varSource.ChangeType( destVartype)))
65 p[i]= V_UI2( &varSource);
66 break;
68 case VT_I4:
70 long* p= (long*)pData;
71 if( SUCCEEDED( hr=varSource.ChangeType( destVartype)))
72 p[i]= V_I4( &varSource);
73 break;
75 case VT_UI4:
77 unsigned long* p= (unsigned long*)pData;
78 if( SUCCEEDED( hr=varSource.ChangeType( destVartype)))
79 p[i]= V_UI4( &varSource);
80 break;
82 case VT_R4:
84 float* p= (float*)pData;
85 if( SUCCEEDED( hr=varSource.ChangeType( destVartype)))
86 p[i]= V_R4( &varSource);
87 break;
89 case VT_R8:
91 double* p= (double*)pData;
92 if( SUCCEEDED( hr=varSource.ChangeType( destVartype)))
93 p[i]= V_R8( &varSource);
94 break;
96 case VT_BOOL:
98 VARIANT_BOOL* p= (VARIANT_BOOL*)pData;
99 if( SUCCEEDED( hr=varSource.ChangeType( destVartype)))
100 p[i]= V_BOOL( &varSource);
101 break;
103 case VT_BSTR:
105 BSTR* pBstr= ( BSTR*)pData;
106 if( SUCCEEDED( hr=varSource.ChangeType( destVartype)))
107 pBstr[i]= SysAllocString(V_BSTR( &varSource));
108 break;
110 case VT_VARIANT:
112 VARIANT *pVariant= (VARIANT*)pData;
113 hr= VariantCopy( &pVariant[i], &varSource); break;
115 // case VT_UNKNOWN:
116 // {
117 // long* pUnk= (long*)pData;
118 // pUnk[i]= reinterpret_cast<long>(parParams[i]);
119 // ((IUnknown*)pUnk[i])->AddRef(); break;
120 // }
121 // case VT_DISPATCH:
122 // {
123 // long* pDisp= (long*)pData;
124 // pDisp[i]= (long)parParams[i];
125 // ((IDispatch*)pDisp[i])->AddRef(); break;
126 // }
127 default:
128 hr= E_FAIL;
131 if( FAILED( hr))
133 SafeArrayDestroy( m_array);
134 m_array= NULL;
137 SafeArrayUnaccessData( m_array);
139 ~SmartArray(){
140 SafeArrayUnlock( m_array);
141 SafeArrayDestroy( m_array );
144 operator bool (){ return m_array == NULL ? false : true; }
146 operator SAFEARRAY* (){ return m_array;}
150 template<>
151 class SmartArray<IUnknown*>
153 SAFEARRAY *m_array;
154 public:
156 SmartArray( sourceType * parParams, int count, VARTYPE destVartype);
157 // {
158 // ATLTRACE("SmartArray<IUnknown>");
159 // HRESULT hr= S_OK;
160 // SAFEARRAYBOUND rgsabound[1];
161 // rgsabound[0].cElements= count;
162 // rgsabound[0].lLbound= 0;
163 // m_array= SafeArrayCreateVector( VT_UNKNOWN, 0, count);
164 // SafeArrayLock( m_array);
166 // IUnknown* *pData;
167 // if( m_array && (SUCCEEDED( SafeArrayAccessData( m_array, (void**)&pData)) ) )
168 // {
170 // for( int i=0; i< count; i++)
171 // {
172 // CComVariant varSource( parParams[i]);
173 // switch (destVartype)
174 // {
176 // case VT_UNKNOWN:
177 // {
178 // pData[i]= parParams[i];
179 // pData[i]->AddRef();
180 // }
181 // default:
182 // hr= E_FAIL;
183 // }
184 // }
185 // if( FAILED( hr))
186 // {
187 // SafeArrayDestroy( m_array);
188 // m_array= NULL;
189 // }
190 // }
191 // SafeArrayUnaccessData( m_array);
192 // }
193 ~SmartArray(){
194 SafeArrayUnlock( m_array);
195 SafeArrayDestroy( m_array );
198 operator bool (){ return m_array == NULL ? false : true; }
200 operator SAFEARRAY* (){ return m_array;}
204 template <> SmartArray <IUnknown*>::SmartArray(sourceType * parParams, int count, VARTYPE destVartype):m_array(NULL)
206 ATLTRACE("SmartArray<IUnknown>");
207 HRESULT hr= S_OK;
208 m_array= SafeArrayCreateVector( VT_UNKNOWN, 0, count);
209 SafeArrayLock( m_array);
211 IUnknown* *pData;
212 if( m_array && (SUCCEEDED( SafeArrayAccessData( m_array, (void**)&pData)) ) )
214 for( int i=0; i< count; i++)
216 pData[i]= parParams[i];
217 pData[i]->AddRef();
220 SafeArrayUnaccessData( m_array);
222 #endif
224 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */