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