diff options
author | lordjaxom <lordjaxom> | 2005-01-05 19:32:43 +0000 |
---|---|---|
committer | lordjaxom <lordjaxom> | 2005-01-05 19:32:43 +0000 |
commit | 43f57cb99f43a91285ef5df6bd36b3bda5dd719a (patch) | |
tree | 606490e3b1ba0186e82e7f3e7c23b6c99b29650b /xml | |
parent | 180e1063acbb8cedbd4831d7070429dc6d429457 (diff) | |
download | vdr-plugin-text2skin-43f57cb99f43a91285ef5df6bd36b3bda5dd719a.tar.gz vdr-plugin-text2skin-43f57cb99f43a91285ef5df6bd36b3bda5dd719a.tar.bz2 |
- extended consequent use of cxType for strings and numbers in
function/string context
Diffstat (limited to 'xml')
-rw-r--r-- | xml/function.c | 38 | ||||
-rw-r--r-- | xml/function.h | 9 | ||||
-rw-r--r-- | xml/type.c | 11 | ||||
-rw-r--r-- | xml/type.h | 73 |
4 files changed, 101 insertions, 30 deletions
diff --git a/xml/function.c b/xml/function.c index d185559..64d853e 100644 --- a/xml/function.c +++ b/xml/function.c @@ -1,5 +1,5 @@ /* - * $Id: function.c,v 1.6 2005/01/02 20:33:53 lordjaxom Exp $ + * $Id: function.c,v 1.7 2005/01/05 19:32:43 lordjaxom Exp $ */ #include "xml/function.h" @@ -163,49 +163,51 @@ bool cxFunction::Parse(const std::string &Text) return true; } -const std::string &cxFunction::FunFile(const std::string &Param) const +cxType cxFunction::FunFile(const cxType &Param) const { std::string path = cText2SkinRender::ImagePath(Param); Dprintf("checking file(%s) in cache\n", path.c_str()); - return cText2SkinBitmap::Available(path) ? Param : False; + return cText2SkinBitmap::Available(path) + ? (cxType)Param + : (cxType)false; } -std::string cxFunction::FunPlugin(const std::string &Param) const +cxType cxFunction::FunPlugin(const cxType &Param) const { - cPlugin *p = cPluginManager::GetPlugin(Param.c_str()); + cPlugin *p = cPluginManager::GetPlugin(Param); if (p) { const char *entry = p->MainMenuEntry(); if (entry) return entry; } - return False; + return false; } -std::string cxFunction::Evaluate(void) const +cxType cxFunction::Evaluate(void) const { switch (mType) { case string: return mString.Evaluate(); case fun_not: - return mParams[0]->EvaluateToBool() ? False : True; + return !mParams[0]->Evaluate(); case fun_and: for (uint i = 0; i < mNumParams; ++i) { - if (!mParams[i]->EvaluateToBool()) - return False; + if (!mParams[i]->Evaluate()) + return false; } - return True; + return true; case fun_or: for (uint i = 0; i < mNumParams; ++i) { - if (mParams[i]->EvaluateToBool()) - return True; + if (mParams[i]->Evaluate()) + return true; } - return False; + return false; case fun_eq: - return mParams[0]->Evaluate() == mParams[1]->Evaluate() ? True : False; + return mParams[0]->Evaluate() == mParams[1]->Evaluate(); case fun_file: return FunFile(mParams[0]->Evaluate()); @@ -213,7 +215,7 @@ std::string cxFunction::Evaluate(void) const case fun_trans: //Dprintf("|%s| translates to |%s|\n", mParams[0]->Evaluate().c_str(), tr(mParams[0]->Evaluate().c_str())); //return tr(mParams[0]->Evaluate().c_str()); - return mParams[0]->Evaluate().c_str(); + return mParams[0]->Evaluate(); case fun_plugin: return FunPlugin(mParams[0]->Evaluate()); @@ -226,11 +228,13 @@ std::string cxFunction::Evaluate(void) const return False; } +#if 0 bool cxFunction::EvaluateToBool(void) { - std::string result = Evaluate(); + cxType result = Evaluate(); if (result == False/* || result == "0"*/) return false; return true; } +#endif diff --git a/xml/function.h b/xml/function.h index 9aee4c2..afc3465 100644 --- a/xml/function.h +++ b/xml/function.h @@ -1,5 +1,5 @@ /* - * $Id: function.h,v 1.4 2005/01/02 20:33:20 lordjaxom Exp $ + * $Id: function.h,v 1.5 2005/01/05 19:32:43 lordjaxom Exp $ */ #ifndef VDR_TEXT2SKIN_XML_FUNCTION_H @@ -43,8 +43,8 @@ private: uint mNumParams; protected: - const std::string &FunFile(const std::string &Param) const; - std::string FunPlugin(const std::string &Param) const; + cxType FunFile (const cxType &Param) const; + cxType FunPlugin(const cxType &Param) const; public: cxFunction(cxSkin *Skin); @@ -53,8 +53,7 @@ public: ~cxFunction(); bool Parse(const std::string &Text); - std::string Evaluate(void) const; - bool EvaluateToBool(void); + cxType Evaluate(void) const; void SetListIndex(uint Index, int Tab); }; @@ -1,15 +1,21 @@ /* - * $Id: type.c,v 1.1 2004/12/19 22:03:28 lordjaxom Exp $ + * $Id: type.c,v 1.2 2005/01/05 19:32:43 lordjaxom Exp $ */ #include "xml/type.h" #include "xml/function.h" +#include <vdr/tools.h> #include <stdio.h> cxType cxType::False(false); cxType cxType::True(true); -const std::string &cxType::String(void) { +std::string cxType::String(void) const { + if (mType == number) + return (const char*)itoa(mNumber); + return mString; + +#if 0 if (mType == number) { char *buffer; asprintf(&buffer, "%d", mNumber); @@ -21,4 +27,5 @@ const std::string &cxType::String(void) { mType = string; } return mString; +#endif } @@ -1,5 +1,5 @@ /* - * $Id: type.h,v 1.3 2004/12/21 20:26:25 lordjaxom Exp $ + * $Id: type.h,v 1.4 2005/01/05 19:32:43 lordjaxom Exp $ */ #ifndef VDR_TEXT2SKIN_XML_TYPE_H @@ -16,6 +16,8 @@ public: boolean }; + friend class cxFunction; + private: eType mType; std::string mString; @@ -34,15 +36,74 @@ public: cxType(time_t Number): mType(number), mNumber(Number), mUpdateIn(0) {} cxType(bool Value): mType(boolean), mNumber(Value ? 1 : 0), mUpdateIn(0) {} - const std::string &String(void); - int Number(void) const { return mType == number ? mNumber : 0; } + std::string String(void) const; + int Number(void) const { return mType == number ? mNumber : 0; } void SetUpdate(uint UpdateIn) { mUpdateIn = UpdateIn; } uint UpdateIn(void) const { return mUpdateIn; } - operator std::string () { return String(); } - operator int () { return Number(); } - operator bool () { return Number(); } + operator std::string () const { return String(); } + operator int () const { return Number(); } + operator bool () const; + + friend bool operator== (const cxType &a, const cxType &b); + friend bool operator!= (const cxType &a, const cxType &b); + friend bool operator< (const cxType &a, const cxType &b); + friend bool operator> (const cxType &a, const cxType &b); + friend bool operator<= (const cxType &a, const cxType &b); + friend bool operator>= (const cxType &a, const cxType &b); }; +inline cxType::operator bool () const +{ + switch (mType) { + case string: + return mString != ""; + default: + return mNumber != 0; + } +} + +inline bool operator== (const cxType &a, const cxType &b) +{ + if (a.mType == cxType::string || b.mType == cxType::string) + return a.String() == b.String(); + return a.mNumber == b.mNumber; +} + +inline bool operator!= (const cxType &a, const cxType &b) +{ + if (a.mType == cxType::string || b.mType == cxType::string) + return a.String() != b.String(); + return a.mNumber != b.mNumber; +} + +inline bool operator< (const cxType &a, const cxType &b) +{ + if (a.mType == cxType::string || b.mType == cxType::string) + return a.String() < b.String(); + return a.mNumber < b.mNumber; +} + +inline bool operator> (const cxType &a, const cxType &b) +{ + if (a.mType == cxType::string || b.mType == cxType::string) + return a.String() > b.String(); + return a.mNumber > b.mNumber; +} + +inline bool operator<= (const cxType &a, const cxType &b) +{ + if (a.mType == cxType::string || b.mType == cxType::string) + return a.String() <= b.String(); + return a.mNumber <= b.mNumber; +} + +inline bool operator>= (const cxType &a, const cxType &b) +{ + if (a.mType == cxType::string || b.mType == cxType::string) + return a.String() >= b.String(); + return a.mNumber >= b.mNumber; +} + #endif // VDR_TEXT2SKIN_XML_TYPE_H |