xref: /trunk/main/basic/source/sbx/sbxvals.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
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.
14  *
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).
20  *
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.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_basic.hxx"
30 
31 #define _TLBIGINT_INT64
32 #include <tools/bigint.hxx>
33 #include <basic/sbx.hxx>
34 
35 ///////////////////////////// BigInt/Currency //////////////////////////////
36 
37 SbxValues::SbxValues( const BigInt &rBig ) : eType(SbxCURRENCY)
38 {
39     rBig.INT64( &nLong64 );
40 }
41 
42 //TODO:  BigInt is TOOLS_DLLPUBLIC, and its four member functions only declared
43 // and defined within basic (#define _TLBIGINT_INT64) are a bad hack that causes
44 // "warning C4273: 'function' : inconsistent dll linkage" on MSC; this whole
45 // mess should be cleaned up properly (e.g., by completely removing Sbx[U]INT64
46 // and using sal_[u]Int64 instead):
47 #if defined _MSC_VER
48 #pragma warning(disable: 4273)
49 #endif
50 
51 sal_Bool BigInt::INT64( SbxINT64 *p ) const
52 {
53     if( bIsBig ) {
54         if( nLen > 4 || (nNum[3] & 0x8000) )
55             return sal_False;
56 
57         p->nLow  = ((sal_uInt32)nNum[1] << 16) | (sal_uInt32)nNum[0];
58         p->nHigh = ((sal_uInt32)nNum[3] << 16) | (sal_uInt32)nNum[2];
59         if( bIsNeg )
60             p->CHS();
61     }
62     else
63         p->Set( (sal_Int32)nVal );
64 
65     return sal_True;
66 }
67 
68 BigInt::BigInt( const SbxINT64 &r )
69 {
70     BigInt a10000 = 0x10000;
71 
72     *this = r.nHigh;
73     if( r.nHigh )
74         *this *= a10000;
75     *this += (sal_uInt16)(r.nLow >> 16);
76     *this *= a10000;
77     *this += (sal_uInt16)r.nLow;
78 }
79 
80 sal_Bool BigInt::UINT64( SbxUINT64 *p ) const
81 {
82     if( bIsBig ) {
83         if( bIsNeg || nLen > 4 )
84             return sal_False;
85 
86         p->nLow  = ((sal_uInt32)nNum[1] << 16) | (sal_uInt32)nNum[0];
87         p->nHigh = ((sal_uInt32)nNum[3] << 16) | (sal_uInt32)nNum[2];
88     }
89     else {
90         if( nVal < 0 )
91             return sal_False;
92 
93         p->Set( (sal_uInt32)nVal );
94     }
95 
96     return sal_True;
97 }
98 
99 BigInt::BigInt( const SbxUINT64 &r )
100 {
101     BigInt a10000 = 0x10000;
102 
103     *this = BigInt(r.nHigh);
104     if( r.nHigh )
105         *this *= a10000;
106     *this += (sal_uInt16)(r.nLow >> 16);
107     *this *= a10000;
108     *this += (sal_uInt16)r.nLow;
109 }
110