diff --git a/source/gameengine/Expressions/EXP_BoolValue.h b/source/gameengine/Expressions/EXP_BoolValue.h index ed5833e2f444..06fb63340a7f 100644 --- a/source/gameengine/Expressions/EXP_BoolValue.h +++ b/source/gameengine/Expressions/EXP_BoolValue.h @@ -21,12 +21,10 @@ #include "EXP_Value.h" -/** - * Smart Boolean Value class. +/** Smart Boolean Value class. * Is used by parser when an expression tree is build containing booleans. */ - -class CBoolValue : public CPropValue +class CBoolValue : public CPropValue { public: static const std::string sTrueString; @@ -37,25 +35,25 @@ class CBoolValue : public CPropValue CBoolValue(bool innie, const std::string& name); virtual const std::string GetText(); - virtual double GetNumber(); - virtual int GetValueType(); - bool GetBool(); - virtual void SetValue(CValue* newval); - - virtual CValue* Calc(VALUE_OPERATOR op, CValue *val); - virtual CValue* CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val); - - virtual CValue* GetReplica(); + virtual double GetNumber(); + virtual int GetValueType(); + bool GetBool(); + virtual void SetValue(CValue *newval); + + virtual CValue *Calc(VALUE_OPERATOR op, CValue *val); + virtual CValue *CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val); + + virtual CValue *GetReplica(); #ifdef WITH_PYTHON - virtual PyObject* ConvertValueToPython(); + virtual PyObject *ConvertValueToPython(); #endif private: - bool m_bool; + bool m_bool; #ifdef WITH_CXX_GUARDEDALLOC MEM_CXX_CLASS_ALLOC_FUNCS("GE:CBoolValue") #endif }; -#endif /* __EXP_BOOLVALUE_H__ */ +#endif // __EXP_BOOLVALUE_H__ diff --git a/source/gameengine/Expressions/EXP_ConstExpr.h b/source/gameengine/Expressions/EXP_ConstExpr.h index d87a59cab02e..59ec8e9f1621 100644 --- a/source/gameengine/Expressions/EXP_ConstExpr.h +++ b/source/gameengine/Expressions/EXP_ConstExpr.h @@ -20,26 +20,25 @@ #define __EXP_CONSTEXPR_H__ #include "EXP_Expression.h" -#include "EXP_Value.h" // Added by ClassView +#include "EXP_Value.h" -class CConstExpr : public CExpression +class CConstExpr : public CExpression { public: - virtual unsigned char GetExpressionID(); - virtual double GetNumber(); - virtual CValue* Calculate(); - CConstExpr(CValue* constval); CConstExpr(); + CConstExpr(CValue *constval); virtual ~CConstExpr(); - -private: - CValue* m_value; + virtual unsigned char GetExpressionID(); + virtual double GetNumber(); + virtual CValue *Calculate(); +private: + CValue *m_value; #ifdef WITH_CXX_GUARDEDALLOC MEM_CXX_CLASS_ALLOC_FUNCS("GE:CConstExpr") #endif }; -#endif /* __EXP_CONSTEXPR_H__ */ +#endif // __EXP_CONSTEXPR_H__ diff --git a/source/gameengine/Expressions/EXP_ErrorValue.h b/source/gameengine/Expressions/EXP_ErrorValue.h index 1d384cb10a57..a2f20f252247 100644 --- a/source/gameengine/Expressions/EXP_ErrorValue.h +++ b/source/gameengine/Expressions/EXP_ErrorValue.h @@ -21,26 +21,25 @@ #include "EXP_Value.h" -class CErrorValue : public CPropValue +class CErrorValue : public CPropValue { - public: - virtual const std::string GetText(); - virtual int GetValueType(); CErrorValue(); CErrorValue(const std::string& errmsg); virtual ~CErrorValue(); - virtual CValue* Calc(VALUE_OPERATOR op, CValue* val); - virtual CValue* CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val); - virtual CValue* GetReplica(); + + virtual const std::string GetText(); + virtual int GetValueType(); + virtual CValue *Calc(VALUE_OPERATOR op, CValue *val); + virtual CValue *CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val); + virtual CValue *GetReplica(); private: std::string m_strErrorText; - #ifdef WITH_CXX_GUARDEDALLOC MEM_CXX_CLASS_ALLOC_FUNCS("GE:CErrorValue") #endif }; -#endif /* __EXP_ERRORVALUE_H__ */ +#endif // __EXP_ERRORVALUE_H__ diff --git a/source/gameengine/Expressions/EXP_Expression.h b/source/gameengine/Expressions/EXP_Expression.h index a2154a1763d2..c8af620e484a 100644 --- a/source/gameengine/Expressions/EXP_Expression.h +++ b/source/gameengine/Expressions/EXP_Expression.h @@ -21,50 +21,36 @@ #include "EXP_Value.h" -class CExpression +class CExpression { public: enum { - COPERATOR1EXPRESSIONID = 1, - COPERATOR2EXPRESSIONID = 2, - CCONSTEXPRESSIONID = 3, - CIFEXPRESSIONID = 4, - COPERATORVAREXPRESSIONID = 5, - CIDENTIFIEREXPRESSIONID = 6 + COPERATOR1EXPRESSIONID = 1, + COPERATOR2EXPRESSIONID = 2, + CCONSTEXPRESSIONID = 3, + CIFEXPRESSIONID = 4, + COPERATORVAREXPRESSIONID = 5, + CIDENTIFIEREXPRESSIONID = 6 }; - protected: - virtual ~CExpression() = 0; //pure virtual + virtual ~CExpression() = 0; + public: CExpression(); - - virtual CValue* Calculate() = 0; //pure virtual - virtual unsigned char GetExpressionID() = 0; + virtual CValue *Calculate() = 0; + virtual unsigned char GetExpressionID() = 0; - virtual CExpression * AddRef() { // please leave multiline, for debugger !!! - m_refcount++; - return this; - }; - virtual CExpression* Release(CExpression* complicatedtrick=NULL) { - if (--m_refcount < 1) - { - delete this; - } //else - // return this; - return complicatedtrick; - }; - + virtual CExpression *AddRef(); + virtual CExpression *Release(); protected: - int m_refcount; - #ifdef WITH_CXX_GUARDEDALLOC MEM_CXX_CLASS_ALLOC_FUNCS("GE:CExpression") #endif }; -#endif /* __EXP_EXPRESSION_H__ */ +#endif // __EXP_EXPRESSION_H__ diff --git a/source/gameengine/Expressions/EXP_FloatValue.h b/source/gameengine/Expressions/EXP_FloatValue.h index a76e7dc3283f..6d8ae1df3563 100644 --- a/source/gameengine/Expressions/EXP_FloatValue.h +++ b/source/gameengine/Expressions/EXP_FloatValue.h @@ -21,35 +21,34 @@ #include "EXP_Value.h" -class CFloatValue : public CPropValue +class CFloatValue : public CPropValue { public: CFloatValue(); CFloatValue(float fl); - CFloatValue(float fl,const std::string& name); + CFloatValue(float fl, const std::string& name); virtual const std::string GetText(); virtual double GetNumber(); virtual int GetValueType(); - virtual void SetValue(CValue* newval); + virtual void SetValue(CValue *newval); float GetFloat(); void SetFloat(float fl); virtual ~CFloatValue(); - virtual CValue* GetReplica(); - virtual CValue* Calc(VALUE_OPERATOR op, CValue *val); - virtual CValue* CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val); + virtual CValue *GetReplica(); + virtual CValue *Calc(VALUE_OPERATOR op, CValue *val); + virtual CValue *CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val); #ifdef WITH_PYTHON - virtual PyObject* ConvertValueToPython(); + virtual PyObject *ConvertValueToPython(); #endif protected: float m_float; - #ifdef WITH_CXX_GUARDEDALLOC MEM_CXX_CLASS_ALLOC_FUNCS("GE:CFloatValue") #endif }; -#endif /* __EXP_FLOATVALUE_H__ */ +#endif // __EXP_FLOATVALUE_H__ diff --git a/source/gameengine/Expressions/EXP_HashedPtr.h b/source/gameengine/Expressions/EXP_HashedPtr.h index 7c7c5f6e5ec8..0e9ed4a47ac9 100644 --- a/source/gameengine/Expressions/EXP_HashedPtr.h +++ b/source/gameengine/Expressions/EXP_HashedPtr.h @@ -38,22 +38,22 @@ class CHashedPtr { - void* m_valptr; +private: + void *m_valptr; public: - CHashedPtr(void* val); + CHashedPtr(void *val); unsigned int hash() const; - inline friend bool operator ==( const CHashedPtr & rhs,const CHashedPtr & lhs) + inline friend bool operator ==(const CHashedPtr & rhs, const CHashedPtr & lhs) { return rhs.m_valptr == lhs.m_valptr; } - - + #ifdef WITH_CXX_GUARDEDALLOC MEM_CXX_CLASS_ALLOC_FUNCS("GE:CHashedPtr") #endif }; -#endif /* __EXP_HASHEDPTR_H__ */ +#endif // __EXP_HASHEDPTR_H__ diff --git a/source/gameengine/Expressions/EXP_IdentifierExpr.h b/source/gameengine/Expressions/EXP_IdentifierExpr.h index 35474b016756..0676af40d0da 100644 --- a/source/gameengine/Expressions/EXP_IdentifierExpr.h +++ b/source/gameengine/Expressions/EXP_IdentifierExpr.h @@ -36,18 +36,20 @@ class CIdentifierExpr : public CExpression { - CValue* m_idContext; - std::string m_identifier; +private: + CValue *m_idContext; + std::string m_identifier; + public: - CIdentifierExpr(const std::string& identifier,CValue* id_context); + CIdentifierExpr(const std::string& identifier, CValue *id_context); virtual ~CIdentifierExpr(); - virtual CValue* Calculate(); - virtual unsigned char GetExpressionID(); + virtual CValue *Calculate(); + virtual unsigned char GetExpressionID(); #ifdef WITH_CXX_GUARDEDALLOC MEM_CXX_CLASS_ALLOC_FUNCS("GE:CIdentifierExpr") #endif }; -#endif /* __EXP_IDENTIFIEREXPR_H__ */ +#endif // __EXP_IDENTIFIEREXPR_H__ diff --git a/source/gameengine/Expressions/EXP_IfExpr.h b/source/gameengine/Expressions/EXP_IfExpr.h index 3e201e616ccb..ce9803ca6804 100644 --- a/source/gameengine/Expressions/EXP_IfExpr.h +++ b/source/gameengine/Expressions/EXP_IfExpr.h @@ -21,22 +21,24 @@ #include "EXP_Expression.h" -class CIfExpr : public CExpression +class CIfExpr : public CExpression { private: - CExpression *m_guard, *m_e1, *m_e2; + CExpression *m_guard; + CExpression *m_e1; + CExpression *m_e2; public: - CIfExpr(CExpression *guard, CExpression *e1, CExpression *e2); CIfExpr(); - - virtual unsigned char GetExpressionID(); + CIfExpr(CExpression *guard, CExpression *e1, CExpression *e2); virtual ~CIfExpr(); - virtual CValue* Calculate(); + + virtual unsigned char GetExpressionID(); + virtual CValue *Calculate(); #ifdef WITH_CXX_GUARDEDALLOC MEM_CXX_CLASS_ALLOC_FUNCS("GE:CIfExpr") #endif }; -#endif /* __EXP_IFEXPR_H__ */ +#endif // __EXP_IFEXPR_H__ diff --git a/source/gameengine/Expressions/EXP_IntValue.h b/source/gameengine/Expressions/EXP_IntValue.h index c1863567fb52..0dfefb3fc82f 100644 --- a/source/gameengine/Expressions/EXP_IntValue.h +++ b/source/gameengine/Expressions/EXP_IntValue.h @@ -22,44 +22,39 @@ #include "EXP_Value.h" -typedef long long cInt; +typedef long long cInt; -class CIntValue : public CPropValue +class CIntValue : public CPropValue { public: - virtual const std::string GetText(); - virtual double GetNumber(); - virtual int GetValueType(); - - cInt GetInt(); CIntValue(); CIntValue(cInt innie); CIntValue(cInt innie, const std::string& name); - - virtual CValue* Calc(VALUE_OPERATOR op, - CValue *val); + virtual ~CIntValue(); - virtual CValue* CalcFinal(VALUE_DATA_TYPE dtype, - VALUE_OPERATOR op, - CValue *val); + virtual const std::string GetText(); + virtual double GetNumber(); + virtual int GetValueType(); - virtual void SetValue(CValue* newval); + cInt GetInt(); - virtual CValue* GetReplica(); + virtual CValue *Calc(VALUE_OPERATOR op, CValue *val); + virtual CValue *CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val); + + virtual void SetValue(CValue *newval); + + virtual CValue *GetReplica(); #ifdef WITH_PYTHON - virtual PyObject* ConvertValueToPython(); + virtual PyObject *ConvertValueToPython(); #endif -protected: - virtual ~CIntValue(); - private: - cInt m_int; + cInt m_int; #ifdef WITH_CXX_GUARDEDALLOC MEM_CXX_CLASS_ALLOC_FUNCS("GE:CIntValue") #endif }; -#endif /* __EXP_INTVALUE_H__ */ +#endif // __EXP_INTVALUE_H__ diff --git a/source/gameengine/Expressions/EXP_ListValue.h b/source/gameengine/Expressions/EXP_ListValue.h index d2bdb2589ca3..27f8fbceab56 100644 --- a/source/gameengine/Expressions/EXP_ListValue.h +++ b/source/gameengine/Expressions/EXP_ListValue.h @@ -24,7 +24,7 @@ class CListValue : public CPropValue { Py_Header - + private: std::vector m_pValueArray; bool m_bReleaseContents; @@ -44,10 +44,10 @@ class CListValue : public CPropValue template class iterator { - private: +private: baseIterator m_it; - public: +public: iterator(baseIterator it) : m_it(it) { @@ -114,5 +114,5 @@ inline bool operator!=(const CListValue::iterator& it1, const CListValue::ite return it1.m_it != it2.m_it; } -#endif /* __EXP_LISTVALUE_H__ */ +#endif // __EXP_LISTVALUE_H__ diff --git a/source/gameengine/Expressions/EXP_ListWrapper.h b/source/gameengine/Expressions/EXP_ListWrapper.h index ac20cd353084..8c820e1c8865 100644 --- a/source/gameengine/Expressions/EXP_ListWrapper.h +++ b/source/gameengine/Expressions/EXP_ListWrapper.h @@ -31,7 +31,7 @@ #include "EXP_Value.h" -class CListWrapper : public CValue +class CListWrapper : public CValue { Py_Header private: @@ -70,13 +70,13 @@ class CListWrapper : public CValue }; CListWrapper(void *client, - PyObject *base, - bool (*checkValid)(void *), - int (*getSize)(void *), - PyObject *(*getItem)(void *, int), - const std::string (*getItemName)(void *, int), - bool (*setItem)(void *, int, PyObject *), - int flag = FLAG_NONE); + PyObject *base, + bool(*checkValid)(void *), + int(*getSize)(void *), + PyObject *(*getItem)(void *, int), + const std::string(*getItemName)(void *, int), + bool(*setItem)(void *, int, PyObject *), + int flag = FLAG_NONE); ~CListWrapper(); /// \section Python Interface diff --git a/source/gameengine/Expressions/EXP_Operator1Expr.h b/source/gameengine/Expressions/EXP_Operator1Expr.h index 926a38361f8a..7c49a65e5ef2 100644 --- a/source/gameengine/Expressions/EXP_Operator1Expr.h +++ b/source/gameengine/Expressions/EXP_Operator1Expr.h @@ -21,25 +21,23 @@ #include "EXP_Expression.h" -class COperator1Expr : public CExpression +class COperator1Expr : public CExpression { public: - virtual unsigned char GetExpressionID() { return COPERATOR1EXPRESSIONID; } - virtual CValue* Calculate(); - COperator1Expr(VALUE_OPERATOR op, CExpression *lhs); COperator1Expr(); + COperator1Expr(VALUE_OPERATOR op, CExpression *lhs); virtual ~COperator1Expr(); - - - + + virtual unsigned char GetExpressionID(); + virtual CValue *Calculate(); + private: VALUE_OPERATOR m_op; - CExpression * m_lhs; - + CExpression *m_lhs; #ifdef WITH_CXX_GUARDEDALLOC MEM_CXX_CLASS_ALLOC_FUNCS("GE:") #endif }; -#endif /* __EXP_OPERATOR1EXPR_H__ */ +#endif // __EXP_OPERATOR1EXPR_H__ diff --git a/source/gameengine/Expressions/EXP_Operator2Expr.h b/source/gameengine/Expressions/EXP_Operator2Expr.h index f01b97ff5774..fa7949ff3de3 100644 --- a/source/gameengine/Expressions/EXP_Operator2Expr.h +++ b/source/gameengine/Expressions/EXP_Operator2Expr.h @@ -19,32 +19,30 @@ #ifndef __EXP_OPERATOR2EXPR_H__ #define __EXP_OPERATOR2EXPR_H__ - #include "EXP_Expression.h" -#include "EXP_Value.h" // Added by ClassView +#include "EXP_Value.h" -class COperator2Expr : public CExpression +class COperator2Expr : public CExpression { public: - virtual unsigned char GetExpressionID() { return COPERATOR2EXPRESSIONID; } - virtual CValue* Calculate(); - COperator2Expr(VALUE_OPERATOR op, CExpression *lhs, CExpression *rhs); COperator2Expr(); + COperator2Expr(VALUE_OPERATOR op, CExpression *lhs, CExpression *rhs); virtual ~COperator2Expr(); - + virtual unsigned char GetExpressionID(); + virtual CValue *Calculate(); + protected: - CExpression * m_rhs; - CExpression * m_lhs; + CExpression *m_rhs; + CExpression *m_lhs; private: VALUE_OPERATOR m_op; - #ifdef WITH_CXX_GUARDEDALLOC MEM_CXX_CLASS_ALLOC_FUNCS("GE:COperator2Expr") #endif }; -#endif /* __EXP_OPERATOR2EXPR_H__ */ +#endif // __EXP_OPERATOR2EXPR_H__ diff --git a/source/gameengine/Expressions/EXP_PyObjectPlus.h b/source/gameengine/Expressions/EXP_PyObjectPlus.h index dfcdf81614b5..cf46ccd8ef67 100644 --- a/source/gameengine/Expressions/EXP_PyObjectPlus.h +++ b/source/gameengine/Expressions/EXP_PyObjectPlus.h @@ -32,14 +32,9 @@ #ifndef __EXP_PYOBJECTPLUS_H__ #define __EXP_PYOBJECTPLUS_H__ -/* for now keep weakrefs optional */ +// For now keep weakrefs optional. #define USE_WEAKREFS - -#ifndef __cplusplus // c++ only -#error Must be compiled with C++ -#endif - #include "EXP_Python.h" #include #include "MT_Vector3.h" @@ -48,50 +43,54 @@ #ifdef WITH_PYTHON #ifdef USE_MATHUTILS extern "C" { -#include "../../blender/python/mathutils/mathutils.h" /* so we can have mathutils callbacks */ +# include "../../blender/python/mathutils/mathutils.h" // So we can have mathutils callbacks. } #endif #define MAX_PROP_NAME 64 -/* Use with ShowDeprecationWarning macro */ +// Use with ShowDeprecationWarning macro. typedef struct { bool warn_done; void *link; } WarnLink; -#define ShowDeprecationWarning(old_way, new_way) \ -{ \ - static WarnLink wlink = {false, NULL}; \ - if ((PyObjectPlus::m_ignore_deprecation_warnings || wlink.warn_done)==0) \ - { \ - PyObjectPlus::ShowDeprecationWarning_func(old_way, new_way); \ - \ - WarnLink *wlink_last= PyObjectPlus::GetDeprecationWarningLinkLast(); \ - wlink.warn_done = true; \ - wlink.link = NULL; \ - \ - if (wlink_last) { \ - wlink_last->link= (void *)&(wlink); \ - PyObjectPlus::SetDeprecationWarningLinkLast(&(wlink)); \ - } \ - else { \ - PyObjectPlus::SetDeprecationWarningFirst(&(wlink)); \ - PyObjectPlus::SetDeprecationWarningLinkLast(&(wlink)); \ - } \ - } \ -} \ - - +#define ShowDeprecationWarning(old_way, new_way) \ + { \ + static WarnLink wlink = {false, NULL}; \ + if ((PyObjectPlus::m_ignore_deprecation_warnings || wlink.warn_done) == 0) \ + { \ + PyObjectPlus::ShowDeprecationWarning_func(old_way, new_way); \ +\ + WarnLink *wlink_last = PyObjectPlus::GetDeprecationWarningLinkLast(); \ + wlink.warn_done = true; \ + wlink.link = NULL; \ +\ + if (wlink_last) { \ + wlink_last->link = (void *)&(wlink); \ + PyObjectPlus::SetDeprecationWarningLinkLast(&(wlink)); \ + } \ + else { \ + PyObjectPlus::SetDeprecationWarningFirst(&(wlink)); \ + PyObjectPlus::SetDeprecationWarningLinkLast(&(wlink)); \ + } \ + } \ + } typedef struct PyObjectPlus_Proxy { - PyObject_HEAD /* required python macro */ - class PyObjectPlus *ref; // pointer to GE object, it holds a reference to this proxy - void *ptr; // optional pointer to generic structure, the structure holds no reference to this proxy - bool py_owns; // true if the object pointed by ref should be deleted when the proxy is deleted - bool py_ref; // true if proxy is connected to a GE object (ref is used) + /// Required python macro. + PyObject_HEAD + /// Pointer to GE object, it holds a reference to this proxy. + class PyObjectPlus *ref; + /// Optional pointer to generic structure, the structure holds no reference to this proxy. + void *ptr; + /// True if the object pointed by ref should be deleted when the proxy is deleted. + bool py_owns; + /// True if proxy is connected to a GE object (ref is used). + bool py_ref; #ifdef USE_WEAKREFS - PyObject *in_weakreflist; // weak reference enabler + /// Weak reference enabler. + PyObject *in_weakreflist; #endif } PyObjectPlus_Proxy; @@ -104,200 +103,207 @@ typedef struct PyObjectPlus_Proxy { # define BGE_PROXY_WKREF(_self) (((PyObjectPlus_Proxy *)_self)->in_weakreflist) #endif -/* Note, sometimes we don't care what BGE type this is as long as its a proxy */ +/// Note, sometimes we don't care what BGE type this is as long as its a proxy. #define BGE_PROXY_CHECK_TYPE(_type) ((_type)->tp_dealloc == PyObjectPlus::py_base_dealloc) -/* Opposite of BGE_PROXY_REF */ +/// Opposite of BGE_PROXY_REF. #define BGE_PROXY_FROM_REF(_self) (((PyObjectPlus *)_self)->GetProxy()) -/* Same as 'BGE_PROXY_REF' but doesn't incref. */ +/// Same as 'BGE_PROXY_REF' but doesn't incref. #define BGE_PROXY_FROM_REF_BORROW(_self) _bge_proxy_from_ref_borrow((void *)_self) -// This must be the first line of each -// PyC++ class -// AttributesPtr correspond to attributes of proxy generic pointer -// each PyC++ class must be registered in KX_PythonInitTypes.cpp -#define __Py_Header \ -public: \ - static PyTypeObject Type; \ - static PyMethodDef Methods[]; \ - static PyAttributeDef Attributes[]; \ - virtual PyTypeObject *GetType(void) { \ - return &Type; \ - } \ - virtual PyObject *GetProxy() { \ - return GetProxyPlus_Ext(this, &Type, NULL); \ - } \ - virtual PyObject *NewProxy(bool py_owns) { \ - return NewProxyPlus_Ext(this, &Type, NULL, py_owns); \ - } \ - -// leave above line empty (macro)! -// use this macro for class that use generic pointer in proxy -// GetProxy() and NewProxy() must be defined to set the correct pointer in the proxy -#define __Py_HeaderPtr \ -public: \ - static PyTypeObject Type; \ - static PyMethodDef Methods[]; \ - static PyAttributeDef Attributes[]; \ - static PyAttributeDef AttributesPtr[]; \ - virtual PyTypeObject *GetType(void) { \ - return &Type; \ - } \ - virtual PyObject *GetProxy(); \ - virtual PyObject *NewProxy(bool py_owns); \ - -// leave above line empty (macro)! +/** This must be the first line of each + * PyC++ class + * AttributesPtr correspond to attributes of proxy generic pointer + * each PyC++ class must be registered in KX_PythonInitTypes.cpp + */ +#define __Py_Header \ +public: \ + static PyTypeObject Type; \ + static PyMethodDef Methods[]; \ + static PyAttributeDef Attributes[]; \ + virtual PyTypeObject *GetType(void) \ + { \ + return &Type; \ + } \ + virtual PyObject *GetProxy() \ + { \ + return GetProxyPlus_Ext(this, &Type, NULL); \ + } \ + virtual PyObject *NewProxy(bool py_owns) \ + { \ + return NewProxyPlus_Ext(this, &Type, NULL, py_owns); \ + } + +/** Use this macro for class that use generic pointer in proxy + * GetProxy() and NewProxy() must be defined to set the correct pointer in the proxy. + */ +#define __Py_HeaderPtr \ +public: \ + static PyTypeObject Type; \ + static PyMethodDef Methods[]; \ + static PyAttributeDef Attributes[]; \ + static PyAttributeDef AttributesPtr[]; \ + virtual PyTypeObject *GetType(void) \ + { \ + return &Type; \ + } \ + virtual PyObject *GetProxy(); \ + virtual PyObject *NewProxy(bool py_owns); + #ifdef WITH_CXX_GUARDEDALLOC -#define Py_Header __Py_Header \ - void *operator new(size_t num_bytes) { \ - return MEM_mallocN(num_bytes, Type.tp_name); \ - } \ - void operator delete(void *mem) { \ - MEM_freeN(mem); \ - } \ +#define Py_Header __Py_Header \ + void *operator new(size_t num_bytes) \ + { \ + return MEM_mallocN(num_bytes, Type.tp_name); \ + } \ + void operator delete(void *mem) \ + { \ + MEM_freeN(mem); \ + } #else # define Py_Header __Py_Header #endif #ifdef WITH_CXX_GUARDEDALLOC -#define Py_HeaderPtr __Py_HeaderPtr \ - void *operator new(size_t num_bytes) { \ - return MEM_mallocN(num_bytes, Type.tp_name); \ - } \ - void operator delete(void *mem) { \ - MEM_freeN(mem); \ - } \ +#define Py_HeaderPtr __Py_HeaderPtr \ + void *operator new(size_t num_bytes) \ + { \ + return MEM_mallocN(num_bytes, Type.tp_name); \ + } \ + void operator delete(void *mem) \ + { \ + MEM_freeN(mem); \ + } #else # define Py_HeaderPtr __Py_HeaderPtr #endif -/* - * nonzero values are an error for setattr +/** Nonzero values are an error for setattr * however because of the nested lookups we need to know if the errors - * was because the attribute didnt exits of if there was some problem setting the value + * was because the attribute didnt exits of if there was some problem setting the value. */ +#define PY_SET_ATTR_FAIL 1 +#define PY_SET_ATTR_SUCCESS 0 -#define PY_SET_ATTR_COERCE_FAIL 2 -#define PY_SET_ATTR_FAIL 1 -#define PY_SET_ATTR_MISSING -1 -#define PY_SET_ATTR_SUCCESS 0 - -/** - * These macros are helpful when embedding Python routines. The second +/** These macros are helpful when embedding Python routines. The second * macro is one that also requires a documentation string */ -#define KX_PYMETHOD(class_name, method_name) \ - PyObject *Py##method_name(PyObject *args, PyObject *kwds); \ - static PyObject * \ - sPy##method_name(PyObject *self, PyObject *args, PyObject *kwds) { \ - if (BGE_PROXY_REF(self)==NULL) { \ - PyErr_SetString(PyExc_RuntimeError, \ - #class_name "." #method_name "() - " \ - BGE_PROXY_ERROR_MSG); \ - return NULL; \ - } \ - return((class_name*)BGE_PROXY_REF(self))->Py##method_name(args, kwds); \ - } \ - -#define KX_PYMETHOD_VARARGS(class_name, method_name) \ - PyObject *Py##method_name(PyObject *args); \ - static PyObject* \ - sPy##method_name(PyObject *self, PyObject *args) { \ - if (BGE_PROXY_REF(self)==NULL) { \ - PyErr_SetString(PyExc_RuntimeError, \ - #class_name "." #method_name "() - " \ - BGE_PROXY_ERROR_MSG); return NULL; \ - } \ - return((class_name*)BGE_PROXY_REF(self))->Py##method_name(args); \ - } \ - -#define KX_PYMETHOD_NOARGS(class_name, method_name) \ - PyObject *Py##method_name(); \ - static PyObject* \ - sPy##method_name(PyObject *self) { \ - if (BGE_PROXY_REF(self)==NULL) { \ - PyErr_SetString(PyExc_RuntimeError, \ - #class_name "." #method_name "() - " \ - BGE_PROXY_ERROR_MSG); return NULL; \ - } \ - return((class_name*)BGE_PROXY_REF(self))->Py##method_name(); \ - } \ - -#define KX_PYMETHOD_O(class_name, method_name) \ - PyObject *Py##method_name(PyObject *value); \ - static PyObject* \ - sPy##method_name(PyObject *self, PyObject *value) { \ - if (BGE_PROXY_REF(self)==NULL) { \ - PyErr_SetString(PyExc_RuntimeError, \ - #class_name "." #method_name "(value) - " \ - BGE_PROXY_ERROR_MSG); return NULL; \ - } \ - return((class_name*)BGE_PROXY_REF(self))->Py##method_name(value); \ - } \ - -#define KX_PYMETHOD_DOC(class_name, method_name) \ - PyObject *Py##method_name(PyObject *args, PyObject *kwds); \ - static PyObject* \ - sPy##method_name(PyObject *self, PyObject *args, PyObject *kwds) { \ - if (BGE_PROXY_REF(self)==NULL) { \ - PyErr_SetString(PyExc_RuntimeError, \ - #class_name "." #method_name "(...) - " \ - BGE_PROXY_ERROR_MSG); return NULL; \ - } \ - return((class_name*)BGE_PROXY_REF(self))->Py##method_name(args, kwds); \ - } \ - static const char method_name##_doc[]; \ - -#define KX_PYMETHOD_DOC_VARARGS(class_name, method_name) \ - PyObject *Py##method_name(PyObject *args); \ - static PyObject* \ - sPy##method_name(PyObject *self, PyObject *args) { \ - if (BGE_PROXY_REF(self)==NULL) { \ - PyErr_SetString(PyExc_RuntimeError, \ - #class_name "." #method_name "(...) - " \ - BGE_PROXY_ERROR_MSG); \ - return NULL; \ - } \ - return((class_name*)BGE_PROXY_REF(self))->Py##method_name(args); \ - } \ - static const char method_name##_doc[]; \ - -#define KX_PYMETHOD_DOC_O(class_name, method_name) \ - PyObject *Py##method_name(PyObject *value); \ - static PyObject * \ - sPy##method_name(PyObject *self, PyObject *value) { \ - if (BGE_PROXY_REF(self)==NULL) { \ - PyErr_SetString(PyExc_RuntimeError, \ - #class_name "." #method_name "(value) - " \ - BGE_PROXY_ERROR_MSG); \ - return NULL; \ - } \ - return ((class_name*)BGE_PROXY_REF(self))->Py##method_name(value); \ - } \ - static const char method_name##_doc[]; \ - -#define KX_PYMETHOD_DOC_NOARGS(class_name, method_name) \ - PyObject *Py##method_name(); \ - static PyObject * \ - sPy##method_name(PyObject *self) { \ - if (BGE_PROXY_REF(self)==NULL) { \ - PyErr_SetString(PyExc_RuntimeError, \ - #class_name "." #method_name "() - " \ - BGE_PROXY_ERROR_MSG); \ - return NULL; \ - } \ - return ((class_name*)BGE_PROXY_REF(self))->Py##method_name(); \ - } \ - static const char method_name##_doc[]; \ - - -/* The line above should remain empty */ -/** - * Method table macro (with doc) - */ +#define KX_PYMETHOD(class_name, method_name) \ + PyObject * Py##method_name(PyObject * args, PyObject * kwds); \ + static PyObject * \ + sPy##method_name(PyObject * self, PyObject * args, PyObject * kwds) \ + { \ + if (BGE_PROXY_REF(self) == NULL) { \ + PyErr_SetString(PyExc_RuntimeError, \ + #class_name "." #method_name "() - " \ + BGE_PROXY_ERROR_MSG); \ + return NULL; \ + } \ + return ((class_name *)BGE_PROXY_REF(self))->Py##method_name(args, kwds); \ + } + +#define KX_PYMETHOD_VARARGS(class_name, method_name) \ + PyObject * Py##method_name(PyObject * args); \ + static PyObject * \ + sPy##method_name(PyObject * self, PyObject * args) \ + { \ + if (BGE_PROXY_REF(self) == NULL) { \ + PyErr_SetString(PyExc_RuntimeError, \ + #class_name "." #method_name "() - " \ + BGE_PROXY_ERROR_MSG); return NULL; \ + } \ + return ((class_name *)BGE_PROXY_REF(self))->Py##method_name(args); \ + } + +#define KX_PYMETHOD_NOARGS(class_name, method_name) \ + PyObject * Py##method_name(); \ + static PyObject * \ + sPy##method_name(PyObject * self) \ + { \ + if (BGE_PROXY_REF(self) == NULL) { \ + PyErr_SetString(PyExc_RuntimeError, \ + #class_name "." #method_name "() - " \ + BGE_PROXY_ERROR_MSG); return NULL; \ + } \ + return ((class_name *)BGE_PROXY_REF(self))->Py##method_name(); \ + } + +#define KX_PYMETHOD_O(class_name, method_name) \ + PyObject * Py##method_name(PyObject * value); \ + static PyObject * \ + sPy##method_name(PyObject * self, PyObject * value) \ + { \ + if (BGE_PROXY_REF(self) == NULL) { \ + PyErr_SetString(PyExc_RuntimeError, \ + #class_name "." #method_name "(value) - " \ + BGE_PROXY_ERROR_MSG); return NULL; \ + } \ + return ((class_name *)BGE_PROXY_REF(self))->Py##method_name(value); \ + } + +#define KX_PYMETHOD_DOC(class_name, method_name) \ + PyObject * Py##method_name(PyObject * args, PyObject * kwds); \ + static PyObject * \ + sPy##method_name(PyObject * self, PyObject * args, PyObject * kwds) \ + { \ + if (BGE_PROXY_REF(self) == NULL) { \ + PyErr_SetString(PyExc_RuntimeError, \ + #class_name "." #method_name "(...) - " \ + BGE_PROXY_ERROR_MSG); return NULL; \ + } \ + return ((class_name *)BGE_PROXY_REF(self))->Py##method_name(args, kwds); \ + } \ + static const char method_name##_doc[]; + +#define KX_PYMETHOD_DOC_VARARGS(class_name, method_name) \ + PyObject * Py##method_name(PyObject * args); \ + static PyObject * \ + sPy##method_name(PyObject * self, PyObject * args) \ + { \ + if (BGE_PROXY_REF(self) == NULL) { \ + PyErr_SetString(PyExc_RuntimeError, \ + #class_name "." #method_name "(...) - " \ + BGE_PROXY_ERROR_MSG); \ + return NULL; \ + } \ + return ((class_name *)BGE_PROXY_REF(self))->Py##method_name(args); \ + } \ + static const char method_name##_doc[]; + +#define KX_PYMETHOD_DOC_O(class_name, method_name) \ + PyObject * Py##method_name(PyObject * value); \ + static PyObject * \ + sPy##method_name(PyObject * self, PyObject * value) \ + { \ + if (BGE_PROXY_REF(self) == NULL) { \ + PyErr_SetString(PyExc_RuntimeError, \ + #class_name "." #method_name "(value) - " \ + BGE_PROXY_ERROR_MSG); \ + return NULL; \ + } \ + return ((class_name *)BGE_PROXY_REF(self))->Py##method_name(value); \ + } \ + static const char method_name##_doc[]; + +#define KX_PYMETHOD_DOC_NOARGS(class_name, method_name) \ + PyObject * Py##method_name(); \ + static PyObject * \ + sPy##method_name(PyObject * self) \ + { \ + if (BGE_PROXY_REF(self) == NULL) { \ + PyErr_SetString(PyExc_RuntimeError, \ + #class_name "." #method_name "() - " \ + BGE_PROXY_ERROR_MSG); \ + return NULL; \ + } \ + return ((class_name *)BGE_PROXY_REF(self))->Py##method_name(); \ + } \ + static const char method_name##_doc[]; + +/// Method table macro (with doc). #define KX_PYMETHODTABLE(class_name, method_name) \ {#method_name, (PyCFunction) class_name::sPy##method_name, METH_VARARGS, (const char *)class_name::method_name##_doc} @@ -308,30 +314,26 @@ public: \ {#method_name, (PyCFunction) class_name::sPy##method_name, METH_NOARGS, (const char *)class_name::method_name##_doc} #define KX_PYMETHODTABLE_KEYWORDS(class_name, method_name) \ - {#method_name, (PyCFunction) class_name::sPy##method_name, METH_VARARGS|METH_KEYWORDS, (const char *)class_name::method_name##_doc} + {#method_name, (PyCFunction) class_name::sPy##method_name, METH_VARARGS | METH_KEYWORDS, (const char *)class_name::method_name##_doc} -/** - * Function implementation macro - */ +/// Function implementation macro. #define KX_PYMETHODDEF_DOC(class_name, method_name, doc_string) \ -const char class_name::method_name##_doc[] = doc_string; \ -PyObject *class_name::Py##method_name(PyObject *args, PyObject *kwds) + const char class_name::method_name##_doc[] = doc_string; \ + PyObject *class_name::Py##method_name(PyObject * args, PyObject * kwds) #define KX_PYMETHODDEF_DOC_VARARGS(class_name, method_name, doc_string) \ -const char class_name::method_name##_doc[] = doc_string; \ -PyObject *class_name::Py##method_name(PyObject *args) + const char class_name::method_name##_doc[] = doc_string; \ + PyObject *class_name::Py##method_name(PyObject * args) #define KX_PYMETHODDEF_DOC_O(class_name, method_name, doc_string) \ -const char class_name::method_name##_doc[] = doc_string; \ -PyObject *class_name::Py##method_name(PyObject *value) + const char class_name::method_name##_doc[] = doc_string; \ + PyObject *class_name::Py##method_name(PyObject * value) #define KX_PYMETHODDEF_DOC_NOARGS(class_name, method_name, doc_string) \ -const char class_name::method_name##_doc[] = doc_string; \ -PyObject *class_name::Py##method_name() + const char class_name::method_name##_doc[] = doc_string; \ + PyObject *class_name::Py##method_name() -/** - * Attribute management - */ +/// Attribute management. enum KX_PYATTRIBUTE_TYPE { KX_PYATTRIBUTE_TYPE_BOOL, KX_PYATTRIBUTE_TYPE_ENUM, @@ -357,27 +359,45 @@ typedef int (*KX_PYATTRIBUTE_SET_FUNCTION)(void *self, const struct KX_PYATTRIBU typedef PyObject *(*KX_PYATTRIBUTE_GET_FUNCTION)(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); typedef struct KX_PYATTRIBUTE_DEF { - const std::string m_name; // name of the python attribute - KX_PYATTRIBUTE_TYPE m_type; // type of value - KX_PYATTRIBUTE_ACCESS m_access; // read/write access or read-only - int m_imin; // minimum value in case of integer attributes - // (for string: minimum string length, for flag: mask value, for float: matrix row size) - int m_imax; // maximum value in case of integer attributes - // (for string: maximum string length, for flag: 1 if flag is negative, float: vector/matrix col size) - float m_fmin; // minimum value in case of float attributes - float m_fmax; // maximum value in case of float attributes - bool m_clamp; // enforce min/max value by clamping - bool m_usePtr; // the attribute uses the proxy generic pointer, set at runtime - size_t m_offset; // position of field in structure - size_t m_size; // size of field for runtime verification (enum only) - size_t m_length; // length of array, 1=simple attribute - KX_PYATTRIBUTE_CHECK_FUNCTION m_checkFunction; // static function to check the assignment, returns 0 if no error - KX_PYATTRIBUTE_SET_FUNCTION m_setFunction; // static function to check the assignment, returns 0 if no error - KX_PYATTRIBUTE_GET_FUNCTION m_getFunction; // static function to check the assignment, returns 0 if no error - - // The following pointers are just used to have compile time check for attribute type. - // It would have been good to use a union but that would require C99 compatibility - // to initialize specific union fields through designated initializers. + /// Name of the python attribute. + const std::string m_name; + /// Type of value. + KX_PYATTRIBUTE_TYPE m_type; + /// Read/write access or read-only. + KX_PYATTRIBUTE_ACCESS m_access; + /** Minimum value in case of integer attributes + * (for string: minimum string length, for flag: mask value, for float: matrix row size). + */ + int m_imin; + /** Maximum value in case of integer attributes + * (for string: maximum string length, for flag: 1 if flag is negative, float: vector/matrix col size). + */ + int m_imax; + /// Minimum value in case of float attributes. + float m_fmin; + /// Maximum value in case of float attributes. + float m_fmax; + /// Enforce min/max value by clamping. + bool m_clamp; + /// The attribute uses the proxy generic pointer, set at runtime. + bool m_usePtr; + /// Position of field in structure. + size_t m_offset; + /// Size of field for runtime verification (enum only). + size_t m_size; + /// Length of array, 1=simple attribute. + size_t m_length; + /// Static function to check the assignment, returns 0 if no error. + KX_PYATTRIBUTE_CHECK_FUNCTION m_checkFunction; + /// Static function to check the assignment, returns 0 if no error. + KX_PYATTRIBUTE_SET_FUNCTION m_setFunction; + /// Static function to check the assignment, returns 0 if no error. + KX_PYATTRIBUTE_GET_FUNCTION m_getFunction; + + /** The following pointers are just used to have compile time check for attribute type. + * It would have been good to use a union but that would require C99 compatibility + * to initialize specific union fields through designated initializers. + */ struct { bool *m_boolPtr; short int *m_shortPtr; @@ -399,7 +419,7 @@ typedef struct KX_PYATTRIBUTE_DEF { #define KX_PYATTRIBUTE_BOOL_RO(name, object, field) \ { name, KX_PYATTRIBUTE_TYPE_BOOL, KX_PYATTRIBUTE_RO, 0, 1, 0.f, 0.f, false, false, offsetof(object, field), 0, 1, NULL, NULL, NULL, {&((object *)0)->field, NULL, NULL, NULL, NULL, NULL, NULL} } -/* attribute points to a single bit of an integer field, attribute=true if bit is set */ +/// Attribute points to a single bit of an integer field, attribute=true if bit is set. #define KX_PYATTRIBUTE_FLAG_RW(name, object, field, bit) \ { name, KX_PYATTRIBUTE_TYPE_FLAG, KX_PYATTRIBUTE_RW, bit, 0, 0.f, 0.f, false, false, offsetof(object, field), sizeof(((object *)0)->field), 1, NULL, NULL, NULL, {NULL, NULL, NULL, NULL, NULL, NULL, NULL} } #define KX_PYATTRIBUTE_FLAG_RW_CHECK(name, object, field, bit, function) \ @@ -407,7 +427,7 @@ typedef struct KX_PYATTRIBUTE_DEF { #define KX_PYATTRIBUTE_FLAG_RO(name, object, field, bit) \ { name, KX_PYATTRIBUTE_TYPE_FLAG, KX_PYATTRIBUTE_RO, bit, 0, 0.f, 0.f, false, false, offsetof(object, field), sizeof(((object *)0)->field), 1, NULL, NULL, NULL, {NULL, NULL, NULL, NULL, NULL, NULL, NULL} } -/* attribute points to a single bit of an integer field, attribute=true if bit is set*/ +/// Attribute points to a single bit of an integer field, attribute=true if bit is set. #define KX_PYATTRIBUTE_FLAG_NEGATIVE_RW(name, object, field, bit) \ { name, KX_PYATTRIBUTE_TYPE_FLAG, KX_PYATTRIBUTE_RW, bit, 1, 0.f, 0.f, false, false, offsetof(object, field), sizeof(((object *)0)->field), 1, NULL, NULL, NULL, {NULL, NULL, NULL, NULL, NULL, NULL, NULL} } #define KX_PYATTRIBUTE_FLAG_NEGATIVE_RW_CHECK(name, object, field, bit, function) \ @@ -415,8 +435,9 @@ typedef struct KX_PYATTRIBUTE_DEF { #define KX_PYATTRIBUTE_FLAG_NEGATIVE_RO(name, object, field, bit) \ { name, KX_PYATTRIBUTE_TYPE_FLAG, KX_PYATTRIBUTE_RO, bit, 1, 0.f, 0.f, false, false, offsetof(object, field), sizeof(((object *)0)->field), 1, NULL, NULL, NULL, {NULL, NULL, NULL, NULL, NULL, NULL, NULL} } -// enum field cannot be mapped to pointer (because we would need a pointer for each enum) -// use field size to verify mapping at runtime only, assuming enum size is equal to int size. +/** Enum field cannot be mapped to pointer (because we would need a pointer for each enum) + * use field size to verify mapping at runtime only, assuming enum size is equal to int size. + */ #define KX_PYATTRIBUTE_ENUM_RW(name, min, max, clamp, object, field) \ { name, KX_PYATTRIBUTE_TYPE_ENUM, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, false, offsetof(object, field), sizeof(((object *)0)->field), 1, NULL, NULL, NULL, {NULL, NULL, NULL, NULL, NULL, NULL, NULL} } #define KX_PYATTRIBUTE_ENUM_RW_CHECK(name, min, max, clamp, object, field, function) \ @@ -436,7 +457,7 @@ typedef struct KX_PYATTRIBUTE_DEF { { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, false, offsetof(object, field), 0, length, &object::function, NULL, NULL, {NULL, ((object *)0)->field, NULL, NULL, NULL, NULL, NULL} } #define KX_PYATTRIBUTE_SHORT_ARRAY_RO(name, object, field, length) \ { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, false, offsetof(object, field), 0, length, NULL, NULL, NULL, {NULL, ((object *)0)->field, NULL, NULL, NULL, NULL, NULL} } -// SHORT_LIST + #define KX_PYATTRIBUTE_SHORT_LIST_RW(name, min, max, clamp, object, field, length) \ { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, false, offsetof(object, field), 0, length, NULL, NULL, NULL, {NULL, &((object *)0)->field, NULL, NULL, NULL, NULL, NULL} } #define KX_PYATTRIBUTE_SHORT_LIST_RW_CHECK(name, min, max, clamp, object, field, length, function) \ @@ -456,7 +477,7 @@ typedef struct KX_PYATTRIBUTE_DEF { { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, false, offsetof(object, field), 0, length, &object::function, NULL, NULL, {NULL, NULL, ((object *)0)->field, NULL, NULL, NULL, NULL} } #define KX_PYATTRIBUTE_INT_ARRAY_RO(name, object, field, length) \ { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, false, offsetof(object, field), 0, length, NULL, NULL, NULL, {NULL, NULL, ((object *)0)->field, NULL, NULL, NULL, NULL} } -// INT_LIST + #define KX_PYATTRIBUTE_INT_LIST_RW(name, min, max, clamp, object, field, length) \ { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, false, offsetof(object, field), 0, length, NULL, NULL, NULL, {NULL, NULL, &((object *)0)->field, NULL, NULL, NULL, NULL} } #define KX_PYATTRIBUTE_INT_LIST_RW_CHECK(name, min, max, clamp, object, field, length, function) \ @@ -464,28 +485,28 @@ typedef struct KX_PYATTRIBUTE_DEF { #define KX_PYATTRIBUTE_INT_LIST_RO(name, object, field, length) \ { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, false, offsetof(object, field), 0, length, NULL, NULL, NULL, {NULL, NULL, &((object *)0)->field, NULL, NULL, NULL, NULL} } -// always clamp for float +/// Always clamp for float. #define KX_PYATTRIBUTE_FLOAT_RW(name, min, max, object, field) \ { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RW, 0, 0, min, max, true, false, offsetof(object, field), 0, 1, NULL, NULL, NULL, {NULL, NULL, NULL, &((object *)0)->field, NULL, NULL, NULL} } #define KX_PYATTRIBUTE_FLOAT_RW_CHECK(name, min, max, object, field, function) \ { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RW, 0, 0, min, max, true, false, offsetof(object, field), 0, 1, &object::function, NULL, NULL, {NULL, NULL, NULL, &((object *)0)->field, NULL, NULL, NULL} } #define KX_PYATTRIBUTE_FLOAT_RO(name, object, field) \ { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, false, offsetof(object, field), 0, 1, NULL, NULL, NULL, {NULL, NULL, NULL, &((object *)0)->field, NULL, NULL, NULL} } -// field must be float[n], returns a sequence +/// Field must be float[n], returns a sequence. #define KX_PYATTRIBUTE_FLOAT_ARRAY_RW(name, min, max, object, field, length) \ { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RW, 0, 0, min, max, true, false, offsetof(object, field), 0, length, NULL, NULL, NULL, {NULL, NULL, NULL, ((object *)0)->field, NULL, NULL, NULL} } #define KX_PYATTRIBUTE_FLOAT_ARRAY_RW_CHECK(name, min, max, object, field, length, function) \ { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RW, 0, 0, min, max, true, false, offsetof(object, field), 0, length, &object::function, NULL, NULL, {NULL, NULL, NULL, ((object *)0)->field, NULL, NULL, NULL} } #define KX_PYATTRIBUTE_FLOAT_ARRAY_RO(name, object, field, length) \ { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, false, offsetof(object, field), 0, length, NULL, NULL, NULL, {NULL, NULL, NULL, ((object *)0)->field, NULL, NULL, NULL} } -// field must be float[n], returns a vector +/// Field must be float[n], returns a vector. #define KX_PYATTRIBUTE_FLOAT_VECTOR_RW(name, min, max, object, field, length) \ { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RW, 0, length, min, max, true, false, offsetof(object, field), sizeof(((object *)0)->field), 1, NULL, NULL, NULL, {NULL, NULL, NULL, ((object *)0)->field, NULL, NULL, NULL} } #define KX_PYATTRIBUTE_FLOAT_VECTOR_RW_CHECK(name, min, max, object, field, length, function) \ { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RW, 0, length, min, max, true, false, offsetof(object, field), sizeof(((object *)0)->field), 1, &object::function, NULL, NULL, {NULL, NULL, NULL, ((object *)0)->field, NULL, NULL, NULL} } #define KX_PYATTRIBUTE_FLOAT_VECTOR_RO(name, object, field, length) \ { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RO, 0, length, 0.f, 0.f, false, false, offsetof(object, field), sizeof(((object *)0)->field), 1, NULL, NULL, NULL, {NULL, NULL, NULL, ((object *)0)->field, NULL, NULL, NULL} } -// field must be float[n][n], returns a matrix +/// Field must be float[n][n], returns a matrix. #define KX_PYATTRIBUTE_FLOAT_MATRIX_RW(name, min, max, object, field, length) \ { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RW, length, length, min, max, true, false, offsetof(object, field), sizeof(((object *)0)->field), 1, NULL, NULL, NULL, {NULL, NULL, NULL, ((object *)0)->field[0], NULL, NULL, NULL} } #define KX_PYATTRIBUTE_FLOAT_MATRIX_RW_CHECK(name, min, max, object, field, length, function) \ @@ -493,29 +514,29 @@ typedef struct KX_PYATTRIBUTE_DEF { #define KX_PYATTRIBUTE_FLOAT_MATRIX_RO(name, object, field, length) \ { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RO, length, length, 0.f, 0.f, false, false, offsetof(object, field), sizeof(((object *)0)->field), 1, NULL, NULL, NULL, {NULL, NULL, NULL, ((object *)0)->field[0], NULL, NULL, NULL} } -// only for std::string member +/// Only for std::string member. #define KX_PYATTRIBUTE_STRING_RW(name, min, max, clamp, object, field) \ { name, KX_PYATTRIBUTE_TYPE_STRING, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, false, offsetof(object, field), 0, 1, NULL, NULL, NULL, {NULL, NULL, NULL, NULL, &((object *)0)->field, NULL, NULL} } #define KX_PYATTRIBUTE_STRING_RW_CHECK(name, min, max, clamp, object, field, function) \ { name, KX_PYATTRIBUTE_TYPE_STRING, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, false, offsetof(object, field), 0, 1, &object::function, NULL, NULL, {NULL, NULL, NULL, NULL, &((object *)0)->field, NULL, NULL} } #define KX_PYATTRIBUTE_STRING_RO(name, object, field) \ - { name, KX_PYATTRIBUTE_TYPE_STRING, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, false, offsetof(object, field), 0, 1 , NULL, NULL, NULL, {NULL, NULL, NULL, NULL, &((object *)0)->field, NULL, NULL} } + { name, KX_PYATTRIBUTE_TYPE_STRING, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, false, offsetof(object, field), 0, 1, NULL, NULL, NULL, {NULL, NULL, NULL, NULL, &((object *)0)->field, NULL, NULL} } -// only for char [] array +/// Only for char [] array. #define KX_PYATTRIBUTE_CHAR_RW(name, object, field) \ { name, KX_PYATTRIBUTE_TYPE_CHAR, KX_PYATTRIBUTE_RW, 0, 0, 0.f, 0.f, true, false, offsetof(object, field), sizeof(((object *)0)->field), 1, NULL, NULL, NULL, {NULL, NULL, NULL, NULL, NULL, NULL, ((object *)0)->field} } #define KX_PYATTRIBUTE_CHAR_RW_CHECK(name, object, field, function) \ { name, KX_PYATTRIBUTE_TYPE_CHAR, KX_PYATTRIBUTE_RW, 0, 0, 0.f, 0.f, true, false, offsetof(object, field), sizeof(((object *)0)->field), 1, &object::function, NULL, NULL, {NULL, NULL, NULL, NULL, NULL, NULL, ((object *)0)->field} } #define KX_PYATTRIBUTE_CHAR_RO(name, object, field) \ - { name, KX_PYATTRIBUTE_TYPE_CHAR, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, false, offsetof(object, field), sizeof(((object *)0)->field), 1 , NULL, NULL, NULL, {NULL, NULL, NULL, NULL, NULL, NULL, ((object *)0)->field} } + { name, KX_PYATTRIBUTE_TYPE_CHAR, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, false, offsetof(object, field), sizeof(((object *)0)->field), 1, NULL, NULL, NULL, {NULL, NULL, NULL, NULL, NULL, NULL, ((object *)0)->field} } -// for MT_Vector3 member +/// For MT_Vector3 member. #define KX_PYATTRIBUTE_VECTOR_RW(name, min, max, object, field) \ { name, KX_PYATTRIBUTE_TYPE_VECTOR, KX_PYATTRIBUTE_RW, 0, 0, min, max, true, false, offsetof(object, field), 0, 1, NULL, NULL, NULL, {NULL, NULL, NULL, NULL, NULL, &((object *)0)->field, NULL} } #define KX_PYATTRIBUTE_VECTOR_RW_CHECK(name, min, max, clamp, object, field, function) \ { name, KX_PYATTRIBUTE_TYPE_VECTOR, KX_PYATTRIBUTE_RW, 0, 0, min, max, true, false, offsetof(object, field), 0, 1, &object::function, NULL, NULL, {NULL, NULL, NULL, NULL, NULL, &((object *)0)->field, NULL} } #define KX_PYATTRIBUTE_VECTOR_RO(name, object, field) \ - { name, KX_PYATTRIBUTE_TYPE_VECTOR, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, false, offsetof(object, field), 0, 1 , NULL, NULL, NULL, {NULL, NULL, NULL, NULL, NULL, &((object *)0)->field, NULL} } + { name, KX_PYATTRIBUTE_TYPE_VECTOR, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, false, offsetof(object, field), 0, 1, NULL, NULL, NULL, {NULL, NULL, NULL, NULL, NULL, &((object *)0)->field, NULL} } #define KX_PYATTRIBUTE_RW_FUNCTION(name, object, getfunction, setfunction) \ { name, KX_PYATTRIBUTE_TYPE_FUNCTION, KX_PYATTRIBUTE_RW, 0, 0, 0.f, 0.f, false, false, 0, 0, 1, NULL, &object::setfunction, &object::getfunction, {NULL, NULL, NULL, NULL, NULL, NULL, NULL} } @@ -530,20 +551,18 @@ typedef struct KX_PYATTRIBUTE_DEF { /*------------------------------ * PyObjectPlus *------------------------------ */ -typedef PyTypeObject *PyParentObject; /* Define the PyParent Object */ - -#else // WITH_PYTHON +#else // WITH_PYTHON #ifdef WITH_CXX_GUARDEDALLOC -#define Py_Header \ -public: \ - MEM_CXX_CLASS_ALLOC_FUNCS("GE:PyObjectPlus") \ +#define Py_Header \ +public: \ + MEM_CXX_CLASS_ALLOC_FUNCS("GE:PyObjectPlus") \ -#define Py_HeaderPtr \ - MEM_CXX_CLASS_ALLOC_FUNCS("GE:PyObjectPlusPtr") \ +#define Py_HeaderPtr \ + MEM_CXX_CLASS_ALLOC_FUNCS("GE:PyObjectPlusPtr") \ -#else // WITH_CXX_GUARDEDALLOC +#else // WITH_CXX_GUARDEDALLOC #define Py_Header \ public: \ @@ -551,80 +570,77 @@ public: \ #define Py_HeaderPtr \ public: \ -#endif /* WITH_CXX_GUARDEDALLOC */ +#endif // WITH_CXX_GUARDEDALLOC #endif +/// The PyObjectPlus abstract class. class PyObjectPlus -{ // The PyObjectPlus abstract class - Py_Header // Always start with Py_Header +{ + Py_Header // Always start with Py_Header protected: /** Called when the object is freed from a python owner proxy. - * It as effect to use reference count for deletion and to not + * It has effect to use reference count for deletion and to not * be every time deleted in CValue. */ virtual void DestructFromPython(); public: PyObjectPlus(); - - virtual ~PyObjectPlus(); // destructor - + virtual ~PyObjectPlus(); + #ifdef WITH_PYTHON - PyObject *m_proxy; /* actually a PyObjectPlus_Proxy */ + PyObject *m_proxy; // Actually a PyObjectPlus_Proxy. /* These static functions are referenced by ALL PyObjectPlus_Proxy types * they take the C++ reference from the PyObjectPlus_Proxy and call * its own virtual py_repr, py_base_dealloc, etc. functions. */ - - static PyObject* py_base_new(PyTypeObject *type, PyObject *args, PyObject *kwds); /* allows subclassing */ - static void py_base_dealloc(PyObject *self); - static PyObject* py_base_repr(PyObject *self); + static PyObject *py_base_new(PyTypeObject *type, PyObject *args, PyObject *kwds); // Allows subclassing. + static void py_base_dealloc(PyObject *self); + static PyObject *py_base_repr(PyObject *self); /* These are all virtual python methods that are defined in each class * Our own fake subclassing calls these on each class, then calls the parent */ - virtual PyObject* py_repr(void); - /* subclass may overwrite this function to implement more sophisticated method of validating a proxy */ - virtual bool py_is_valid(void) { return true; } + virtual PyObject *py_repr(); + /// Subclass may overwrite this function to implement more sophisticated method of validating a proxy. + virtual bool py_is_valid(); - static PyObject* py_get_attrdef(PyObject *self_py, const PyAttributeDef *attrdef); - static int py_set_attrdef(PyObject *self_py, PyObject *value, const PyAttributeDef *attrdef); - - /* Kindof dumb, always returns True, the false case is checked for, before this function gets accessed */ - static PyObject* pyattr_get_invalid(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); + static PyObject *py_get_attrdef(PyObject *self_py, const PyAttributeDef *attrdef); + static int py_set_attrdef(PyObject *self_py, PyObject *value, const PyAttributeDef *attrdef); + + /// Kindof dumb, always returns True, the false case is checked for, before this function gets accessed. + static PyObject *pyattr_get_invalid(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); static PyObject *GetProxyPlus_Ext(PyObjectPlus *self, PyTypeObject *tp, void *ptr); - /* self=NULL => proxy to generic pointer detached from GE object - * if py_owns is true, the memory pointed by ptr will be deleted automatically with MEM_freeN + /** self=NULL => proxy to generic pointer detached from GE object + * if py_owns is true, the memory pointed by ptr will be deleted automatically with MEM_freeN * self!=NULL=> proxy attached to GE object, ptr is optional and point to a struct from which attributes can be defined - * if py_owns is true, the object will be deleted automatically, ptr will NOT be deleted - * (assume object destructor takes care of it) */ + * if py_owns is true, the object will be deleted automatically, ptr will NOT be deleted + * (assume object destructor takes care of it) */ static PyObject *NewProxyPlus_Ext(PyObjectPlus *self, PyTypeObject *tp, void *ptr, bool py_owns); - static WarnLink* GetDeprecationWarningLinkFirst(void); - static WarnLink* GetDeprecationWarningLinkLast(void); - static void SetDeprecationWarningFirst(WarnLink* wlink); - static void SetDeprecationWarningLinkLast(WarnLink* wlink); - static void NullDeprecationWarning(); - - /** enable/disable display of deprecation warnings */ - static void SetDeprecationWarnings(bool ignoreDeprecationWarnings); - /** Shows a deprecation warning */ - static void ShowDeprecationWarning_func(const std::string& old_way, const std::string& new_way); - static void ClearDeprecationWarning(); - + static WarnLink *GetDeprecationWarningLinkFirst(); + static WarnLink *GetDeprecationWarningLinkLast(); + static void SetDeprecationWarningFirst(WarnLink *wlink); + static void SetDeprecationWarningLinkLast(WarnLink *wlink); + static void NullDeprecationWarning(); + + /// Enable/disable display of deprecation warnings. + static void SetDeprecationWarnings(bool ignoreDeprecationWarnings); + /// Shows a deprecation warning. + static void ShowDeprecationWarning_func(const std::string& old_way, const std::string& new_way); + static void ClearDeprecationWarning(); + #endif - void InvalidateProxy(); + void InvalidateProxy(); - /** - * Makes sure any internal data owned by this class is deep copied. - */ + /// Makes sure any internal data owned by this class is deep copied. virtual void ProcessReplica(); - static bool m_ignore_deprecation_warnings; + static bool m_ignore_deprecation_warnings; }; #ifdef WITH_PYTHON @@ -641,4 +657,4 @@ inline PyObject *_bge_proxy_from_ref_borrow(void *self_v) #endif -#endif /* __EXP_PYOBJECTPLUS_H__ */ +#endif // __EXP_PYOBJECTPLUS_H__ diff --git a/source/gameengine/Expressions/EXP_Python.h b/source/gameengine/Expressions/EXP_Python.h index f904151085ea..2f041ac1a253 100644 --- a/source/gameengine/Expressions/EXP_Python.h +++ b/source/gameengine/Expressions/EXP_Python.h @@ -32,9 +32,7 @@ #ifndef __EXP_PYTHON_H__ #define __EXP_PYTHON_H__ -//#define USE_DL_EXPORT - -/* python redefines, quiet the compiler */ +// Python redefines, quiet the compiler. #ifdef _XOPEN_SOURCE #undef _XOPEN_SOURCE #endif @@ -79,4 +77,4 @@ #undef toupper #endif -#endif /* __EXP_PYTHON_H__ */ +#endif // __EXP_PYTHON_H__ diff --git a/source/gameengine/Expressions/EXP_StringValue.h b/source/gameengine/Expressions/EXP_StringValue.h index 81a35336fb0b..e05d965989e9 100644 --- a/source/gameengine/Expressions/EXP_StringValue.h +++ b/source/gameengine/Expressions/EXP_StringValue.h @@ -21,38 +21,40 @@ #include "EXP_Value.h" -class CStringValue : public CPropValue +class CStringValue : public CPropValue { public: - /// Construction / destruction CStringValue(); CStringValue(const std::string& txt, const std::string& name); + virtual ~CStringValue() + { + } - virtual ~CStringValue() {} /// CValue implementation - virtual bool IsEqual(const std::string & other); + virtual bool IsEqual(const std::string & other); virtual const std::string GetText(); - virtual double GetNumber(); - virtual int GetValueType(); - - virtual CValue* Calc(VALUE_OPERATOR op, CValue *val); - virtual CValue* CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val); - virtual void SetValue(CValue* newval) { m_strString = newval->GetText(); } - virtual CValue* GetReplica(); + virtual double GetNumber(); + virtual int GetValueType(); + + virtual CValue *Calc(VALUE_OPERATOR op, CValue *val); + virtual CValue *CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val); + virtual void SetValue(CValue *newval); + virtual CValue *GetReplica(); + #ifdef WITH_PYTHON - virtual PyObject* ConvertValueToPython() { + virtual PyObject *ConvertValueToPython() + { return PyUnicode_FromStdString(m_strString); } -#endif /* WITH_PYTHON */ +#endif // WITH_PYTHON private: - // data member - std::string m_strString; - + /// Data member. + std::string m_strString; #ifdef WITH_CXX_GUARDEDALLOC MEM_CXX_CLASS_ALLOC_FUNCS("GE:CStringValue") #endif }; -#endif /* __EXP_STRINGVALUE_H__ */ +#endif // __EXP_STRINGVALUE_H__ diff --git a/source/gameengine/Expressions/EXP_Value.h b/source/gameengine/Expressions/EXP_Value.h index bf35b9b8af89..1c8054bb98e9 100644 --- a/source/gameengine/Expressions/EXP_Value.h +++ b/source/gameengine/Expressions/EXP_Value.h @@ -23,58 +23,41 @@ # pragma warning (disable:4786) #endif -#include // array functionality for the propertylist +#include // Array functionality for the property list. #include -#include // std::string class +#include // std::string class. #ifdef WITH_CXX_GUARDEDALLOC #include "MEM_guardedalloc.h" #endif -#ifndef GEN_NO_ASSERT -#undef assert -#define assert(exp) ((void)NULL) -#endif - - #ifndef GEN_NO_TRACE #undef trace -#define trace(exp) ((void)NULL) -#endif - -#ifndef GEN_NO_DEBUG -#undef debug -#define debug(exp) ((void)NULL) -#endif - -#ifndef GEN_NO_ASSERTD -#undef BLI_assert -#define BLI_assert(exp) ((void)NULL) +#define trace(exp) ((void)NULL) #endif enum VALUE_OPERATOR { - - VALUE_MOD_OPERATOR, // % - VALUE_ADD_OPERATOR, // + - VALUE_SUB_OPERATOR, // - - VALUE_MUL_OPERATOR, // * - VALUE_DIV_OPERATOR, // / - VALUE_NEG_OPERATOR, // - - VALUE_POS_OPERATOR, // + - VALUE_AND_OPERATOR, // && - VALUE_OR_OPERATOR, // || - VALUE_EQL_OPERATOR, // == - VALUE_NEQ_OPERATOR, // != - VALUE_GRE_OPERATOR, // > - VALUE_LES_OPERATOR, // < - VALUE_GEQ_OPERATOR, // >= - VALUE_LEQ_OPERATOR, // <= - VALUE_NOT_OPERATOR, // ! - VALUE_NO_OPERATOR // no operation at all + VALUE_MOD_OPERATOR, // % + VALUE_ADD_OPERATOR, // + + VALUE_SUB_OPERATOR, // - + VALUE_MUL_OPERATOR, // * + VALUE_DIV_OPERATOR, // / + VALUE_NEG_OPERATOR, // - + VALUE_POS_OPERATOR, // + + VALUE_AND_OPERATOR, // && + VALUE_OR_OPERATOR, // || + VALUE_EQL_OPERATOR, // == + VALUE_NEQ_OPERATOR, // != + VALUE_GRE_OPERATOR, // > + VALUE_LES_OPERATOR, // < + VALUE_GEQ_OPERATOR, // >= + VALUE_LEQ_OPERATOR, // <= + VALUE_NOT_OPERATOR, // ! + VALUE_NO_OPERATOR // no operation at all }; enum VALUE_DATA_TYPE { - VALUE_NO_TYPE, // abstract baseclass + VALUE_NO_TYPE, // Abstract baseclass. VALUE_INT_TYPE, VALUE_FLOAT_TYPE, VALUE_STRING_TYPE, @@ -84,7 +67,7 @@ enum VALUE_DATA_TYPE { VALUE_LIST_TYPE, VALUE_VOID_TYPE, VALUE_VECTOR_TYPE, - VALUE_MAX_TYPE //only here to provide number of types + VALUE_MAX_TYPE // Only here to provide number of types. }; #include "EXP_PyObjectPlus.h" @@ -97,174 +80,147 @@ enum VALUE_DATA_TYPE { * * Together with CExpression, CValue and it's derived classes can be used to * parse expressions into a parsetree with error detecting/correcting capabilities - * also expandable by a CFactory pluginsystem + * also expandable by a CFactory pluginsystem * * Base class for all editor functionality, flexible object type that allows * calculations and uses reference counting for memory management. - * + * * Features: * - Reference Counting (AddRef() / Release()) * - Calculations (Calc() / CalcFinal()) * - Property system (SetProperty() / GetProperty() / FindIdentifier()) * - Replication (GetReplica()) * - Flags (IsError()) - * + * * - Some small editor-specific things added * - A helperclass CompressorArchive handles the serialization - * + * */ -class CValue : public PyObjectPlus - +class CValue : public PyObjectPlus { -Py_Header + Py_Header public: - // Construction / Destruction CValue(); + virtual ~CValue(); #ifdef WITH_PYTHON - //static PyObject *PyMake(PyObject *, PyObject *); virtual PyObject *py_repr(void) { return PyUnicode_FromStdString(GetText()); } - virtual PyObject *ConvertValueToPython() { + virtual PyObject *ConvertValueToPython() + { return NULL; } virtual CValue *ConvertPythonToValue(PyObject *pyobj, const bool do_type_exception, const char *error_prefix); - - static PyObject *pyattr_get_name(void *self, const KX_PYATTRIBUTE_DEF *attrdef); - - virtual PyObject *ConvertKeysToPython( void ); -#endif /* WITH_PYTHON */ - - - - // Expression Calculation - virtual CValue* Calc(VALUE_OPERATOR op, CValue *val); - virtual CValue* CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val); - /// Reference Counting - int GetRefCount() - { - return m_refcount; - } + static PyObject *pyattr_get_name(void *self, const KX_PYATTRIBUTE_DEF *attrdef); - // Add a reference to this value - CValue *AddRef() - { - // Increase global reference count, used to see at the end of the program - // if all CValue-derived classes have been dereferenced to 0 - m_refcount++; - return this; - } + virtual PyObject *ConvertKeysToPython(void); +#endif // WITH_PYTHON - // Release a reference to this value (when reference count reaches 0, the value is removed from the heap) - int Release() - { - // Decrease global reference count, used to see at the end of the program - // if all CValue-derived classes have been dereferenced to 0 - // Decrease local reference count, if it reaches 0 the object should be freed - if (--m_refcount > 0) - { - // Reference count normal, return new reference count - return m_refcount; - } - else - { - // Reference count reached 0, delete ourselves and return 0 - // BLI_assert(m_refcount==0, "Reference count reached sub-zero, object released too much"); - - delete this; - return 0; - } - } + /// Expression Calculation + virtual CValue *Calc(VALUE_OPERATOR op, CValue *val); + virtual CValue *CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val); + /// Reference Counting + int GetRefCount(); + /// Add a reference to this value + CValue *AddRef(); + /// Release a reference to this value (when reference count reaches 0, the value is removed from the heap) + int Release(); /// Property Management - virtual void SetProperty(const std::string& name,CValue* ioProperty); // Set property , overwrites and releases a previous property with the same name if needed - virtual CValue* GetProperty(const std::string & inName); - const std::string GetPropertyText(const std::string & inName); // Get text description of property with name , returns an empty string if there is no property named - float GetPropertyNumber(const std::string& inName,float defnumber); - virtual bool RemoveProperty(const std::string& inName); // Remove the property named , returns true if the property was succesfully removed, false if property was not found or could not be removed - virtual std::vector GetPropertyNames(); - virtual void ClearProperties(); // Clear all properties - - virtual CValue* GetProperty(int inIndex); // Get property number - virtual int GetPropertyCount(); // Get the amount of properties assiocated with this value - - virtual CValue* FindIdentifier(const std::string& identifiername); + /// Set property , overwrites and releases a previous property with the same name if needed. + virtual void SetProperty(const std::string& name, CValue *ioProperty); + virtual CValue *GetProperty(const std::string & inName); + /// Get text description of property with name , returns an empty string if there is no property named . + const std::string GetPropertyText(const std::string & inName); + float GetPropertyNumber(const std::string& inName, float defnumber); + /// Remove the property named , returns true if the property was succesfully removed, false if property was not found or could not be removed. + virtual bool RemoveProperty(const std::string& inName); + virtual std::vector GetPropertyNames(); + /// Clear all properties. + virtual void ClearProperties(); + + /// Get property number . + virtual CValue *GetProperty(int inIndex); + /// Get the amount of properties assiocated with this value. + virtual int GetPropertyCount(); + + virtual CValue *FindIdentifier(const std::string& identifiername); virtual const std::string GetText(); - virtual double GetNumber(); - virtual int GetValueType(); // Get Prop value type - - virtual std::string GetName() = 0; // Retrieve the name of the value - virtual void SetName(const std::string& name); // Set the name of the value + virtual double GetNumber(); + /// Get Prop value type. + virtual int GetValueType(); + + /// Retrieve the name of the value. + virtual std::string GetName() = 0; + /// Set the name of the value. + virtual void SetName(const std::string& name); /** Sets the value to this cvalue. - * \attention this particular function should never be called. Why not abstract? */ - virtual void SetValue(CValue* newval); - virtual CValue* GetReplica(); - virtual void ProcessReplica(); - //virtual CValue* Copy() = 0; - - std::string op2str(VALUE_OPERATOR op); + * \attention this particular function should never be called. Why not abstract? + */ + virtual void SetValue(CValue *newval); + virtual CValue *GetReplica(); + virtual void ProcessReplica(); - inline void SetError(bool err) { m_error=err; } - inline bool IsError() { return m_error; } + std::string op2str(VALUE_OPERATOR op); + + inline void SetError(bool err) + { + m_error = err; + } + inline bool IsError() + { + return m_error; + } protected: virtual void DestructFromPython(); - virtual ~CValue(); private: - // Member variables - std::map* m_pNamedPropertyArray; // Properties for user/game etc + /// Properties for user/game etc. + std::map *m_pNamedPropertyArray; bool m_error; - int m_refcount; // Reference Counter + /// Reference Counter. + int m_refcount; }; -//////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// - -// CPropValue is a CValue derived class, that implements the identification (String name) -// SetName() / GetName(), -// normal classes should derive from CPropValue, real lightweight classes straight from CValue - - +/** CPropValue is a CValue derived class, that implements the identification (String name) + * SetName() / GetName(), + * normal classes should derive from CPropValue, real lightweight classes straight from CValue + */ class CPropValue : public CValue { public: - CPropValue() : - CValue(), - m_strNewName() - + CPropValue() { } - + virtual ~CPropValue() { } - - virtual void SetName(const std::string& name) { + + virtual void SetName(const std::string& name) + { m_strNewName = name; } - - virtual std::string GetName() { - //std::string namefromprop = GetPropertyText("Name"); - //if (namefromprop.size() > 0) - // return namefromprop; + + virtual std::string GetName() + { return m_strNewName; - } // name of Value - + } + protected: - std::string m_strNewName; // Identification + std::string m_strNewName; #ifdef WITH_CXX_GUARDEDALLOC MEM_CXX_CLASS_ALLOC_FUNCS("GE:CPropValue") #endif }; -#endif /* __EXP_VALUE_H__ */ +#endif // __EXP_VALUE_H__ diff --git a/source/gameengine/Expressions/intern/Expression.cpp b/source/gameengine/Expressions/intern/Expression.cpp index 27134ff6df42..7ce2ee36667a 100644 --- a/source/gameengine/Expressions/intern/Expression.cpp +++ b/source/gameengine/Expressions/intern/Expression.cpp @@ -31,3 +31,18 @@ CExpression::~CExpression() { assert (m_refcount == 0); } + +CExpression *CExpression::AddRef() +{ + m_refcount++; + return this; +} + +CExpression *CExpression::Release() +{ + if (--m_refcount < 1) { + delete this; + return NULL; + } + return this; +} diff --git a/source/gameengine/Expressions/intern/Operator1Expr.cpp b/source/gameengine/Expressions/intern/Operator1Expr.cpp index 5de3f0bcbfde..bb74f33f118d 100644 --- a/source/gameengine/Expressions/intern/Operator1Expr.cpp +++ b/source/gameengine/Expressions/intern/Operator1Expr.cpp @@ -50,6 +50,11 @@ effect: deletes the object if (m_lhs) m_lhs->Release(); } +unsigned char COperator1Expr::GetExpressionID() +{ + return COPERATOR1EXPRESSIONID; +} + CValue * COperator1Expr::Calculate() /* pre: diff --git a/source/gameengine/Expressions/intern/Operator2Expr.cpp b/source/gameengine/Expressions/intern/Operator2Expr.cpp index 948d34c81cd4..e162891c2918 100644 --- a/source/gameengine/Expressions/intern/Operator2Expr.cpp +++ b/source/gameengine/Expressions/intern/Operator2Expr.cpp @@ -63,6 +63,12 @@ effect: deletes the object m_rhs->Release(); } + +unsigned char COperator2Expr::GetExpressionID() +{ + return COPERATOR2EXPRESSIONID; +} + CValue* COperator2Expr::Calculate() /* pre: diff --git a/source/gameengine/Expressions/intern/PyObjectPlus.cpp b/source/gameengine/Expressions/intern/PyObjectPlus.cpp index 23acc398eb98..6b1a7326aec7 100644 --- a/source/gameengine/Expressions/intern/PyObjectPlus.cpp +++ b/source/gameengine/Expressions/intern/PyObjectPlus.cpp @@ -1124,6 +1124,11 @@ PyObject *PyObjectPlus::py_repr(void) return NULL; } +bool PyObjectPlus::py_is_valid(void) +{ + return true; +} + PyObject *PyObjectPlus::GetProxyPlus_Ext(PyObjectPlus *self, PyTypeObject *tp, void *ptr) { if (self->m_proxy==NULL) diff --git a/source/gameengine/Expressions/intern/StringValue.cpp b/source/gameengine/Expressions/intern/StringValue.cpp index a309cddfabbb..37e81f48cbf8 100644 --- a/source/gameengine/Expressions/intern/StringValue.cpp +++ b/source/gameengine/Expressions/intern/StringValue.cpp @@ -102,7 +102,10 @@ CValue* CStringValue::CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue return ret; } - +void CStringValue::SetValue(CValue *newval) +{ + m_strString = newval->GetText(); +} double CStringValue::GetNumber() { diff --git a/source/gameengine/Expressions/intern/Value.cpp b/source/gameengine/Expressions/intern/Value.cpp index 411aa3085c80..72f0a539d3ec 100644 --- a/source/gameengine/Expressions/intern/Value.cpp +++ b/source/gameengine/Expressions/intern/Value.cpp @@ -547,6 +547,37 @@ CValue *CValue::CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val) return NULL; } +int CValue::GetRefCount() +{ + return m_refcount; +} + +CValue *CValue::AddRef() +{ + // Increase global reference count, used to see at the end of the program + // if all CValue-derived classes have been dereferenced to 0 + m_refcount++; + return this; +} + +int CValue::Release() +{ + // Decrease global reference count, used to see at the end of the program + // if all CValue-derived classes have been dereferenced to 0 + // Decrease local reference count, if it reaches 0 the object should be freed + if (--m_refcount > 0) { + // Reference count normal, return new reference count + return m_refcount; + } + else { + // Reference count reached 0, delete ourselves and return 0 + // BLI_assert(m_refcount==0, "Reference count reached sub-zero, object released too much"); + + delete this; + return 0; + } +} + void CValue::SetValue(CValue* newval) { // no one should get here