1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #pragma once
21 
22 #ifdef _WIN32
23 #include <prewin.h>
24 #include <postwin.h>
25 #include <comutil.h>
26 #include <oleauto.h>
27 #endif
28 
29 #include <com/sun/star/bridge/oleautomation/Decimal.hpp>
30 
31 
32 // Decimal support
33 // Implementation only for windows
34 
35 class SbxDecimal
36 {
37     friend void releaseDecimalPtr( SbxDecimal*& rpDecimal );
38 
39 #ifdef _WIN32
40     DECIMAL     maDec;
41 #endif
42     sal_Int32       mnRefCount;
43 
44 public:
45     SbxDecimal();
46     SbxDecimal( const SbxDecimal& rDec );
47     explicit SbxDecimal( const css::bridge::oleautomation::Decimal& rAutomationDec );
48 
49     ~SbxDecimal();
50 
addRef()51     void addRef()
52         { mnRefCount++; }
53 
54     void fillAutomationDecimal( css::bridge::oleautomation::Decimal& rAutomationDec );
55 
56     void setChar( sal_Unicode val );
57     void setByte( sal_uInt8 val );
58     void setShort( sal_Int16 val );
59     void setLong( sal_Int32 val );
60     void setUShort( sal_uInt16 val );
61     void setULong( sal_uInt32 val );
62     bool setSingle( float val );
63     bool setDouble( double val );
64     void setInt( int val );
65     void setUInt( unsigned int val );
66     bool setString( OUString* pOUString );
setDecimal(SbxDecimal const * pDecimal)67     void setDecimal( SbxDecimal const * pDecimal )
68     {
69 #ifdef _WIN32
70         if( pDecimal )
71             maDec = pDecimal->maDec;
72 #else
73         (void)pDecimal;
74 #endif
75     }
76 
77     bool getChar( sal_Unicode& rVal );
78     bool getShort( sal_Int16& rVal );
79     bool getLong( sal_Int32& rVal );
80     bool getUShort( sal_uInt16& rVal );
81     bool getULong( sal_uInt32& rVal );
82     bool getSingle( float& rVal );
83     bool getDouble( double& rVal );
84     void getString( OUString& rString );
85 
86     bool operator -= ( const SbxDecimal &r );
87     bool operator += ( const SbxDecimal &r );
88     bool operator /= ( const SbxDecimal &r );
89     bool operator *= ( const SbxDecimal &r );
90     bool neg();
91 
92     bool isZero() const;
93 
94     // must match the return values of the Microsoft VarDecCmp Automation function
95     enum class CmpResult { LT, EQ, GT };
96     friend CmpResult compare( const SbxDecimal &rLeft, const SbxDecimal &rRight );
97 };
98 
99 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
100