LibreOffice Module chart2 (master) 1
CommonFunctors.hxx
Go to the documentation of this file.
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#pragma once
20
21#include <o3tl/any.hxx>
22#include <rtl/math.hxx>
23#include <com/sun/star/uno/Any.hxx>
24#include <rtl/ustring.hxx>
25#include "charttoolsdllapi.hxx"
26
27#include <limits>
28
30{
31
37template< typename T >
38 struct makeAny
39{
40 css::uno::Any operator() ( const T & aVal )
41 {
42 return css::uno::Any( aVal );
43 }
44};
45
51{
52 double operator() ( const css::uno::Any & rAny )
53 {
54 double fResult = std::numeric_limits<double>::quiet_NaN();
55 rAny >>= fResult;
56 return fResult;
57 }
58};
59
64{
65 OUString operator() ( const css::uno::Any & rAny )
66 {
67 if( auto pDouble = o3tl::tryAccess<double>(rAny) )
68 {
69 if( std::isnan(*pDouble) )
70 return OUString();
71 return ::rtl::math::doubleToUString(
72 * pDouble,
73 rtl_math_StringFormat_Automatic,
74 rtl_math_DecimalPlaces_Max, // use maximum decimal places available
75 '.', // decimal separator
76 true // remove trailing zeros
77 );
78 }
79 else if( auto s = o3tl::tryAccess<OUString>(rAny) )
80 {
81 return *s;
82 }
83
84 return OUString();
85 }
86};
87
93{
94 double operator() ( std::u16string_view rStr )
95 {
96 rtl_math_ConversionStatus eConversionStatus;
97 double fResult = ::rtl::math::stringToDouble( rStr, '.', ',', & eConversionStatus );
98
99 if( eConversionStatus != rtl_math_ConversionStatus_Ok )
100 return std::numeric_limits<double>::quiet_NaN();
101
102 return fResult;
103 }
104};
105
111{
112 OUString operator() ( double fNumber )
113 {
114 return ::rtl::math::doubleToUString(
115 fNumber,
116 rtl_math_StringFormat_Automatic,
117 rtl_math_DecimalPlaces_Max, // use maximum decimal places available
118 '.',
119 true
120 );
121 }
122};
123
124} // namespace chart::CommonFunctors
125
126/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define OOO_DLLPUBLIC_CHARTTOOLS
detail::Optional< double >::type tryAccess< double >(css::uno::Any const &any)
unary function to convert css::uno::Any into a double number.
unary function to convert css::uno::Any into an OUString.
unary function to convert a double number into an OUString.
unary function to convert an OUString into a double number.
unary function to convert any type T into a css::uno::Any.
css::uno::Any operator()(const T &aVal)