1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
31 template< class sourceType
>
37 SmartArray( sourceType
* parParams
, int count
, VARTYPE destVartype
): m_array(NULL
)
40 SAFEARRAYBOUND rgsabound
[1];
41 rgsabound
[0].cElements
= count
;
42 rgsabound
[0].lLbound
= 0;
43 m_array
= SafeArrayCreate( destVartype
, 1, rgsabound
);
44 SafeArrayLock( m_array
);
47 if( m_array
&& (SUCCEEDED( SafeArrayAccessData( m_array
, (void**)&pData
)) ) )
50 for( int i
=0; i
< count
; i
++)
52 CComVariant
varSource( parParams
[i
]);
57 char* p
= (char*) pData
;
58 if( SUCCEEDED( hr
= varSource
.ChangeType( destVartype
)))
59 p
[i
]= V_I1( &varSource
);
64 short* p
= (short*) pData
;
65 if( SUCCEEDED( hr
=varSource
.ChangeType( destVartype
)))
66 p
[i
]= V_I2( &varSource
);
71 unsigned short* p
= (unsigned short*) pData
;
72 if( SUCCEEDED( hr
=varSource
.ChangeType( destVartype
)))
73 p
[i
]= V_UI2( &varSource
);
78 long* p
= (long*)pData
;
79 if( SUCCEEDED( hr
=varSource
.ChangeType( destVartype
)))
80 p
[i
]= V_I4( &varSource
);
85 unsigned long* p
= (unsigned long*)pData
;
86 if( SUCCEEDED( hr
=varSource
.ChangeType( destVartype
)))
87 p
[i
]= V_UI4( &varSource
);
92 float* p
= (float*)pData
;
93 if( SUCCEEDED( hr
=varSource
.ChangeType( destVartype
)))
94 p
[i
]= V_R4( &varSource
);
99 double* p
= (double*)pData
;
100 if( SUCCEEDED( hr
=varSource
.ChangeType( destVartype
)))
101 p
[i
]= V_R8( &varSource
);
106 VARIANT_BOOL
* p
= (VARIANT_BOOL
*)pData
;
107 if( SUCCEEDED( hr
=varSource
.ChangeType( destVartype
)))
108 p
[i
]= V_BOOL( &varSource
);
113 BSTR
* pBstr
= ( BSTR
*)pData
;
114 if( SUCCEEDED( hr
=varSource
.ChangeType( destVartype
)))
115 pBstr
[i
]= SysAllocString(V_BSTR( &varSource
));
120 VARIANT
*pVariant
= (VARIANT
*)pData
;
121 hr
= VariantCopy( &pVariant
[i
], &varSource
); break;
125 // long* pUnk= (long*)pData;
126 // pUnk[i]= reinterpret_cast<long>(parParams[i]);
127 // ((IUnknown*)pUnk[i])->AddRef(); break;
131 // long* pDisp= (long*)pData;
132 // pDisp[i]= (long)parParams[i];
133 // ((IDispatch*)pDisp[i])->AddRef(); break;
141 SafeArrayDestroy( m_array
);
145 SafeArrayUnaccessData( m_array
);
148 SafeArrayUnlock( m_array
);
149 SafeArrayDestroy( m_array
);
152 operator bool (){ return m_array
== NULL
? false : true; }
154 operator SAFEARRAY
* (){ return m_array
;}
159 class SmartArray
<IUnknown
*>
164 SmartArray( sourceType
* parParams
, int count
, VARTYPE destVartype
);
166 // ATLTRACE("SmartArray<IUnknown>");
168 // SAFEARRAYBOUND rgsabound[1];
169 // rgsabound[0].cElements= count;
170 // rgsabound[0].lLbound= 0;
171 // m_array= SafeArrayCreateVector( VT_UNKNOWN, 0, count);
172 // SafeArrayLock( m_array);
175 // if( m_array && (SUCCEEDED( SafeArrayAccessData( m_array, (void**)&pData)) ) )
178 // for( int i=0; i< count; i++)
180 // CComVariant varSource( parParams[i]);
181 // switch (destVartype)
186 // pData[i]= parParams[i];
187 // pData[i]->AddRef();
195 // SafeArrayDestroy( m_array);
199 // SafeArrayUnaccessData( m_array);
202 SafeArrayUnlock( m_array
);
203 SafeArrayDestroy( m_array
);
206 operator bool (){ return m_array
== NULL
? false : true; }
208 operator SAFEARRAY
* (){ return m_array
;}
212 template <> SmartArray
<IUnknown
*>::SmartArray(sourceType
* parParams
, int count
, VARTYPE destVartype
):m_array(NULL
)
214 ATLTRACE("SmartArray<IUnknown>");
216 SAFEARRAYBOUND rgsabound
[1];
217 rgsabound
[0].cElements
= count
;
218 rgsabound
[0].lLbound
= 0;
219 m_array
= SafeArrayCreateVector( VT_UNKNOWN
, 0, count
);
220 SafeArrayLock( m_array
);
223 if( m_array
&& (SUCCEEDED( SafeArrayAccessData( m_array
, (void**)&pData
)) ) )
225 for( int i
=0; i
< count
; i
++)
227 pData
[i
]= parParams
[i
];
231 SafeArrayUnaccessData( m_array
);