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