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 2024           Expression(Expression&&) noexcept = default;
28              
29 25080           ~Expression() = default;
30              
31 26583           const std::vector<Term> &terms() const
32             {
33 26583           return m_terms;
34             }
35              
36 14008           double constant() const
37             {
38 14008           return m_constant;
39             }
40              
41 2           double value() const
42             {
43 2           double result = m_constant;
44              
45 7 100         for (const Term &term : m_terms)
46 5 50         result += term.value();
47              
48 2           return result;
49             }
50              
51             Expression& operator=(const Expression&) = default;
52              
53             Expression& operator=(Expression&&) noexcept = default;
54              
55             private:
56             std::vector<Term> m_terms;
57             double m_constant;
58             };
59              
60             } // namespace kiwi