1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
>
29 SmartArray( sourceType
* parParams
, int count
, VARTYPE destVartype
): m_array(NULL
)
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
);
39 if( m_array
&& (SUCCEEDED( SafeArrayAccessData( m_array
, (void**)&pData
)) ) )
42 for( int i
=0; i
< count
; i
++)
44 CComVariant
varSource( parParams
[i
]);
49 char* p
= (char*) pData
;
50 if( SUCCEEDED( hr
= varSource
.ChangeType( destVartype
)))
51 p
[i
]= V_I1( &varSource
);
56 short* p
= (short*) pData
;
57 if( SUCCEEDED( hr
=varSource
.ChangeType( destVartype
)))
58 p
[i
]= V_I2( &varSource
);
63 unsigned short* p
= (unsigned short*) pData
;
64 if( SUCCEEDED( hr
=varSource
.ChangeType( destVartype
)))
65 p
[i
]= V_UI2( &varSource
);
70 long* p
= (long*)pData
;
71 if( SUCCEEDED( hr
=varSource
.ChangeType( destVartype
)))
72 p
[i
]= V_I4( &varSource
);
77 unsigned long* p
= (unsigned long*)pData
;
78 if( SUCCEEDED( hr
=varSource
.ChangeType( destVartype
)))
79 p
[i
]= V_UI4( &varSource
);
84 float* p
= (float*)pData
;
85 if( SUCCEEDED( hr
=varSource
.ChangeType( destVartype
)))
86 p
[i
]= V_R4( &varSource
);
91 double* p
= (double*)pData
;
92 if( SUCCEEDED( hr
=varSource
.ChangeType( destVartype
)))
93 p
[i
]= V_R8( &varSource
);
98 VARIANT_BOOL
* p
= (VARIANT_BOOL
*)pData
;
99 if( SUCCEEDED( hr
=varSource
.ChangeType( destVartype
)))
100 p
[i
]= V_BOOL( &varSource
);
105 BSTR
* pBstr
= ( BSTR
*)pData
;
106 if( SUCCEEDED( hr
=varSource
.ChangeType( destVartype
)))
107 pBstr
[i
]= SysAllocString(V_BSTR( &varSource
));
112 VARIANT
*pVariant
= (VARIANT
*)pData
;
113 hr
= VariantCopy( &pVariant
[i
], &varSource
); break;
117 // long* pUnk= (long*)pData;
118 // pUnk[i]= reinterpret_cast<long>(parParams[i]);
119 // ((IUnknown*)pUnk[i])->AddRef(); break;
123 // long* pDisp= (long*)pData;
124 // pDisp[i]= (long)parParams[i];
125 // ((IDispatch*)pDisp[i])->AddRef(); break;
133 SafeArrayDestroy( m_array
);
137 SafeArrayUnaccessData( m_array
);
140 SafeArrayUnlock( m_array
);
141 SafeArrayDestroy( m_array
);
144 operator bool (){ return m_array
== NULL
? false : true; }
146 operator SAFEARRAY
* (){ return m_array
;}
151 class SmartArray
<IUnknown
*>
156 SmartArray( sourceType
* parParams
, int count
, VARTYPE destVartype
);
158 // ATLTRACE("SmartArray<IUnknown>");
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);
167 // if( m_array && (SUCCEEDED( SafeArrayAccessData( m_array, (void**)&pData)) ) )
170 // for( int i=0; i< count; i++)
172 // CComVariant varSource( parParams[i]);
173 // switch (destVartype)
178 // pData[i]= parParams[i];
179 // pData[i]->AddRef();
187 // SafeArrayDestroy( m_array);
191 // SafeArrayUnaccessData( m_array);
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>");
208 m_array
= SafeArrayCreateVector( VT_UNKNOWN
, 0, count
);
209 SafeArrayLock( m_array
);
212 if( m_array
&& (SUCCEEDED( SafeArrayAccessData( m_array
, (void**)&pData
)) ) )
214 for( int i
=0; i
< count
; i
++)
216 pData
[i
]= parParams
[i
];
220 SafeArrayUnaccessData( m_array
);
224 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */