| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | // ListValue.cpp: implementation of the CListValue 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. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "ListValue.h"
 | 
					
						
							|  |  |  | #include "StringValue.h"
 | 
					
						
							|  |  |  | #include "VoidValue.h"
 | 
					
						
							|  |  |  | #include <algorithm>
 | 
					
						
							| 
									
										
										
										
											2009-05-10 20:53:58 +00:00
										 |  |  | #include "BoolValue.h"
 | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-11-25 15:29:57 +00:00
										 |  |  | #ifdef HAVE_CONFIG_H
 | 
					
						
							|  |  |  | #include <config.h>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-12-03 20:27:59 +00:00
										 |  |  | #if  ((PY_MAJOR_VERSION == 2) &&(PY_MINOR_VERSION < 5))
 | 
					
						
							|  |  |  | #define Py_ssize_t int
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-19 12:46:39 +00:00
										 |  |  | Py_ssize_t listvalue_bufferlen(PyObject* self) | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-04-19 12:46:39 +00:00
										 |  |  | 	CListValue *list= static_cast<CListValue *>(BGE_PROXY_REF(self)); | 
					
						
							|  |  |  | 	if (list==NULL) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	return (Py_ssize_t)list->GetCount(); | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-19 12:46:39 +00:00
										 |  |  | PyObject* listvalue_buffer_item(PyObject* self, Py_ssize_t index) | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-04-19 12:46:39 +00:00
										 |  |  | 	CListValue *list= static_cast<CListValue *>(BGE_PROXY_REF(self)); | 
					
						
							| 
									
										
										
										
											2009-04-23 00:32:33 +00:00
										 |  |  | 	CValue *cval; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-04-19 12:46:39 +00:00
										 |  |  | 	if (list==NULL) { | 
					
						
							| 
									
										
										
										
											2009-04-23 00:32:33 +00:00
										 |  |  | 		PyErr_SetString(PyExc_SystemError, "val = CList[i], "BGE_PROXY_ERROR_MSG); | 
					
						
							| 
									
										
										
										
											2009-04-19 12:46:39 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	int count = list->GetCount(); | 
					
						
							| 
									
										
										
										
											2009-02-19 07:01:49 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	if (index < 0) | 
					
						
							|  |  |  | 		index = count+index; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-04-23 00:32:33 +00:00
										 |  |  | 	if (index < 0 || index >= count) { | 
					
						
							|  |  |  | 		PyErr_SetString(PyExc_IndexError, "CList[i]: Python ListIndex out of range in CValueList"); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-04-23 00:32:33 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	cval= list->GetValue(index); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	PyObject* pyobj = cval->ConvertValueToPython(); | 
					
						
							|  |  |  | 	if (pyobj) | 
					
						
							|  |  |  | 		return pyobj; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		return cval->GetProxy(); | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-19 12:46:39 +00:00
										 |  |  | PyObject* listvalue_mapping_subscript(PyObject* self, PyObject* pyindex) | 
					
						
							| 
									
										
										
										
											2004-06-04 03:00:13 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-04-19 12:46:39 +00:00
										 |  |  | 	CListValue *list= static_cast<CListValue *>(BGE_PROXY_REF(self)); | 
					
						
							|  |  |  | 	if (list==NULL) { | 
					
						
							| 
									
										
										
										
											2009-04-23 00:32:33 +00:00
										 |  |  | 		PyErr_SetString(PyExc_SystemError, "value = CList[i], "BGE_PROXY_ERROR_MSG); | 
					
						
							| 
									
										
										
										
											2009-04-19 12:46:39 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2004-06-04 03:00:13 +00:00
										 |  |  | 	if (PyString_Check(pyindex)) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2009-05-26 16:15:40 +00:00
										 |  |  | 		CValue *item = ((CListValue*) list)->FindValue(PyString_AsString(pyindex)); | 
					
						
							| 
									
										
										
										
											2009-05-31 17:44:38 +00:00
										 |  |  | 		if (item) { | 
					
						
							|  |  |  | 			PyObject* pyobj = item->ConvertValueToPython(); | 
					
						
							|  |  |  | 			if(pyobj) | 
					
						
							|  |  |  | 				return pyobj; | 
					
						
							|  |  |  | 			else | 
					
						
							|  |  |  | 				return item->GetProxy(); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2004-06-04 03:00:13 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-05-09 17:24:21 +00:00
										 |  |  | 	else if (PyInt_Check(pyindex)) | 
					
						
							| 
									
										
										
										
											2004-06-07 11:03:12 +00:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		int index = PyInt_AsLong(pyindex); | 
					
						
							| 
									
										
										
										
											2009-05-09 17:24:21 +00:00
										 |  |  | 		return listvalue_buffer_item(self, index); /* wont add a ref */ | 
					
						
							| 
									
										
										
										
											2004-06-07 11:03:12 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	PyObject *pyindex_str = PyObject_Repr(pyindex); /* new ref */ | 
					
						
							| 
									
										
										
										
											2009-04-23 00:32:33 +00:00
										 |  |  | 	PyErr_Format(PyExc_KeyError, "CList[key]: '%s' key not in list", PyString_AsString(pyindex_str)); | 
					
						
							| 
									
										
										
										
											2004-06-07 11:03:12 +00:00
										 |  |  | 	Py_DECREF(pyindex_str); | 
					
						
							|  |  |  | 	return NULL; | 
					
						
							| 
									
										
										
										
											2004-06-04 03:00:13 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* just slice it into a python list... */ | 
					
						
							| 
									
										
										
										
											2009-04-19 12:46:39 +00:00
										 |  |  | PyObject* listvalue_buffer_slice(PyObject* self,Py_ssize_t ilow, Py_ssize_t ihigh) | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-04-19 12:46:39 +00:00
										 |  |  | 	CListValue *list= static_cast<CListValue *>(BGE_PROXY_REF(self)); | 
					
						
							|  |  |  | 	if (list==NULL) { | 
					
						
							| 
									
										
										
										
											2009-04-23 00:32:33 +00:00
										 |  |  | 		PyErr_SetString(PyExc_SystemError, "val = CList[i:j], "BGE_PROXY_ERROR_MSG); | 
					
						
							| 
									
										
										
										
											2009-04-19 12:46:39 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 	int i, j; | 
					
						
							| 
									
										
										
										
											2009-04-19 12:46:39 +00:00
										 |  |  | 	PyObject *newlist; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (ilow < 0) ilow = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	int n = ((CListValue*) list)->GetCount(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (ihigh >= n) | 
					
						
							|  |  |  | 		ihigh = n; | 
					
						
							|  |  |  |     if (ihigh < ilow) | 
					
						
							|  |  |  |         ihigh = ilow; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-19 12:46:39 +00:00
										 |  |  | 	newlist = PyList_New(ihigh - ilow); | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 	if (!newlist) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (i = ilow, j = 0; i < ihigh; i++, j++) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2009-04-19 12:46:39 +00:00
										 |  |  | 		PyObject* pyobj = list->GetValue(i)->ConvertValueToPython(); | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 		if (!pyobj) | 
					
						
							| 
									
										
										
										
											2009-04-19 12:46:39 +00:00
										 |  |  | 			pyobj = list->GetValue(i)->GetProxy(); | 
					
						
							|  |  |  | 		PyList_SET_ITEM(newlist, i, pyobj); | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 	}	 | 
					
						
							| 
									
										
										
										
											2009-04-19 12:46:39 +00:00
										 |  |  | 	return newlist; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-23 00:32:33 +00:00
										 |  |  | /* clist + list, return a list that python owns */ | 
					
						
							|  |  |  | static PyObject *listvalue_buffer_concat(PyObject * self, PyObject * other) | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-04-19 12:46:39 +00:00
										 |  |  | 	CListValue *listval= static_cast<CListValue *>(BGE_PROXY_REF(self)); | 
					
						
							| 
									
										
										
										
											2009-04-23 00:32:33 +00:00
										 |  |  | 	int i, numitems, numitems_orig; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-04-19 12:46:39 +00:00
										 |  |  | 	if (listval==NULL) { | 
					
						
							| 
									
										
										
										
											2009-04-23 00:32:33 +00:00
										 |  |  | 		PyErr_SetString(PyExc_SystemError, "CList+other, "BGE_PROXY_ERROR_MSG); | 
					
						
							| 
									
										
										
										
											2009-04-19 12:46:39 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-04-23 00:32:33 +00:00
										 |  |  | 	numitems_orig= listval->GetCount(); | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 	// for now, we support CListValue concatenated with items
 | 
					
						
							|  |  |  | 	// and CListValue concatenated to Python Lists
 | 
					
						
							|  |  |  | 	// and CListValue concatenated with another CListValue
 | 
					
						
							| 
									
										
										
										
											2009-04-19 12:46:39 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-04-23 00:32:33 +00:00
										 |  |  | 	/* Shallow copy, dont use listval->GetReplica(), it will screw up with KX_GameObjects */ | 
					
						
							|  |  |  | 	CListValue* listval_new = new CListValue(); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if (PyList_Check(other)) | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2009-04-23 00:32:33 +00:00
										 |  |  | 		CValue* listitemval; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 		bool error = false; | 
					
						
							| 
									
										
										
										
											2009-04-23 00:32:33 +00:00
										 |  |  | 		 | 
					
						
							|  |  |  | 		numitems = PyList_Size(other); | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		/* copy the first part of the list */ | 
					
						
							|  |  |  | 		listval_new->Resize(numitems_orig + numitems); | 
					
						
							|  |  |  | 		for (i=0;i<numitems_orig;i++) | 
					
						
							|  |  |  | 			listval_new->SetValue(i, listval->GetValue(i)->AddRef()); | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 		for (i=0;i<numitems;i++) | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2009-04-23 00:32:33 +00:00
										 |  |  | 			listitemval = listval->ConvertPythonToValue(PyList_GetItem(other,i), "cList + pyList: CListValue, "); | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 			if (listitemval) { | 
					
						
							|  |  |  | 				listval_new->SetValue(i+numitems_orig, listitemval); | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				error= true; | 
					
						
							|  |  |  | 				break; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-04-23 00:32:33 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2008-08-14 03:23:36 +00:00
										 |  |  | 		if (error) { | 
					
						
							| 
									
										
										
										
											2009-04-23 00:32:33 +00:00
										 |  |  | 			listval_new->Resize(numitems_orig+i); /* resize so we dont try release NULL pointers */ | 
					
						
							|  |  |  | 			listval_new->Release(); | 
					
						
							|  |  |  | 			return NULL; /* ConvertPythonToValue above sets the error */  | 
					
						
							| 
									
										
										
										
											2008-08-14 03:23:36 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-04-23 00:32:33 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else if (PyObject_TypeCheck(other, &CListValue::Type)) { | 
					
						
							|  |  |  | 		// add items from otherlist to this list
 | 
					
						
							|  |  |  | 		CListValue* otherval = static_cast<CListValue *>(BGE_PROXY_REF(other)); | 
					
						
							|  |  |  | 		if(otherval==NULL) { | 
					
						
							|  |  |  | 			listval_new->Release(); | 
					
						
							|  |  |  | 			PyErr_SetString(PyExc_SystemError, "CList+other, "BGE_PROXY_ERROR_MSG); | 
					
						
							|  |  |  | 			return NULL; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-04-23 00:32:33 +00:00
										 |  |  | 		 | 
					
						
							|  |  |  | 		numitems = otherval->GetCount(); | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		/* copy the first part of the list */ | 
					
						
							|  |  |  | 		listval_new->Resize(numitems_orig + numitems); /* resize so we dont try release NULL pointers */ | 
					
						
							|  |  |  | 		for (i=0;i<numitems_orig;i++) | 
					
						
							|  |  |  | 			listval_new->SetValue(i, listval->GetValue(i)->AddRef()); | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		/* now copy the other part of the list */ | 
					
						
							|  |  |  | 		for (i=0;i<numitems;i++) | 
					
						
							|  |  |  | 			listval_new->SetValue(i+numitems_orig, otherval->GetValue(i)->AddRef()); | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-04-23 00:32:33 +00:00
										 |  |  | 	return listval_new->NewProxy(true); /* python owns this list */ | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-12 12:56:12 +00:00
										 |  |  | static int listvalue_buffer_contains(PyObject *self_v, PyObject *value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	CListValue *self= static_cast<CListValue *>(BGE_PROXY_REF(self_v)); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if (self==NULL) { | 
					
						
							|  |  |  | 		PyErr_SetString(PyExc_SystemError, "val in CList, "BGE_PROXY_ERROR_MSG); | 
					
						
							|  |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if (PyString_Check(value)) { | 
					
						
							|  |  |  | 		if (self->FindValue((const char *)PyString_AsString(value))) { | 
					
						
							|  |  |  | 			return 1; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else if (BGE_PROXY_CHECK_TYPE(value)) { /* not dict like at all but this worked before __contains__ was used */ | 
					
						
							|  |  |  | 		CValue *item= static_cast<CValue *>(BGE_PROXY_REF(value)); | 
					
						
							|  |  |  | 		for (int i=0; i < self->GetCount(); i++) | 
					
						
							|  |  |  | 			if (self->GetValue(i) == item) // Com
 | 
					
						
							|  |  |  | 				return 1; | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 	} // not using CheckEqual
 | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-12-03 20:27:59 +00:00
										 |  |  | static  PySequenceMethods listvalue_as_sequence = { | 
					
						
							|  |  |  | 	listvalue_bufferlen,//(inquiry)buffer_length, /*sq_length*/
 | 
					
						
							|  |  |  | 	listvalue_buffer_concat, /*sq_concat*/ | 
					
						
							|  |  |  |  	NULL, /*sq_repeat*/ | 
					
						
							|  |  |  | 	listvalue_buffer_item, /*sq_item*/ | 
					
						
							| 
									
										
										
										
											2009-04-29 16:54:45 +00:00
										 |  |  | #if (PY_VERSION_HEX >= 0x03000000) // TODO, slicing in py3?
 | 
					
						
							|  |  |  | 	NULL, | 
					
						
							|  |  |  | 	NULL, | 
					
						
							|  |  |  | 	NULL, | 
					
						
							|  |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2006-12-03 20:27:59 +00:00
										 |  |  | 	listvalue_buffer_slice, /*sq_slice*/ | 
					
						
							| 
									
										
										
										
											2009-05-02 04:53:01 +00:00
										 |  |  |  	NULL, /*sq_ass_item*/ | 
					
						
							| 
									
										
										
										
											2009-04-29 16:54:45 +00:00
										 |  |  |  	NULL, /*sq_ass_slice*/ | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2009-06-12 12:56:12 +00:00
										 |  |  | 	(objobjproc)listvalue_buffer_contains,	/* sq_contains */ | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Is this one used ? */ | 
					
						
							| 
									
										
										
										
											2006-12-03 20:27:59 +00:00
										 |  |  | static  PyMappingMethods instance_as_mapping = { | 
					
						
							|  |  |  | 	listvalue_bufferlen, /*mp_length*/ | 
					
						
							|  |  |  | 	listvalue_mapping_subscript, /*mp_subscript*/ | 
					
						
							|  |  |  | 	NULL /*mp_ass_subscript*/ | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyTypeObject CListValue::Type = { | 
					
						
							| 
									
										
										
										
											2009-04-29 16:54:45 +00:00
										 |  |  | #if (PY_VERSION_HEX >= 0x02060000)
 | 
					
						
							|  |  |  | 	PyVarObject_HEAD_INIT(NULL, 0) | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | 	/* python 2.5 and below */ | 
					
						
							|  |  |  | 	PyObject_HEAD_INIT( NULL )  /* required py macro */ | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 	0,				/*ob_size*/ | 
					
						
							| 
									
										
										
										
											2009-04-29 16:54:45 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 	"CListValue",			/*tp_name*/ | 
					
						
							| 
									
										
										
										
											2009-04-19 14:57:52 +00:00
										 |  |  | 	sizeof(PyObjectPlus_Proxy), /*tp_basicsize*/ | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 	0,				/*tp_itemsize*/ | 
					
						
							|  |  |  | 	/* methods */ | 
					
						
							| 
									
										
										
										
											2009-04-19 14:57:52 +00:00
										 |  |  | 	py_base_dealloc,	  		/*tp_dealloc*/ | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 	0,			 	/*tp_print*/ | 
					
						
							| 
									
										
										
										
											2009-04-03 14:51:06 +00:00
										 |  |  | 	0, 			/*tp_getattr*/ | 
					
						
							|  |  |  | 	0, 			/*tp_setattr*/ | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 	0,			        /*tp_compare*/ | 
					
						
							| 
									
										
										
										
											2009-04-03 14:51:06 +00:00
										 |  |  | 	py_base_repr,			        /*tp_repr*/ | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 	0,			        /*tp_as_number*/ | 
					
						
							|  |  |  | 	&listvalue_as_sequence, /*tp_as_sequence*/ | 
					
						
							| 
									
										
										
										
											2004-06-07 11:03:12 +00:00
										 |  |  | 	&instance_as_mapping,	        /*tp_as_mapping*/ | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 	0,			        /*tp_hash*/ | 
					
						
							|  |  |  | 	0,				/*tp_call */ | 
					
						
							| 
									
										
										
										
											2009-04-03 14:51:06 +00:00
										 |  |  | 	0, | 
					
						
							|  |  |  | 	py_base_getattro, | 
					
						
							|  |  |  | 	py_base_setattro, | 
					
						
							| 
									
										
										
										
											2009-06-12 12:56:12 +00:00
										 |  |  | 	0, | 
					
						
							|  |  |  | 	Py_TPFLAGS_DEFAULT, | 
					
						
							|  |  |  | 	0,0,0,0,0,0,0, | 
					
						
							| 
									
										
										
										
											2009-04-03 04:12:20 +00:00
										 |  |  | 	Methods | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyParentObject CListValue::Parents[] = { | 
					
						
							|  |  |  | 	&CListValue::Type, | 
					
						
							|  |  |  | 	&CValue::Type, | 
					
						
							|  |  |  | 		NULL | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyMethodDef CListValue::Methods[] = { | 
					
						
							| 
									
										
										
										
											2009-05-26 16:15:40 +00:00
										 |  |  | 	/* List style access */ | 
					
						
							| 
									
										
										
										
											2009-02-23 06:41:10 +00:00
										 |  |  | 	{"append", (PyCFunction)CListValue::sPyappend,METH_O}, | 
					
						
							|  |  |  | 	{"reverse", (PyCFunction)CListValue::sPyreverse,METH_NOARGS}, | 
					
						
							|  |  |  | 	{"index", (PyCFunction)CListValue::sPyindex,METH_O}, | 
					
						
							|  |  |  | 	{"count", (PyCFunction)CListValue::sPycount,METH_O}, | 
					
						
							| 
									
										
										
										
											2009-05-26 16:15:40 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* Dict style access */ | 
					
						
							|  |  |  | 	{"get", (PyCFunction)CListValue::sPyget,METH_VARARGS}, | 
					
						
							|  |  |  | 	{"has_key", (PyCFunction)CListValue::sPyhas_key,METH_O}, | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* Own cvalue funcs */ | 
					
						
							| 
									
										
										
										
											2009-04-11 20:58:09 +00:00
										 |  |  | 	{"from_id", (PyCFunction)CListValue::sPyfrom_id,METH_O}, | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	{NULL,NULL} //Sentinel
 | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-26 09:04:06 +00:00
										 |  |  | PyAttributeDef CListValue::Attributes[] = { | 
					
						
							|  |  |  | 	{ NULL }	//Sentinel
 | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-03 14:51:06 +00:00
										 |  |  | PyObject* CListValue::py_getattro(PyObject* attr) { | 
					
						
							|  |  |  | 	py_getattro_up(CValue); | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-20 23:17:52 +00:00
										 |  |  | PyObject* CListValue::py_getattro_dict() { | 
					
						
							|  |  |  | 	py_getattro_dict_up(CValue); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | //////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | // Construction/Destruction
 | 
					
						
							|  |  |  | //////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | CListValue::CListValue(PyTypeObject *T )  | 
					
						
							|  |  |  | : CPropValue(T) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	m_bReleaseContents=true;	 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | CListValue::~CListValue() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (m_bReleaseContents) { | 
					
						
							| 
									
										
										
										
											2004-04-24 06:40:15 +00:00
										 |  |  | 		for (unsigned int i=0;i<m_pValueArray.size();i++) { | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 			m_pValueArray[i]->Release(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static STR_String gstrListRep=STR_String("List"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const STR_String & CListValue::GetText() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	gstrListRep = "["; | 
					
						
							|  |  |  | 	STR_String commastr = ""; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (int i=0;i<GetCount();i++) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		gstrListRep += commastr; | 
					
						
							|  |  |  | 		gstrListRep += GetValue(i)->GetText(); | 
					
						
							|  |  |  | 		commastr = ","; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	gstrListRep += "]"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return gstrListRep; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | CValue* CListValue::GetReplica() {  | 
					
						
							|  |  |  | 	CListValue* replica = new CListValue(*this); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-22 14:42:00 +00:00
										 |  |  | 	replica->ProcessReplica(); | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	replica->m_bReleaseContents=true; // for copy, complete array is copied for now...
 | 
					
						
							|  |  |  | 	// copy all values
 | 
					
						
							|  |  |  | 	int numelements = m_pValueArray.size(); | 
					
						
							| 
									
										
										
										
											2004-04-24 06:40:15 +00:00
										 |  |  | 	unsigned int i=0; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 	replica->m_pValueArray.resize(numelements); | 
					
						
							|  |  |  | 	for (i=0;i<m_pValueArray.size();i++) | 
					
						
							|  |  |  | 		replica->m_pValueArray[i] = m_pValueArray[i]->GetReplica(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return replica; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void CListValue::SetValue(int i, CValue *val) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	assertd(i < m_pValueArray.size()); | 
					
						
							|  |  |  | 	m_pValueArray[i]=val; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void CListValue::Resize(int num) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	m_pValueArray.resize(num); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void CListValue::Remove(int i) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	assertd(i<m_pValueArray.size()); | 
					
						
							|  |  |  | 	m_pValueArray.erase(m_pValueArray.begin()+i); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void CListValue::ReleaseAndRemoveAll() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2004-04-24 06:40:15 +00:00
										 |  |  | 	for (unsigned int i=0;i<m_pValueArray.size();i++) | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 		m_pValueArray[i]->Release(); | 
					
						
							|  |  |  | 	m_pValueArray.clear();//.Clear();
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-26 16:15:40 +00:00
										 |  |  | CValue* CListValue::FindValue(const STR_String & name) | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-05-26 16:15:40 +00:00
										 |  |  | 	for (int i=0; i < GetCount(); i++) | 
					
						
							|  |  |  | 		if (GetValue(i)->GetName() == name) | 
					
						
							|  |  |  | 			return GetValue(i); | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-05-26 16:15:40 +00:00
										 |  |  | 	return NULL; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-26 16:15:40 +00:00
										 |  |  | CValue* CListValue::FindValue(const char * name) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	for (int i=0; i < GetCount(); i++) | 
					
						
							|  |  |  | 		if (GetValue(i)->GetName() == name) | 
					
						
							|  |  |  | 			return GetValue(i); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	return NULL; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | bool CListValue::SearchValue(CValue *val) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	for (int i=0;i<GetCount();i++) | 
					
						
							|  |  |  | 		if (val == GetValue(i)) | 
					
						
							|  |  |  | 			return true; | 
					
						
							|  |  |  | 	return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void CListValue::SetReleaseOnDestruct(bool bReleaseContents) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	m_bReleaseContents = bReleaseContents; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool CListValue::RemoveValue(CValue *val) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	bool result=false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (int i=GetCount()-1;i>=0;i--) | 
					
						
							|  |  |  | 		if (val == GetValue(i)) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			Remove(i); | 
					
						
							|  |  |  | 			result=true; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	return result; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void CListValue::MergeList(CListValue *otherlist) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	int numelements = this->GetCount(); | 
					
						
							|  |  |  | 	int numotherelements = otherlist->GetCount(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Resize(numelements+numotherelements); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (int i=0;i<numotherelements;i++) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		SetValue(i+numelements,otherlist->GetValue(i)->AddRef()); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-19 17:29:07 +00:00
										 |  |  | PyObject* CListValue::Pyappend(PyObject* value) | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-04-23 00:32:33 +00:00
										 |  |  | 	CValue* objval = ConvertPythonToValue(value, "CList.append(i): CValueList, "); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!objval) /* ConvertPythonToValue sets the error */ | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if (!BGE_PROXY_PYOWNS(m_proxy)) { | 
					
						
							|  |  |  | 		PyErr_SetString(PyExc_TypeError, "CList.append(i): this CValueList is used internally for the game engine and can't be modified"); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	Add(objval); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	Py_RETURN_NONE; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-19 17:29:07 +00:00
										 |  |  | PyObject* CListValue::Pyreverse() | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	std::reverse(m_pValueArray.begin(),m_pValueArray.end()); | 
					
						
							| 
									
										
										
										
											2009-02-21 12:43:24 +00:00
										 |  |  | 	Py_RETURN_NONE; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool CListValue::CheckEqual(CValue* first,CValue* second) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	bool result = false; | 
					
						
							| 
									
										
										
										
											2009-06-12 12:56:12 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 	CValue* eqval =  ((CValue*)first)->Calc(VALUE_EQL_OPERATOR,(CValue*)second); | 
					
						
							| 
									
										
										
										
											2009-04-05 14:55:50 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	if (eqval==NULL) | 
					
						
							|  |  |  | 		return false; | 
					
						
							| 
									
										
										
										
											2009-05-10 20:53:58 +00:00
										 |  |  | 	const STR_String& text = eqval->GetText(); | 
					
						
							|  |  |  | 	if (&text==&CBoolValue::sTrueString) | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		result = true; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-05-10 20:53:58 +00:00
										 |  |  | 	eqval->Release(); | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 	return result; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-19 17:29:07 +00:00
										 |  |  | PyObject* CListValue::Pyindex(PyObject *value) | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	PyObject* result = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-23 00:32:33 +00:00
										 |  |  | 	CValue* checkobj = ConvertPythonToValue(value, "val = cList[i]: CValueList, "); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:41:10 +00:00
										 |  |  | 	if (checkobj==NULL) | 
					
						
							|  |  |  | 		return NULL; /* ConvertPythonToValue sets the error */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	int numelem = GetCount(); | 
					
						
							|  |  |  | 	for (int i=0;i<numelem;i++) | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2009-02-23 06:41:10 +00:00
										 |  |  | 		CValue* elem = 			GetValue(i); | 
					
						
							| 
									
										
										
										
											2009-06-12 12:56:12 +00:00
										 |  |  | 		if (checkobj==elem || CheckEqual(checkobj,elem)) | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2009-02-23 06:41:10 +00:00
										 |  |  | 			result = PyInt_FromLong(i); | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-02-23 06:41:10 +00:00
										 |  |  | 	checkobj->Release(); | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-23 06:41:10 +00:00
										 |  |  | 	if (result==NULL) { | 
					
						
							| 
									
										
										
										
											2009-04-23 00:32:33 +00:00
										 |  |  | 		PyErr_SetString(PyExc_ValueError, "CList.index(x): x not in CListValue"); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:41:10 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 	return result; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-19 17:29:07 +00:00
										 |  |  | PyObject* CListValue::Pycount(PyObject* value) | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	int numfound = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-24 20:27:04 +00:00
										 |  |  | 	CValue* checkobj = ConvertPythonToValue(value, ""); /* error ignored */ | 
					
						
							| 
									
										
										
										
											2009-02-23 06:41:10 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	if (checkobj==NULL) { /* in this case just return that there are no items in the list */ | 
					
						
							|  |  |  | 		PyErr_Clear(); | 
					
						
							| 
									
										
										
										
											2009-04-05 14:55:50 +00:00
										 |  |  | 		return PyInt_FromLong(0); | 
					
						
							| 
									
										
										
										
											2009-02-23 06:41:10 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	int numelem = GetCount(); | 
					
						
							|  |  |  | 	for (int i=0;i<numelem;i++) | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2009-02-23 06:41:10 +00:00
										 |  |  | 		CValue* elem = 			GetValue(i); | 
					
						
							| 
									
										
										
										
											2009-06-12 12:56:12 +00:00
										 |  |  | 		if (checkobj==elem || CheckEqual(checkobj,elem)) | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2009-02-23 06:41:10 +00:00
										 |  |  | 			numfound ++; | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-02-23 06:41:10 +00:00
										 |  |  | 	checkobj->Release(); | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return PyInt_FromLong(numfound); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-26 16:15:40 +00:00
										 |  |  | /* Matches python dict.get(key, [default]) */ | 
					
						
							|  |  |  | PyObject* CListValue::Pyget(PyObject *args) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	char *key; | 
					
						
							|  |  |  | 	PyObject* def = Py_None; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!PyArg_ParseTuple(args, "s|O:get", &key, &def)) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	CValue *item = FindValue((const char *)key); | 
					
						
							| 
									
										
										
										
											2009-05-31 17:44:38 +00:00
										 |  |  | 	if (item) {	 | 
					
						
							|  |  |  | 		PyObject* pyobj = item->ConvertValueToPython(); | 
					
						
							|  |  |  | 		if (pyobj) | 
					
						
							|  |  |  | 			return pyobj; | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			return item->GetProxy(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-05-26 16:15:40 +00:00
										 |  |  | 	Py_INCREF(def); | 
					
						
							|  |  |  | 	return def; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-26 16:15:40 +00:00
										 |  |  | /* Matches python dict.has_key() */ | 
					
						
							|  |  |  | PyObject* CListValue::Pyhas_key(PyObject* value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (PyString_Check(value) && FindValue((const char *)PyString_AsString(value))) | 
					
						
							|  |  |  | 		Py_RETURN_TRUE; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	Py_RETURN_FALSE; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-19 17:29:07 +00:00
										 |  |  | PyObject* CListValue::Pyfrom_id(PyObject* value) | 
					
						
							| 
									
										
										
										
											2009-04-11 20:58:09 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-04-19 17:26:03 +00:00
										 |  |  | 	uintptr_t id= (uintptr_t)PyLong_AsVoidPtr(value); | 
					
						
							| 
									
										
										
										
											2009-04-11 20:58:09 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2009-04-17 20:06:06 +00:00
										 |  |  | 	if (PyErr_Occurred()) | 
					
						
							| 
									
										
										
										
											2009-04-11 20:58:09 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	int numelem = GetCount(); | 
					
						
							|  |  |  | 	for (int i=0;i<numelem;i++) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2009-04-19 17:26:03 +00:00
										 |  |  | 		if (reinterpret_cast<uintptr_t>(m_pValueArray[i]->m_proxy) == id) | 
					
						
							| 
									
										
										
										
											2009-04-19 12:46:39 +00:00
										 |  |  | 			return GetValue(i)->GetProxy(); | 
					
						
							| 
									
										
										
										
											2009-04-11 20:58:09 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-04-19 21:01:12 +00:00
										 |  |  | 	PyErr_SetString(PyExc_IndexError, "from_id(#): id not found in CValueList"); | 
					
						
							| 
									
										
										
										
											2009-04-11 20:58:09 +00:00
										 |  |  | 	return NULL;	 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | /* --------------------------------------------------------------------- 
 | 
					
						
							|  |  |  |  * Some stuff taken from the header | 
					
						
							|  |  |  |  * --------------------------------------------------------------------- */ | 
					
						
							|  |  |  | CValue* CListValue::Calc(VALUE_OPERATOR op,CValue *val)  | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2009-04-05 14:55:50 +00:00
										 |  |  | 	//assert(false); // todo: implement me!
 | 
					
						
							| 
									
										
										
										
											2009-04-24 20:27:04 +00:00
										 |  |  | 	static int error_printed =  0; | 
					
						
							|  |  |  | 	if (error_printed==0) { | 
					
						
							|  |  |  | 		fprintf(stderr, "CValueList::Calc not yet implimented\n"); | 
					
						
							|  |  |  | 		error_printed = 1; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 	return NULL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | CValue* CListValue::CalcFinal(VALUE_DATA_TYPE dtype, | 
					
						
							|  |  |  | 							  VALUE_OPERATOR op,  | 
					
						
							|  |  |  | 							  CValue* val)  | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2009-04-05 14:55:50 +00:00
										 |  |  | 	//assert(false); // todo: implement me!
 | 
					
						
							| 
									
										
										
										
											2009-04-24 20:27:04 +00:00
										 |  |  | 	static int error_printed =  0; | 
					
						
							|  |  |  | 	if (error_printed==0) { | 
					
						
							|  |  |  | 		fprintf(stderr, "CValueList::CalcFinal not yet implimented\n"); | 
					
						
							|  |  |  | 		error_printed = 1; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 	return NULL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void CListValue::Add(CValue* value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	m_pValueArray.push_back(value); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-12 06:41:01 +00:00
										 |  |  | double CListValue::GetNumber() | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	return -1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void CListValue::SetModified(bool bModified) | 
					
						
							|  |  |  | {	 | 
					
						
							|  |  |  | 	CValue::SetModified(bModified); | 
					
						
							|  |  |  | 	int numels = GetCount(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (int i=0;i<numels;i++) | 
					
						
							|  |  |  | 		GetValue(i)->SetModified(bModified); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool CListValue::IsModified() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	bool bmod = CValue::IsModified(); //normal own flag
 | 
					
						
							|  |  |  | 	int numels = GetCount(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (int i=0;i<numels;i++) | 
					
						
							|  |  |  | 		bmod = bmod || GetValue(i)->IsModified(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return bmod; | 
					
						
							| 
									
										
										
										
											2002-11-25 15:29:57 +00:00
										 |  |  | } |