src/tools/values/veLogic.cpp

Go to the documentation of this file.
00001 /*
00002 
00003 *************************************************************************
00004 
00005 ArmageTron -- Just another Tron Lightcycle Game in 3D.
00006 Copyright (C) 2000  Manuel Moos (manuel@moosnet.de)
00007 
00008 **************************************************************************
00009 
00010 This program is free software; you can redistribute it and/or
00011 modify it under the terms of the GNU General Public License
00012 as published by the Free Software Foundation; either version 2
00013 of the License, or (at your option) any later version.
00014 
00015 This program is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 GNU General Public License for more details.
00019 
00020 You should have received a copy of the GNU General Public License
00021 along with this program; if not, write to the Free Software
00022 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
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     // In the future, we might want to define some kind of rules for truth
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 }

Generated on Sat Mar 15 22:56:04 2008 for Armagetron Advanced by  doxygen 1.5.4