Blender V2.61 - r43446
|
00001 /* 00002 * Expression.h: interface for the CExpression class. 00003 * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org> 00004 * 00005 * Permission to use, copy, modify, distribute and sell this software 00006 * and its documentation for any purpose is hereby granted without fee, 00007 * provided that the above copyright notice appear in all copies and 00008 * that both that copyright notice and this permission notice appear 00009 * in supporting documentation. Erwin Coumans makes no 00010 * representations about the suitability of this software for any 00011 * purpose. It is provided "as is" without express or implied warranty. 00012 * 00013 */ 00014 00019 #if !defined _EXPRESSION_H 00020 #define _EXPRESSION_H 00021 00022 #include "Value.h" 00023 00024 //extern int gRefCountExpr; // only for debugging purposes (detect mem.leaks) 00025 00026 00027 #define PLUGIN_DECLARE_SERIAL_EXPRESSION(class_name, base_class_name) \ 00028 public: \ 00029 virtual base_class_name * Copy() { \ 00030 return new class_name; \ 00031 } \ 00032 virtual bool EdSerialize(CompressorArchive& arch, \ 00033 class CFactoryManager* facmgr, \ 00034 bool bIsStoring); \ 00035 virtual bool EdIdSerialize(CompressorArchive& arch, \ 00036 class CFactoryManager* facmgr, \ 00037 bool bIsStoring) \ 00038 { \ 00039 if (bIsStoring) \ 00040 { \ 00041 unsigned char exprID = GetExpressionID(); \ 00042 arch << exprID; \ 00043 } \ 00044 return true; \ 00045 } \ 00046 00047 00048 00049 class CExpression; 00050 00051 00052 // for undo/redo system the deletion in the expressiontree can be restored by replacing broken links 'inplace' 00053 class CBrokenLinkInfo 00054 { 00055 public: 00056 CBrokenLinkInfo(CExpression** pmemexpr,CExpression* expr) 00057 :m_pmemExpr(pmemexpr), 00058 m_pExpr(expr) 00059 { 00060 assertd(pmemexpr); 00061 m_bRestored=false; 00062 }; 00063 00064 virtual ~CBrokenLinkInfo(); 00065 void RestoreLink(); 00066 void BreakLink(); 00067 00068 00069 // members vars 00070 private: 00071 CExpression** m_pmemExpr; 00072 CExpression* m_pExpr; 00073 bool m_bRestored; 00074 00075 00076 #ifdef WITH_CXX_GUARDEDALLOC 00077 public: 00078 void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GE:CBrokenLinkInfo"); } 00079 void operator delete( void *mem ) { MEM_freeN(mem); } 00080 #endif 00081 }; 00082 00083 00084 00085 00086 00087 00088 00089 00090 class CExpression 00091 { 00092 public: 00093 enum { 00094 COPERATOR1EXPRESSIONID = 1, 00095 COPERATOR2EXPRESSIONID = 2, 00096 CCONSTEXPRESSIONID = 3, 00097 CIFEXPRESSIONID = 4, 00098 COPERATORVAREXPRESSIONID = 5, 00099 CIDENTIFIEREXPRESSIONID = 6 00100 }; 00101 00102 00103 protected: 00104 virtual ~CExpression() = 0; //pure virtual 00105 public: 00106 virtual bool MergeExpression(CExpression* otherexpr) = 0; 00107 CExpression(); 00108 00109 00110 virtual CValue* Calculate() = 0; //pure virtual 00111 virtual unsigned char GetExpressionID() = 0; 00112 //virtual bool IsInside(float x,float y,float z,bool bBorderInclude=true) = 0; //pure virtual 00113 virtual bool NeedsRecalculated() = 0; // another pure one 00114 virtual CExpression * CheckLink(std::vector<CBrokenLinkInfo*>& brokenlinks) =0; // another pure one 00115 virtual void ClearModified() = 0; // another pure one 00116 //virtual CExpression * Copy() =0; 00117 virtual void BroadcastOperators(VALUE_OPERATOR op) =0; 00118 00119 virtual CExpression * AddRef() { // please leave multiline, for debugger !!! 00120 00121 #ifdef _DEBUG 00122 //gRefCountExpr++; 00123 assertd(m_refcount < 255); 00124 #endif 00125 m_refcount++; 00126 return this; 00127 }; 00128 virtual CExpression* Release(CExpression* complicatedtrick=NULL) { 00129 #ifdef _DEBUG 00130 //gRefCountExpr--; 00131 #endif 00132 if (--m_refcount < 1) 00133 { 00134 delete this; 00135 } //else 00136 // return this; 00137 return complicatedtrick; 00138 }; 00139 00140 00141 protected: 00142 00143 int m_refcount; 00144 00145 00146 #ifdef WITH_CXX_GUARDEDALLOC 00147 public: 00148 void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GE:CExpression"); } 00149 void operator delete( void *mem ) { MEM_freeN(mem); } 00150 #endif 00151 }; 00152 00153 #endif // !defined _EXPRESSION_H 00154