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

IfExpr.cpp

Go to the documentation of this file.
00001 // IfExpr.cpp: implementation of the CIfExpr class.
00002 /*
00003  * Copyright (c) 1996-2000 Erwin Coumans <[email protected]>

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

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

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

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

00009  * in supporting documentation.  Erwin Coumans makes no

00010  * representations about the suitability of this software for any

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

00012  *
00013  */
00014 
00015 #include "IfExpr.h"
00016 #include "EmptyValue.h"
00017 #include "ErrorValue.h"
00018 
00019 
00021 // Construction/Destruction
00023 
00024 CIfExpr::CIfExpr(CExpression *guard, CExpression *e1, CExpression *e2)
00025 /*
00026 pre:

00027 effect: constructs an CifExpr-object corresponding to IF(guard, e1, e2)

00028 */
00029 {
00030         m_guard = guard;
00031         m_e1 = e1;
00032         m_e2 = e2;
00033 }
00034 
00035 CIfExpr::~CIfExpr()
00036 /*
00037 pre:

00038 effect: dereferences the object

00039 */
00040 {
00041         if (m_guard) m_guard->Release();
00042         if (m_e1) m_e1->Release();
00043         if (m_e2) m_e2->Release();
00044 }
00045 
00046 CValue* CIfExpr::Calculate()
00047 /*
00048 pre:

00049 ret: a new object containing the value of m_e1 if m_guard is a boolean TRUE

00050          a new object containing the value of m_e2 if m_guard is a boolean FALSE

00051          an new errorvalue if m_guard is not a boolean

00052 */
00053 {
00054         CValue *guardval;
00055         guardval = m_guard->Calculate();
00056         CCString text = guardval->GetText();
00057         guardval->Release();
00058         if (text == CCString("TRUE"))
00059                 return m_e1->Calculate();
00060         else if (text == CCString("FALSE"))
00061                 return m_e2->Calculate();
00062         else return new CErrorValue("Guard should be of boolean type");
00063 }
00064 
00065 
00066 
00067 
00068 
00069 bool CIfExpr::MergeExpression(CExpression *otherexpr)

00070 {
00071         // TODO: do if-expressions need merge ability ?
00072         assertd(false);
00073         return false;
00074 }

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