xref: /haiku/headers/private/debugger/model/ExpressionInfo.h (revision a3e794ae459fec76826407f8ba8c94cd3535f128)
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 
16 class Type;
17 class Value;
18 class ValueNodeChild;
19 
20 
21 enum 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 
29 class ExpressionResult : public BReferenceable {
30 public:
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);
47 private:
48 			void				_Unset();
49 
50 private:
51 			expression_result_kind fResultKind;
52 			Value*				fPrimitiveValue;
53 			ValueNodeChild*		fValueNodeValue;
54 			Type*				fTypeResult;
55 };
56 
57 
58 class ExpressionInfo : public BReferenceable {
59 public:
60 	class Listener;
61 
62 public:
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 
78 private:
79 			typedef 			DoublyLinkedList<Listener> ListenerList;
80 
81 private:
82 			BString				fExpression;
83 			ListenerList		fListeners;
84 };
85 
86 
87 class ExpressionInfo::Listener : public DoublyLinkedListLinkImpl<Listener> {
88 public:
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