Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

BoolValue.cpp

Go to the documentation of this file.
00001 
00002 // BoolValue.cpp: implementation of the CBoolValue class.
00003 /*
00004  * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org>

00005  *
00006  * Permission to use, copy, modify, distribute and sell this software

00007  * and its documentation for any purpose is hereby granted without fee,

00008  * provided that the above copyright notice appear in all copies and

00009  * that both that copyright notice and this permission notice appear

00010  * in supporting documentation.  Erwin Coumans makes no

00011  * representations about the suitability of this software for any

00012  * purpose.  It is provided "as is" without express or implied warranty.

00013  *
00014  */
00015 
00016 
00017 
00018 #include "BoolValue.h"
00019 #include "StringValue.h"
00020 #include "ErrorValue.h"
00021 #include "VoidValue.h"
00022 //#include "FactoryManager.h"
00023 
00025 // Construction/Destruction
00027 
00028 
00029 CBoolValue::CBoolValue()
00030 /*
00031 pre: false

00032 effect: constructs a new CBoolValue

00033 */
00034 {
00035         trace("Bool constructor error");
00036 }
00037 
00038 CBoolValue::CBoolValue(bool innie,CCString name,AllocationTYPE alloctype)

00039 {
00040 
00041         m_bool = innie;
00042         SetName(name);
00043         if (alloctype==CValue::STACKVALUE)
00044         {
00045                 CValue::DisableRefCount();
00046         }
00047 }
00048 
00049 
00050 CValue* CBoolValue::Calc(VALUE_OPERATOR op, CValue *val)
00051 /*
00052 pre:

00053 ret: a new object containing the result of applying operator op to this

00054 object and val

00055 */
00056 {
00057         switch (op) {
00058         case VALUE_NEG_OPERATOR:
00059                 return new CErrorValue (op2str(op) + GetText());
00060                 break;
00061         case VALUE_NOT_OPERATOR:
00062                 return new CBoolValue (!m_bool);
00063                 break;
00064         default:
00065                 return val->CalcFinal(VALUE_BOOL_TYPE, op, this);
00066                 break;
00067         }
00068 }
00069 
00070 CValue* CBoolValue::CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val)
00071 /*
00072 pre: the type of val is dtype

00073 ret: a new object containing the result of applying operator op to val and

00074 this object

00075 */
00076 {
00077         CValue *ret;
00078         
00079         switch(dtype) {
00080         case VALUE_EMPTY_TYPE:
00081         case VALUE_BOOL_TYPE:
00082                 {
00083                         switch(op) {
00084                         case VALUE_AND_OPERATOR:
00085                                 ret = new CBoolValue (((CBoolValue *) val)->GetBool() && m_bool);
00086                                 break;
00087                         case VALUE_OR_OPERATOR:
00088                                 ret = new CBoolValue (((CBoolValue *) val)->GetBool() || m_bool);
00089                                 break;
00090                         case VALUE_EQL_OPERATOR:
00091                                 ret = new CBoolValue (((CBoolValue *) val)->GetBool() == m_bool);
00092                                 break;
00093                         case VALUE_NEQ_OPERATOR:
00094                                 ret = new CBoolValue (((CBoolValue *) val)->GetBool() != m_bool);
00095                                 break;
00096                         case VALUE_NOT_OPERATOR:
00097                                 return new CBoolValue (!m_bool);
00098                         break;
00099                         default:
00100                                 ret =  new CErrorValue(val->GetText() + op2str(op) +
00101                                         "[operator not allowed on booleans]");
00102                                 break;
00103                         }
00104                         break;
00105                 }
00106         case VALUE_STRING_TYPE:
00107                 {
00108                         switch(op) {
00109                         case VALUE_ADD_OPERATOR:
00110                                 ret = new CStringValue(val->GetText() + GetText(),"");
00111                                 break;
00112                         default:
00113                                 ret =  new CErrorValue(val->GetText() + op2str(op) + "[Only + allowed on boolean and string]");
00114                                 break;
00115                         }
00116                         break;
00117                 }
00118         default:
00119                 ret =  new CErrorValue("[type mismatch]" + op2str(op) + GetText());
00120         }
00121         return ret;
00122 }
00123 
00124 bool CBoolValue::GetBool()
00125 /*
00126 pre:

00127 ret: the bool stored in the object

00128 */
00129 {
00130         return m_bool;
00131 }
00132 
00133 
00134 
00135 float CBoolValue::GetNumber()

00136 {
00137         return (float)m_bool;
00138 }
00139 
00140 
00141 
00142 const CCString & CBoolValue::GetText()

00143 {
00144         static CCString sTrueString  = CCString("TRUE");
00145         static CCString sFalseString = CCString("FALSE");
00146         
00147         return m_bool ? sTrueString : sFalseString;
00148 }
00149 
00150 CValue* CBoolValue::GetReplica()

00151 {
00152         CBoolValue* replica = new CBoolValue(*this);
00153         CValue::AddDataToReplica(replica);
00154         
00155         return replica;
00156 }
00157 

Generated at Thu Feb 1 13:03:01 2001 for Ketsji Game Engine by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000