2002-10-12 11:37:38 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2011-02-22 10:33:14 +00:00
|
|
|
/** \file Expression.h
|
|
|
|
* \ingroup expressions
|
|
|
|
*/
|
|
|
|
|
2012-03-09 19:17:19 +00:00
|
|
|
#ifndef __EXPRESSION_H__
|
|
|
|
#define __EXPRESSION_H__
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
#include "Value.h"
|
|
|
|
|
2002-12-27 13:11:01 +00:00
|
|
|
//extern int gRefCountExpr; // only for debugging purposes (detect mem.leaks)
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
|
2011-11-06 01:39:36 +00:00
|
|
|
#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; \
|
|
|
|
} \
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2009-08-18 15:37:31 +00:00
|
|
|
|
|
|
|
#ifdef WITH_CXX_GUARDEDALLOC
|
2012-06-25 09:14:37 +00:00
|
|
|
MEM_CXX_CLASS_ALLOC_FUNCS("GE:CBrokenLinkInfo")
|
2009-08-18 15:37:31 +00:00
|
|
|
#endif
|
2002-10-12 11:37:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
2009-08-18 15:37:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef WITH_CXX_GUARDEDALLOC
|
2012-06-25 09:14:37 +00:00
|
|
|
MEM_CXX_CLASS_ALLOC_FUNCS("GE:CExpression")
|
2009-08-18 15:37:31 +00:00
|
|
|
#endif
|
2002-10-12 11:37:38 +00:00
|
|
|
};
|
|
|
|
|
2012-10-09 13:36:42 +00:00
|
|
|
#endif /* __EXPRESSION_H__ */
|