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