2 * Copyright 2014, Rene Gollent, rene@gollent.com.
3 * Distributed under the terms of the MIT License.
7 #include "ExpressionInfo.h"
11 #include "ValueNode.h"
14 // #pragma mark - ExpressionResult
17 ExpressionResult::ExpressionResult()
19 fResultKind(EXPRESSION_RESULT_KIND_UNKNOWN
),
20 fPrimitiveValue(NULL
),
21 fValueNodeValue(NULL
),
27 ExpressionResult::~ExpressionResult()
29 if (fPrimitiveValue
!= NULL
)
30 fPrimitiveValue
->ReleaseReference();
32 if (fValueNodeValue
!= NULL
)
33 fValueNodeValue
->ReleaseReference();
35 if (fTypeResult
!= NULL
)
36 fTypeResult
->ReleaseReference();
41 ExpressionResult::SetToPrimitive(Value
* value
)
45 fPrimitiveValue
= value
;
46 if (fPrimitiveValue
!= NULL
) {
47 fPrimitiveValue
->AcquireReference();
48 fResultKind
= EXPRESSION_RESULT_KIND_PRIMITIVE
;
54 ExpressionResult::SetToValueNode(ValueNodeChild
* child
)
58 fValueNodeValue
= child
;
59 if (fValueNodeValue
!= NULL
) {
60 fValueNodeValue
->AcquireReference();
61 fResultKind
= EXPRESSION_RESULT_KIND_VALUE_NODE
;
64 // if the child has a node with a resolved value, store
65 // it as a primitive, so the consumer of the expression
66 // can use it as-is if desired.
68 ValueNode
* node
= child
->Node();
72 fPrimitiveValue
= node
->GetValue();
73 if (fPrimitiveValue
!= NULL
)
74 fPrimitiveValue
->AcquireReference();
79 ExpressionResult::SetToType(Type
* type
)
84 if (fTypeResult
!= NULL
) {
85 fTypeResult
->AcquireReference();
86 fResultKind
= EXPRESSION_RESULT_KIND_TYPE
;
92 ExpressionResult::_Unset()
94 if (fPrimitiveValue
!= NULL
) {
95 fPrimitiveValue
->ReleaseReference();
96 fPrimitiveValue
= NULL
;
99 if (fValueNodeValue
!= NULL
) {
100 fValueNodeValue
->ReleaseReference();
101 fValueNodeValue
= NULL
;
104 if (fTypeResult
!= NULL
) {
105 fTypeResult
->ReleaseReference();
109 fResultKind
= EXPRESSION_RESULT_KIND_UNKNOWN
;
113 // #pragma mark - ExpressionInfo
116 ExpressionInfo::ExpressionInfo()
123 ExpressionInfo::ExpressionInfo(const ExpressionInfo
& other
)
125 fExpression(other
.fExpression
)
130 ExpressionInfo::~ExpressionInfo()
135 ExpressionInfo::ExpressionInfo(const BString
& expression
)
137 fExpression(expression
)
143 ExpressionInfo::SetTo(const BString
& expression
)
145 fExpression
= expression
;
150 ExpressionInfo::AddListener(Listener
* listener
)
152 fListeners
.Add(listener
);
157 ExpressionInfo::RemoveListener(Listener
* listener
)
159 fListeners
.Remove(listener
);
164 ExpressionInfo::NotifyExpressionEvaluated(status_t result
,
165 ExpressionResult
* value
)
167 for (ListenerList::Iterator it
= fListeners
.GetIterator();
168 Listener
* listener
= it
.Next();) {
169 listener
->ExpressionEvaluated(this, result
, value
);
174 // #pragma mark - ExpressionInfo::Listener
177 ExpressionInfo::Listener::~Listener()