Coverage Report

Created: 2025-12-31 10:39

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/chart2/source/inc/CommonFunctors.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
#pragma once
20
21
#include <o3tl/any.hxx>
22
#include <rtl/math.hxx>
23
#include <com/sun/star/uno/Any.hxx>
24
#include <com/sun/star/uno/Sequence.hxx>
25
#include <rtl/ustring.hxx>
26
27
#include <algorithm>
28
#include <limits>
29
30
namespace chart::CommonFunctors
31
{
32
33
/** unary function to convert any type T into a css::uno::Any.
34
35
    <p>uno::makeAny is an inline function.  Thus is cannot be taken directly
36
    (via mem_fun_ptr)</p>
37
*/
38
struct makeAny
39
{
40
    template< typename T >
41
    css::uno::Any operator() ( const T & aVal )
42
0
    {
43
0
        return css::uno::Any( aVal );
44
0
    }
Unexecuted instantiation: com::sun::star::uno::Any chart::CommonFunctors::makeAny::operator()<double>(double const&)
Unexecuted instantiation: com::sun::star::uno::Any chart::CommonFunctors::makeAny::operator()<rtl::OUString>(rtl::OUString const&)
45
};
46
47
/** unary function to convert an OUString or css::uno::Any into a double number.
48
49
    <p>For conversion of OUString, rtl::math::StringToDouble is used.</p>
50
    <p>In case no number can be generated from the Any, NaN is returned.</p>
51
 */
52
struct ToDouble
53
{
54
    double operator() ( const css::uno::Any & rAny )
55
0
    {
56
0
        double fResult = std::numeric_limits<double>::quiet_NaN();
57
0
        rAny >>= fResult;
58
0
        return fResult;
59
0
    }
60
61
    double operator() ( std::u16string_view rStr )
62
0
    {
63
0
        rtl_math_ConversionStatus eConversionStatus;
64
0
        double fResult = ::rtl::math::stringToDouble( rStr, '.', ',', & eConversionStatus );
65
66
0
        if( eConversionStatus != rtl_math_ConversionStatus_Ok )
67
0
            return std::numeric_limits<double>::quiet_NaN();
68
69
0
        return fResult;
70
0
    }
71
};
72
73
/** unary function to convert a double number or css::uno::Any into an OUString.
74
75
    <p>For conversion of doubles, rtl::math::DoubleToOUString is used.</p>
76
 */
77
struct ToString
78
{
79
    OUString operator() ( const css::uno::Any & rAny )
80
0
    {
81
0
        if( auto pDouble = o3tl::tryAccess<double>(rAny) )
82
0
        {
83
0
            if( std::isnan(*pDouble) )
84
0
                return OUString();
85
0
            return ::rtl::math::doubleToUString(
86
0
                * pDouble,
87
0
                rtl_math_StringFormat_Automatic,
88
0
                rtl_math_DecimalPlaces_Max, // use maximum decimal places available
89
0
                '.', // decimal separator
90
0
                true // remove trailing zeros
91
0
                );
92
0
        }
93
0
        else if( auto s = o3tl::tryAccess<OUString>(rAny) )
94
0
        {
95
0
            return *s;
96
0
        }
97
98
0
        return OUString();
99
0
    }
100
101
    OUString operator() ( double fNumber )
102
0
    {
103
0
        return ::rtl::math::doubleToUString(
104
0
            fNumber,
105
0
            rtl_math_StringFormat_Automatic,
106
0
            rtl_math_DecimalPlaces_Max, // use maximum decimal places available
107
0
            '.',
108
0
            true
109
0
            );
110
0
    }
111
};
112
113
template <class Container, class Func> auto convertToSequence(const Container& container, Func f)
114
0
{
115
0
    css::uno::Sequence<decltype(f(container[0]))> result(container.size());
116
0
    std::transform(container.begin(), container.end(), result.getArray(), f);
117
0
    return result;
118
0
}
Unexecuted instantiation: auto chart::CommonFunctors::convertToSequence<com::sun::star::uno::Sequence<rtl::OUString>, chart::CommonFunctors::ToDouble>(com::sun::star::uno::Sequence<rtl::OUString> const&, chart::CommonFunctors::ToDouble)
Unexecuted instantiation: auto chart::CommonFunctors::convertToSequence<com::sun::star::uno::Sequence<com::sun::star::uno::Any>, chart::CommonFunctors::ToDouble>(com::sun::star::uno::Sequence<com::sun::star::uno::Any> const&, chart::CommonFunctors::ToDouble)
Unexecuted instantiation: auto chart::CommonFunctors::convertToSequence<com::sun::star::uno::Sequence<double>, chart::CommonFunctors::ToString>(com::sun::star::uno::Sequence<double> const&, chart::CommonFunctors::ToString)
Unexecuted instantiation: auto chart::CommonFunctors::convertToSequence<com::sun::star::uno::Sequence<com::sun::star::uno::Any>, chart::CommonFunctors::ToString>(com::sun::star::uno::Sequence<com::sun::star::uno::Any> const&, chart::CommonFunctors::ToString)
Unexecuted instantiation: auto chart::CommonFunctors::convertToSequence<com::sun::star::uno::Sequence<double>, chart::CommonFunctors::makeAny>(com::sun::star::uno::Sequence<double> const&, chart::CommonFunctors::makeAny)
Unexecuted instantiation: auto chart::CommonFunctors::convertToSequence<com::sun::star::uno::Sequence<rtl::OUString>, chart::CommonFunctors::makeAny>(com::sun::star::uno::Sequence<rtl::OUString> const&, chart::CommonFunctors::makeAny)
Unexecuted instantiation: InternalDataProvider.cxx:auto chart::CommonFunctors::convertToSequence<std::__1::vector<std::__1::vector<com::sun::star::uno::Any, std::__1::allocator<com::sun::star::uno::Any> >, std::__1::allocator<std::__1::vector<com::sun::star::uno::Any, std::__1::allocator<com::sun::star::uno::Any> > > >, chart::(anonymous namespace)::lcl_copyFromLevel>(std::__1::vector<std::__1::vector<com::sun::star::uno::Any, std::__1::allocator<com::sun::star::uno::Any> >, std::__1::allocator<std::__1::vector<com::sun::star::uno::Any, std::__1::allocator<com::sun::star::uno::Any> > > > const&, chart::(anonymous namespace)::lcl_copyFromLevel)
Unexecuted instantiation: InternalDataProvider.cxx:auto chart::CommonFunctors::convertToSequence<std::__1::vector<std::__1::vector<com::sun::star::uno::Any, std::__1::allocator<com::sun::star::uno::Any> >, std::__1::allocator<std::__1::vector<com::sun::star::uno::Any, std::__1::allocator<com::sun::star::uno::Any> > > >, chart::(anonymous namespace)::lcl_convertComplexAnyVectorToStringSequence(std::__1::vector<std::__1::vector<com::sun::star::uno::Any, std::__1::allocator<com::sun::star::uno::Any> >, std::__1::allocator<std::__1::vector<com::sun::star::uno::Any, std::__1::allocator<com::sun::star::uno::Any> > > > const&)::$_0>(std::__1::vector<std::__1::vector<com::sun::star::uno::Any, std::__1::allocator<com::sun::star::uno::Any> >, std::__1::allocator<std::__1::vector<com::sun::star::uno::Any, std::__1::allocator<com::sun::star::uno::Any> > > > const&, chart::(anonymous namespace)::lcl_convertComplexAnyVectorToStringSequence(std::__1::vector<std::__1::vector<com::sun::star::uno::Any, std::__1::allocator<com::sun::star::uno::Any> >, std::__1::allocator<std::__1::vector<com::sun::star::uno::Any, std::__1::allocator<com::sun::star::uno::Any> > > > const&)::$_0)
Unexecuted instantiation: auto chart::CommonFunctors::convertToSequence<std::__1::vector<com::sun::star::uno::Any, std::__1::allocator<com::sun::star::uno::Any> >, chart::CommonFunctors::ToString>(std::__1::vector<com::sun::star::uno::Any, std::__1::allocator<com::sun::star::uno::Any> > const&, chart::CommonFunctors::ToString)
Unexecuted instantiation: InternalDataProvider.cxx:auto chart::CommonFunctors::convertToSequence<std::__1::vector<std::__1::vector<com::sun::star::uno::Any, std::__1::allocator<com::sun::star::uno::Any> >, std::__1::allocator<std::__1::vector<com::sun::star::uno::Any, std::__1::allocator<com::sun::star::uno::Any> > > >, chart::(anonymous namespace)::lcl_getStringFromLevelVector>(std::__1::vector<std::__1::vector<com::sun::star::uno::Any, std::__1::allocator<com::sun::star::uno::Any> >, std::__1::allocator<std::__1::vector<com::sun::star::uno::Any, std::__1::allocator<com::sun::star::uno::Any> > > > const&, chart::(anonymous namespace)::lcl_getStringFromLevelVector)
Unexecuted instantiation: InternalDataProvider.cxx:auto chart::CommonFunctors::convertToSequence<std::__1::vector<std::__1::vector<com::sun::star::uno::Any, std::__1::allocator<com::sun::star::uno::Any> >, std::__1::allocator<std::__1::vector<com::sun::star::uno::Any, std::__1::allocator<com::sun::star::uno::Any> > > >, chart::(anonymous namespace)::lcl_convertVectorVectorToSequenceSequence<com::sun::star::uno::Any>(std::__1::vector<std::__1::vector<com::sun::star::uno::Any, std::__1::allocator<com::sun::star::uno::Any> >, std::__1::allocator<std::__1::vector<com::sun::star::uno::Any, std::__1::allocator<com::sun::star::uno::Any> > > > const&)::{lambda(auto:1&)#1}>(std::__1::vector<std::__1::vector<com::sun::star::uno::Any, std::__1::allocator<com::sun::star::uno::Any> >, std::__1::allocator<std::__1::vector<com::sun::star::uno::Any, std::__1::allocator<com::sun::star::uno::Any> > > > const&, chart::(anonymous namespace)::lcl_convertVectorVectorToSequenceSequence<com::sun::star::uno::Any>(std::__1::vector<std::__1::vector<com::sun::star::uno::Any, std::__1::allocator<com::sun::star::uno::Any> >, std::__1::allocator<std::__1::vector<com::sun::star::uno::Any, std::__1::allocator<com::sun::star::uno::Any> > > > const&)::{lambda(auto:1&)#1})
119
120
} //  namespace chart::CommonFunctors
121
122
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */