aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/kiwisolver/py3/kiwi/term.h
blob: 85e00b1b12851c87c88aeb90c8f44dc4d0e6041b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*-----------------------------------------------------------------------------
| Copyright (c) 2013-2017, Nucleic Development Team.
|
| Distributed under the terms of the Modified BSD License.
|
| The full license is in the file LICENSE, distributed with this software.
|----------------------------------------------------------------------------*/
#pragma once
#include <utility>
#include "variable.h"


namespace kiwi
{

class Term
{

public:

	Term( Variable variable, double coefficient = 1.0 ) :
		m_variable( std::move(variable) ), m_coefficient( coefficient ) {}

	// to facilitate efficient map -> vector copies
	Term( const std::pair<const Variable, double>& pair ) :
		m_variable( pair.first ), m_coefficient( pair.second ) {}

	Term(const Term&) = default;

	Term(Term&&) noexcept = default;

	~Term() = default;

	const Variable& variable() const
	{
		return m_variable;
	}

	double coefficient() const
	{
		return m_coefficient;
	}

	double value() const
	{
		return m_coefficient * m_variable.value();
	}

	Term& operator=(const Term&) = default;

	Term& operator=(Term&&) noexcept = default;

private:

	Variable m_variable;
	double m_coefficient;
};

} // namespace kiwi