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