Blender V2.61 - r43446

IfExpr.cpp

Go to the documentation of this file.
00001 
00004 // IfExpr.cpp: implementation of the CIfExpr class.
00005 /*
00006  * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org>
00007  *
00008  * Permission to use, copy, modify, distribute and sell this software
00009  * and its documentation for any purpose is hereby granted without fee,
00010  * provided that the above copyright notice appear in all copies and
00011  * that both that copyright notice and this permission notice appear
00012  * in supporting documentation.  Erwin Coumans makes no
00013  * representations about the suitability of this software for any
00014  * purpose.  It is provided "as is" without express or implied warranty.
00015  *
00016  */
00017 
00018 #include "IfExpr.h"
00019 #include "EmptyValue.h"
00020 #include "ErrorValue.h"
00021 #include "BoolValue.h"
00022 
00024 // Construction/Destruction
00026 
00027 
00028 CIfExpr::CIfExpr()
00029 {
00030 }
00031 
00032 
00033 
00034 CIfExpr::CIfExpr(CExpression *guard, CExpression *e1, CExpression *e2)
00035 /*
00036 pre:
00037 effect: constructs an CifExpr-object corresponding to IF(guard, e1, e2)
00038 */
00039 {
00040     m_guard = guard;
00041     m_e1 = e1;
00042     m_e2 = e2;
00043 }
00044 
00045 
00046 
00047 CIfExpr::~CIfExpr()
00048 /*
00049 pre:
00050 effect: dereferences the object
00051 */
00052 {
00053     if (m_guard)
00054         m_guard->Release();
00055 
00056     if (m_e1)
00057         m_e1->Release();
00058 
00059     if (m_e2)
00060         m_e2->Release();
00061 }
00062 
00063 
00064 
00065 CValue* CIfExpr::Calculate()
00066 /*
00067 pre:
00068 ret: a new object containing the value of m_e1 if m_guard is a boolean TRUE
00069      a new object containing the value of m_e2 if m_guard is a boolean FALSE
00070      an new errorvalue if m_guard is not a boolean
00071 */
00072 {
00073     CValue *guardval;
00074     guardval = m_guard->Calculate();
00075     const STR_String& text = guardval->GetText();
00076     guardval->Release();
00077 
00078     if (&text == &CBoolValue::sTrueString)
00079     {
00080         return m_e1->Calculate();
00081     }
00082     else if (&text == &CBoolValue::sFalseString)
00083     {
00084         return m_e2->Calculate();
00085     }
00086     else
00087     {
00088         return new CErrorValue("Guard should be of boolean type");
00089     }
00090 }
00091 
00092 
00093 
00094 bool CIfExpr::MergeExpression(CExpression *otherexpr)
00095 {
00096     assertd(false);
00097     return false;
00098 }
00099 
00100 
00101 
00102 bool CIfExpr::IsInside(float x,float y,float z,bool bBorderInclude)
00103 {
00104     assertd(false);
00105     return false;
00106 }
00107     
00108 
00109 
00110 bool CIfExpr::NeedsRecalculated() 
00111 {
00112     return  (m_guard->NeedsRecalculated() ||
00113         m_e1->NeedsRecalculated() ||
00114         m_e2->NeedsRecalculated());
00115 }
00116 
00117 
00118 
00119 CExpression* CIfExpr::CheckLink(std::vector<CBrokenLinkInfo*>& brokenlinks)
00120 {
00121     assertd(false);
00122     return NULL;
00123 }
00124 
00125 
00126 
00127 void CIfExpr::ClearModified()
00128 {
00129     assertd(false);
00130 }
00131 
00132 
00133 
00134 void CIfExpr::BroadcastOperators(VALUE_OPERATOR op)
00135 {
00136     assertd(false);
00137 }
00138 
00139 
00140 
00141 unsigned char CIfExpr::GetExpressionID()
00142 {
00143     return CIFEXPRESSIONID;
00144 }