aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/kiwisolver/py3/kiwi/variable.h
blob: eaee93f2a13ad22e7bf636b223c6f491b62a238a (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*-----------------------------------------------------------------------------
| 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 <memory>
#include <string>
#include "shareddata.h"


namespace kiwi
{

class Variable
{

public:

	class Context
	{
	public:
		Context() {}
		virtual ~Context() {}  // LCOV_EXCL_LINE
	};

	Variable( Context* context = 0 ) :
		m_data( new VariableData( "", context ) ) {}

	Variable( const std::string& name, Context* context = 0 ) :
		m_data( new VariableData( name, context ) ) {}

	Variable( const char* name, Context* context = 0 ) :
		m_data( new VariableData( name, context ) ) {}

	~Variable() {}

	const std::string& name() const
	{
		return m_data->m_name;
	}

	void setName( const char* name )
	{
		m_data->m_name = name;
	}

	void setName( const std::string& name )
	{
		m_data->m_name = name;
	}

	Context* context() const
	{
		return m_data->m_context.get();
	}

	void setContext( Context* context )
	{
		m_data->m_context.reset( context );
	}

	double value() const
	{
		return m_data->m_value;
	}

	void setValue( double value )
	{
		m_data->m_value = value;
	}

	// operator== is used for symbolics
	bool equals( const Variable& other )
	{
		return m_data == other.m_data;
	}

private:

	class VariableData : public SharedData
	{

	public:

		VariableData( const std::string& name, Context* context ) :
			SharedData(),
			m_name( name ),
			m_context( context ),
			m_value( 0.0 ) {}

		VariableData( const char* name, Context* context ) :
			SharedData(),
			m_name( name ),
			m_context( context ),
			m_value( 0.0 ) {}

		~VariableData() {}

		std::string m_name;
		std::auto_ptr<Context> m_context;
		double m_value;

	private:

		VariableData( const VariableData& other );

		VariableData& operator=( const VariableData& other );
	};

	SharedDataPtr<VariableData> m_data;

	friend bool operator<( const Variable& lhs, const Variable& rhs )
	{
		return lhs.m_data < rhs.m_data;
	}
};

} // namespace kiwi