blender/source/gameengine/Expressions/ListValue.h
Campbell Barton fd2b115678 Python BGE API
- Initialize python types with PyType_Ready, which adds methods to the type dictionary.
- use Pythons get/setattro (uses a python string for the attribute rather then char*). Using basic C strings seems nice but internally python converts them to python strings and discards them for most functions that accept char arrays.
- Method lookups use the PyTypes dictionary (should be faster then Py_FindMethod)
- Renamed __getattr -> py_base_getattro, _getattr -> py_getattro, __repr -> py_base_repr, py_delattro, py_getattro_self etc.

From here is possible to put all the parent classes methods into each python types dictionary to avoid nested lookups (api has 4 levels of lookups in some places), tested this but its not ready yet.

Simple tests for getting a method within a loop show this to be between 0.5 and 3.2x faster then using Py_FindMethod()
2009-04-03 14:51:06 +00:00

78 lines
2.1 KiB
C++

/*
* ListValue.h: interface for the CListValue class.
* $Id$
* 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.
*
*/
#if !defined _LISTVALUE_H
#define _LISTVALUE_H
#include "Value.h"
class CListValue : public CPropValue
{
Py_Header;
//PLUGIN_DECLARE_SERIAL (CListValue,CValue)
public:
CListValue(PyTypeObject *T = &Type);
virtual ~CListValue();
void AddConfigurationData(CValue* menuvalue);
void Configure(CValue* menuvalue);
void Add(CValue* value);
/** @attention not implemented yet :( */
virtual CValue* Calc(VALUE_OPERATOR op,CValue *val);
virtual CValue* CalcFinal(VALUE_DATA_TYPE dtype,
VALUE_OPERATOR op,
CValue* val);
virtual float GetNumber();
virtual CValue* GetReplica();
public:
void MergeList(CListValue* otherlist);
bool RemoveValue(CValue* val);
void SetReleaseOnDestruct(bool bReleaseContents);
bool SearchValue(CValue* val);
CValue* FindValue(const STR_String & name);
void ReleaseAndRemoveAll();
virtual void SetModified(bool bModified);
virtual inline bool IsModified();
void Remove(int i);
void Resize(int num);
void SetValue(int i,CValue* val);
CValue* GetValue(int i){ assertd(i < m_pValueArray.size()); return m_pValueArray[i];}
int GetCount() { return m_pValueArray.size();};
virtual const STR_String & GetText();
bool CheckEqual(CValue* first,CValue* second);
virtual PyObject* py_getattro(PyObject* attr);
KX_PYMETHOD_O(CListValue,append);
KX_PYMETHOD_NOARGS(CListValue,reverse);
KX_PYMETHOD_O(CListValue,index);
KX_PYMETHOD_O(CListValue,count);
private:
std::vector<CValue*> m_pValueArray;
bool m_bReleaseContents;
};
#endif // !defined _LISTVALUE_H