1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_connectivity.hxx"
26 #include "ado/Aolevariant.hxx"
27 #include "connectivity/dbconversion.hxx"
28 #include <com/sun/star/sdbc/SQLException.hpp>
29 #include <com/sun/star/util/Time.hpp>
30 #include <com/sun/star/util/Date.hpp>
31 #include <com/sun/star/util/DateTime.hpp>
32 #include "diagnose_ex.h"
33 #include "resource/sharedresources.hxx"
34 #include "resource/ado_res.hrc"
35 #include "com/sun/star/bridge/oleautomation/Date.hpp"
36 #include "com/sun/star/bridge/oleautomation/Currency.hpp"
37 #include "com/sun/star/bridge/oleautomation/SCode.hpp"
38 #include "com/sun/star/bridge/oleautomation/Decimal.hpp"
39
40 using namespace com::sun::star::beans;
41 using namespace com::sun::star::uno;
42 using namespace com::sun::star::bridge::oleautomation;
43 using namespace connectivity::ado;
44 using ::rtl::OUString;
45
OLEString()46 OLEString::OLEString()
47 :m_sStr(NULL)
48 {
49 }
OLEString(const BSTR & _sBStr)50 OLEString::OLEString(const BSTR& _sBStr)
51 :m_sStr(_sBStr)
52 {
53 }
OLEString(const::rtl::OUString & _sBStr)54 OLEString::OLEString(const ::rtl::OUString& _sBStr)
55 {
56 m_sStr = ::SysAllocString(reinterpret_cast<LPCOLESTR>(_sBStr.getStr()));
57 }
~OLEString()58 OLEString::~OLEString()
59 {
60 if(m_sStr)
61 ::SysFreeString(m_sStr);
62 }
operator =(const::rtl::OUString & _rSrc)63 OLEString& OLEString::operator=(const ::rtl::OUString& _rSrc)
64 {
65 if(m_sStr)
66 ::SysFreeString(m_sStr);
67 m_sStr = ::SysAllocString(reinterpret_cast<LPCOLESTR>(_rSrc.getStr()));
68 return *this;
69 }
operator =(const OLEString & _rSrc)70 OLEString& OLEString::operator=(const OLEString& _rSrc)
71 {
72 if(this != &_rSrc)
73 {
74 if(m_sStr)
75 ::SysFreeString(m_sStr);
76 m_sStr = ::SysAllocString(_rSrc.m_sStr);
77 }
78 return *this;
79 }
operator =(const BSTR & _rSrc)80 OLEString& OLEString::operator=(const BSTR& _rSrc)
81 {
82 if(m_sStr)
83 ::SysFreeString(m_sStr);
84 m_sStr = _rSrc;
85 return *this;
86 }
operator ::rtl::OUString() const87 OLEString::operator ::rtl::OUString() const
88 {
89 return (m_sStr != NULL) ? ::rtl::OUString(reinterpret_cast<const sal_Unicode*>(LPCOLESTR(m_sStr)),::SysStringLen(m_sStr)) : ::rtl::OUString();
90 }
operator BSTR() const91 OLEString::operator BSTR() const
92 {
93 return m_sStr;
94 }
operator &()95 BSTR* OLEString::operator &()
96 {
97 return &m_sStr;
98 }
length() const99 sal_Int32 OLEString::length() const
100 {
101 return (m_sStr != NULL) ? ::SysStringLen(m_sStr) : 0;
102 }
103
OLEVariant()104 OLEVariant::OLEVariant()
105 {
106 VariantInit(this);
107 }
OLEVariant(const VARIANT & varSrc)108 OLEVariant::OLEVariant(const VARIANT& varSrc)
109 {
110 ::VariantInit(this);
111 HRESULT eRet = ::VariantCopy(this, const_cast<VARIANT*>(&varSrc));
112 OSL_ENSURE(eRet == S_OK,"Error while copying an ado variant!");
113 OSL_UNUSED(eRet);
114 }
OLEVariant(const OLEVariant & varSrc)115 OLEVariant::OLEVariant(const OLEVariant& varSrc)
116 {
117 ::VariantInit(this);
118 HRESULT eRet = ::VariantCopy(this, const_cast<VARIANT*>(static_cast<const VARIANT*>(&varSrc)));
119 OSL_ENSURE(eRet == S_OK,"Error while copying an ado variant!");
120 OSL_UNUSED(eRet);
121 }
122
OLEVariant(sal_Bool x)123 OLEVariant::OLEVariant(sal_Bool x) { VariantInit(this); vt = VT_BOOL; boolVal = (x ? VARIANT_TRUE : VARIANT_FALSE);}
OLEVariant(sal_Int8 n)124 OLEVariant::OLEVariant(sal_Int8 n) { VariantInit(this); vt = VT_I1; bVal = n;}
OLEVariant(sal_Int16 n)125 OLEVariant::OLEVariant(sal_Int16 n) { VariantInit(this); vt = VT_I2; intVal = n;}
OLEVariant(sal_Int32 n)126 OLEVariant::OLEVariant(sal_Int32 n) { VariantInit(this); vt = VT_I4; lVal = n;}
OLEVariant(sal_Int64 x)127 OLEVariant::OLEVariant(sal_Int64 x) { VariantInit(this); vt = VT_I4; lVal = (LONG)x;}
128
OLEVariant(const rtl::OUString & us)129 OLEVariant::OLEVariant(const rtl::OUString& us)
130 {
131 ::VariantInit(this);
132 vt = VT_BSTR;
133 bstrVal = SysAllocString(reinterpret_cast<LPCOLESTR>(us.getStr()));
134 }
~OLEVariant()135 OLEVariant::~OLEVariant()
136 {
137 HRESULT eRet = ::VariantClear(this);
138 OSL_ENSURE(eRet == S_OK,"Error while clearing an ado variant!");
139 OSL_UNUSED(eRet);
140 } // clears all the memory that was allocated before
141
OLEVariant(const::com::sun::star::util::Date & x)142 OLEVariant::OLEVariant(const ::com::sun::star::util::Date& x )
143 {
144 VariantInit(this);
145 vt = VT_DATE;
146 dblVal = ::dbtools::DBTypeConversion::toDouble(x,::com::sun::star::util::Date(30,12,1899));
147 }
OLEVariant(const::com::sun::star::util::Time & x)148 OLEVariant::OLEVariant(const ::com::sun::star::util::Time& x )
149 {
150 VariantInit(this);
151 vt = VT_DATE;
152 dblVal = ::dbtools::DBTypeConversion::toDouble(x);
153 }
OLEVariant(const::com::sun::star::util::DateTime & x)154 OLEVariant::OLEVariant(const ::com::sun::star::util::DateTime& x )
155 {
156 VariantInit(this);
157 vt = VT_DATE;
158 dblVal = ::dbtools::DBTypeConversion::toDouble(x,::com::sun::star::util::Date(30,12,1899));
159 }
OLEVariant(const float & x)160 OLEVariant::OLEVariant(const float &x)
161 {
162 VariantInit(this);
163 vt = VT_R4;
164 fltVal = x;
165 }
OLEVariant(const double & x)166 OLEVariant::OLEVariant(const double &x)
167 {
168 VariantInit(this);
169 vt = VT_R8;
170 dblVal = x;
171 }
172
173
OLEVariant(IDispatch * pDispInterface)174 OLEVariant::OLEVariant(IDispatch* pDispInterface)
175 {
176 VariantInit(this);
177 setIDispatch( pDispInterface );
178 }
179
OLEVariant(const::com::sun::star::uno::Sequence<sal_Int8> & x)180 OLEVariant::OLEVariant(const ::com::sun::star::uno::Sequence< sal_Int8 >& x)
181 {
182 VariantInit(this);
183
184 vt = VT_ARRAY|VT_UI1;
185
186 SAFEARRAYBOUND rgsabound[1];
187 rgsabound[0].lLbound = 0;
188 rgsabound[0].cElements = x.getLength();
189 // parray = SafeArrayCreate(VT_UI1,1,rgsabound);
190 parray = SafeArrayCreateVector(VT_UI1, 0, x.getLength());
191 const sal_Int8* pBegin = x.getConstArray();
192 const sal_Int8* pEnd = pBegin + x.getLength();
193
194 for(sal_Int32 i=0;pBegin != pEnd;++i,++pBegin)
195 {
196 sal_Int32 nData = *pBegin;
197 HRESULT rs = SafeArrayPutElement(parray,&i,&nData);
198 OSL_ENSURE(S_OK == rs,"Error while copy byte data");
199 OSL_UNUSED(rs);
200 }
201 }
202 //
operator =(const OLEVariant & varSrc)203 OLEVariant& OLEVariant::operator=(const OLEVariant& varSrc)
204 {
205 HRESULT eRet = ::VariantCopy(this, const_cast<VARIANT*>(static_cast<const VARIANT*>(&varSrc)));
206 OSL_ENSURE(eRet == S_OK,"Error while copying an ado variant!");
207 OSL_UNUSED(eRet);
208 return *this;
209 }
210 // Assign a const VARIANT& (::VariantCopy handles everything)
211 //
operator =(const tagVARIANT & varSrc)212 OLEVariant& OLEVariant::operator=(const tagVARIANT& varSrc)
213 {
214 HRESULT eRet = ::VariantCopy(this, const_cast<VARIANT*>(&varSrc));
215 OSL_ENSURE(eRet == S_OK,"Error while copying an ado variant!");
216 OSL_UNUSED(eRet);
217
218 return *this;
219 }
220
221 // Assign a const VARIANT* (::VariantCopy handles everything)
222 //
operator =(const VARIANT * pSrc)223 OLEVariant& OLEVariant::operator=(const VARIANT* pSrc)
224 {
225 HRESULT eRet = ::VariantCopy(this, const_cast<VARIANT*>(pSrc));
226 OSL_ENSURE(eRet == S_OK,"Error while copying an ado variant!");
227 OSL_UNUSED(eRet);
228
229 return *this;
230 }
231
setByte(sal_uInt8 n)232 void OLEVariant::setByte(sal_uInt8 n)
233 {
234 HRESULT eRet = VariantClear(this);
235 OSL_ENSURE(eRet == S_OK,"Error while clearing an ado variant!");
236 OSL_UNUSED(eRet);
237 vt = VT_UI1;
238 bVal = n;
239 }
setInt16(sal_Int16 n)240 void OLEVariant::setInt16(sal_Int16 n)
241 {
242 HRESULT eRet = VariantClear(this);
243 OSL_ENSURE(eRet == S_OK,"Error while clearing an ado variant!");
244 OSL_UNUSED(eRet);
245 vt = VT_I2;
246 iVal = n;
247 }
setInt32(sal_Int32 n)248 void OLEVariant::setInt32(sal_Int32 n)
249 {
250 HRESULT eRet = VariantClear(this);
251 OSL_ENSURE(eRet == S_OK,"Error while clearing an ado variant!");
252 OSL_UNUSED(eRet);
253 vt = VT_I4;
254 lVal = n;
255 }
setFloat(float f)256 void OLEVariant::setFloat(float f)
257 { HRESULT eRet = VariantClear(this);
258 OSL_ENSURE(eRet == S_OK,"Error while clearing an ado variant!");
259 OSL_UNUSED(eRet);
260 vt = VT_R4;
261 fltVal = f;
262 }
setDouble(double d)263 void OLEVariant::setDouble(double d)
264 {
265 HRESULT eRet = VariantClear(this);
266 OSL_ENSURE(eRet == S_OK,"Error while clearing an ado variant!");
267 OSL_UNUSED(eRet);
268 vt = VT_R8;
269 dblVal = d;
270 }
setDate(DATE d)271 void OLEVariant::setDate(DATE d)
272 { HRESULT eRet = VariantClear(this);
273 OSL_ENSURE(eRet == S_OK,"Error while clearing an ado variant!");
274 OSL_UNUSED(eRet);
275 vt = VT_DATE;
276 date = d;
277 }
setChar(unsigned char a)278 void OLEVariant::setChar(unsigned char a)
279 {
280 HRESULT eRet = VariantClear(this);
281 OSL_ENSURE(eRet == S_OK,"Error while clearing an ado variant!");
282 OSL_UNUSED(eRet);
283 vt = VT_UI1;
284 bVal = a;
285 }
setCurrency(double aCur)286 void OLEVariant::setCurrency(double aCur)
287 {
288 HRESULT eRet = VariantClear(this);
289 OSL_ENSURE(eRet == S_OK,"Error while clearing an ado variant!");
290 OSL_UNUSED(eRet);
291 vt = VT_CY;
292 set(aCur*10000);
293 }
setBool(sal_Bool b)294 void OLEVariant::setBool(sal_Bool b)
295 {
296 HRESULT eRet = VariantClear(this);
297 OSL_ENSURE(eRet == S_OK,"Error while clearing an ado variant!");
298 OSL_UNUSED(eRet);
299 vt = VT_BOOL;
300 boolVal = b ? VARIANT_TRUE : VARIANT_FALSE;
301 }
setString(const rtl::OUString & us)302 void OLEVariant::setString(const rtl::OUString& us)
303 {
304 HRESULT eRet = VariantClear(this);
305 OSL_ENSURE(eRet == S_OK,"Error while clearing an ado variant!");
306 OSL_UNUSED(eRet);
307 vt = VT_BSTR;
308 bstrVal = ::SysAllocString(reinterpret_cast<LPCOLESTR>(us.getStr()));
309 }
setNoArg()310 void OLEVariant::setNoArg()
311 {
312 HRESULT eRet = VariantClear(this);
313 OSL_ENSURE(eRet == S_OK,"Error while clearing an ado variant!");
314 OSL_UNUSED(eRet);
315 vt = VT_ERROR;
316 scode = DISP_E_PARAMNOTFOUND;
317 }
318
setNull()319 void OLEVariant::setNull()
320 {
321 HRESULT eRet = VariantClear(this);
322 OSL_ENSURE(eRet == S_OK,"Error while clearing an ado variant!");
323 OSL_UNUSED(eRet);
324 vt = VT_NULL;
325 }
setEmpty()326 void OLEVariant::setEmpty()
327 {
328 HRESULT eRet = VariantClear(this);
329 OSL_ENSURE(eRet == S_OK,"Error while clearing an ado variant!");
330 OSL_UNUSED(eRet);
331 vt = VT_EMPTY;
332 }
333
setUI1SAFEARRAYPtr(SAFEARRAY * pSafeAr)334 void OLEVariant::setUI1SAFEARRAYPtr(SAFEARRAY* pSafeAr)
335 {
336 HRESULT eRet = VariantClear(this);
337 OSL_ENSURE(eRet == S_OK,"Error while clearing an ado variant!");
338 OSL_UNUSED(eRet);
339 vt = VT_ARRAY|VT_UI1; parray = pSafeAr;
340 }
341
setArray(SAFEARRAY * pSafeArray,VARTYPE vtType)342 void OLEVariant::setArray(SAFEARRAY* pSafeArray, VARTYPE vtType)
343 {
344 HRESULT eRet = VariantClear(this);
345 OSL_ENSURE(eRet == S_OK,"Error while clearing an ado variant!");
346 OSL_UNUSED(eRet);
347 vt = (VARTYPE)(VT_ARRAY|vtType);
348 parray = pSafeArray;
349 }
350
setIDispatch(IDispatch * pDispInterface)351 void OLEVariant::setIDispatch(IDispatch* pDispInterface)
352 {
353 HRESULT eRet = VariantClear(this);
354 OSL_ENSURE(eRet == S_OK,"Error while clearing an ado variant!");
355 OSL_UNUSED(eRet);
356
357 vt = VT_DISPATCH;
358 pdispVal = pDispInterface;
359
360 if ( pDispInterface )
361 pDispInterface->AddRef();
362 }
363
364
isNull() const365 sal_Bool OLEVariant::isNull() const { return (vt == VT_NULL); }
isEmpty() const366 sal_Bool OLEVariant::isEmpty() const { return (vt == VT_EMPTY); }
367
getType() const368 VARTYPE OLEVariant::getType() const { return vt; }
369
operator ::com::sun::star::util::Date() const370 OLEVariant::operator ::com::sun::star::util::Date() const
371 {
372 return isNull() ? ::com::sun::star::util::Date(30,12,1899) : ::dbtools::DBTypeConversion::toDate(getDate(),::com::sun::star::util::Date(30,12,1899));
373 }
operator ::com::sun::star::util::Time() const374 OLEVariant::operator ::com::sun::star::util::Time() const
375 {
376 return isNull() ? ::com::sun::star::util::Time() : ::dbtools::DBTypeConversion::toTime(getDate());
377 }
operator ::com::sun::star::util::DateTime() const378 OLEVariant::operator ::com::sun::star::util::DateTime()const
379 {
380 return isNull() ? ::com::sun::star::util::DateTime() : ::dbtools::DBTypeConversion::toDateTime(getDate(),::com::sun::star::util::Date(30,12,1899));
381 }
382
VariantBool(sal_Bool bEinBoolean)383 VARIANT_BOOL OLEVariant::VariantBool(sal_Bool bEinBoolean)
384 {
385 return (bEinBoolean ? VARIANT_TRUE : VARIANT_FALSE);
386 }
387
CHS()388 void OLEVariant::CHS()
389 {
390 cyVal.Lo ^= (sal_uInt32)-1;
391 cyVal.Hi ^= -1;
392 cyVal.Lo++;
393 if( !cyVal.Lo )
394 cyVal.Hi++;
395 }
396
set(double n)397 void OLEVariant::set(double n)
398 {
399 if( n >= 0 )
400 {
401 cyVal.Hi = (sal_Int32)(n / (double)4294967296.0);
402 cyVal.Lo = (sal_uInt32)(n - ((double)cyVal.Hi * (double)4294967296.0));
403 }
404 else {
405 cyVal.Hi = (sal_Int32)(-n / (double)4294967296.0);
406 cyVal.Lo = (sal_uInt32)(-n - ((double)cyVal.Hi * (double)4294967296.0));
407 CHS();
408 }
409 }
410
operator rtl::OUString() const411 OLEVariant::operator rtl::OUString() const
412 {
413 if (V_VT(this) == VT_BSTR)
414 return reinterpret_cast<const sal_Unicode*>(LPCOLESTR(V_BSTR(this)));
415
416 if(isNull())
417 return ::rtl::OUString();
418
419 OLEVariant varDest;
420
421 varDest.ChangeType(VT_BSTR, this);
422
423 return reinterpret_cast<const sal_Unicode*>(LPCOLESTR(V_BSTR(&varDest)));
424 }
425
426 // -----------------------------------------------------------------------------
ChangeType(VARTYPE vartype,const OLEVariant * pSrc)427 void OLEVariant::ChangeType(VARTYPE vartype, const OLEVariant* pSrc)
428 {
429 //
430 // If pDest is NULL, convert type in place
431 //
432 if (pSrc == NULL)
433 pSrc = this;
434
435 if ( ( this != pSrc )
436 || ( vartype != V_VT( this ) )
437 )
438 {
439 if ( FAILED( ::VariantChangeType( static_cast< VARIANT* >( this ),
440 const_cast< VARIANT* >( static_cast< const VARIANT* >( pSrc ) ),
441 0,
442 vartype ) ) )
443 {
444 ::connectivity::SharedResources aResources;
445 const ::rtl::OUString sError( aResources.getResourceString(STR_TYPE_NOT_CONVERT));
446 throw ::com::sun::star::sdbc::SQLException(
447 sError,
448 NULL,
449 ::rtl::OUString::createFromAscii( "S1000" ),
450 1000,
451 ::com::sun::star::uno::Any()
452 );
453 }
454 }
455 }
456
457 // -----------------------------------------------------------------------------
operator ::com::sun::star::uno::Sequence<sal_Int8>() const458 OLEVariant::operator ::com::sun::star::uno::Sequence< sal_Int8 >() const
459 {
460 ::com::sun::star::uno::Sequence< sal_Int8 > aRet;
461 if(V_VT(this) == VT_BSTR)
462 {
463 OLEString sStr(V_BSTR(this));
464 aRet = ::com::sun::star::uno::Sequence<sal_Int8>(reinterpret_cast<const sal_Int8*>((const wchar_t*)sStr),sizeof(sal_Unicode)*sStr.length());
465 }
466 else if(!isNull())
467 {
468 SAFEARRAY* pArray = getUI1SAFEARRAYPtr();
469
470 if(pArray)
471 {
472 HRESULT hresult1,hresult2;
473 long lBound,uBound;
474 // Verify that the SafeArray is the proper shape.
475 hresult1 = ::SafeArrayGetLBound(pArray, 1, &lBound);
476 hresult2 = ::SafeArrayGetUBound(pArray, 1, &uBound);
477 if ( SUCCEEDED(hresult1) && SUCCEEDED(hresult2) )
478 {
479 long nCount = uBound-lBound+1;
480 aRet.realloc(nCount);
481 sal_Int8* pData = aRet.getArray();
482 for(long i=0; SUCCEEDED(hresult1) && lBound <= uBound ;++i,++lBound)
483 {
484 sal_Int32 nData = 0;
485 hresult1 = ::SafeArrayGetElement(pArray,&lBound,&nData);
486 if ( SUCCEEDED(hresult1) )
487 {
488 *pData = static_cast<sal_Int8>(nData);
489 ++pData;
490 }
491 }
492 }
493 }
494 }
495
496 return aRet;
497 }
498 // -----------------------------------------------------------------------------
getString() const499 ::rtl::OUString OLEVariant::getString() const
500 {
501 if(isNull())
502 return ::rtl::OUString();
503 else
504 return *this;
505 }
506 // -----------------------------------------------------------------------------
getBool() const507 sal_Bool OLEVariant::getBool() const
508 {
509 if (V_VT(this) == VT_BOOL)
510 return V_BOOL(this) == VARIANT_TRUE ? sal_True : sal_False;
511 if(isNull())
512 return sal_False;
513
514 OLEVariant varDest;
515
516 varDest.ChangeType(VT_BOOL, this);
517
518 return V_BOOL(&varDest) == VARIANT_TRUE ? sal_True : sal_False;
519 }
520 // -----------------------------------------------------------------------------
getIUnknown() const521 IUnknown* OLEVariant::getIUnknown() const
522 {
523 if (V_VT(this) == VT_UNKNOWN)
524 {
525 return V_UNKNOWN(this);
526 }
527 if(isNull())
528 return NULL;
529
530 OLEVariant varDest;
531
532 varDest.ChangeType(VT_UNKNOWN, this);
533
534 V_UNKNOWN(&varDest)->AddRef();
535 return V_UNKNOWN(&varDest);
536 }
537 // -----------------------------------------------------------------------------
getIDispatch() const538 IDispatch* OLEVariant::getIDispatch() const
539 {
540 if (V_VT(this) == VT_DISPATCH)
541 {
542 return V_DISPATCH(this);
543 }
544
545 if(isNull())
546 return NULL;
547
548 OLEVariant varDest;
549
550 varDest.ChangeType(VT_DISPATCH, this);
551
552 V_DISPATCH(&varDest)->AddRef();
553 return V_DISPATCH(&varDest);
554 }
555 // -----------------------------------------------------------------------------
getByte() const556 sal_uInt8 OLEVariant::getByte() const
557 {
558 if (V_VT(this) == VT_UI1)
559 return V_UI1(this);
560
561 if(isNull())
562 return sal_Int8(0);
563 OLEVariant varDest;
564
565 varDest.ChangeType(VT_UI1, this);
566
567 return V_UI1(&varDest);
568 }
569 // -----------------------------------------------------------------------------
getInt16() const570 sal_Int16 OLEVariant::getInt16() const
571 {
572 if (V_VT(this) == VT_I2)
573 return V_I2(this);
574
575 if(isNull())
576 return sal_Int16(0);
577 OLEVariant varDest;
578
579 varDest.ChangeType(VT_I2, this);
580
581 return V_I2(&varDest);
582 }
583 // -----------------------------------------------------------------------------
getInt8() const584 sal_Int8 OLEVariant::getInt8() const
585 {
586 if (V_VT(this) == VT_I1)
587 return V_I1(this);
588
589 if(isNull())
590 return sal_Int8(0);
591
592 OLEVariant varDest;
593
594 varDest.ChangeType(VT_I1, this);
595
596 return V_I1(&varDest);
597 }
598 // -----------------------------------------------------------------------------
getInt32() const599 sal_Int32 OLEVariant::getInt32() const
600 {
601 if (V_VT(this) == VT_I4)
602 return V_I4(this);
603
604 if(isNull())
605 return sal_Int32(0);
606
607 OLEVariant varDest;
608
609 varDest.ChangeType(VT_I4, this);
610
611 return V_I4(&varDest);
612 }
613 // -----------------------------------------------------------------------------
getUInt32() const614 sal_uInt32 OLEVariant::getUInt32() const
615 {
616 if (V_VT(this) == VT_UI4)
617 return V_UI4(this);
618
619 if(isNull())
620 return sal_uInt32(0);
621
622 OLEVariant varDest;
623
624 varDest.ChangeType(VT_UI4, this);
625
626 return V_UI4(&varDest);
627 }
628 // -----------------------------------------------------------------------------
getFloat() const629 float OLEVariant::getFloat() const
630 {
631 if (V_VT(this) == VT_R4)
632 return V_R4(this);
633
634 if(isNull())
635 return float(0);
636 OLEVariant varDest;
637
638 varDest.ChangeType(VT_R4, this);
639
640 return V_R4(&varDest);
641 }
642 // -----------------------------------------------------------------------------
getDouble() const643 double OLEVariant::getDouble() const
644 {
645 if (V_VT(this) == VT_R8)
646 return V_R8(this);
647
648 if(isNull())
649 return double(0);
650 OLEVariant varDest;
651
652 varDest.ChangeType(VT_R8, this);
653
654 return V_R8(&varDest);
655 }
656 // -----------------------------------------------------------------------------
getDate() const657 double OLEVariant::getDate() const
658 {
659 if (V_VT(this) == VT_DATE)
660 return V_DATE(this);
661
662 if(isNull())
663 return double(0);
664 OLEVariant varDest;
665
666 varDest.ChangeType(VT_DATE, this);
667
668 return V_DATE(&varDest);
669 }
670 // -----------------------------------------------------------------------------
getCurrency() const671 CY OLEVariant::getCurrency() const
672 {
673 if (V_VT(this) == VT_CY)
674 return V_CY(this);
675
676 if(isNull())
677 {
678 CY aVar;
679 aVar.int64 = sal_Int64(0);
680 return aVar;
681 }
682 OLEVariant varDest;
683
684 varDest.ChangeType(VT_CY, this);
685
686 return V_CY(&varDest);
687 }
688 // -----------------------------------------------------------------------------
getUI1SAFEARRAYPtr() const689 SAFEARRAY* OLEVariant::getUI1SAFEARRAYPtr() const
690 {
691 if (V_VT(this) == (VT_ARRAY|VT_UI1))
692 return V_ARRAY(this);
693
694 if(isNull())
695 return (0);
696 OLEVariant varDest;
697
698 varDest.ChangeType((VT_ARRAY|VT_UI1), this);
699
700 return V_ARRAY(&varDest);
701 }
702 // -----------------------------------------------------------------------------
makeAny() const703 ::com::sun::star::uno::Any OLEVariant::makeAny() const
704 {
705 ::com::sun::star::uno::Any aValue;
706 switch (V_VT(this))
707 {
708 case VT_EMPTY:
709 case VT_NULL:
710 aValue.setValue(NULL, Type());
711 break;
712 case VT_I2:
713 aValue.setValue( & iVal, getCppuType( (sal_Int16*)0));
714 break;
715 case VT_I4:
716 aValue.setValue( & lVal, getCppuType( (sal_Int32*)0));
717 break;
718 case VT_R4:
719 aValue.setValue( & fltVal, getCppuType( (float*)0));
720 break;
721 case VT_R8:
722 aValue.setValue(& dblVal, getCppuType( (double*)0));
723 break;
724 case VT_CY:
725 {
726 Currency cy(cyVal.int64);
727 aValue <<= cy;
728 break;
729 }
730 case VT_DATE:
731 {
732 aValue <<= (::com::sun::star::util::Date)*this;
733 break;
734 }
735 case VT_BSTR:
736 {
737 OUString b(reinterpret_cast<const sal_Unicode*>(bstrVal));
738 aValue.setValue( &b, getCppuType( &b));
739 break;
740 }
741 case VT_BOOL:
742 {
743 sal_Bool b= boolVal == VARIANT_TRUE;
744 aValue.setValue( &b, getCppuType( &b));
745 break;
746 }
747 case VT_I1:
748 aValue.setValue( & cVal, getCppuType((sal_Int8*)0));
749 break;
750 case VT_UI1: // there is no unsigned char in UNO
751 aValue.setValue( & bVal, getCppuType( (sal_Int8*)0));
752 break;
753 case VT_UI2:
754 aValue.setValue( & uiVal, getCppuType( (sal_uInt16*)0));
755 break;
756 case VT_UI4:
757 aValue.setValue( & ulVal, getCppuType( (sal_uInt32*)0));
758 break;
759 case VT_INT:
760 aValue.setValue( & intVal, getCppuType( (sal_Int32*)0));
761 break;
762 case VT_UINT:
763 aValue.setValue( & uintVal, getCppuType( (sal_uInt32*)0));
764 break;
765 case VT_VOID:
766 aValue.setValue( NULL, Type());
767 break;
768 case VT_DECIMAL:
769 {
770 Decimal dec;
771 dec.Scale = decVal.scale;
772 dec.Sign = decVal.sign;
773 dec.LowValue = decVal.Lo32;
774 dec.MiddleValue = decVal.Mid32;
775 dec.HighValue = decVal.Hi32;
776 aValue <<= dec;
777 break;
778 }
779
780 default:
781 break;
782 }
783 return aValue;
784 }
785 // -----------------------------------------------------------------------------
786 // -----------------------------------------------------------------------------
787 // -----------------------------------------------------------------------------
788