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 .
22 template< class sourceType
>
28 SmartArray( sourceType
* parParams
, int count
, VARTYPE destVartype
): m_array(NULL
)
31 SAFEARRAYBOUND rgsabound
[1];
32 rgsabound
[0].cElements
= count
;
33 rgsabound
[0].lLbound
= 0;
34 m_array
= SafeArrayCreate( destVartype
, 1, rgsabound
);
35 SafeArrayLock( m_array
);
38 if( m_array
&& (SUCCEEDED( SafeArrayAccessData( m_array
, (void**)&pData
)) ) )
41 for( int i
=0; i
< count
; i
++)
43 CComVariant
varSource( parParams
[i
]);
48 char* p
= (char*) pData
;
49 if( SUCCEEDED( hr
= varSource
.ChangeType( destVartype
)))
50 p
[i
]= V_I1( &varSource
);
55 short* p
= (short*) pData
;
56 if( SUCCEEDED( hr
=varSource
.ChangeType( destVartype
)))
57 p
[i
]= V_I2( &varSource
);
62 unsigned short* p
= (unsigned short*) pData
;
63 if( SUCCEEDED( hr
=varSource
.ChangeType( destVartype
)))
64 p
[i
]= V_UI2( &varSource
);
69 long* p
= (long*)pData
;
70 if( SUCCEEDED( hr
=varSource
.ChangeType( destVartype
)))
71 p
[i
]= V_I4( &varSource
);
76 unsigned long* p
= (unsigned long*)pData
;
77 if( SUCCEEDED( hr
=varSource
.ChangeType( destVartype
)))
78 p
[i
]= V_UI4( &varSource
);
83 float* p
= (float*)pData
;
84 if( SUCCEEDED( hr
=varSource
.ChangeType( destVartype
)))
85 p
[i
]= V_R4( &varSource
);
90 double* p
= (double*)pData
;
91 if( SUCCEEDED( hr
=varSource
.ChangeType( destVartype
)))
92 p
[i
]= V_R8( &varSource
);
97 VARIANT_BOOL
* p
= (VARIANT_BOOL
*)pData
;
98 if( SUCCEEDED( hr
=varSource
.ChangeType( destVartype
)))
99 p
[i
]= V_BOOL( &varSource
);
104 BSTR
* pBstr
= ( BSTR
*)pData
;
105 if( SUCCEEDED( hr
=varSource
.ChangeType( destVartype
)))
106 pBstr
[i
]= SysAllocString(V_BSTR( &varSource
));
111 VARIANT
*pVariant
= (VARIANT
*)pData
;
112 hr
= VariantCopy( &pVariant
[i
], &varSource
); break;
116 // long* pUnk= (long*)pData;
117 // pUnk[i]= reinterpret_cast<long>(parParams[i]);
118 // ((IUnknown*)pUnk[i])->AddRef(); break;
122 // long* pDisp= (long*)pData;
123 // pDisp[i]= (long)parParams[i];
124 // ((IDispatch*)pDisp[i])->AddRef(); break;
132 SafeArrayDestroy( m_array
);
136 SafeArrayUnaccessData( m_array
);
139 SafeArrayUnlock( m_array
);
140 SafeArrayDestroy( m_array
);
143 operator bool (){ return m_array
== NULL
? false : true; }
145 operator SAFEARRAY
* (){ return m_array
;}
150 class SmartArray
<IUnknown
*>
155 SmartArray( sourceType
* parParams
, int count
, VARTYPE destVartype
);
157 // ATLTRACE("SmartArray<IUnknown>");
159 // SAFEARRAYBOUND rgsabound[1];
160 // rgsabound[0].cElements= count;
161 // rgsabound[0].lLbound= 0;
162 // m_array= SafeArrayCreateVector( VT_UNKNOWN, 0, count);
163 // SafeArrayLock( m_array);
166 // if( m_array && (SUCCEEDED( SafeArrayAccessData( m_array, (void**)&pData)) ) )
169 // for( int i=0; i< count; i++)
171 // CComVariant varSource( parParams[i]);
172 // switch (destVartype)
177 // pData[i]= parParams[i];
178 // pData[i]->AddRef();
186 // SafeArrayDestroy( m_array);
190 // SafeArrayUnaccessData( m_array);
193 SafeArrayUnlock( m_array
);
194 SafeArrayDestroy( m_array
);
197 operator bool (){ return m_array
== NULL
? false : true; }
199 operator SAFEARRAY
* (){ return m_array
;}
203 template <> SmartArray
<IUnknown
*>::SmartArray(sourceType
* parParams
, int count
, VARTYPE destVartype
):m_array(NULL
)
205 ATLTRACE("SmartArray<IUnknown>");
207 m_array
= SafeArrayCreateVector( VT_UNKNOWN
, 0, count
);
208 SafeArrayLock( m_array
);
211 if( m_array
&& (SUCCEEDED( SafeArrayAccessData( m_array
, (void**)&pData
)) ) )
213 for( int i
=0; i
< count
; i
++)
215 pData
[i
]= parParams
[i
];
219 SafeArrayUnaccessData( m_array
);
222 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */