Blender  V2.59
Operator1Expr.cpp
Go to the documentation of this file.
00001 
00004 // Operator1Expr.cpp: implementation of the COperator1Expr 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 "Operator1Expr.h"
00019 #include "EmptyValue.h"
00020 
00022 // Construction/Destruction
00024 
00025 COperator1Expr::COperator1Expr()
00026 /*
00027 pre:
00028 effect: constucts an empty COperator1Expr
00029 */
00030 {
00031         m_lhs = NULL;
00032 }
00033 
00034 COperator1Expr::COperator1Expr(VALUE_OPERATOR op, CExpression * lhs)
00035 /*
00036 pre:
00037 effect: constucts a COperator1Expr with op and lhs in it
00038 */
00039 {
00040         m_lhs = lhs;
00041         m_op = op;
00042 }
00043 
00044 COperator1Expr::~COperator1Expr()
00045 /*
00046 pre:
00047 effect: deletes the object
00048 */
00049 {
00050         if (m_lhs) m_lhs->Release();
00051 }
00052 
00053 CValue * COperator1Expr::Calculate()
00054 /*
00055 pre:
00056 ret: a new object containing the result of applying the operator m_op to the
00057          value of m_lhs
00058 */
00059 {
00060         CValue *ret;
00061         CValue *temp = m_lhs->Calculate();
00062         CValue* empty = new CEmptyValue();
00063         ret = empty->Calc(m_op, temp);
00064         empty->Release();
00065         temp->Release();
00066         
00067         return ret;
00068 }
00069 
00070 /*
00071 bool COperator1Expr::IsInside(float x, float y, float z,bool bBorderInclude)
00072 {
00073 
00074         bool result = true;
00075         switch (m_op)
00076         {
00077                 
00078         case VALUE_ADD_OPERATOR:
00079                 {
00080                         
00081                         if (m_lhs)
00082                         {
00083                                 result = result || m_lhs->IsInside(x,y,z,bBorderInclude);
00084                         }
00085                         break;
00086                 }
00087         case VALUE_SUB_OPERATOR:
00088                 {
00089                         result = true;
00090                         if (m_lhs)
00091                         {
00092                                 result = result && (!m_lhs->IsInside(x,y,z,bBorderInclude));
00093                         }
00094                         break;
00095                 }
00096         }
00097         return result;
00098 }
00099 
00100 */
00101 bool COperator1Expr::NeedsRecalculated() {
00102         
00103         return m_lhs->NeedsRecalculated();
00104 
00105 }
00106 
00107 CExpression* COperator1Expr::CheckLink(std::vector<CBrokenLinkInfo*>& brokenlinks) {
00108 
00109         CExpression* newlhs = m_lhs->CheckLink(brokenlinks);
00110 
00111         if (newlhs)
00112         {
00113                 if (newlhs==m_lhs) {
00114                         // not changed
00115                 } else {
00116                         // changed
00117                         //numchanges++;
00118                         newlhs->AddRef();
00119                         
00120                         //m_lhs->Release();
00121                         brokenlinks.push_back(new CBrokenLinkInfo(&m_lhs,m_lhs));
00122 
00123                         m_lhs = newlhs;
00124                 }
00125                 return this;
00126         } else {
00127                 //numchanges++;
00128                 AddRef();
00129 
00130                 return Release();
00131         }
00132         
00133 }
00134 
00135 void COperator1Expr::BroadcastOperators(VALUE_OPERATOR op)
00136 {
00137         if (m_lhs)
00138                 m_lhs->BroadcastOperators(m_op);
00139 }
00140 
00141 
00142 
00143 
00144 bool COperator1Expr::MergeExpression(CExpression *otherexpr)
00145 {
00146         if (m_lhs)
00147                 return m_lhs->MergeExpression(otherexpr);
00148         
00149         assertd(false); // should not get here, expression is not compatible for merge
00150         return false;
00151 }