fixed spacing in the headers to get rid of some warnings and some other
[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
25
26 #define PLUGIN_DECLARE_SERIAL_EXPRESSION(class_name,base_class_name)                                                                    \
27 public:                                                                                                                                                                         \
28         virtual base_class_name *       Copy()                                          { return new class_name; }              \
29         virtual bool EdSerialize(CompressorArchive& arch,class CFactoryManager* facmgr,bool bIsStoring);    \
30         virtual bool EdIdSerialize(CompressorArchive& arch,class CFactoryManager* facmgr,bool bIsStoring)  \
31 {                               \
32         if (bIsStoring)                 \
33         {                                                       \
34                 unsigned char exprID = GetExpressionID(); \
35                 arch << exprID;                                 \
36         }                                               \
37         return true; \
38 }                               \
39
40
41
42 class CExpression;
43
44
45 // for undo/redo system the deletion in the expressiontree can be restored by replacing broken links 'inplace'
46 class CBrokenLinkInfo
47 {
48         public:
49                 CBrokenLinkInfo(CExpression** pmemexpr,CExpression* expr)
50                         :m_pmemExpr(pmemexpr),
51                         m_pExpr(expr)
52                  { 
53                         assertd(pmemexpr);
54                         m_bRestored=false;
55                 };
56
57                 virtual ~CBrokenLinkInfo();
58                 void RestoreLink();
59                 void BreakLink();
60                 
61                 
62         // members vars
63         private:
64         CExpression** m_pmemExpr;
65         CExpression* m_pExpr;
66         bool            m_bRestored;
67         
68 };
69
70
71
72
73
74
75
76
77 class CExpression  
78 {
79 public:
80         enum {
81                         COPERATOR1EXPRESSIONID = 1,
82                         COPERATOR2EXPRESSIONID = 2,
83                         CCONSTEXPRESSIONID = 3,
84                         CIFEXPRESSIONID = 4,
85                         COPERATORVAREXPRESSIONID = 5,
86                         CIDENTIFIEREXPRESSIONID = 6
87         };
88
89
90 protected:
91         virtual                         ~CExpression() = 0;                     //pure virtual
92 public:
93         virtual bool MergeExpression(CExpression* otherexpr) = 0;
94         CExpression();
95
96         
97         virtual                         CValue* Calculate() = 0;        //pure virtual
98         virtual unsigned char GetExpressionID() = 0;
99         //virtual bool          IsInside(float x,float y,float z,bool bBorderInclude=true) = 0;         //pure virtual
100         virtual bool            NeedsRecalculated() = 0; // another pure one
101         virtual CExpression * CheckLink(std::vector<CBrokenLinkInfo*>& brokenlinks) =0; // another pure one
102         virtual void                            ClearModified() = 0; // another pure one
103         //virtual CExpression * Copy() =0;
104         virtual void            BroadcastOperators(VALUE_OPERATOR op) =0;
105
106         virtual CExpression * AddRef() { // please leave multiline, for debugger !!!
107
108 #ifdef _DEBUG
109                 //gRefCountExpr++;
110                 assertd(m_refcount < 255);
111 #endif
112                 m_refcount++; 
113                 return this;
114         };
115         virtual CExpression* Release(CExpression* complicatedtrick=NULL) { 
116 #ifdef _DEBUG
117                 //gRefCountExpr--;
118 #endif
119                 if (--m_refcount < 1) 
120                 {
121                         delete this;
122                 } //else
123                 //      return this;
124                 return complicatedtrick;
125         };
126         
127
128 protected:
129
130         int m_refcount;
131 };
132
133 #endif // !defined _EXPRESSION_H
134