Blender V2.61 - r43446

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 CExpression* COperator1Expr::CheckLink(std::vector<CBrokenLinkInfo*>& brokenlinks) {
00107 
00108     CExpression* newlhs = m_lhs->CheckLink(brokenlinks);
00109 
00110     if (newlhs)
00111     {
00112         if (newlhs==m_lhs) {
00113             // not changed
00114         } else {
00115             // changed
00116             //numchanges++;
00117             newlhs->AddRef();
00118             
00119             //m_lhs->Release();
00120             brokenlinks.push_back(new CBrokenLinkInfo(&m_lhs,m_lhs));
00121 
00122             m_lhs = newlhs;
00123         }
00124         return this;
00125     } else {
00126         //numchanges++;
00127         AddRef();
00128 
00129         return Release();
00130     }
00131     
00132 }
00133 
00134 void COperator1Expr::BroadcastOperators(VALUE_OPERATOR op)
00135 {
00136     if (m_lhs)
00137         m_lhs->BroadcastOperators(m_op);
00138 }
00139 
00140 
00141 
00142 
00143 bool COperator1Expr::MergeExpression(CExpression *otherexpr)
00144 {
00145     if (m_lhs)
00146         return m_lhs->MergeExpression(otherexpr);
00147     
00148     assertd(false); // should not get here, expression is not compatible for merge
00149     return false;
00150 }