ExpressionInfo.h revision fce4895d
1/*
2 * Copyright 2014, Rene Gollent, rene@gollent.com.
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef EXPRESSION_INFO_H
6#define EXPRESSION_INFO_H
7
8
9#include <String.h>
10
11#include <Referenceable.h>
12#include <util/DoublyLinkedList.h>
13#include <Variant.h>
14
15
16class Type;
17class Value;
18class ValueNodeChild;
19
20
21enum expression_result_kind {
22	EXPRESSION_RESULT_KIND_UNKNOWN = 0,
23	EXPRESSION_RESULT_KIND_PRIMITIVE,
24	EXPRESSION_RESULT_KIND_VALUE_NODE,
25	EXPRESSION_RESULT_KIND_TYPE
26};
27
28
29class ExpressionResult : public BReferenceable {
30public:
31								ExpressionResult();
32	virtual						~ExpressionResult();
33
34
35			expression_result_kind Kind() const { return fResultKind; }
36
37			Value*				PrimitiveValue() const
38									{ return fPrimitiveValue; }
39			ValueNodeChild*		ValueNodeValue() const
40									{ return fValueNodeValue; }
41			Type*				GetType() const
42									{ return fTypeResult; }
43
44			void				SetToPrimitive(Value* value);
45			void				SetToValueNode(ValueNodeChild* child);
46			void				SetToType(Type* type);
47private:
48			void				_Unset();
49
50private:
51			expression_result_kind fResultKind;
52			Value*				fPrimitiveValue;
53			ValueNodeChild*		fValueNodeValue;
54			Type*				fTypeResult;
55};
56
57
58class ExpressionInfo : public BReferenceable {
59public:
60	class Listener;
61
62public:
63								ExpressionInfo();
64								ExpressionInfo(const ExpressionInfo& other);
65								ExpressionInfo(const BString& expression);
66	virtual						~ExpressionInfo();
67
68			void				SetTo(const BString& expression);
69
70			const BString&		Expression() const		{ return fExpression; }
71
72			void				AddListener(Listener* listener);
73			void				RemoveListener(Listener* listener);
74
75			void				NotifyExpressionEvaluated(status_t result,
76									ExpressionResult* value);
77
78private:
79			typedef 			DoublyLinkedList<Listener> ListenerList;
80
81private:
82			BString				fExpression;
83			ListenerList		fListeners;
84};
85
86
87class ExpressionInfo::Listener : public DoublyLinkedListLinkImpl<Listener> {
88public:
89	virtual						~Listener();
90
91	virtual	void				ExpressionEvaluated(ExpressionInfo* info,
92									status_t result,
93									ExpressionResult* value) = 0;
94};
95
96
97#endif	// EXPRESSION_INFO_H
98