doxygen: gameengine/Expressions tagged.
[blender-staging.git] / source / gameengine / Expressions / Operator1Expr.cpp
1 /** \file gameengine/Expressions/Operator1Expr.cpp
2  *  \ingroup expressions
3  */
4 // Operator1Expr.cpp: implementation of the COperator1Expr class.
5 /*
6  * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org>
7  *
8  * Permission to use, copy, modify, distribute and sell this software
9  * and its documentation for any purpose is hereby granted without fee,
10  * provided that the above copyright notice appear in all copies and
11  * that both that copyright notice and this permission notice appear
12  * in supporting documentation.  Erwin Coumans makes no
13  * representations about the suitability of this software for any
14  * purpose.  It is provided "as is" without express or implied warranty.
15  *
16  */
17
18 #include "Operator1Expr.h"
19 #include "EmptyValue.h"
20
21 //////////////////////////////////////////////////////////////////////
22 // Construction/Destruction
23 //////////////////////////////////////////////////////////////////////
24
25 COperator1Expr::COperator1Expr()
26 /*
27 pre:
28 effect: constucts an empty COperator1Expr
29 */
30 {
31         m_lhs = NULL;
32 }
33
34 COperator1Expr::COperator1Expr(VALUE_OPERATOR op, CExpression * lhs)
35 /*
36 pre:
37 effect: constucts a COperator1Expr with op and lhs in it
38 */
39 {
40         m_lhs = lhs;
41         m_op = op;
42 }
43
44 COperator1Expr::~COperator1Expr()
45 /*
46 pre:
47 effect: deletes the object
48 */
49 {
50         if (m_lhs) m_lhs->Release();
51 }
52
53 CValue * COperator1Expr::Calculate()
54 /*
55 pre:
56 ret: a new object containing the result of applying the operator m_op to the
57          value of m_lhs
58 */
59 {
60         CValue *ret;
61         CValue *temp = m_lhs->Calculate();
62         CValue* empty = new CEmptyValue();
63         ret = empty->Calc(m_op, temp);
64         empty->Release();
65         temp->Release();
66         
67         return ret;
68 }
69
70 /*
71 bool COperator1Expr::IsInside(float x, float y, float z,bool bBorderInclude)
72 {
73
74         bool result = true;
75         switch (m_op)
76         {
77                 
78         case VALUE_ADD_OPERATOR:
79                 {
80                         
81                         if (m_lhs)
82                         {
83                                 result = result || m_lhs->IsInside(x,y,z,bBorderInclude);
84                         }
85                         break;
86                 }
87         case VALUE_SUB_OPERATOR:
88                 {
89                         result = true;
90                         if (m_lhs)
91                         {
92                                 result = result && (!m_lhs->IsInside(x,y,z,bBorderInclude));
93                         }
94                         break;
95                 }
96         }
97         return result;
98 }
99
100 */
101 bool COperator1Expr::NeedsRecalculated() {
102         
103         return m_lhs->NeedsRecalculated();
104
105 }
106
107 CExpression* COperator1Expr::CheckLink(std::vector<CBrokenLinkInfo*>& brokenlinks) {
108
109         CExpression* newlhs = m_lhs->CheckLink(brokenlinks);
110
111         if (newlhs)
112         {
113                 if (newlhs==m_lhs) {
114                         // not changed
115                 } else {
116                         // changed
117                         //numchanges++;
118                         newlhs->AddRef();
119                         
120                         //m_lhs->Release();
121                         brokenlinks.push_back(new CBrokenLinkInfo(&m_lhs,m_lhs));
122
123                         m_lhs = newlhs;
124                 }
125                 return this;
126         } else {
127                 //numchanges++;
128                 AddRef();
129
130                 return Release();
131         }
132         
133 }
134
135 void COperator1Expr::BroadcastOperators(VALUE_OPERATOR op)
136 {
137         if (m_lhs)
138                 m_lhs->BroadcastOperators(m_op);
139 }
140
141
142
143
144 bool COperator1Expr::MergeExpression(CExpression *otherexpr)
145 {
146         if (m_lhs)
147                 return m_lhs->MergeExpression(otherexpr);
148         
149         assertd(false); // should not get here, expression is not compatible for merge
150         return false;
151 }