Rapicorn - Experimental UI Toolkit - Source Code
13.07.0
|
00001 // Licensed GNU LGPL v3 or later: http://www.gnu.org/licenses/lgpl.html 00002 #ifndef __RAPICORN_SINFEX_HH__ 00003 #define __RAPICORN_SINFEX_HH__ 00004 00005 #include <ui/utilities.hh> 00006 00007 namespace Rapicorn { 00008 00009 class Sinfex : public virtual ReferenceCountable { 00010 RAPICORN_CLASS_NON_COPYABLE (Sinfex); 00011 protected: 00012 uint *start_; 00013 explicit Sinfex (); 00014 virtual ~Sinfex (); 00015 public: 00016 static Sinfex* parse_string (const String &expression); 00017 class Value; 00018 struct Scope { 00019 virtual Value resolve_variable (const String &entity, 00020 const String &name) = 0; 00021 virtual Value call_function (const String &entity, 00022 const String &name, 00023 const vector<Value> &args) = 0; 00024 }; 00025 virtual Value eval (Scope &scope) = 0; 00026 /* Sinfex::Value implementation */ 00027 class Value { 00028 String string_; 00029 double real_; 00030 bool strflag_; 00031 String real2string () const; 00032 double string2real () const; 00033 public: 00034 bool isreal () const { return !strflag_; } 00035 bool isstring () const { return strflag_; } 00036 double real () const { return !strflag_ ? real_ : string2real(); } 00037 String string () const { return strflag_ ? string_ : real2string(); } 00038 bool asbool () const { return (!strflag_ && real_) || (strflag_ && string_ != ""); } 00039 explicit Value (double d) : real_ (d), strflag_ (0) {} 00040 explicit Value (const String &s); 00041 }; 00042 }; 00043 00044 } // Rapicorn 00045 00046 #endif /* __RAPICORN_SINFEX_HH__ */