Debian Codegraph @

kiwi/term.h

raw
1 /*-----------------------------------------------------------------------------
2 | Copyright (c) 2013-2026, 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 <utility>
10 #include "variable.h"
11
12
13 namespace kiwi
14 {
15
16 class Term
17 {
18
19 public:
20
21 Term( Variable variable, double coefficient = 1.0 ) :
22 m_variable( std::move(variable) ), m_coefficient( coefficient ) {}
23
24 // to facilitate efficient map -> vector copies
25 Term( const std::pair<const Variable, double>& pair ) :
26 m_variable( pair.first ), m_coefficient( pair.second ) {}
27
28 Term(const Term&) = default;
29
30 Term(Term&&) noexcept = default;
31
32 ~Term() = default;
33
34 const Variable& variable() const
35 {
36 return m_variable;
37 }
38
39 double coefficient() const
40 {
41 return m_coefficient;
42 }
43
44 double value() const
45 {
46 return m_coefficient * m_variable.value();
47 }
48
49 Term& operator=(const Term&) = default;
50
51 Term& operator=(Term&&) noexcept = default;
52
53 private:
54
55 Variable m_variable;
56 double m_coefficient;
57 };
58
59 } // namespace kiwi