File Coverage

/usr/local/lib/perl5/site_perl/5.26.1/x86_64-linux/auto/share/dist/Alien-Kiwisolver/include/kiwi/expression.h
Criterion Covered Total %
statement 15 15 100.0
branch 4 6 66.6
condition n/a
subroutine n/a
pod n/a
total 19 21 90.4


line stmt bran cond sub pod time code
1             /*-----------------------------------------------------------------------------
2             | Copyright (c) 2013-2017, Nucleic Development Team.
3             |
4             | Distributed under the terms of the Modified BSD License.
5             |
6             | The full license is in the file LICENSE, distributed with this software.
7             |----------------------------------------------------------------------------*/
8             #pragma once
9             #include <vector>
10             #include "term.h"
11              
12             namespace kiwi
13             {
14              
15             class Expression
16             {
17              
18             public:
19 1028           Expression(double constant = 0.0) : m_constant(constant) {}
20              
21 4291 50         Expression(const Term &term, double constant = 0.0) : m_terms(1, term), m_constant(constant) {}
22              
23 18448           Expression(std::vector<Term> terms, double constant = 0.0) : m_terms(std::move(terms)), m_constant(constant) {}
24              
25 2200           Expression(const Expression&) = default;
26              
27             // Could be marked noexcept but for a bug in the GCC of the manylinux1 image
28 2024           Expression(Expression&&) = default;
29              
30 25080           ~Expression() = default;
31              
32 26583           const std::vector<Term> &terms() const
33             {
34 26583           return m_terms;
35             }
36              
37 14008           double constant() const
38             {
39 14008           return m_constant;
40             }
41              
42 2           double value() const
43             {
44 2           double result = m_constant;
45              
46 7 100         for (const Term &term : m_terms)
47 5 50         result += term.value();
48              
49 2           return result;
50             }
51              
52             Expression& operator=(const Expression&) = default;
53              
54             // Could be marked noexcept but for a bug in the GCC of the manylinux1 image
55             Expression& operator=(Expression&&) = default;
56              
57             private:
58             std::vector<Term> m_terms;
59             double m_constant;
60             };
61              
62             } // namespace kiwi