/src/libreoffice/basic/source/sbx/sbxdec.hxx
Line | Count | Source |
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 | | void addRef() |
50 | 0 | { mnRefCount++; } |
51 | | |
52 | | void fillAutomationDecimal( css::bridge::oleautomation::Decimal& rAutomationDec ); |
53 | | |
54 | | void setChar( sal_Unicode val ); |
55 | | void setByte( sal_uInt8 val ); |
56 | | void setShort( sal_Int16 val ); |
57 | | void setLong( sal_Int32 val ); |
58 | | bool setHyper( sal_Int64 val ); |
59 | | void setUShort( sal_uInt16 val ); |
60 | | void setULong( sal_uInt32 val ); |
61 | | bool setUHyper( sal_uInt64 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 ); |
67 | | void setDecimal( SbxDecimal const * pDecimal ) |
68 | 0 | { |
69 | | #ifdef _WIN32 |
70 | | if( pDecimal ) |
71 | | maDec = pDecimal->maDec; |
72 | | #else |
73 | 0 | (void)pDecimal; |
74 | 0 | #endif |
75 | 0 | } |
76 | | |
77 | 0 | void setWithOverflow(float val) { HandleFailure(setSingle(val)); } |
78 | 0 | void setWithOverflow(double val) { HandleFailure(setDouble(val)); } |
79 | 0 | void setWithOverflow(sal_Int64 val) { HandleFailure(setHyper(val)); } |
80 | 0 | void setWithOverflow(sal_uInt64 val) { HandleFailure(setUHyper(val)); } |
81 | | |
82 | | bool getChar( sal_Unicode& rVal ); |
83 | | bool getByte( sal_uInt8& rVal ); |
84 | | bool getShort( sal_Int16& rVal ); |
85 | | bool getLong( sal_Int32& rVal ); |
86 | | bool getHyper( sal_Int64& rVal ); |
87 | | bool getUShort( sal_uInt16& rVal ); |
88 | | bool getULong( sal_uInt32& rVal ); |
89 | | bool getUHyper( sal_uInt64& rVal ); |
90 | | bool getSingle( float& rVal ); |
91 | | bool getDouble( double& rVal ); |
92 | | void getString( OUString& rString ); |
93 | | |
94 | | // Only handles types, which have corresponding getWithOverflow_impl |
95 | | template <typename T> T getWithOverflow() |
96 | 0 | { |
97 | 0 | T n = 0; |
98 | 0 | HandleFailure(getWithOverflow_impl(n)); |
99 | 0 | return n; |
100 | 0 | } Unexecuted instantiation: double SbxDecimal::getWithOverflow<double>() Unexecuted instantiation: char16_t SbxDecimal::getWithOverflow<char16_t>() Unexecuted instantiation: unsigned char SbxDecimal::getWithOverflow<unsigned char>() Unexecuted instantiation: short SbxDecimal::getWithOverflow<short>() Unexecuted instantiation: unsigned short SbxDecimal::getWithOverflow<unsigned short>() Unexecuted instantiation: int SbxDecimal::getWithOverflow<int>() Unexecuted instantiation: unsigned int SbxDecimal::getWithOverflow<unsigned int>() Unexecuted instantiation: long SbxDecimal::getWithOverflow<long>() Unexecuted instantiation: unsigned long SbxDecimal::getWithOverflow<unsigned long>() Unexecuted instantiation: float SbxDecimal::getWithOverflow<float>() |
101 | | |
102 | | bool operator -= ( const SbxDecimal &r ); |
103 | | bool operator += ( const SbxDecimal &r ); |
104 | | bool operator /= ( const SbxDecimal &r ); |
105 | | bool operator *= ( const SbxDecimal &r ); |
106 | | bool neg(); |
107 | | |
108 | | bool isZero() const; |
109 | | |
110 | | // must match the return values of the Microsoft VarDecCmp Automation function |
111 | | enum class CmpResult { LT, EQ, GT }; |
112 | | friend CmpResult compare( const SbxDecimal &rLeft, const SbxDecimal &rRight ); |
113 | | |
114 | | private: |
115 | 0 | bool getWithOverflow_impl(sal_Unicode& n) { return getChar(n); } |
116 | 0 | bool getWithOverflow_impl(sal_uInt8& n) { return getByte(n); } |
117 | 0 | bool getWithOverflow_impl(sal_Int16& n) { return getShort(n); } |
118 | 0 | bool getWithOverflow_impl(sal_uInt16& n) { return getUShort(n); } |
119 | 0 | bool getWithOverflow_impl(sal_Int32& n) { return getLong(n); } |
120 | 0 | bool getWithOverflow_impl(sal_uInt32& n) { return getULong(n); } |
121 | 0 | bool getWithOverflow_impl(sal_Int64& n) { return getHyper(n); } |
122 | 0 | bool getWithOverflow_impl(sal_uInt64& n) { return getUHyper(n); } |
123 | 0 | bool getWithOverflow_impl(float& n) { return getSingle(n); } |
124 | 0 | bool getWithOverflow_impl(double& n) { return getDouble(n); } |
125 | | |
126 | | void HandleFailure(bool isSuccess); |
127 | | }; |
128 | | |
129 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |