library of assembled shared sources

http://lass.cocamware.com

pysequence.cpp

Go to the documentation of this file.
00001 /** @file
00002  *  @author Bram de Greve (bramz@users.sourceforge.net)
00003  *  @author Tom De Muer (tomdemuer@users.sourceforge.net)
00004  *
00005  *  *** BEGIN LICENSE INFORMATION ***
00006  *  
00007  *  The contents of this file are subject to the Common Public Attribution License 
00008  *  Version 1.0 (the "License"); you may not use this file except in compliance with 
00009  *  the License. You may obtain a copy of the License at 
00010  *  http://lass.sourceforge.net/cpal-license. The License is based on the 
00011  *  Mozilla Public License Version 1.1 but Sections 14 and 15 have been added to cover 
00012  *  use of software over a computer network and provide for limited attribution for 
00013  *  the Original Developer. In addition, Exhibit A has been modified to be consistent 
00014  *  with Exhibit B.
00015  *  
00016  *  Software distributed under the License is distributed on an "AS IS" basis, WITHOUT 
00017  *  WARRANTY OF ANY KIND, either express or implied. See the License for the specific 
00018  *  language governing rights and limitations under the License.
00019  *  
00020  *  The Original Code is LASS - Library of Assembled Shared Sources.
00021  *  
00022  *  The Initial Developer of the Original Code is Bram de Greve and Tom De Muer.
00023  *  The Original Developer is the Initial Developer.
00024  *  
00025  *  All portions of the code written by the Initial Developer are:
00026  *  Copyright (C) 2004-2007 the Initial Developer.
00027  *  All Rights Reserved.
00028  *  
00029  *  Contributor(s):
00030  *
00031  *  Alternatively, the contents of this file may be used under the terms of the 
00032  *  GNU General Public License Version 2 or later (the GPL), in which case the 
00033  *  provisions of GPL are applicable instead of those above.  If you wish to allow use
00034  *  of your version of this file only under the terms of the GPL and not to allow 
00035  *  others to use your version of this file under the CPAL, indicate your decision by 
00036  *  deleting the provisions above and replace them with the notice and other 
00037  *  provisions required by the GPL License. If you do not delete the provisions above,
00038  *  a recipient may use your version of this file under either the CPAL or the GPL.
00039  *  
00040  *  *** END LICENSE INFORMATION ***
00041  */
00042 
00043 
00044 
00045 #include "util_common.h"
00046 #include "pysequence.h"
00047 #include "pyobject_macros.h"
00048 
00049 namespace lass
00050 {
00051 namespace python
00052 {
00053 namespace impl
00054 {
00055     PY_DECLARE_CLASS( PySequence )
00056     //typedef meta::type_list::Make<PyObject*>::Type TArguments;
00057     //PY_CLASS_CONSTRUCTOR(PySequence, TArguments) // constructor with some arguments. *
00058 
00059     PY_CLASS_METHOD( PySequence, append )
00060     PY_CLASS_METHOD( PySequence, pop )
00061     PY_CLASS_METHOD( PySequence, clear )
00062     PY_CLASS_METHOD( PySequence, reserve )
00063 
00064     PySequenceMethods PySequence::pySequenceMethods = {
00065     (lenfunc)PySequence_Length,         /* sq_length */
00066     (binaryfunc)PySequence_Concat,      /* sq_concat */
00067     (ssizeargfunc)PySequence_Repeat,        /* sq_repeat */
00068     (ssizeargfunc)PySequence_Item,          /* sq_item */
00069     (ssizessizeargfunc)PySequence_Slice,        /* sq_slice */
00070     (ssizeobjargproc)PySequence_AssItem,        /* sq_ass_item */
00071     (ssizessizeobjargproc)PySequence_AssSlice,  /* sq_ass_slice */
00072     (objobjproc)PySequence_Contains,        /* sq_contains */
00073     (binaryfunc)PySequence_InplaceConcat,   /* sq_inplace_concat */
00074     (ssizeargfunc)PySequence_InplaceRepeat, /* sq_inplace_repeat */
00075     };
00076 
00077     bool PySequence::isInitialized = false;
00078 
00079     /* POSTPONED: parsing of the arguments needs some work
00080     PySequence::PySequence( PyObject* iP ) : PyObjectPlus(&Type)
00081     {
00082         // we will default to the vector implementation
00083         typedef std::vector<PyObject*>  TVPyObj;
00084         TVPyObj*    newContainer  = new TVPyObj;
00085         pyGetSimpleObject(iP, newContainer );
00086         pimpl_ = new PySequenceContainer<TVPyObj,ContainerOwned<TVPyObj> >(*newContainer,false);
00087         initialize();
00088     }
00089     */
00090 
00091     PySequence::~PySequence()
00092     {
00093         delete pimpl_;
00094     }
00095     void PySequence::initialize()
00096     {
00097         if (!isInitialized)
00098         {
00099             //PySequence::Type.tp_iter = &PySequence::PySequence_ListIter;
00100             PySequence::_lassPyType.tp_as_sequence= &pySequenceMethods;
00101 #ifdef LASS_PYTHON_INHERITANCE_FROM_EMBEDDING
00102             // [TDM] for some reason the dict member is not getting properly initialized on PySequence?!
00103             // switch off inheritance
00104             PySequence::_lassPyType.tp_dictoffset = 0;
00105             PySequence::_lassPyType.tp_flags &= ~Py_TPFLAGS_BASETYPE;
00106 #endif
00107             finalizePyType( PySequence::_lassPyType, *PySequence::_lassPyGetParentType(), 
00108                 PySequence::_lassPyMethods, PySequence::_lassPyGetSetters, 
00109                 PySequence::_lassPyStatics, NULL, NULL);
00110             LASS_ENFORCE( PyType_Ready( &_lassPyType ) >= 0 );
00111             isInitialized = true;
00112         }
00113     }
00114 
00115     Py_ssize_t PySequence::PySequence_Length( PyObject* iPO)
00116     {
00117         return static_cast<PySequence*>(iPO)->pimpl_->PySequence_Length();
00118     }
00119     PyObject* PySequence::PySequence_Concat(PyObject *iPO, PyObject *bb)
00120     {
00121         return static_cast<PySequence*>(iPO)->pimpl_->PySequence_Concat(bb);
00122     }
00123     PyObject* PySequence::PySequence_Repeat(PyObject *iPO, Py_ssize_t n)
00124     {
00125         return static_cast<PySequence*>(iPO)->pimpl_->PySequence_Repeat(n);
00126     }
00127     PyObject* PySequence::PySequence_Item(PyObject*iPO, Py_ssize_t i)
00128     {
00129         return static_cast<PySequence*>(iPO)->pimpl_->PySequence_Item(i);
00130     }
00131     PyObject* PySequence::PySequence_Slice(PyObject *iPO, Py_ssize_t ilow, Py_ssize_t ihigh)
00132     {
00133         return static_cast<PySequence*>(iPO)->pimpl_->PySequence_Slice(ilow,ihigh);
00134     }
00135     int PySequence::PySequence_AssItem(PyObject *iPO, Py_ssize_t i, PyObject *v)
00136     {
00137         return static_cast<PySequence*>(iPO)->pimpl_->PySequence_AssItem(i,v);
00138     }
00139     int PySequence::PySequence_AssSlice(PyObject *iPO, Py_ssize_t ilow, Py_ssize_t ihigh, PyObject *v)
00140     {
00141         return static_cast<PySequence*>(iPO)->pimpl_->PySequence_AssSlice(ilow,ihigh,v);
00142     }
00143     int PySequence::PySequence_Contains(PyObject *iPO, PyObject *el)
00144     {
00145         return static_cast<PySequence*>(iPO)->pimpl_->PySequence_Contains(el);
00146     }
00147     PyObject * PySequence::PySequence_InplaceConcat(PyObject *iPO, PyObject *other)
00148     {
00149         int r = static_cast<PySequence*>(iPO)->pimpl_->PySequence_InplaceConcat(other);
00150         if (r)
00151             return NULL;
00152         Py_INCREF(iPO);
00153         return iPO;
00154     }
00155     PyObject * PySequence::PySequence_InplaceRepeat(PyObject *iPO, Py_ssize_t n)
00156     {
00157         int r = static_cast<PySequence*>(iPO)->pimpl_->PySequence_InplaceRepeat(n);
00158         if (r)
00159             return NULL;
00160         Py_INCREF(iPO);
00161         return iPO;
00162     }
00163 }
00164 
00165 }
00166 
00167 }
00168 

Generated on Mon Nov 10 14:21:06 2008 for Library of Assembled Shared Sources by doxygen 1.5.7.1
SourceForge.net Logo