aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/kiwisolver/py3/kiwi/expression.h
blob: 6d757206bd77922a961f3ba373110c0d3b3ec138 (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
/*-----------------------------------------------------------------------------
| Copyright (c) 2013-2017, Nucleic Development Team.
|
| Distributed under the terms of the Modified BSD License.
|
| The full license is in the file COPYING.txt, distributed with this software.
|----------------------------------------------------------------------------*/
#pragma once
#include <vector>
#include "term.h"


namespace kiwi
{

class Expression
{

public:

	Expression( double constant = 0.0 ) : m_constant( constant ) {}

	Expression( const Term& term, double constant = 0.0 ) :
		m_terms( 1, term ), m_constant( constant ) {}

	Expression( const std::vector<Term>& terms, double constant = 0.0 ) :
		m_terms( terms ), m_constant( constant ) {}

	~Expression() {}

	const std::vector<Term>& terms() const
	{
		return m_terms;
	}

	double constant() const
	{
		return m_constant;
	}

	double value() const
	{
		typedef std::vector<Term>::const_iterator iter_t;
		double result = m_constant;
		iter_t end = m_terms.end();
		for( iter_t it = m_terms.begin(); it != end; ++it )
			result += it->value();
		return result;
	}

private:

	std::vector<Term> m_terms;
	double m_constant;
};

} // namespace kiwi