BGE Py api, deleting properties didnt raise an error when the property wasnt there...
[blender.git] / source / gameengine / Expressions / Expression.h
1 /*
2  * Expression.h: interface for the CExpression class.
3  * $Id$
4  * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org>
5  *
6  * Permission to use, copy, modify, distribute and sell this software
7  * and its documentation for any purpose is hereby granted without fee,
8  * provided that the above copyright notice appear in all copies and
9  * that both that copyright notice and this permission notice appear
10  * in supporting documentation.  Erwin Coumans makes no
11  * representations about the suitability of this software for any
12  * purpose.  It is provided "as is" without express or implied warranty.
13  *
14  */
15
16 #if !defined _EXPRESSION_H
17 #define _EXPRESSION_H
18
19 #include "Value.h"
20
21 //extern int gRefCountExpr; // only for debugging purposes (detect mem.leaks)
22
23
24 #define PLUGIN_DECLARE_SERIAL_EXPRESSION(class_name,base_class_name)                                                                    \
25 public:                                                                                                                                                                         \
26         virtual base_class_name *       Copy()                                          { return new class_name; }              \
27         virtual bool EdSerialize(CompressorArchive& arch,class CFactoryManager* facmgr,bool bIsStoring);    \
28         virtual bool EdIdSerialize(CompressorArchive& arch,class CFactoryManager* facmgr,bool bIsStoring)  \
29 {                               \
30         if (bIsStoring)                 \
31         {                                                       \
32                 unsigned char exprID = GetExpressionID(); \
33                 arch << exprID;                                 \
34         }                                               \
35         return true; \
36 }                               \
37
38
39
40 class CExpression;
41
42
43 // for undo/redo system the deletion in the expressiontree can be restored by replacing broken links 'inplace'
44 class CBrokenLinkInfo
45 {
46         public:
47                 CBrokenLinkInfo(CExpression** pmemexpr,CExpression* expr)
48                         :m_pmemExpr(pmemexpr),
49                         m_pExpr(expr)
50                  { 
51                         assertd(pmemexpr);
52                         m_bRestored=false;
53                 };
54
55                 virtual ~CBrokenLinkInfo();
56                 void RestoreLink();
57                 void BreakLink();
58                 
59                 
60         // members vars
61         private:
62         CExpression** m_pmemExpr;
63         CExpression* m_pExpr;
64         bool            m_bRestored;
65         
66 };
67
68
69
70
71
72
73
74
75 class CExpression  
76 {
77 public:
78         enum {
79                         COPERATOR1EXPRESSIONID = 1,
80                         COPERATOR2EXPRESSIONID = 2,
81                         CCONSTEXPRESSIONID = 3,
82                         CIFEXPRESSIONID = 4,
83                         COPERATORVAREXPRESSIONID = 5,
84                         CIDENTIFIEREXPRESSIONID = 6
85         };
86
87
88 protected:
89         virtual                         ~CExpression() = 0;                     //pure virtual
90 public:
91         virtual bool MergeExpression(CExpression* otherexpr) = 0;
92         CExpression();
93
94         
95         virtual                         CValue* Calculate() = 0;        //pure virtual
96         virtual unsigned char GetExpressionID() = 0;
97         //virtual bool          IsInside(float x,float y,float z,bool bBorderInclude=true) = 0;         //pure virtual
98         virtual bool            NeedsRecalculated() = 0; // another pure one
99         virtual CExpression * CheckLink(std::vector<CBrokenLinkInfo*>& brokenlinks) =0; // another pure one
100         virtual void                            ClearModified() = 0; // another pure one
101         //virtual CExpression * Copy() =0;
102         virtual void            BroadcastOperators(VALUE_OPERATOR op) =0;
103
104         virtual CExpression * AddRef() { // please leave multiline, for debugger !!!
105
106 #ifdef _DEBUG
107                 //gRefCountExpr++;
108                 assertd(m_refcount < 255);
109 #endif
110                 m_refcount++; 
111                 return this;
112         };
113         virtual CExpression* Release(CExpression* complicatedtrick=NULL) { 
114 #ifdef _DEBUG
115                 //gRefCountExpr--;
116 #endif
117                 if (--m_refcount < 1) 
118                 {
119                         delete this;
120                 } //else
121                 //      return this;
122                 return complicatedtrick;
123         };
124         
125
126 protected:
127
128         int m_refcount;
129 };
130
131 #endif // !defined _EXPRESSION_H
132