00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <boost/lexical_cast.hpp>
00029
00030 #include "vCore.h"
00031 #include "vRegistry.h"
00032 #include "veLogic.h"
00033
00034 using namespace vValue::Registry;
00035
00036 namespace vValue {
00037 namespace Expr {
00038 namespace Logic {
00039
00040 Registration register_iff("func\nlogic", "iff", 3, (Registration::fptr)
00041 ( ctor::a3* )& Creator<Condition>::create<BasePtr,BasePtr,BasePtr> );
00042
00047 Condition::Condition(BasePtr condvalue, BasePtr truevalue, BasePtr falsevalue) :
00048 m_condvalue (condvalue ),
00049 m_truevalue (truevalue ),
00050 m_falsevalue(falsevalue)
00051 {
00052 }
00053
00056 Condition::Condition(Condition const &other) :
00057 Base (other ),
00058 m_condvalue (other.m_condvalue ->copy()),
00059 m_truevalue (other.m_truevalue ->copy()),
00060 m_falsevalue(other.m_falsevalue->copy())
00061 { }
00062
00065 Base *Condition::copy(void) const {
00066 return new Condition(*this);
00067 }
00068
00072 Base const &Condition::GetExpr() const {
00073 bool truth = false;
00074
00075 try {
00076 truth = boost::lexical_cast<bool>(m_condvalue->GetValue());
00077 }
00078 catch(boost::bad_lexical_cast &) { }
00079 return truth ? *m_truevalue : *m_falsevalue;
00080 }
00081
00084 Variant Condition::GetValue(void) const {
00085 return GetExpr().GetValue();
00086 }
00087
00090 int Condition::GetInt(void) const {
00091 return GetExpr().GetInt();
00092 }
00093
00096 float Condition::GetFloat(void) const {
00097 return GetExpr().GetFloat();
00098 }
00099
00102 tString Condition::GetString(Expr::Base const *other) const {
00103 return GetExpr().GetString(other);
00104 }
00105
00106 bool Condition::operator==(Base const &other) const { return GetExpr() == other; }
00107 bool Condition::operator!=(Base const &other) const { return GetExpr() != other; }
00108 bool Condition::operator>=(Base const &other) const { return GetExpr() >= other; }
00109 bool Condition::operator<=(Base const &other) const { return GetExpr() <= other; }
00110 bool Condition::operator> (Base const &other) const { return GetExpr() > other; }
00111 bool Condition::operator< (Base const &other) const { return GetExpr() < other; }
00112
00115 Variant
00116 Not::GetValue(void) const {
00117 bool truth = false;
00118 try {
00119 truth = boost::lexical_cast<bool>(m_value->GetValue());
00120 }
00121 catch(boost::bad_lexical_cast &) { }
00122 return (int)(!truth);
00123 }
00124
00125 Base *Not::copy(void) const {
00126 return new Not(*this);
00127 }
00128
00129 }
00130 }
00131 }